-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtests.py
73 lines (63 loc) · 2.03 KB
/
tests.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
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python3
import unittest
from unittest.mock import Mock, patch
import speedtest_wrapper
# 20220921 return
MOCK_SPEEDTEST_JSON = {
"type": "result",
"timestamp": "2022-09-22T04:29:10Z",
"ping": {"jitter": 4.077, "latency": 13.814, "low": 9.838, "high": 17.448},
"download": {
"bandwidth": 73593870,
"bytes": 561306538,
"elapsed": 7814,
"latency": {"iqm": 49.645, "low": 12.847, "high": 81.176, "jitter": 11.933},
},
"upload": {
"bandwidth": 4550470,
"bytes": 27235440,
"elapsed": 5903,
"latency": {"iqm": 13.94, "low": 10.793, "high": 140.264, "jitter": 4.597},
},
"packetLoss": 0,
"isp": "Spectrum",
"interface": {
"internalIp": "172.17.0.2",
"name": "eth0",
"macAddr": "02:42:AC:11:00:02",
"isVpn": False,
"externalIp": "47.33.15.75",
},
"server": {
"id": 2408,
"host": "spt01renonv.reno.nv.charter.com",
"port": 8080,
"name": "Spectrum",
"location": "Reno, NV",
"country": "United States",
"ip": "24.205.192.190",
},
"result": {
"id": "00420ff7-e453-44d9-8caa-b018cf72105e",
"url": "https://www.speedtest.net/result/c/00420ff7-e453-44d9-8caa-b018cf72105e",
"persisted": True,
},
}
# Shitty tests just to ensure file has valid syntax and imports
class TestSpeedTest(unittest.TestCase):
def setUp(self) -> None:
self.stc = speedtest_wrapper.SpeedtestCollector(debug=False)
def test_stc_valid(self) -> None:
self.assertTrue(self.stc)
@patch(
"speedtest_wrapper.SpeedtestCollector.run_speedtest",
return_value=MOCK_SPEEDTEST_JSON,
)
def test_collect(self, mock_run_speedtest: Mock) -> None:
guages = []
for guage in self.stc.collect():
guages.append(guage)
self.assertEqual("spt01renonv.reno.nv.charter.com", self.stc.speedtest_host)
self.assertEqual(19, len(guages))
if __name__ == "__main__":
unittest.main()