Skip to content

Commit

Permalink
Missing test coverage for cloud (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
rokam authored May 28, 2024
1 parent 27164ff commit d8d1155
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
46 changes: 43 additions & 3 deletions tests/cloud_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
from unittest import IsolatedAsyncioTestCase
from unittest.mock import AsyncMock, Mock

from midealocal.cloud import MeijuCloud, MideaAirCloud, MSmartHomeCloud, get_midea_cloud
from midealocal.cloud import (
MeijuCloud,
MideaAirCloud,
MSmartHomeCloud,
MideaCloud,
get_midea_cloud,
)


class CloudTest(IsolatedAsyncioTestCase):
Expand All @@ -30,6 +36,24 @@ def test_get_midea_cloud(self) -> None:
assert isinstance(get_midea_cloud("NetHome Plus", None, "", ""), MideaAirCloud)
assert isinstance(get_midea_cloud("Ariston Clima", None, "", ""), MideaAirCloud)

async def test_midea_cloud_unimplemented(self) -> None:
"""Test unimplemented MideaCloud methods"""
session = Mock()
security = Mock()
cloud = MideaCloud(
session=session,
security=security,
app_id="appid",
app_key="appkey",
account="account",
password="password",
api_url="http://api.url/",
)
with self.assertRaises(NotImplementedError):
await cloud.login()
with self.assertRaises(NotImplementedError):
await cloud.list_appliances(None)

async def test_meijucloud_login_success(self) -> None:
"""Test MeijuCloud login"""
session = Mock()
Expand Down Expand Up @@ -107,6 +131,11 @@ async def test_meijucloud_list_home(self) -> None:
assert homes[1] == "Home 1"
assert homes[2] == "Home 2"

response.read = AsyncMock(
return_value=self.responses["cloud_invalid_response.json"],
)
assert await cloud.list_home() is None

async def test_meijucloud_list_appliances(self) -> None:
"""Test MeijuCloud list_appliances"""
session = Mock()
Expand All @@ -116,6 +145,7 @@ async def test_meijucloud_list_appliances(self) -> None:
self.responses["cloud_login_id.json"],
self.responses["meijucloud_login.json"],
self.responses["meijucloud_list_appliances.json"],
self.responses["cloud_invalid_response.json"],
],
)
session.request = AsyncMock(return_value=response)
Expand Down Expand Up @@ -147,11 +177,14 @@ async def test_meijucloud_list_appliances(self) -> None:
assert appliance.get("type") == 0xAC
assert appliance.get("sn") == ""
assert appliance.get("sn8") == "00000000"
assert appliance.get("model_number") == 10
assert appliance.get("model_number") == 0
assert appliance.get("manufacturer_code") == "1234"
assert appliance.get("model") == "00000000"
assert not appliance.get("online")

appliances = await cloud.list_appliances("1")
assert appliances is None

async def test_meijucloud_get_device_info(self) -> None:
"""Test MeijuCloud get_device_info"""
session = Mock()
Expand All @@ -162,6 +195,7 @@ async def test_meijucloud_get_device_info(self) -> None:
self.responses["meijucloud_login.json"],
self.responses["meijucloud_get_device_info.json"],
self.responses["meijucloud_get_device_info_alt.json"],
self.responses["cloud_invalid_response.json"],
],
)
session.request = AsyncMock(return_value=response)
Expand Down Expand Up @@ -191,11 +225,14 @@ async def test_meijucloud_get_device_info(self) -> None:
assert device.get("type") == 0xAC
assert device.get("sn") == ""
assert device.get("sn8") == "00000000"
assert device.get("model_number") == 10
assert device.get("model_number") == 0
assert device.get("manufacturer_code") == "1234"
assert device.get("model") == "00000000"
assert not device.get("online")

device = await cloud.get_device_info(99)
assert device is None

async def test_meijucloud_download_lua(self) -> None:
"""Test MeijuCloud download_lua"""
session = Mock()
Expand Down Expand Up @@ -371,6 +408,9 @@ async def test_msmartcloud_get_device_info(self) -> None:
assert device.get("model") == "0abcdef1"
assert device.get("online")

device = await cloud.get_device_info(99)
assert device is None

async def test_msmartcloud_download_lua(self) -> None:
"""Test MSmartCloud download_lua"""
session = Mock()
Expand Down
2 changes: 1 addition & 1 deletion tests/responses/meijucloud_get_device_info_alt.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"code": 0,
"data": {
"modelNumber": 10,
"modelNumber": "ss10",
"name": "Appliance Name 2",
"type": "0xAC",
"sn": "",
Expand Down
2 changes: 1 addition & 1 deletion tests/responses/meijucloud_list_appliances.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"applianceCode": "1"
},
{
"modelNumber": 10,
"modelNumber": "ss10",
"name": "Appliance Name 2",
"type": "0xAC",
"sn": "",
Expand Down

0 comments on commit d8d1155

Please sign in to comment.