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 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464
|
import os
import sys
from typing import Tuple
import pytest
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
# noinspection PyProtectedMember
def test_parse_dict_lines(dict_text):
from ndms2_client.client import _parse_dict_lines
_parse_dict_lines(dict_text.split('\n'))
def test_hotspot_data(hostpot_sample: Tuple[str, int]):
from ndms2_client.client import _parse_dict_lines
sample, expected_hosts = hostpot_sample
parsed = _parse_dict_lines(sample.split('\n'))
print(parsed['host'])
if expected_hosts > 1:
assert isinstance(parsed['host'], list)
assert len(parsed['host']) == expected_hosts
else:
assert isinstance(parsed['host'], dict)
@pytest.fixture(params=range(4))
def dict_text(request):
data = ['''
station:
mac: 60:ff:ff:ff:ff:ff
ap: WifiMaster0/AccessPoint0
authenticated: yes
txrate: 65
rxrate: 54
uptime: 3558
txbytes: 56977
rxbytes: 21754
ht: 20
mode: 11n
gi: 800
rssi: -46
mcs: 7
txss: 1
station:
mac: b8:ff:ff:ff:ff:ff
ap: WifiMaster0/AccessPoint0
authenticated: yes
txrate: 65
rxrate: 24
uptime: 3557
txbytes: 9261871
rxbytes: 196082452
ht: 20
mode: 11n
gi: 800
rssi: -54
mcs: 7
txss: 1
station:
mac: 5c:ff:ff:ff:ff:ff
ap: WifiMaster0/AccessPoint0
authenticated: yes
txrate: 65
rxrate: 36
uptime: 3555
txbytes: 74073
rxbytes: 21007
ht: 20
mode: 11n
gi: 800
rssi: -54
mcs: 7
txss: 1
station:
mac: 60:ff:ff:ff:ff:ff
ap: WifiMaster0/AccessPoint0
authenticated: yes
txrate: 65
rxrate: 6
uptime: 3554
txbytes: 92221
rxbytes: 21475
ht: 20
mode: 11n
gi: 800
rssi: -63
mcs: 7
txss: 1
station:
mac: 48:ff:ff:ff:ff:ff
ap: WifiMaster0/AccessPoint0
authenticated: yes
txrate: 65
rxrate: 65
uptime: 3423
txbytes: 697534
rxbytes: 732250
ht: 20
mode: 11n
gi: 800
rssi: -20
mcs: 7
txss: 1
station:
mac: a4:ff:ff:ff:ff:ff
ap: WifiMaster1/AccessPoint0
authenticated: yes
txrate: 200
rxrate: 200
uptime: 1749
txbytes: 1012970
rxbytes: 1183758
ht: 40
mode: 11ac
gi: 400
rssi: -63
mcs: 9
txss: 1
station:
mac: a4:ff:ff:ff:ff:ff
ap: WifiMaster1/AccessPoint0
authenticated: yes
txrate: 200
rxrate: 180
uptime: 1741
txbytes: 586118
rxbytes: 658847
ht: 40
mode: 11ac
gi: 400
rssi: -71
mcs: 9
txss: 1
''', '''
buttons:
button, name = RESET:
is_switch: no
position: 2
position_count: 2
clicks: 0
elapsed: 0
hold_delay: 10000
button, name = WLAN:
is_switch: no
position: 2
position_count: 2
clicks: 0
elapsed: 0
hold_delay: 3000
button, name = FN1:
is_switch: no
position: 2
position_count: 2
clicks: 0
elapsed: 0
hold_delay: 3000
button, name = FN2:
is_switch: no
position: 2
position_count: 2
clicks: 0
elapsed: 0
hold_delay: 3000
''', '''
id: WifiMaster0/AccessPoint0
index: 0
type: AccessPoint
description: Wi-Fi access point
interface-name: AccessPoint
link: up
connected: yes
state: up
mtu: 1500
tx-queue: 1000
group: Home
usedby: Bridge0
mac: 00:ff:00:00:00:00
auth-type: none
ssid: home
encryption: wpa2,wpa3
''', '''
release: v2.08(AAUR.4)C2
arch: mips
ndm:
exact: 0-df82a04
cdate: 16 Oct 2017
bsp:
exact: 0-02ec1b2
cdate: 16 Oct 2017
ndw:
version: 4.2.0.166
features: wifi_button,single_usb_port,nopack,
flexible_menu,emulate_firmware_progress
components: ddns,dot1x,interface-extras,kabinet,
miniupnpd,nathelper-ftp,nathelper-h323,nathelper-pptp,
nathelper-rtsp,nathelper-sip,ppe,trafficcontrol,usblte,
usbserial,base,cloud,cloudcontrol,components,config-ap,
config-client,config-repeater,corewireless,dhcpd,
easyconfig,igmp,ipsec,l2tp,madwimax,pingcheck,ppp,pptp,
pppoe,skydns,usb,usbdsl,usbmodem,usbnet,ydns,vpnserver,
base-l10n,sysmode,easyconfig-3.2,modems,theme-ZyXEL-Intl,
base-theme,ispdb,base-ZyXEL-Intl
manufacturer: ZyXEL
vendor: ZyXEL
series: Keenetic series
model: Keenetic
hw_version: 12131000-G
hw_id: kn_rg
device: Keenetic 4G III
class: Internet Center
''']
return data[request.param]
@pytest.fixture(params=range(2))
def hostpot_sample(request) -> Tuple[str, int]:
samples = [
('''
host:
mac: dc:09:xx:xx:xx:xx
via: dc:09:xx:xx:xx:xx
ip: 192.xx.xx.xx
hostname: xxxxxxxxxxxxx
name: xxxxxxxxxxxxxxxxxx
interface:
id: Bridge0
name: Home
description: Home VLAN
expires: 181613
registered: yes
access: permit
schedule:
active: yes
rxbytes: 34442317
txbytes: 2176340
uptime: 59
first-seen: 157428
last-seen: 7
link: up
auto-negotiation: yes
speed: 1000
duplex: yes
ever-seen: yes
traffic-shape:
rx: 0
tx: 0
mode: mac
schedule:
host:
mac: 10:40:xx:xx:xx:xx
via: 10:40:xx:xx:xx:xx
ip: 192.xx.xx.xx
hostname: xxxxxxxxxxxxx
name: xxxxxxxxxxxxxx
interface:
id: Bridge0
name: Home
description: Home VLAN
expires: 0
registered: yes
access: permit
schedule:
active: no
rxbytes: 0
txbytes: 0
uptime: 0
link: down
ever-seen: yes
traffic-shape:
rx: 0
tx: 0
mode: mac
schedule:
''', 2),
('''
host:
mac: 74:ff:ff:ff:ff:ff
via: 74:ff:ff:ff:ff:ff
ip: 250:250:250:218
hostname: foxel-desktop
name: foxel-desktop
interface:
id: Bridge0
name: Home
description: Home network
expires: 0
registered: yes
access: permit
schedule:
active: yes
rxbytes: 3664009359
txbytes: 280968424
uptime: 354617
first-seen: 656249
last-seen: 1
link: up
auto-negotiation: yes
speed: 1000
duplex: yes
traffic-shape:
rx: 0
tx: 0
mode: none
schedule:
mac-access, id = Bridge0: deny
host:
mac: 10:ff:ff:ff:ff:ff
via: 10:ff:ff:ff:ff:ff
ip: 250:250:250:200
hostname: foxhome-server
name: foxhome, server
interface:
id: Bridge0
name: Home
description: Home network
expires: 0
registered: yes
access: permit
schedule:
active: yes
rxbytes: 2077239992
txbytes: 665641019
uptime: 614018
first-seen: 656255
last-seen: 1
link: up
auto-negotiation: yes
speed: 1000
duplex: yes
traffic-shape:
rx: 0
tx: 0
mode: none
schedule:
mac-access, id = Bridge0: deny
host:
mac: a4:ff:ff:ff:ff:ff
via: a4:ff:ff:ff:ff:ff
ip: 250:250:250:224
hostname: Chromecast-Audio
name: foxcast-bedroom
description: This is very long description with newline
and colon: foo
interface:
id: Bridge0
name: Home
description: Home network
expires: 670979
registered: yes
access: permit
schedule:
active: yes
rxbytes: 48388740
txbytes: 10987076
uptime: 23108
first-seen: 656255
last-seen: 1
link: up
auto-negotiation: yes
speed: 1000
duplex: yes
traffic-shape:
rx: 0
tx: 0
mode: none
schedule:
mac-access, id = Bridge0: deny
host:
mac: a4:ff:ff:ff:ff:ff
via: a4:ff:ff:ff:ff:ff
ip: 250:250:250:220
hostname: Chromecast-Audio
name: foxcast-kitchen
interface:
id: Bridge0
name: Home
description: Home network
expires: 679721
registered: yes
access: permit
schedule:
active: yes
rxbytes: 531016115
txbytes: 27461293
uptime: 23482
first-seen: 656238
last-seen: 1
link: up
ssid: FOXHOME-5G
ap: WifiMaster1/AccessPoint0
authenticated: yes
txrate: 200
ht: 40
mode: 11ac
gi: 400
rssi: -57
mcs: 9
txss: 1
traffic-shape:
rx: 0
tx: 0
mode: none
schedule:
mac-access, id = Bridge0: permit
''', 4)
]
return samples[request.param]
|