From d8d11555c03831fe2520c0a0ba4745d7c6bc5f9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Mind=C3=AAllo=20de=20Andrade?= Date: Tue, 28 May 2024 15:13:17 -0300 Subject: [PATCH] Missing test coverage for cloud (#41) --- tests/cloud_test.py | 46 +++++++++++++++++-- .../meijucloud_get_device_info_alt.json | 2 +- .../responses/meijucloud_list_appliances.json | 2 +- 3 files changed, 45 insertions(+), 5 deletions(-) diff --git a/tests/cloud_test.py b/tests/cloud_test.py index 073c2164..1aef19a1 100644 --- a/tests/cloud_test.py +++ b/tests/cloud_test.py @@ -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): @@ -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() @@ -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() @@ -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) @@ -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() @@ -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) @@ -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() @@ -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() diff --git a/tests/responses/meijucloud_get_device_info_alt.json b/tests/responses/meijucloud_get_device_info_alt.json index 4d81cf54..71b3fe3c 100644 --- a/tests/responses/meijucloud_get_device_info_alt.json +++ b/tests/responses/meijucloud_get_device_info_alt.json @@ -1,7 +1,7 @@ { "code": 0, "data": { - "modelNumber": 10, + "modelNumber": "ss10", "name": "Appliance Name 2", "type": "0xAC", "sn": "", diff --git a/tests/responses/meijucloud_list_appliances.json b/tests/responses/meijucloud_list_appliances.json index 7ed513f6..6cb3aad5 100644 --- a/tests/responses/meijucloud_list_appliances.json +++ b/tests/responses/meijucloud_list_appliances.json @@ -20,7 +20,7 @@ "applianceCode": "1" }, { - "modelNumber": 10, + "modelNumber": "ss10", "name": "Appliance Name 2", "type": "0xAC", "sn": "",