|
1 | 1 | import uuid |
2 | 2 | from collections.abc import Callable |
| 3 | +from typing import Literal |
3 | 4 | from unittest.mock import MagicMock, Mock, call, patch |
4 | 5 |
|
5 | 6 | import pytest |
|
39 | 40 | DeviceModel(name="bar", protocols=[]), |
40 | 41 | ] |
41 | 42 | ) |
| 43 | +DEVICES_AND_CHILDREN = DeviceResponse( |
| 44 | + devices=[ |
| 45 | + DeviceModel(name="foo", protocols=[]), |
| 46 | + DeviceModel(name="bar", protocols=[]), |
| 47 | + DeviceModel(name="foo-bar", protocols=[]), |
| 48 | + ] |
| 49 | +) |
| 50 | +DEVICES_AND_ALL_DESCENDENTS = DeviceResponse( |
| 51 | + devices=[ |
| 52 | + DeviceModel(name="foo", protocols=[]), |
| 53 | + DeviceModel(name="bar", protocols=[]), |
| 54 | + DeviceModel(name="foo-bar", protocols=[]), |
| 55 | + DeviceModel(name="foo-bar-baz", protocols=[]), |
| 56 | + ] |
| 57 | +) |
42 | 58 | DEVICE = DeviceModel(name="foo", protocols=[]) |
43 | 59 | TASK = TrackableTask(task_id="foo", task=Task(name="bar", params={})) |
44 | 60 | TASKS = TasksListResponse(tasks=[TASK]) |
|
67 | 83 |
|
68 | 84 | @pytest.fixture |
69 | 85 | def mock_rest() -> BlueapiRestClient: |
| 86 | + def get_devices(depth: int | Literal["all"]) -> DeviceResponse: |
| 87 | + if depth == "all" or depth > 1: |
| 88 | + return DEVICES_AND_ALL_DESCENDENTS |
| 89 | + if depth == 1: |
| 90 | + return DEVICES_AND_CHILDREN |
| 91 | + return DEVICES |
| 92 | + |
70 | 93 | mock = Mock(spec=BlueapiRestClient) |
71 | 94 |
|
72 | 95 | mock.get_plans.return_value = PLANS |
73 | 96 | mock.get_plan.return_value = PLAN |
74 | | - mock.get_devices.return_value = DEVICES |
| 97 | + mock.get_devices.side_effect = get_devices |
75 | 98 | mock.get_device.return_value = DEVICE |
76 | 99 | mock.get_state.return_value = WorkerState.IDLE |
77 | 100 | mock.get_task.return_value = TASK |
@@ -121,7 +144,7 @@ def test_get_nonexistant_plan( |
121 | 144 |
|
122 | 145 |
|
123 | 146 | def test_get_devices(client: BlueapiClient): |
124 | | - assert client.get_devices() == DEVICES |
| 147 | + assert client.get_devices(depth=0) == DEVICES |
125 | 148 |
|
126 | 149 |
|
127 | 150 | def test_get_device(client: BlueapiClient): |
@@ -511,7 +534,7 @@ def test_get_plan_span_ok(exporter: JsonObjectSpanExporter, client: BlueapiClien |
511 | 534 |
|
512 | 535 | def test_get_devices_span_ok(exporter: JsonObjectSpanExporter, client: BlueapiClient): |
513 | 536 | with asserting_span_exporter(exporter, "get_devices"): |
514 | | - client.get_devices() |
| 537 | + client.get_devices(depth=0) |
515 | 538 |
|
516 | 539 |
|
517 | 540 | def test_get_device_span_ok(exporter: JsonObjectSpanExporter, client: BlueapiClient): |
|
0 commit comments