From 7325143bb3edd663d4cdfd7d98e9e08766265862 Mon Sep 17 00:00:00 2001 From: David Bonnes Date: Sun, 19 Jan 2025 10:24:21 +0000 Subject: [PATCH] move more constants around --- tests/tests/const.py | 12 +++++++++++- tests/tests/test_v0_urls_cred.py | 25 ++++++------------------- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/tests/tests/const.py b/tests/tests/const.py index d8f254d..0fdce4c 100644 --- a/tests/tests/const.py +++ b/tests/tests/const.py @@ -11,6 +11,12 @@ TEST_DIR = Path(__file__).resolve().parent +MSG_INVALID_SESSION: Final = ( + "The session_id has been rejected (will re-authenticate): " + "GET https://tccna.resideo.com/WebAPI/api/accountInfo: " + '401 Unauthorized, response=[{"code": "Unauthorized", "message": "Unauthorized"}]' +) + MSG_INVALID_TOKEN: Final = ( "The access_token has been rejected (will re-authenticate): " # noqa: S105 "GET https://tccna.resideo.com/WebAPI/emea/api/v1/userAccount: " @@ -26,6 +32,10 @@ LOG_04 = ("evohome.credentials", logging.DEBUG, " - authenticating with client_id/secret") # fmt: off LOG_11 = ("evohome.credentials", logging.ERROR, HINT_BAD_CREDS) -LOG_12 = ("evohome.credentials", logging.ERROR, HINT_CHECK_NETWORK) +LOG_12 = ("evohome.credentials", logging.ERROR, HINT_CHECK_NETWORK) # usu. Conn refused LOG_13 = ("evohome.auth", logging.ERROR, HINT_CHECK_NETWORK) + + +LOG_90 = ("evohome.credentials", logging.DEBUG, "Fetching session_id...") +LOG_91 = ("evohomeasync", logging.WARNING, MSG_INVALID_SESSION) diff --git a/tests/tests/test_v0_urls_cred.py b/tests/tests/test_v0_urls_cred.py index f764f01..3274f96 100644 --- a/tests/tests/test_v0_urls_cred.py +++ b/tests/tests/test_v0_urls_cred.py @@ -5,16 +5,18 @@ import logging from datetime import UTC, datetime as dt, timedelta as td from http import HTTPMethod, HTTPStatus -from typing import TYPE_CHECKING, Final +from typing import TYPE_CHECKING import pytest from aioresponses import aioresponses -from evohome.const import HINT_BAD_CREDS, HINT_CHECK_NETWORK +from evohome.const import HINT_CHECK_NETWORK from evohomeasync import EvohomeClient, exceptions as exc from evohomeasync.auth import _APPLICATION_ID from tests.const import HEADERS_BASE, HEADERS_CRED_V0, URL_CRED_V0 +from .const import LOG_04, LOG_11, LOG_12, LOG_90, LOG_91 + if TYPE_CHECKING: from collections.abc import AsyncGenerator from pathlib import Path @@ -22,12 +24,6 @@ from cli.auth import CredentialsManager -MSG_INVALID_SESSION: Final = ( - "The session_id has been rejected (will re-authenticate): " - "GET https://tccna.resideo.com/WebAPI/api/accountInfo: " - '401 Unauthorized, response=[{"code": "Unauthorized", "message": "Unauthorized"}]' -) - _TEST_SESSION_ID = "-- session id --" @@ -77,11 +73,7 @@ async def test_bad1( # bad credentials (client_id/secret) assert err.value.status == HTTPStatus.UNAUTHORIZED - assert caplog.record_tuples == [ - ("evohome.credentials", logging.DEBUG, "Fetching session_id..."), - ("evohome.credentials", logging.DEBUG, " - authenticating with client_id/secret"), - ("evohome.credentials", logging.ERROR, HINT_BAD_CREDS), - ] # fmt: off + assert caplog.record_tuples == [LOG_90, LOG_04, LOG_11] assert len(rsp.requests) == 1 @@ -127,12 +119,7 @@ async def test_bad2( # bad session id assert err.value.status is None # Connection refused - assert caplog.record_tuples == [ - ("evohomeasync", logging.WARNING, MSG_INVALID_SESSION), - ("evohome.credentials", logging.DEBUG, "Fetching session_id..."), - ("evohome.credentials", logging.DEBUG, " - authenticating with client_id/secret"), - ("evohome.credentials", logging.ERROR, HINT_CHECK_NETWORK), # Connection refused - ] # fmt: off + assert caplog.record_tuples == [LOG_91, LOG_90, LOG_04, LOG_12] assert len(rsp.requests) == 2 # noqa: PLR2004