Skip to content

Commit bb63317

Browse files
committed
[#88979] server: tests: Add unsupported actions test
Signed-off-by: Anna Roszkiewicz <[email protected]>
1 parent edb7fa2 commit bb63317

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

server/tests/test-actions.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
DEVICE_ACTIONS_ENDPOINT = f"{SERVER}/api/v2/devices/00:00:00:00:00:00/action/list"
1212
DEVICE_ACTIONS_VALID_EXEC_ENDPOINT = f"{SERVER}/api/v2/devices/00:00:00:00:00:00/action/exec/valid"
1313
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"
1415
DEVICE_ACTION_LOG_ENDPOINT = f"{SERVER}/api/v2/devices/00:00:00:00:00:00/action/log"
1516
DEVICE_PENDING_ACTIONS_ENDPOINT = f"{SERVER}/api/v2/devices/00:00:00:00:00:00/action/pending"
1617
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():
9697
return False
9798

9899

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+
99120
@pytest.mark.asyncio
100121
async def test_actions(process):
101122
# Request action before device connects
@@ -244,3 +265,36 @@ async def test_removing_selected_actions(process):
244265
assert actions[0]["action"] == "valid"
245266
assert actions[0]["status"] == "pending"
246267
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

Comments
 (0)