# 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_envirtonments(default_domino_client):
    """
    Confirm that python-domino client can list environments (v1 API).
    """
    env_list = default_domino_client.environments_list()
    assert env_list["objectType"] == "list", \
        f"environments_list returned unexpected result:\n{pformat(env_list)}"
    assert any("Domino Standard Environment" in env["name"] for env in env_list["data"]), \
        "Could not find Domino Standard Environment in environment list"



# 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_environments.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_envirtonments(default_domino_client):
    """
    Confirm that python-domino client can list environments (v1 API).
    """
    env_list = default_domino_client.environments_list()
    assert env_list["objectType"] == "list", \
        f"environments_list returned unexpected result:\n{pformat(env_list)}"
    assert any("Domino Standard Environment" in env["name"] for env in env_list["data"]), \
        "Could not find Domino Standard Environment in environment list"



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