-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.py
65 lines (51 loc) · 2.09 KB
/
test.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
import unittest
import api
tests = [
dict(text="""PING 10.228.44.1 (10.228.44.1): 56 data bytes
64 bytes from 10.228.44.1: icmp_seq=0 ttl=63 time=0.843 ms
64 bytes from 10.228.44.1: icmp_seq=1 ttl=63 time=0.424 ms
--- 10.228.44.1 ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max/stddev = 0.424/0.633/0.843/0.210 ms""",
parsed=dict(packets='2', received='2', loss="0%")),
dict(text="""PING 10.228.44.1 (10.228.44.1): 56 data bytes
64 bytes from 10.228.44.1: icmp_seq=0 ttl=63 time=0.843 ms
64 bytes from 10.228.44.1: icmp_seq=1 ttl=63 time=0.424 ms
--- 10.228.44.1 ping statistics ---
2 packets transmitted, 1 packets received, 50% packet loss
round-trip min/avg/max/stddev = 0.424/0.633/0.843/0.210 ms""",
parsed=dict(packets='2', received='1', loss="50%")),
dict(text="""PING 10.228.44.111 (10.228.44.111): 56 data bytes
92 bytes from 10.228.44.99: Destination Host Unreachable
92 bytes from 10.228.44.99: Destination Host Unreachable
--- 10.228.44.111 ping statistics ---
2 packets transmitted, 0 packets received, 100% packet loss""",
parsed=dict(packets='2', received='0', loss="100%"))]
class ParsePing(unittest.TestCase):
def doTest(self, i):
parsed = api.parse_ping(tests[i]['text'])
self.assertIsInstance(parsed, dict)
for k in parsed.keys():
self.assertEqual(parsed[k], tests[i]['parsed'][k])
def test_0(self):
self.doTest(0)
def test_50(self):
self.doTest(1)
def test_100(self):
self.doTest(2)
class Ping(unittest.TestCase):
def test_ping_ipv4(self):
ping = api.ping("127.0.0.1")
self.assertEqual(ping['status'], 0)
def test_ping_ipv6(self):
ping = api.ping("::1")
self.assertEqual(ping['status'], 0)
class Traceroute(unittest.TestCase):
def test_traceroute_ipv4(self):
r = api.traceroute("127.0.0.1")
self.assertEqual(r['status'], 0)
def test_traceroute_ipv6(self):
r = api.traceroute("::1")
self.assertEqual(r['status'], 0)
if __name__ == '__main__':
unittest.main()