Skip to content

Commit 0f52445

Browse files
committed
Add XM testing
1 parent 732fe25 commit 0f52445

File tree

1 file changed

+51
-1
lines changed

1 file changed

+51
-1
lines changed

tests/test_stations6.py

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import json
55
import os
66
from typing import Any
7-
from unittest.mock import AsyncMock, patch
7+
from unittest.mock import AsyncMock, MagicMock, patch
88

99
import aiofiles
1010
import pytest
@@ -65,3 +65,53 @@ async def test_ap_object(
6565
cookie = SimpleCookie()
6666
cookie["session_id"] = "test-cookie"
6767
cookie["AIROS_TOKEN"] = "abc123"
68+
69+
70+
@pytest.mark.asyncio
71+
async def test_login_v6_flow() -> None:
72+
"""Test AirOS v6 XM login flow with manual cookie handling."""
73+
74+
# Create a mock session
75+
session = MagicMock()
76+
77+
# Mock response for GET /login.cgi
78+
get_login_response = MagicMock()
79+
get_login_response.__aenter__.return_value = get_login_response
80+
get_login_response.status = 200
81+
get_login_response.cookies = {
82+
"AIROS_ABC123": MagicMock(key="AIROS_ABC123", value="xyz789")
83+
}
84+
85+
# Mock response for POST /login.cgi
86+
post_login_response = MagicMock()
87+
post_login_response.__aenter__.return_value = post_login_response
88+
post_login_response.status = 302
89+
90+
# Mock response for GET /index.cgi
91+
get_index_response = MagicMock()
92+
get_index_response.__aenter__.return_value = get_index_response
93+
get_index_response.status = 200
94+
get_index_response.url = "http://192.168.1.3/index.cgi"
95+
96+
# Set side effects for session.request
97+
session.request.side_effect = [
98+
get_login_response,
99+
post_login_response,
100+
get_index_response,
101+
]
102+
103+
# Create device
104+
airos6_device = AirOS6(
105+
host="http://192.168.1.3",
106+
username="ubnt",
107+
password="ubnt",
108+
session=session,
109+
)
110+
111+
await airos6_device._login_v6() # noqa: SLF001
112+
113+
# Assertions
114+
assert airos6_device.connected is True
115+
assert airos6_device.api_version == 6
116+
assert airos6_device._auth_cookie == "AIROS_ABC123=xyz789" # noqa: SLF001
117+
assert session.request.call_count == 3

0 commit comments

Comments
 (0)