|
11 | 11 | DEVICE_ACTIONS_ENDPOINT = f"{SERVER}/api/v2/devices/00:00:00:00:00:00/action/list" |
12 | 12 | DEVICE_ACTIONS_VALID_EXEC_ENDPOINT = f"{SERVER}/api/v2/devices/00:00:00:00:00:00/action/exec/valid" |
13 | 13 | DEVICE_ACTIONS_INVALID_EXEC_ENDPOINT = f"{SERVER}/api/v2/devices/00:00:00:00:00:00/action/exec/invalid" |
| 14 | +DEVICE_ACTIONS_UNSUPPORTED_EXEC_ENDPOINT = f"{SERVER}/api/v2/devices/00:00:00:00:00:00/action/exec/unsupported" |
14 | 15 | DEVICE_ACTION_LOG_ENDPOINT = f"{SERVER}/api/v2/devices/00:00:00:00:00:00/action/log" |
15 | 16 | DEVICE_PENDING_ACTIONS_ENDPOINT = f"{SERVER}/api/v2/devices/00:00:00:00:00:00/action/pending" |
16 | 17 | DEVICE_REMOVE_ACTIONS_ENDPOINT = f"{SERVER}/api/v2/devices/00:00:00:00:00:00/action/remove" |
@@ -96,6 +97,26 @@ def wait_for_device_connection(): |
96 | 97 | return False |
97 | 98 |
|
98 | 99 |
|
| 100 | +def check_action_log(): |
| 101 | + resp = requests.get(DEVICE_ACTION_LOG_ENDPOINT) |
| 102 | + assert resp.status_code == 200 |
| 103 | + actions = resp.json() |
| 104 | + |
| 105 | + # Wait until actions are executed |
| 106 | + retry_count = 0 |
| 107 | + status_codes = [action["status"] for action in actions] |
| 108 | + while retry_count < 5 and ("pending" in status_codes or "sent" in status_codes): |
| 109 | + time.sleep(1) |
| 110 | + resp = requests.get(DEVICE_ACTION_LOG_ENDPOINT) |
| 111 | + assert resp.status_code == 200 |
| 112 | + actions = resp.json() |
| 113 | + status_codes = [action["status"] for action in actions] |
| 114 | + retry_count += 1 |
| 115 | + assert retry_count < 5, "too many retries" |
| 116 | + |
| 117 | + return actions |
| 118 | + |
| 119 | + |
99 | 120 | @pytest.mark.asyncio |
100 | 121 | async def test_actions(process): |
101 | 122 | # Request action before device connects |
@@ -244,3 +265,36 @@ async def test_removing_selected_actions(process): |
244 | 265 | assert actions[0]["action"] == "valid" |
245 | 266 | assert actions[0]["status"] == "pending" |
246 | 267 | assert len(actions) == 1 |
| 268 | + |
| 269 | + |
| 270 | +@pytest.mark.asyncio |
| 271 | +async def test_unsupported_actions(process): |
| 272 | + # Request action before device connects |
| 273 | + resp = requests.get(DEVICE_ACTIONS_VALID_EXEC_ENDPOINT) |
| 274 | + assert resp.status_code == 202 |
| 275 | + |
| 276 | + # Request unsupported action before device connects |
| 277 | + resp = requests.get(DEVICE_ACTIONS_UNSUPPORTED_EXEC_ENDPOINT) |
| 278 | + assert resp.status_code == 202 |
| 279 | + |
| 280 | + # Check action log |
| 281 | + resp = requests.get(DEVICE_ACTION_LOG_ENDPOINT) |
| 282 | + assert resp.status_code == 200 |
| 283 | + actions = resp.json() |
| 284 | + assert actions[0]["action"] == "unsupported" |
| 285 | + assert actions[0]["status"] == "pending" |
| 286 | + assert actions[1]["action"] == "valid" |
| 287 | + assert actions[1]["status"] == "pending" |
| 288 | + |
| 289 | + # Connect device |
| 290 | + dev = MockedDevice("00:00:00:00:00:00", "v0", "dummy") |
| 291 | + await client(dev) |
| 292 | + connected = wait_for_device_connection() |
| 293 | + assert connected == True |
| 294 | + |
| 295 | + actions = check_action_log() |
| 296 | + |
| 297 | + assert actions[0]["action"] == "unsupported" |
| 298 | + assert actions[0]["status"] == "error" |
| 299 | + assert actions[1]["action"] == "valid" |
| 300 | + assert actions[1]["status"] == "0" |
0 commit comments