-
Notifications
You must be signed in to change notification settings - Fork 0
/
wlanconnectorunittest.py
62 lines (43 loc) · 1.43 KB
/
wlanconnectorunittest.py
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
import application
import unittest
from wlanconnector import WlanConnector
class WlanMock:
def __init__(self) -> None:
pass
def active(self, somIgnoredValue : bool):
pass
def connect(self, ignoredSsid : str, ingoredPw : str):
pass
def status(self) -> int:
return 1
def ifconfig(self):
return ('99.99.99.99')
class StatefulWlanMock(WlanMock):
def __init__(self) -> None:
self.statusCallCounter = 0
def status(self) -> int:
if self.statusCallCounter < 3:
self.statusCallCounter += self.statusCallCounter + 1
return 1
else: return 3
class NetworkMock:
def __init__(self, wlanMock) -> None:
self.STA_IF = 'dummy value'
self.wlanMock = wlanMock
def WLAN(self, ignoredDummyValue) -> WlanMock:
return self.wlanMock
class WlanConnectorUnitTest(unittest.TestCase):
def test_no_connection(self):
network = NetworkMock(WlanMock())
wlanConnectort = WlanConnector(network, 2)
try:
wlanConnectort.connect('someSsid', 'somePw')
self.fail('Shuld raise RuntimeError')
except RuntimeError:
pass
def test_connection(self):
network = NetworkMock(StatefulWlanMock())
wlanConnectort = WlanConnector(network, 3)
wlanConnectort.connect('someSsid', 'somePw')
if __name__ == '__main__': # type: ignore
unittest.main()