diff --git a/kasa/aestransport.py b/kasa/aestransport.py index 74f59560..e00b1084 100644 --- a/kasa/aestransport.py +++ b/kasa/aestransport.py @@ -38,7 +38,6 @@ _LOGGER = logging.getLogger(__name__) ONE_DAY_SECONDS = 86400 SESSION_EXPIRE_BUFFER_SECONDS = 60 * 20 -BACKOFF_SECONDS_AFTER_LOGIN_ERROR = 1 def _sha1(payload: bytes) -> str: @@ -72,6 +71,7 @@ class AesTransport(BaseTransport): } CONTENT_LENGTH = "Content-Length" KEY_PAIR_CONTENT_LENGTH = 314 + BACKOFF_SECONDS_AFTER_LOGIN_ERROR = 1 def __init__( self, @@ -213,7 +213,7 @@ class AesTransport(BaseTransport): self._default_credentials = get_default_credentials( DEFAULT_CREDENTIALS["TAPO"] ) - await asyncio.sleep(BACKOFF_SECONDS_AFTER_LOGIN_ERROR) + await asyncio.sleep(self.BACKOFF_SECONDS_AFTER_LOGIN_ERROR) await self.perform_handshake() await self.try_login(self._get_login_params(self._default_credentials)) _LOGGER.debug( diff --git a/kasa/tests/conftest.py b/kasa/tests/conftest.py index bec48bde..a3bd6df2 100644 --- a/kasa/tests/conftest.py +++ b/kasa/tests/conftest.py @@ -1,6 +1,6 @@ import warnings from typing import Dict -from unittest.mock import MagicMock +from unittest.mock import MagicMock, patch import pytest @@ -48,8 +48,8 @@ def dummy_protocol(): transport = DummyTransport(config=DeviceConfig(host="127.0.0.123")) protocol = SmartProtocol(transport=transport) - - return protocol + with patch.object(protocol, "BACKOFF_SECONDS_AFTER_TIMEOUT", 0): + yield protocol def pytest_configure(): diff --git a/kasa/tests/fixtureinfo.py b/kasa/tests/fixtureinfo.py index 08414ad4..bee3e749 100644 --- a/kasa/tests/fixtureinfo.py +++ b/kasa/tests/fixtureinfo.py @@ -148,4 +148,5 @@ def filter_fixtures( print(f"# {desc}") for value in filtered: print(f"\t{value.name}") + filtered.sort() return filtered diff --git a/kasa/tests/test_aestransport.py b/kasa/tests/test_aestransport.py index cc7aeece..859c35be 100644 --- a/kasa/tests/test_aestransport.py +++ b/kasa/tests/test_aestransport.py @@ -135,6 +135,7 @@ async def test_login_errors(mocker, inner_error_codes, expectation, call_count): transport._state = TransportState.LOGIN_REQUIRED transport._session_expire_at = time.time() + 86400 transport._encryption_session = mock_aes_device.encryption_session + mocker.patch.object(transport, "BACKOFF_SECONDS_AFTER_LOGIN_ERROR", 0) assert transport._token_url is None diff --git a/kasa/tests/test_cli.py b/kasa/tests/test_cli.py index 01d02273..885fbcd0 100644 --- a/kasa/tests/test_cli.py +++ b/kasa/tests/test_cli.py @@ -149,10 +149,15 @@ async def test_command_with_child(dev, mocker): runner = CliRunner() update_mock = mocker.patch.object(dev, "update") - dummy_child = mocker.create_autospec(IotDevice) - query_mock = mocker.patch.object( - dummy_child, "_query_helper", return_value={"dummy": "response"} - ) + # create_autospec for device slows tests way too much, so we use a dummy here + class DummyDevice(dev.__class__): + def __init__(self): + super().__init__("127.0.0.1") + + async def _query_helper(*_, **__): + return {"dummy": "response"} + + dummy_child = DummyDevice() mocker.patch.object(dev, "_children", {"XYZ": dummy_child}) mocker.patch.object(dev, "get_child_device", return_value=dummy_child) @@ -165,7 +170,6 @@ async def test_command_with_child(dev, mocker): ) update_mock.assert_called() - query_mock.assert_called() assert '{"dummy": "response"}' in res.output assert res.exit_code == 0