1111import aiofiles
1212import aiohttp
1313
14+ from . import AirOSData
15+
1416
1517async def _read_fixture (fixture : str = "ap-ptp" ):
1618 """Read fixture file per device type."""
@@ -27,7 +29,7 @@ async def _read_fixture(fixture: str = "ap-ptp"):
2729
2830@pytest .mark .parametrize ("mode" , ["ap-ptp" , "sta-ptp" ])
2931@pytest .mark .asyncio
30- async def test_ap (airos_device , base_url , mode ):
32+ async def test_ap_json (airos_device , base_url , mode ):
3133 """Test device operation."""
3234 cookie = SimpleCookie ()
3335 cookie ["session_id" ] = "test-cookie"
@@ -54,12 +56,47 @@ async def test_ap(airos_device, base_url, mode):
5456 patch .object (airos_device .session , "get" , return_value = mock_status_response ),
5557 ):
5658 assert await airos_device .login ()
57- status = await airos_device .status ()
59+ status = await airos_device .status (return_json = True )
5860
5961 # Verify the fixture returns the correct mode
6062 assert status .get ("wireless" , {}).get ("mode" ) == mode
6163
6264
65+ @pytest .mark .parametrize ("mode" , ["ap-ptp" , "sta-ptp" ])
66+ @pytest .mark .asyncio
67+ async def test_ap_object (airos_device , base_url , mode ):
68+ """Test device operation."""
69+ cookie = SimpleCookie ()
70+ cookie ["session_id" ] = "test-cookie"
71+ cookie ["AIROS_TOKEN" ] = "abc123"
72+
73+ # --- Prepare fake POST /api/auth response with cookies ---
74+ mock_login_response = MagicMock ()
75+ mock_login_response .__aenter__ .return_value = mock_login_response
76+ mock_login_response .text = AsyncMock (return_value = "{}" )
77+ mock_login_response .status = 200
78+ mock_login_response .cookies = cookie
79+ mock_login_response .headers = {"X-CSRF-ID" : "test-csrf-token" }
80+ # --- Prepare fake GET /api/status response ---
81+ fixture_data = await _read_fixture (mode )
82+ mock_status_payload = fixture_data
83+ mock_status_response = MagicMock ()
84+ mock_status_response .__aenter__ .return_value = mock_status_response
85+ mock_status_response .text = AsyncMock (return_value = json .dumps (fixture_data ))
86+ mock_status_response .status = 200
87+ mock_status_response .json = AsyncMock (return_value = mock_status_payload )
88+
89+ with (
90+ patch .object (airos_device .session , "post" , return_value = mock_login_response ),
91+ patch .object (airos_device .session , "get" , return_value = mock_status_response ),
92+ ):
93+ assert await airos_device .login ()
94+ status : AirOSData = await airos_device .status () # Implies return_json = False
95+
96+ # Verify the fixture returns the correct mode
97+ assert status .wireless .mode .value == mode
98+
99+
63100@pytest .mark .asyncio
64101async def test_reconnect (airos_device , base_url ):
65102 """Test reconnect client."""
0 commit comments