# Path: domino/helpers.py
# def domino_is_reachable(url=os.getenv(DOMINO_HOST_KEY_NAME), port="443"):
#     """
#     Confirm that a deployment is accessible.
# 
#     Returns Boolean value.
#     """
#     if url is None:
#         return False
# 
#     fqdn = urllib.parse.urlsplit(url).netloc
#     s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
#     try:
#         s.connect((fqdn, int(port)))
#         is_reachable = True
#     except OSError:
#         print(f"{fqdn}:{port} is not reachable")
#         is_reachable = False
#     finally:
#         s.close()
# 
#     return is_reachable


from pprint import pformat
from domino.helpers import domino_is_reachable
import pytest
@pytest.mark.skipif(not domino_is_reachable(), reason="No access to a live Domino deployment")
def test_list_models(default_domino_client):
    """
    Confirm that the python-domino client can list the models from a project.
    """
    models_list = default_domino_client.models_list()
    assert models_list["objectType"] == "list", \
        f"models_list returned unexpected result:\n{pformat(models_list)}"
    assert isinstance(models_list["data"], list), \
        f"Unable to retrieve models:\n{pformat(models_list)}"


@pytest.mark.skipif(not domino_is_reachable(), reason="No access to a live Domino deployment")
def test_publish_a_model(default_domino_client):
    """
    Confirm that the python-domino client can publish a model.
    """
    filename = "model.py"
    function = "my_model"
    env_id = ""
    model_name = "Model Name"
    model_description = "Model Description"

    model = default_domino_client.model_publish(filename, function, env_id,
                                                model_name, model_description)

    assert model["data"]["name"] == model_name
    assert model["data"]["description"] == model_description



# Path: domino/helpers.py
# def domino_is_reachable(url=os.getenv(DOMINO_HOST_KEY_NAME), port="443"):
#     """
#     Confirm that a deployment is accessible.
# 
#     Returns Boolean value.
#     """
#     if url is None:
#         return False
# 
#     fqdn = urllib.parse.urlsplit(url).netloc
#     s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
#     try:
#         s.connect((fqdn, int(port)))
#         is_reachable = True
#     except OSError:
#         print(f"{fqdn}:{port} is not reachable")
#         is_reachable = False
#     finally:
#         s.close()
# 
#     return is_reachable


# Path: tests/test_models.py
from pprint import pformat
from domino.helpers import domino_is_reachable
import pytest

@pytest.mark.skipif(not domino_is_reachable(), reason="No access to a live Domino deployment")
def test_list_models(default_domino_client):
    """
    Confirm that the python-domino client can list the models from a project.
    """
    models_list = default_domino_client.models_list()
    assert models_list["objectType"] == "list", \
        f"models_list returned unexpected result:\n{pformat(models_list)}"
    assert isinstance(models_list["data"], list), \
        f"Unable to retrieve models:\n{pformat(models_list)}"


@pytest.mark.skipif(not domino_is_reachable(), reason="No access to a live Domino deployment")
def test_publish_a_model(default_domino_client):
    """
    Confirm that the python-domino client can publish a model.
    """
    filename = "model.py"
    function = "my_model"
    env_id = ""
    model_name = "Model Name"
    model_description = "Model Description"

    model = default_domino_client.model_publish(filename, function, env_id,
                                                model_name, model_description)

    assert model["data"]["name"] == model_name
    assert model["data"]["description"] == model_description



@pytest.mark.skipif(not domino_is_reachable(), reason="No access to a live Domino deployment")