|
1
|
|
|
"""Test exceptions.py""" |
|
2
|
|
|
|
|
3
|
1 |
|
from napps.kytos.telemetry_int.exceptions import ( |
|
4
|
|
|
UnrecoverableError, |
|
5
|
|
|
EVCError, |
|
6
|
|
|
ProxyPortError, |
|
7
|
|
|
ProxyPortNotFound, |
|
8
|
|
|
ProxyPortMetadataNotFound, |
|
9
|
|
|
ProxyPortDestNotFound, |
|
10
|
|
|
ProxyPortConflict, |
|
11
|
|
|
ProxyPortRequired, |
|
12
|
|
|
ProxyPortAsymmetric, |
|
13
|
|
|
ProxyPortStatusNotUP, |
|
14
|
|
|
ProxyPortSameSourceIntraEVC, |
|
15
|
|
|
ProxyPortShared, |
|
16
|
|
|
EVCHasNoINT, |
|
17
|
|
|
EVCHasINT, |
|
18
|
|
|
EVCNotFound, |
|
19
|
|
|
FlowsNotFound, |
|
20
|
|
|
PriorityOverflow, |
|
21
|
|
|
) |
|
22
|
|
|
|
|
23
|
|
|
|
|
24
|
1 |
|
class TestExceptions: |
|
25
|
|
|
"""Test class for all exception classes.""" |
|
26
|
|
|
|
|
27
|
1 |
|
def setup_method(self): |
|
28
|
|
|
"""Set up test fixtures.""" |
|
29
|
1 |
|
self.evc_id = "test_evc_id" |
|
30
|
1 |
|
self.message = "test message" |
|
31
|
|
|
|
|
32
|
1 |
|
def test_unrecoverable_error(self): |
|
33
|
|
|
"""Test UnrecoverableError exception.""" |
|
34
|
1 |
|
message = "Test error message" |
|
35
|
1 |
|
error = UnrecoverableError(message) |
|
36
|
|
|
|
|
37
|
1 |
|
assert error.message == message |
|
38
|
1 |
|
assert str(error) == message |
|
39
|
|
|
|
|
40
|
1 |
|
def test_evc_error(self): |
|
41
|
|
|
"""Test EVCError exception.""" |
|
42
|
1 |
|
error = EVCError(self.evc_id, self.message) |
|
43
|
|
|
|
|
44
|
1 |
|
assert error.evc_id == self.evc_id |
|
45
|
1 |
|
assert error.message == self.message |
|
46
|
1 |
|
assert str(error) == f"EVC {self.evc_id} {self.message}" |
|
47
|
|
|
|
|
48
|
1 |
|
def test_evc_has_no_int_default_message(self): |
|
49
|
|
|
"""Test EVCHasNoINT with default message.""" |
|
50
|
1 |
|
error = EVCHasNoINT(self.evc_id) |
|
51
|
|
|
|
|
52
|
1 |
|
assert error.evc_id == self.evc_id |
|
53
|
1 |
|
assert error.message == "INT isn't enabled" |
|
54
|
1 |
|
assert str(error) == f"EVC {self.evc_id} INT isn't enabled" |
|
55
|
|
|
|
|
56
|
1 |
|
def test_evc_has_no_int_custom_message(self): |
|
57
|
|
|
"""Test EVCHasNoINT with custom message.""" |
|
58
|
1 |
|
custom_message = "custom message" |
|
59
|
1 |
|
error = EVCHasNoINT(self.evc_id, custom_message) |
|
60
|
|
|
|
|
61
|
1 |
|
assert error.evc_id == self.evc_id |
|
62
|
1 |
|
assert error.message == custom_message |
|
63
|
1 |
|
assert str(error) == f"EVC {self.evc_id} {custom_message}" |
|
64
|
|
|
|
|
65
|
1 |
|
def test_evc_has_int_default_message(self): |
|
66
|
|
|
"""Test EVCHasINT with default message.""" |
|
67
|
1 |
|
error = EVCHasINT(self.evc_id) |
|
68
|
|
|
|
|
69
|
1 |
|
assert error.evc_id == self.evc_id |
|
70
|
1 |
|
assert error.message == "INT is already enabled" |
|
71
|
1 |
|
assert str(error) == f"EVC {self.evc_id} INT is already enabled" |
|
72
|
|
|
|
|
73
|
1 |
|
def test_evc_has_int_custom_message(self): |
|
74
|
|
|
"""Test EVCHasINT with custom message.""" |
|
75
|
1 |
|
custom_message = "custom message" |
|
76
|
1 |
|
error = EVCHasINT(self.evc_id, custom_message) |
|
77
|
|
|
|
|
78
|
1 |
|
assert error.evc_id == self.evc_id |
|
79
|
1 |
|
assert error.message == custom_message |
|
80
|
1 |
|
assert str(error) == f"EVC {self.evc_id} {custom_message}" |
|
81
|
|
|
|
|
82
|
1 |
|
def test_evc_not_found_default_message(self): |
|
83
|
|
|
"""Test EVCNotFound with default message.""" |
|
84
|
1 |
|
error = EVCNotFound(self.evc_id) |
|
85
|
|
|
|
|
86
|
1 |
|
assert error.evc_id == self.evc_id |
|
87
|
1 |
|
assert error.message == "not found" |
|
88
|
1 |
|
assert str(error) == f"EVC {self.evc_id} not found" |
|
89
|
|
|
|
|
90
|
1 |
|
def test_evc_not_found_custom_message(self): |
|
91
|
|
|
"""Test EVCNotFound with custom message.""" |
|
92
|
1 |
|
custom_message = "custom message" |
|
93
|
1 |
|
error = EVCNotFound(self.evc_id, custom_message) |
|
94
|
|
|
|
|
95
|
1 |
|
assert error.evc_id == self.evc_id |
|
96
|
1 |
|
assert error.message == custom_message |
|
97
|
1 |
|
assert str(error) == f"EVC {self.evc_id} {custom_message}" |
|
98
|
|
|
|
|
99
|
1 |
|
def test_flows_not_found_default_message(self): |
|
100
|
|
|
"""Test FlowsNotFound with default message.""" |
|
101
|
1 |
|
error = FlowsNotFound(self.evc_id) |
|
102
|
|
|
|
|
103
|
1 |
|
assert error.evc_id == self.evc_id |
|
104
|
1 |
|
assert error.message == "flows not found" |
|
105
|
1 |
|
assert str(error) == f"EVC {self.evc_id} flows not found" |
|
106
|
|
|
|
|
107
|
1 |
|
def test_flows_not_found_custom_message(self): |
|
108
|
|
|
"""Test FlowsNotFound with custom message.""" |
|
109
|
1 |
|
custom_message = "custom message" |
|
110
|
1 |
|
error = FlowsNotFound(self.evc_id, custom_message) |
|
111
|
|
|
|
|
112
|
1 |
|
assert error.evc_id == self.evc_id |
|
113
|
1 |
|
assert error.message == custom_message |
|
114
|
1 |
|
assert str(error) == f"EVC {self.evc_id} {custom_message}" |
|
115
|
|
|
|
|
116
|
1 |
|
def test_priority_overflow_default_message(self): |
|
117
|
|
|
"""Test PriorityOverflow with default message.""" |
|
118
|
1 |
|
error = PriorityOverflow(self.evc_id) |
|
119
|
|
|
|
|
120
|
1 |
|
assert error.evc_id == self.evc_id |
|
121
|
1 |
|
assert error.message == "setting a higher priority would overflow" |
|
122
|
1 |
|
assert "would overflow" in str(error) |
|
123
|
|
|
|
|
124
|
1 |
|
def test_priority_overflow_custom_message(self): |
|
125
|
|
|
"""Test PriorityOverflow with custom message.""" |
|
126
|
1 |
|
custom_message = "custom message" |
|
127
|
1 |
|
error = PriorityOverflow(self.evc_id, custom_message) |
|
128
|
|
|
|
|
129
|
1 |
|
assert error.evc_id == self.evc_id |
|
130
|
1 |
|
assert error.message == custom_message |
|
131
|
1 |
|
assert str(error) == f"EVC {self.evc_id} {custom_message}" |
|
132
|
|
|
|
|
133
|
1 |
|
def test_exception_inheritance(self): |
|
134
|
|
|
"""Test exception inheritance hierarchy.""" |
|
135
|
1 |
|
assert issubclass(EVCError, UnrecoverableError) |
|
136
|
1 |
|
assert issubclass(ProxyPortError, EVCError) |
|
137
|
1 |
|
assert issubclass(ProxyPortNotFound, ProxyPortError) |
|
138
|
1 |
|
assert issubclass(ProxyPortMetadataNotFound, ProxyPortNotFound) |
|
139
|
1 |
|
assert issubclass(ProxyPortDestNotFound, ProxyPortNotFound) |
|
140
|
1 |
|
assert issubclass(ProxyPortConflict, ProxyPortError) |
|
141
|
1 |
|
assert issubclass(ProxyPortRequired, ProxyPortConflict) |
|
142
|
1 |
|
assert issubclass(ProxyPortAsymmetric, ProxyPortConflict) |
|
143
|
1 |
|
assert issubclass(ProxyPortStatusNotUP, ProxyPortConflict) |
|
144
|
1 |
|
assert issubclass(ProxyPortSameSourceIntraEVC, ProxyPortConflict) |
|
145
|
1 |
|
assert issubclass(ProxyPortShared, ProxyPortConflict) |
|
146
|
1 |
|
assert issubclass(EVCHasNoINT, EVCError) |
|
147
|
1 |
|
assert issubclass(EVCHasINT, EVCError) |
|
148
|
1 |
|
assert issubclass(EVCNotFound, EVCError) |
|
149
|
1 |
|
assert issubclass(FlowsNotFound, EVCError) |
|
150
|
1 |
|
assert issubclass(PriorityOverflow, EVCError) |
|
151
|
|
|
|
|
152
|
1 |
|
def test_proxy_port_error_instantiation(self): |
|
153
|
|
|
"""Test ProxyPortError and its subclasses can be instantiated.""" |
|
154
|
1 |
|
errors = [ |
|
155
|
|
|
ProxyPortError(self.evc_id, self.message), |
|
156
|
|
|
ProxyPortNotFound(self.evc_id, self.message), |
|
157
|
|
|
ProxyPortMetadataNotFound(self.evc_id, self.message), |
|
158
|
|
|
ProxyPortDestNotFound(self.evc_id, self.message), |
|
159
|
|
|
ProxyPortConflict(self.evc_id, self.message), |
|
160
|
|
|
ProxyPortRequired(self.evc_id, self.message), |
|
161
|
|
|
ProxyPortAsymmetric(self.evc_id, self.message), |
|
162
|
|
|
ProxyPortStatusNotUP(self.evc_id, self.message), |
|
163
|
|
|
ProxyPortSameSourceIntraEVC(self.evc_id, self.message), |
|
164
|
|
|
ProxyPortShared(self.evc_id, self.message), |
|
165
|
|
|
] |
|
166
|
|
|
|
|
167
|
1 |
|
for error in errors: |
|
168
|
1 |
|
assert error.evc_id == self.evc_id |
|
169
|
1 |
|
assert error.message == self.message |
|
170
|
|
|
assert str(error) == f"EVC {self.evc_id} {self.message}" |
|
171
|
|
|
|