44import json
55import os
66from typing import Any
7- from unittest .mock import AsyncMock , patch
7+ from unittest .mock import AsyncMock , MagicMock , patch
88
99from airos .airos8 import AirOS
10- from airos .data import AirOS8Data as AirOSData
10+ from airos .data import AirOS8Data as AirOSData , Wireless
11+ from airos .exceptions import AirOSDeviceConnectionError , AirOSKeyDataMissingError
1112import pytest
1213
1314import aiofiles
15+ from mashumaro import MissingField
1416
1517
1618async def _read_fixture (fixture : str = "loco5ac_ap-ptp" ) -> Any :
@@ -26,8 +28,7 @@ async def _read_fixture(fixture: str = "loco5ac_ap-ptp") -> Any:
2628 pytest .fail (f"Invalid JSON in fixture file { path } : { e } " )
2729
2830
29- # pylint: disable=pointless-string-statement
30- '''
31+ @pytest .mark .skip (reason = "broken, needs investigation" )
3132@patch ("airos.airos8._LOGGER" )
3233@pytest .mark .asyncio
3334async def test_status_logs_redacted_data_on_invalid_value (
@@ -91,11 +92,9 @@ async def test_status_logs_redacted_data_on_invalid_value(
9192 assert "status" in logged_data ["interfaces" ][2 ]
9293 assert "ipaddr" in logged_data ["interfaces" ][2 ]["status" ]
9394 assert logged_data ["interfaces" ][2 ]["status" ]["ipaddr" ] == "127.0.0.3"
94- '''
9595
9696
97- # pylint: disable=pointless-string-statement
98- '''
97+ @pytest .mark .skip (reason = "broken, needs investigation" )
9998@patch ("airos.airos8._LOGGER" )
10099@pytest .mark .asyncio
101100async def test_status_logs_exception_on_missing_field (
@@ -139,7 +138,6 @@ async def test_status_logs_exception_on_missing_field(
139138 assert log_args [0 ] == "API call to %s failed with status %d: %s"
140139 assert log_args [2 ] == 500
141140 assert log_args [3 ] == "Error"
142- '''
143141
144142
145143@pytest .mark .parametrize (
@@ -157,8 +155,6 @@ async def test_status_logs_exception_on_missing_field(
157155async def test_ap_object (
158156 airos_device : AirOS , base_url : str , mode : str , fixture : str
159157) -> None :
160- """Test device operation."""
161-
162158 """Test device operation using the new _request_json method."""
163159 fixture_data = await _read_fixture (fixture )
164160
@@ -190,8 +186,7 @@ async def test_ap_object(
190186 cookie ["AIROS_TOKEN" ] = "abc123"
191187
192188
193- # pylint: disable=pointless-string-statement
194- '''
189+ @pytest .mark .skip (reason = "broken, needs investigation" )
195190@pytest .mark .asyncio
196191async def test_reconnect (airos_device : AirOS , base_url : str ) -> None :
197192 """Test reconnect client."""
@@ -209,82 +204,3 @@ async def test_reconnect(airos_device: AirOS, base_url: str) -> None:
209204 patch .object (airos_device , "connected" , True ),
210205 ):
211206 assert await airos_device .stakick ("01:23:45:67:89:aB" )
212- '''
213-
214-
215- # pylint: disable=pointless-string-statement
216- '''
217- @pytest.mark.asyncio
218- async def test_ap_corners(
219- airos_device: AirOS, base_url: str, mode: str = "ap-ptp"
220- ) -> None:
221- """Test device operation."""
222- cookie = SimpleCookie()
223- cookie["session_id"] = "test-cookie"
224- cookie["AIROS_TOKEN"] = "abc123"
225-
226- mock_login_response = MagicMock()
227- mock_login_response.__aenter__.return_value = mock_login_response
228- mock_login_response.text = AsyncMock(return_value="{}")
229- mock_login_response.status = 200
230- mock_login_response.cookies = cookie
231- mock_login_response.headers = {"X-CSRF-ID": "test-csrf-token"}
232-
233- # Test case 1: Successful login
234- with (
235- patch.object(airos_device.session, "post", return_value=mock_login_response),
236- patch.object(airos_device, "_use_json_for_login_post", return_value=True),
237- ):
238- assert await airos_device.login()
239-
240- # Test case 2: Login fails with missing cookies (expects an exception)
241- mock_login_response.cookies = {}
242- with (
243- patch.object(airos_device.session, "post", return_value=mock_login_response),
244- patch.object(airos_device, "_use_json_for_login_post", return_value=True),
245- pytest.raises(AirOSConnectionSetupError),
246- ):
247- # Only call the function; no return value to assert.
248- await airos_device.login()
249-
250- # Test case 3: Login successful, returns None due to missing headers
251- mock_login_response.cookies = cookie
252- mock_login_response.headers = {}
253- with (
254- patch.object(airos_device.session, "post", return_value=mock_login_response),
255- patch.object(airos_device, "_use_json_for_login_post", return_value=True),
256- ):
257- result = await airos_device.login()
258- assert result is False
259-
260- # Test case 4: Login fails with bad data from the API (expects an exception)
261- mock_login_response.headers = {"X-CSRF-ID": "test-csrf-token"}
262- mock_login_response.text = AsyncMock(return_value="abc123")
263- with (
264- patch.object(airos_device.session, "post", return_value=mock_login_response),
265- patch.object(airos_device, "_use_json_for_login_post", return_value=True),
266- pytest.raises(AirOSDataMissingError),
267- ):
268- # Only call the function; no return value to assert.
269- await airos_device.login()
270-
271- # Test case 5: Login fails due to HTTP status code (expects an exception)
272- mock_login_response.text = AsyncMock(return_value="{}")
273- mock_login_response.status = 400
274- with (
275- patch.object(airos_device.session, "post", return_value=mock_login_response),
276- patch.object(airos_device, "_use_json_for_login_post", return_value=True),
277- pytest.raises(AirOSConnectionAuthenticationError),
278- ):
279- # Only call the function; no return value to assert.
280- await airos_device.login()
281-
282- # Test case 6: Login fails due to client-level connection error (expects an exception)
283- mock_login_response.status = 200
284- with (
285- patch.object(airos_device.session, "post", side_effect=aiohttp.ClientError),
286- pytest.raises(AirOSDeviceConnectionError),
287- ):
288- # Only call the function; no return value to assert.
289- await airos_device.login()
290- '''
0 commit comments