Skip to content

Commit 10e5132

Browse files
committed
CRAI suggestions
1 parent b9f058e commit 10e5132

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

tests/test_stations.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,15 @@
1212

1313
async def _read_fixture(fixture: str = "ap-ptp"):
1414
"""Read fixture file per device type."""
15-
path = os.path.join(os.path.dirname(__file__), f"../fixtures/{fixture}.json")
16-
async with aiofiles.open(path, encoding="utf-8") as f:
17-
return json.loads(await f.read())
15+
fixture_dir = os.path.join(os.path.dirname(__file__), "..", "fixtures")
16+
path = os.path.join(fixture_dir, f"{fixture}.json")
17+
try:
18+
async with aiofiles.open(path, encoding="utf-8") as f:
19+
return json.loads(await f.read())
20+
except FileNotFoundError:
21+
pytest.fail(f"Fixture file not found: {path}")
22+
except json.JSONDecodeError as e:
23+
pytest.fail(f"Invalid JSON in fixture file {path}: {e}")
1824

1925

2026
@pytest.mark.parametrize("mode", ["ap-ptp", "sta-ptp"])
@@ -31,12 +37,13 @@ async def test_ap(airos_device, base_url, mode):
3137
mock_login_response.text = "{}"
3238
mock_login_response.status = 200
3339
mock_login_response.cookies = cookie
34-
40+
mock_login_response.headers = {"X-CSRF-ID": "test-csrf-token"}
3541
# --- Prepare fake GET /api/status response ---
42+
fixture_data = await _read_fixture(mode)
3643
mock_status_payload = {"mode": await _read_fixture(fixture=mode)}
3744
mock_status_response = MagicMock()
3845
mock_status_response.__aenter__.return_value = mock_status_response
39-
mock_status_response.text = json.dumps(await _read_fixture(mode))
46+
mock_status_response.text = json.dumps(fixture_data)
4047
mock_status_response.status = 200
4148
mock_status_response.json = AsyncMock(return_value=mock_status_payload)
4249

0 commit comments

Comments
 (0)