|
4 | 4 | import json |
5 | 5 | import os |
6 | 6 | from typing import Any |
7 | | -from unittest.mock import AsyncMock, patch |
| 7 | +from unittest.mock import AsyncMock, MagicMock, patch |
8 | 8 |
|
9 | 9 | import aiofiles |
10 | 10 | import pytest |
@@ -65,3 +65,53 @@ async def test_ap_object( |
65 | 65 | cookie = SimpleCookie() |
66 | 66 | cookie["session_id"] = "test-cookie" |
67 | 67 | 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