-
Notifications
You must be signed in to change notification settings - Fork 0
/
input_processing_test.py
87 lines (73 loc) · 3.05 KB
/
input_processing_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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
from socket import AF_INET
from unittest import TestCase, main
from unittest.mock import Mock, patch
from input_processing import validate_entry
from packet import ResponseEntry
from routingtable import RoutingTable
from validate_data import MAX_ID, MAX_METRIC, MIN_ID, MIN_METRIC
class TestValidateEntry(TestCase):
table: RoutingTable
def setUp(self):
self.table = RoutingTable(2, 1, 1, 1)
def assertOutputEqual(self, expected: str, logger: Mock):
actual = ""
for item in logger.call_args:
if isinstance(item, tuple):
for i in item:
actual += i
self.assertEqual(expected, actual)
def test_valid_entry(self):
entry = ResponseEntry(afi=AF_INET, router_id=1, metric=1)
self.assertEqual(validate_entry(self.table, entry), True)
@patch("input_processing.logger")
def test_afi(self, logger):
entry = ResponseEntry(afi=1, router_id=1, metric=1)
self.assertEqual(validate_entry(self.table, entry), False)
self.assertOutputEqual(
"The value 1 for AFI does not match the expected "
"value of AF_INET = 2.",
logger,
)
@patch("input_processing.logger")
def test_router_id(self, logger):
self.table = RoutingTable(1, 1, 1, 1)
entry = ResponseEntry(afi=AF_INET, router_id=1, metric=17)
self.assertEqual(validate_entry(self.table, entry), False)
@patch("input_processing.logger")
def test_router_id_low(self, logger):
entry = ResponseEntry(afi=AF_INET, router_id=0, metric=1)
self.assertEqual(validate_entry(self.table, entry), False)
self.assertOutputEqual(
"The entry's router id of 0 should be an integer between "
f"{MIN_ID} and {MAX_ID}, inclusive.",
logger,
)
@patch("input_processing.logger")
def test_router_id_high(self, logger):
entry = ResponseEntry(afi=AF_INET, router_id=64001, metric=1)
self.assertEqual(validate_entry(self.table, entry), False)
self.assertOutputEqual(
"The entry's router id of 64001 should be an integer between "
f"{MIN_ID} and {MAX_ID}, inclusive.",
logger,
)
@patch("input_processing.logger")
def test_metric_low(self, logger):
entry = ResponseEntry(afi=AF_INET, router_id=1, metric=0)
self.assertEqual(validate_entry(self.table, entry), False)
self.assertOutputEqual(
"The entry's metric of 0 was not between the "
f"expected range of {MIN_METRIC} and {MAX_METRIC}, inclusive.",
logger,
)
@patch("input_processing.logger")
def test_metric_high(self, logger):
entry = ResponseEntry(afi=AF_INET, router_id=1, metric=17)
self.assertEqual(validate_entry(self.table, entry), False)
self.assertOutputEqual(
"The entry's metric of 17 was not between the "
f"expected range of {MIN_METRIC} and {MAX_METRIC}, inclusive.",
logger,
)
if __name__ == "__main__":
main()