Skip to content

Commit

Permalink
fix: rollback get_keys with 3 keys
Browse files Browse the repository at this point in the history
  • Loading branch information
wuwentao committed Jul 7, 2024
1 parent 995a90b commit 2b5394e
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 9 deletions.
5 changes: 2 additions & 3 deletions midealocal/cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,8 @@ async def get_keys(self, appliance_id: int) -> dict[int, dict[str, Any]]:
"token": token["token"].lower(),
"key": token["key"].lower(),
}
break
if not result:
result.update(default_keys)
# add default key with method 1 and method 2 key
result.update(default_keys)
return result

@staticmethod
Expand Down
38 changes: 34 additions & 4 deletions tests/cloud_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,12 @@ async def test_meijucloud_get_keys(self) -> None:
response = Mock()
response.read = AsyncMock(
side_effect=[
self.responses["meijucloud_get_keys.json"],
self.responses["meijucloud_get_keys1.json"],
self.responses["meijucloud_get_keys2.json"],
self.responses["meijucloud_get_keys1.json"],
self.responses["cloud_invalid_response.json"],
self.responses["cloud_invalid_response.json"],
self.responses["meijucloud_get_keys2.json"],
self.responses["cloud_invalid_response.json"],
self.responses["cloud_invalid_response.json"],
],
Expand All @@ -134,11 +139,36 @@ async def test_meijucloud_get_keys(self) -> None:
password="password",
)
assert cloud is not None
keys: dict = await cloud.get_keys(100)
assert keys[1]["token"] == "returnedappliancetoken"
assert keys[1]["key"] == "returnedappliancekey"

# test method1 + method2 + default key
keys3: dict = await cloud.get_keys(100)
# test response token/key
assert keys3[1]["token"] == "method1_return_token1"
assert keys3[1]["key"] == "method1_return_key1"
assert keys3[2]["token"] == "method2_return_token2"
assert keys3[2]["key"] == "method2_return_key2"
# simple test default key with length
assert len(keys3) == 3

# test method1 + default key
keys1: dict = await cloud.get_keys(100)
# test response token/key
assert keys1[1]["token"] == "method1_return_token1"
assert keys1[1]["key"] == "method1_return_key1"
# simple test default key with length
assert len(keys1) == 2

# test method2 + default key
keys2: dict = await cloud.get_keys(100)
# test response token/key
assert keys2[2]["token"] == "method2_return_token2"
assert keys2[2]["key"] == "method2_return_key2"
# simple test default key with length
assert len(keys2) == 2

# test only default key
keys = await cloud.get_keys(100)
assert len(keys) == 1
assert keys == default_keys

async def test_meijucloud_list_home(self) -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"tokenlist": [
{
"udpId": "dec4da86e0aeefadde14a4e553680b9b",
"token": "returnedappliancetoken",
"key": "returnedappliancekey"
"token": "method1_return_token1",
"key": "method1_return_key1"
}
]
}
Expand Down
12 changes: 12 additions & 0 deletions tests/responses/meijucloud_get_keys2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"code": 0,
"data": {
"tokenlist": [
{
"udpId": "b2dd199071d527a33c8239833a5bf5fb",
"token": "method2_return_token2",
"key": "method2_return_key2"
}
]
}
}

0 comments on commit 2b5394e

Please sign in to comment.