-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathconftest.py
More file actions
358 lines (328 loc) · 10.1 KB
/
Copy pathconftest.py
File metadata and controls
358 lines (328 loc) · 10.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
"""Shared pytest fixtures for UI-CLI tests."""
import os
from pathlib import Path
from typing import Any
from unittest.mock import AsyncMock, MagicMock
import pytest
from dotenv import load_dotenv
# Load .env file for integration tests
env_file = Path(__file__).parent.parent / ".env"
if env_file.exists():
load_dotenv(env_file)
# ============================================================
# Mock Data Fixtures
# ============================================================
@pytest.fixture
def mock_hosts_response() -> list[dict[str, Any]]:
"""Sample hosts response from Site Manager API."""
return [
{
"id": "host-001",
"hardwareId": "hw-001",
"reportedState": {
"hostname": "UDM-Pro",
"ip": "192.168.1.1",
"mac": "aa:bb:cc:dd:ee:ff",
"firmwareVersion": "4.0.6",
"state": "connected",
"releaseChannel": "release",
},
"userData": {"name": "Home Gateway"},
},
{
"id": "host-002",
"hardwareId": "hw-002",
"reportedState": {
"hostname": "Cloud-Key",
"ip": "192.168.1.2",
"mac": "11:22:33:44:55:66",
"firmwareVersion": "3.0.0",
"state": "connected",
"releaseChannel": "release",
},
"userData": {"name": "Office Controller"},
},
]
@pytest.fixture
def mock_sites_response() -> list[dict[str, Any]]:
"""Sample sites response from Site Manager API."""
return [
{
"siteId": "site-001",
"siteName": "Home Network",
"meta": {"timezone": "America/New_York", "desc": "Primary home"},
"statistics": {"counts": {"totalDevice": 10, "offlineDevice": 1}},
"isOwner": True,
"hostId": "host-001",
},
{
"siteId": "site-002",
"siteName": "Office Network",
"meta": {"timezone": "America/New_York", "desc": "Work office"},
"statistics": {"counts": {"totalDevice": 5, "offlineDevice": 0}},
"isOwner": False,
"hostId": "host-002",
},
]
@pytest.fixture
def mock_devices_response() -> list[dict[str, Any]]:
"""Sample devices response from Site Manager API."""
return [
{
"id": "dev-001",
"name": "Living Room AP",
"model": "U6-Pro",
"mac": "aa:11:bb:22:cc:33",
"ip": "192.168.1.100",
"status": "online",
"version": "6.6.55",
"productLine": "network",
"hostId": "host-001",
},
{
"id": "dev-002",
"name": "Main Switch",
"model": "USW-24-POE",
"mac": "dd:44:ee:55:ff:66",
"ip": "192.168.1.101",
"status": "online",
"version": "7.0.0",
"productLine": "network",
"hostId": "host-001",
},
]
@pytest.fixture
def mock_local_clients_response() -> list[dict[str, Any]]:
"""Sample clients response from Local Controller API."""
return [
{
"_id": "client-001",
"mac": "aa:bb:cc:11:22:33",
"ip": "10.0.0.100",
"hostname": "laptop",
"name": "Work Laptop",
"is_wired": False,
"network": "Default",
"satisfaction": 98,
"rssi": -45,
"rx_bytes": 1000000000,
"tx_bytes": 500000000,
"uptime": 3600,
},
{
"_id": "client-002",
"mac": "dd:ee:ff:44:55:66",
"ip": "10.0.0.101",
"hostname": "desktop",
"name": "Gaming PC",
"is_wired": True,
"network": "Default",
"satisfaction": 100,
"rx_bytes": 5000000000,
"tx_bytes": 2000000000,
"uptime": 86400,
},
]
@pytest.fixture
def mock_local_devices_response() -> list[dict[str, Any]]:
"""Sample devices response from Local Controller API."""
return [
{
"_id": "device-001",
"mac": "70:a7:41:00:00:01",
"ip": "192.168.1.1",
"name": "Home Gateway",
"model": "UDMPROSE",
"type": "udm",
"version": "4.0.6",
"state": 1,
"uptime": 604800,
"num_sta": 50,
"sys_stats": {"loadavg_1": "1.5", "mem_used": 4000000000, "mem_total": 8000000000},
},
{
"_id": "device-002",
"mac": "70:a7:41:00:00:02",
"ip": "192.168.1.100",
"name": "Office AP",
"model": "U6-Pro",
"type": "uap",
"version": "6.6.55",
"state": 1,
"uptime": 259200,
"num_sta": 15,
"radio_table": [
{"radio": "ng", "channel": 6},
{"radio": "na", "channel": 149},
],
},
]
@pytest.fixture
def mock_events_response() -> list[dict[str, Any]]:
"""Sample events response from Local Controller API."""
return [
{
"_id": "event-001",
"time": 1700000000000,
"key": "EVT_AP_Connected",
"msg": "AP connected",
"subsystem": "wlan",
},
{
"_id": "event-002",
"time": 1700000100000,
"key": "EVT_SW_Connected",
"msg": "Switch connected",
"subsystem": "lan",
},
]
@pytest.fixture
def mock_networks_response() -> list[dict[str, Any]]:
"""Sample networks response from Local Controller API."""
return [
{
"_id": "net-001",
"name": "Default",
"vlan": 1,
"ip_subnet": "192.168.1.0/24",
"dhcpd_enabled": True,
"dhcpd_start": "192.168.1.100",
"dhcpd_stop": "192.168.1.254",
"purpose": "corporate",
},
{
"_id": "net-002",
"name": "Guest",
"vlan": 100,
"ip_subnet": "192.168.100.0/24",
"dhcpd_enabled": True,
"purpose": "guest",
},
]
@pytest.fixture
def mock_vouchers_response() -> list[dict[str, Any]]:
"""Sample vouchers response from Local Controller API."""
return [
{
"_id": "voucher-001",
"code": "12345-67890",
"duration": 1440,
"quota": 1,
"used": 0,
"create_time": 1700000000,
"qos_usage_quota": 1024,
"note": "Guest access",
},
{
"_id": "voucher-002",
"code": "abcde-fghij",
"duration": 60,
"quota": 5,
"used": 2,
"create_time": 1700000000,
"note": "Event vouchers",
},
]
@pytest.fixture
def mock_daily_stats_response() -> list[dict[str, Any]]:
"""Sample daily stats response from Local Controller API."""
return [
{
"time": 1700000000000,
"wan-rx_bytes": 50000000000,
"wan-tx_bytes": 5000000000,
"num_sta": 80,
},
{
"time": 1699913600000,
"wan-rx_bytes": 45000000000,
"wan-tx_bytes": 4500000000,
"num_sta": 75,
},
]
# ============================================================
# Groups Fixtures
# ============================================================
@pytest.fixture
def mock_groups_data() -> dict[str, Any]:
"""Sample groups data for testing."""
return {
"version": 1,
"groups": {
"kids-devices": {
"name": "Kids Devices",
"description": "Tablets and phones for the kids",
"type": "static",
"members": [
{"mac": "AA:BB:CC:DD:EE:FF", "alias": "Timmy iPad"},
{"mac": "11:22:33:44:55:66", "alias": "Sarah Phone"},
],
"created_at": "2024-01-15T10:30:00",
"updated_at": "2024-01-15T10:35:00",
},
"apple-devices": {
"name": "Apple Devices",
"type": "auto",
"rules": {"vendor": ["Apple"]},
"created_at": "2024-01-15T11:00:00",
"updated_at": "2024-01-15T11:00:00",
},
}
}
@pytest.fixture
def mock_clients_for_groups() -> list[dict[str, Any]]:
"""Sample clients for testing group matching."""
return [
{
"mac": "AA:BB:CC:DD:EE:FF",
"ip": "192.168.1.100",
"name": "Timmy iPad",
"hostname": "timmys-ipad",
"oui": "Apple",
"network": "Default",
"is_wired": False,
},
{
"mac": "11:22:33:44:55:66",
"ip": "192.168.1.101",
"name": "Sarah Phone",
"hostname": "sarahs-phone",
"oui": "Apple",
"network": "Default",
"is_wired": False,
},
{
"mac": "22:33:44:55:66:77",
"ip": "192.168.1.102",
"name": "Gaming PC",
"hostname": "gaming-pc",
"oui": "Dell",
"network": "Default",
"is_wired": True,
},
{
"mac": "33:44:55:66:77:88",
"ip": "192.168.100.50",
"name": "Guest Phone",
"hostname": "guest-phone",
"oui": "Samsung",
"network": "Guest",
"is_wired": False,
},
]
# ============================================================
# Environment Fixtures
# ============================================================
@pytest.fixture
def integration_env_vars():
"""Check if integration test environment variables are set."""
required_vars = [
"UNIFI_API_KEY",
"UNIFI_CONTROLLER_URL",
"UNIFI_CONTROLLER_USERNAME",
"UNIFI_CONTROLLER_PASSWORD",
]
missing = [var for var in required_vars if not os.getenv(var)]
if missing:
pytest.skip(f"Missing environment variables: {', '.join(missing)}")
return True