Skip to content

Commit f19ad7a

Browse files
committed
Fix testing
1 parent 65d84ac commit f19ad7a

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

airos/airos8data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class WirelessMode(Enum):
1818
"""Enum definition."""
1919

2020
AccessPoint_PointToPoint = "ap-ptp"
21-
Station_PointToPoint = "ap-ptp"
21+
Station_PointToPoint = "sta-ptp"
2222
# More to be added when known
2323

2424

tests/test_stations.py

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import aiofiles
1212
import aiohttp
1313

14+
from . import AirOSData
15+
1416

1517
async 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
64101
async def test_reconnect(airos_device, base_url):
65102
"""Test reconnect client."""

0 commit comments

Comments
 (0)