Skip to content

Commit

Permalink
move more constants around
Browse files Browse the repository at this point in the history
  • Loading branch information
zxdavb committed Jan 19, 2025
1 parent 4736223 commit 7325143
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
12 changes: 11 additions & 1 deletion tests/tests/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -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: "
Expand All @@ -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)
25 changes: 6 additions & 19 deletions tests/tests/test_v0_urls_cred.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,25 @@
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

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 --"


Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 7325143

Please sign in to comment.