|
6 | 6 | from aioresponses.compat import normalize_url |
7 | 7 |
|
8 | 8 | from roborock import HomeData, HomeDataScene, UserData |
| 9 | +from roborock.exceptions import RoborockAccountDoesNotExist |
9 | 10 | from roborock.web_api import IotLoginInfo, RoborockApiClient |
10 | 11 | from tests.mock_data import HOME_DATA_RAW, USER_DATA |
11 | 12 |
|
@@ -88,6 +89,42 @@ async def test_code_login_v4_flow(mock_rest) -> None: |
88 | 89 | assert ud == UserData.from_dict(USER_DATA) |
89 | 90 |
|
90 | 91 |
|
| 92 | +async def test_code_login_v4_account_does_not_exist(mock_rest) -> None: |
| 93 | + """Test that response code 3039 raises RoborockAccountDoesNotExist.""" |
| 94 | + mock_rest.clear() |
| 95 | + |
| 96 | + mock_rest.post( |
| 97 | + re.compile(r"https://.*iot\.roborock\.com/api/v1/getUrlByEmail.*"), |
| 98 | + status=200, |
| 99 | + payload={ |
| 100 | + "code": 200, |
| 101 | + "data": {"country": "US", "countrycode": "1", "url": "https://usiot.roborock.com"}, |
| 102 | + "msg": "success", |
| 103 | + }, |
| 104 | + ) |
| 105 | + mock_rest.post( |
| 106 | + re.compile(r"https://.*iot\.roborock\.com/api/v4/email/code/send.*"), |
| 107 | + status=200, |
| 108 | + payload={"code": 200, "data": None, "msg": "success"}, |
| 109 | + ) |
| 110 | + mock_rest.post( |
| 111 | + re.compile(r"https://.*iot\.roborock\.com/api/v3/key/sign.*"), |
| 112 | + status=200, |
| 113 | + payload={"code": 200, "data": {"k": "mock_k"}, "msg": "success"}, |
| 114 | + ) |
| 115 | + mock_rest.post( |
| 116 | + re.compile(r"https://.*iot\.roborock\.com/api/v4/auth/email/login/code.*"), |
| 117 | + status=200, |
| 118 | + payload={"code": 3039, "data": None, "msg": "account does not exist"}, |
| 119 | + ) |
| 120 | + |
| 121 | + api = RoborockApiClient(username="test_user@gmail.com") |
| 122 | + await api.request_code_v4() |
| 123 | + with pytest.raises(RoborockAccountDoesNotExist) as exc_info: |
| 124 | + await api.code_login_v4(4123, "US", 1) |
| 125 | + assert "This account does not exist" in str(exc_info.value) |
| 126 | + |
| 127 | + |
91 | 128 | async def test_url_cycling(mock_rest) -> None: |
92 | 129 | """Test that we cycle through the URLs correctly.""" |
93 | 130 | # Clear mock rest so that we can override the patches. |
|
0 commit comments