From a1d51c73566d24b480a62aace8aaa1294268ebb9 Mon Sep 17 00:00:00 2001 From: David Bonnes Date: Mon, 2 Sep 2024 00:21:39 +0100 Subject: [PATCH] doctweak --- tests/tests_rf/conftest.py | 2 +- tests/tests_rf/test_v1_apis.py | 10 ++- tests/tests_rf/test_v1_xxxx.py | 140 +++++++++++++++++---------------- tests/tests_rf/test_v2_task.py | 1 + 4 files changed, 83 insertions(+), 70 deletions(-) diff --git a/tests/tests_rf/conftest.py b/tests/tests_rf/conftest.py index f6bad8eb..4c8383d4 100644 --- a/tests/tests_rf/conftest.py +++ b/tests/tests_rf/conftest.py @@ -17,7 +17,7 @@ from .faked_server import FakedServer # normally, we want these debug flags to be False -_DBG_USE_REAL_AIOHTTP = True +_DBG_USE_REAL_AIOHTTP = False _DBG_DISABLE_STRICT_ASSERTS = False # of response content-type, schema if _DBG_USE_REAL_AIOHTTP: diff --git a/tests/tests_rf/test_v1_apis.py b/tests/tests_rf/test_v1_apis.py index 2b7371b2..fd17735d 100644 --- a/tests/tests_rf/test_v1_apis.py +++ b/tests/tests_rf/test_v1_apis.py @@ -16,6 +16,9 @@ from collections.abc import Awaitable +####################################################################################### + + async def _test_client_apis(evo: ev1.EvohomeClient) -> None: """Instantiate a client, and logon to the vendor API.""" @@ -34,13 +37,16 @@ async def _test_client_apis(evo: ev1.EvohomeClient) -> None: # _ = await evo.get_temperatures() -async def test_client_apis(evo2: Awaitable[ev1.EvohomeClient]) -> None: +####################################################################################### + + +async def test_client_apis(evo1: Awaitable[ev1.EvohomeClient]) -> None: """Test _populate_user_data() & _populate_full_data()""" if not _DBG_USE_REAL_AIOHTTP: pytest.skip(ExitTestReason.NOT_IMPLEMENTED) try: - await _test_client_apis(await evo2) + await _test_client_apis(await evo1) except ev1.AuthenticationFailedError as err: pytest.fail(ExitTestReason.AUTHENTICATE_FAIL + f": {err}") diff --git a/tests/tests_rf/test_v1_xxxx.py b/tests/tests_rf/test_v1_xxxx.py index 6b0e9be7..45e03a90 100644 --- a/tests/tests_rf/test_v1_xxxx.py +++ b/tests/tests_rf/test_v1_xxxx.py @@ -18,73 +18,7 @@ from collections.abc import Awaitable -async def _test_url_locations(evo: ev1.EvohomeClient) -> None: - # evo.broker._headers["sessionId"] = evo.user_info["sessionId"] # what is this? - user_id: int = evo.user_info["userID"] # type: ignore[assignment] - - assert evo.broker.session_id - - url = f"locations?userId={user_id}&allData=True" - _ = await should_work_v1(evo, HTTPMethod.GET, url) - - # why isn't this one METHOD_NOT_ALLOWED? - _ = await should_fail_v1(evo, HTTPMethod.PUT, url, status=HTTPStatus.NOT_FOUND) - - url = f"locations?userId={user_id}" - _ = await should_work_v1(evo, HTTPMethod.GET, url) - - url = "locations?userId=123456" - _ = await should_fail_v1(evo, HTTPMethod.GET, url, status=HTTPStatus.UNAUTHORIZED) - - url = "locations?userId='123456'" - _ = await should_fail_v1(evo, HTTPMethod.GET, url, status=HTTPStatus.BAD_REQUEST) - - url = "xxxxxxx" # NOTE: a general test, not a test specific to the 'locations' URL - _ = await should_fail_v1( - evo, - HTTPMethod.GET, - url, - status=HTTPStatus.NOT_FOUND, - content_type="text/html", # not the usual content-type - ) - - -async def _test_client_apis(evo: ev1.EvohomeClient) -> None: - """Instantiate a client, and logon to the vendor API.""" - - user_data = await evo._populate_user_data() - assert user_data # aka evo.user_data - - assert evo.user_info - - await evo._populate_locn_data() - - temps = await evo.get_temperatures() - assert temps - - -async def test_locations(evo2: Awaitable[ev1.EvohomeClient]) -> None: - """Test /locations""" - - if not _DBG_USE_REAL_AIOHTTP: - pytest.skip(ExitTestReason.NOT_IMPLEMENTED) - - try: - await _test_url_locations(await evo2) - except ev1.AuthenticationFailedError as err: - pytest.fail(ExitTestReason.AUTHENTICATE_FAIL + f": {err}") - - -async def test_client_apis(evo2: Awaitable[ev1.EvohomeClient]) -> None: - """Test _populate_user_data() & _populate_full_data()""" - - if not _DBG_USE_REAL_AIOHTTP: - pytest.skip(ExitTestReason.NOT_IMPLEMENTED) - - try: - await _test_client_apis(await evo2) - except ev1.AuthenticationFailedError as err: - pytest.fail(ExitTestReason.AUTHENTICATE_FAIL + f": {err}") +####################################################################################### USER_DATA = { @@ -977,3 +911,75 @@ async def test_client_apis(evo2: Awaitable[ev1.EvohomeClient]) -> None: "monitoring": {"levelOfAccess": "Partial", "contactPreferences": []}, }, } + + +async def _test_url_locations(evo: ev1.EvohomeClient) -> None: + # evo.broker._headers["sessionId"] = evo.user_info["sessionId"] # what is this? + user_id: int = evo.user_info["userID"] # type: ignore[assignment] + + assert evo.broker.session_id + + url = f"locations?userId={user_id}&allData=True" + _ = await should_work_v1(evo, HTTPMethod.GET, url) + + # why isn't this one METHOD_NOT_ALLOWED? + _ = await should_fail_v1(evo, HTTPMethod.PUT, url, status=HTTPStatus.NOT_FOUND) + + url = f"locations?userId={user_id}" + _ = await should_work_v1(evo, HTTPMethod.GET, url) + + url = "locations?userId=123456" + _ = await should_fail_v1(evo, HTTPMethod.GET, url, status=HTTPStatus.UNAUTHORIZED) + + url = "locations?userId='123456'" + _ = await should_fail_v1(evo, HTTPMethod.GET, url, status=HTTPStatus.BAD_REQUEST) + + url = "xxxxxxx" # NOTE: a general test, not a test specific to the 'locations' URL + _ = await should_fail_v1( + evo, + HTTPMethod.GET, + url, + status=HTTPStatus.NOT_FOUND, + content_type="text/html", # not the usual content-type + ) + + +async def _test_client_apis(evo: ev1.EvohomeClient) -> None: + """Instantiate a client, and logon to the vendor API.""" + + user_data = await evo._populate_user_data() + assert user_data # aka evo.user_data + + assert evo.user_info + + await evo._populate_locn_data() + + temps = await evo.get_temperatures() + assert temps + + +####################################################################################### + + +async def test_locations(evo1: Awaitable[ev1.EvohomeClient]) -> None: + """Test /locations""" + + if not _DBG_USE_REAL_AIOHTTP: + pytest.skip(ExitTestReason.NOT_IMPLEMENTED) + + try: + await _test_url_locations(await evo1) + except ev1.AuthenticationFailedError as err: + pytest.fail(ExitTestReason.AUTHENTICATE_FAIL + f": {err}") + + +async def test_client_apis(evo1: Awaitable[ev1.EvohomeClient]) -> None: + """Test _populate_user_data() & _populate_full_data()""" + + if not _DBG_USE_REAL_AIOHTTP: + pytest.skip(ExitTestReason.NOT_IMPLEMENTED) + + try: + await _test_client_apis(await evo1) + except ev1.AuthenticationFailedError as err: + pytest.fail(ExitTestReason.AUTHENTICATE_FAIL + f": {err}") diff --git a/tests/tests_rf/test_v2_task.py b/tests/tests_rf/test_v2_task.py index 97f8cb47..65f15734 100644 --- a/tests/tests_rf/test_v2_task.py +++ b/tests/tests_rf/test_v2_task.py @@ -34,6 +34,7 @@ import evohomeasync2 as ev2 from evohomeasync2 import Gateway, Location, System + #######################################################################################