Skip to content

Commit

Permalink
doctweak
Browse files Browse the repository at this point in the history
  • Loading branch information
zxdavb committed Sep 1, 2024
1 parent c5a80b0 commit a1d51c7
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 70 deletions.
2 changes: 1 addition & 1 deletion tests/tests_rf/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 8 additions & 2 deletions tests/tests_rf/test_v1_apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""

Expand All @@ -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}")
140 changes: 73 additions & 67 deletions tests/tests_rf/test_v1_xxxx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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}")
1 change: 1 addition & 0 deletions tests/tests_rf/test_v2_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import evohomeasync2 as ev2
from evohomeasync2 import Gateway, Location, System


#######################################################################################


Expand Down

0 comments on commit a1d51c7

Please sign in to comment.