From 995a90bb5016e98345ea173eeca9dafa00e0f812 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Mind=C3=AAllo=20de=20Andrade?= Date: Tue, 2 Jul 2024 21:07:14 -0300 Subject: [PATCH] test(cloud): missing coverage (#198) ## Summary by CodeRabbit - **New Features** - Added a new test method `test_get_cloud_servers` to improve cloud server testing. - **Bug Fixes** - Updated logic for setting the "cool" mode to ensure correct behavior. - **Tests** - Enhanced `test_meijucloud_get_keys` to handle multiple responses and validate key retrieval. - **Chores** - Updated Python testing configuration in `.vscode/settings.json` to enable `pytest` and disable `unittest`. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .vscode/settings.json | 7 ++++--- midealocal/devices/ac/message.py | 2 +- tests/cloud_test.py | 18 +++++++++++++++++- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 81d3d318..5a30d876 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,6 @@ { - "python.testing.pytestArgs": ["--no-cov"], - "python.testing.pytestEnabled": false, - "pylint.importStrategy": "fromEnvironment" + "python.testing.pytestArgs": ["tests", "--no-cov"], + "python.testing.pytestEnabled": true, + "pylint.importStrategy": "fromEnvironment", + "python.testing.unittestEnabled": false } diff --git a/midealocal/devices/ac/message.py b/midealocal/devices/ac/message.py index 586bbca3..cb6040e0 100644 --- a/midealocal/devices/ac/message.py +++ b/midealocal/devices/ac/message.py @@ -705,7 +705,7 @@ def __init__(self, body: bytearray, bt: int) -> None: v = params[Capabilities.MODES][0] self.modes: dict[str, bool] = {} self.modes["heat"] = v in [1, 2, 4, 6, 7, 9] - self.modes["cool"] = v not in [2] + self.modes["cool"] = v != 2 # noqa: PLR2004 self.modes["dry"] = v in [0, 1, 5, 6, 9] self.modes["auto"] = v in [0, 1, 2, 7, 8, 9] diff --git a/tests/cloud_test.py b/tests/cloud_test.py index 9720902f..565dba41 100644 --- a/tests/cloud_test.py +++ b/tests/cloud_test.py @@ -14,8 +14,10 @@ MideaAirCloud, MideaCloud, MSmartHomeCloud, + default_keys, get_midea_cloud, ) +from midealocal.exceptions import ElementMissing class CloudTest(IsolatedAsyncioTestCase): @@ -50,6 +52,13 @@ def test_get_midea_cloud(self) -> None: get_midea_cloud("Ariston Clima", session, "", ""), MideaAirCloud, ) + with pytest.raises(ElementMissing): + get_midea_cloud("Invalid", session, "", "") + + async def test_get_cloud_servers(self) -> None: + """Test get cloud servers.""" + servers = await MideaCloud.get_cloud_servers() + assert len(servers.items()) == 5 async def test_midea_cloud_unimplemented(self) -> None: """Test unimplemented MideaCloud methods.""" @@ -111,7 +120,11 @@ async def test_meijucloud_get_keys(self) -> None: session = Mock() response = Mock() response.read = AsyncMock( - return_value=self.responses["meijucloud_get_keys.json"], + side_effect=[ + self.responses["meijucloud_get_keys.json"], + self.responses["cloud_invalid_response.json"], + self.responses["cloud_invalid_response.json"], + ], ) session.request = AsyncMock(return_value=response) cloud = get_midea_cloud( @@ -125,6 +138,9 @@ async def test_meijucloud_get_keys(self) -> None: assert keys[1]["token"] == "returnedappliancetoken" assert keys[1]["key"] == "returnedappliancekey" + keys = await cloud.get_keys(100) + assert keys == default_keys + async def test_meijucloud_list_home(self) -> None: """Test MeijuCloud list_home.""" session = Mock()