1212
1313async 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