Skip to content

Commit

Permalink
test(cloud): missing coverage (midea-lan#198)
Browse files Browse the repository at this point in the history
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## 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`.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
rokam and pre-commit-ci[bot] authored Jul 3, 2024
1 parent 43d9918 commit 995a90b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
7 changes: 4 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 1 addition & 1 deletion midealocal/devices/ac/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
18 changes: 17 additions & 1 deletion tests/cloud_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
MideaAirCloud,
MideaCloud,
MSmartHomeCloud,
default_keys,
get_midea_cloud,
)
from midealocal.exceptions import ElementMissing


class CloudTest(IsolatedAsyncioTestCase):
Expand Down Expand Up @@ -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."""
Expand Down Expand Up @@ -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(
Expand All @@ -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()
Expand Down

0 comments on commit 995a90b

Please sign in to comment.