1
|
|
|
"""Module to test the KytosGraph in graph.py.""" |
2
|
|
|
from itertools import combinations |
3
|
|
|
|
4
|
|
|
# module under test |
5
|
|
|
from tests.integration.edges_settings import EdgesSettings |
6
|
|
|
|
7
|
|
|
|
8
|
|
|
class TestResultsEdges(EdgesSettings): |
9
|
|
|
"""Tests for the graph class. |
10
|
|
|
|
11
|
|
|
Tests to see if reflexive searches and impossible searches |
12
|
|
|
show correct results. |
13
|
|
|
""" |
14
|
|
|
|
15
|
|
|
def test_path1(self): |
16
|
|
|
"""Tests paths between all users using unconstrained path algorithm.""" |
17
|
|
|
combos = combinations(["User1", "User2", "User3", "User4"], 2) |
18
|
|
|
self.initializer() |
19
|
|
|
|
20
|
|
|
valid = True |
21
|
|
|
for point_a, point_b in combos: |
22
|
|
|
results = self.get_path(point_a, point_b) |
23
|
|
|
if not results: |
24
|
|
|
valid = False |
25
|
|
|
break |
26
|
|
|
|
27
|
|
|
self.assertNotEqual(valid, False) |
28
|
|
|
|
29
|
|
|
def test_path12(self): |
30
|
|
|
"""Tests paths between all users using unconstrained path algorithm.""" |
31
|
|
|
combos = combinations(["User1", "User2", "User3", "User4", "User5"], 2) |
32
|
|
|
self.initializer() |
33
|
|
|
|
34
|
|
|
valid = True |
35
|
|
|
for point_a, point_b in combos: |
36
|
|
|
results = self.get_path(point_a, point_b) |
37
|
|
|
if not results: |
38
|
|
|
valid = False |
39
|
|
|
break |
40
|
|
|
|
41
|
|
|
self.assertEqual(valid, False) |
42
|
|
|
|
43
|
|
|
def test_path2(self): |
44
|
|
|
"""Tests paths between all users using constrained path algorithm, |
45
|
|
|
with no constraints set. |
46
|
|
|
""" |
47
|
|
|
combos = combinations(["User1", "User2", "User3", "User4"], 2) |
48
|
|
|
self.initializer() |
49
|
|
|
|
50
|
|
|
for point_a, point_b in combos: |
51
|
|
|
results = self.get_path_constrained(point_a, point_b) |
52
|
|
|
self.assertNotEqual(results, []) |
53
|
|
|
|
54
|
|
|
def test_path3_1(self): |
55
|
|
|
"""Tests paths between all users using constrained path algorithm, |
56
|
|
|
with the ownership constraint set to B. |
57
|
|
|
""" |
58
|
|
|
self.assertTrue(self.paths_between_all_users("S4:1", {'ownership': "B"})) |
59
|
|
|
|
60
|
|
|
def test_path3_2(self): |
61
|
|
|
"""Tests paths between all users using constrained path algorithm, |
62
|
|
|
with the ownership constraint set to B. |
63
|
|
|
""" |
64
|
|
|
self.assertTrue(self.paths_between_all_users("S5:2", {'ownership': "B"})) |
65
|
|
|
|
66
|
|
|
def test_path3_3(self): |
67
|
|
|
"""Tests paths between all users using constrained path algorithm, |
68
|
|
|
with the ownership constraint set to B. |
69
|
|
|
""" |
70
|
|
|
self.assertTrue(self.paths_between_all_users("S4:2", {'ownership': "B"})) |
71
|
|
|
|
72
|
|
|
def test_path3_4(self): |
73
|
|
|
"""Tests paths between all users using constrained path algorithm, |
74
|
|
|
with the ownership constraint set to B. |
75
|
|
|
""" |
76
|
|
|
self.assertTrue(self.paths_between_all_users("User1:2", {'ownership': "B"})) |
77
|
|
|
|
78
|
|
|
def test_path3_5(self): |
79
|
|
|
"""Tests paths between all users using constrained path algorithm, |
80
|
|
|
with the ownership constraint set to B. |
81
|
|
|
""" |
82
|
|
|
self.assertTrue(self.paths_between_all_users("S5:4", {'ownership': "B"})) |
83
|
|
|
|
84
|
|
|
def test_path3_6(self): |
85
|
|
|
"""Tests paths between all users using constrained path algorithm, |
86
|
|
|
with the ownership constraint set to B. |
87
|
|
|
""" |
88
|
|
|
self.assertTrue(self.paths_between_all_users("S6:2", {'ownership': "B"})) |
89
|
|
|
|
90
|
|
|
def test_path3_7(self): |
91
|
|
|
"""Tests paths between all users using constrained path algorithm, |
92
|
|
|
with the ownership constraint set to B. |
93
|
|
|
""" |
94
|
|
|
self.assertTrue(self.paths_between_all_users("S6:5", {'ownership': "B"})) |
95
|
|
|
|
96
|
|
|
def test_path3_8(self): |
97
|
|
|
"""Tests paths between all users using constrained path algorithm, |
98
|
|
|
with the ownership constraint set to B. |
99
|
|
|
""" |
100
|
|
|
self.assertTrue(self.paths_between_all_users("S10:1", {'ownership': "B"})) |
101
|
|
|
|
102
|
|
|
def test_path3_9(self): |
103
|
|
|
"""Tests paths between all users using constrained path algorithm, |
104
|
|
|
with the ownership constraint set to B. |
105
|
|
|
""" |
106
|
|
|
self.assertTrue(self.paths_between_all_users("S8:6", {'ownership': "B"})) |
107
|
|
|
|
108
|
|
|
def test_path3_1_0(self): |
109
|
|
|
"""Tests paths between all users using constrained path algorithm, |
110
|
|
|
with the ownership constraint set to B. |
111
|
|
|
""" |
112
|
|
|
self.assertTrue(self.paths_between_all_users("S10:2", {'ownership': "B"})) |
113
|
|
|
|
114
|
|
|
def test_path3_1_1(self): |
115
|
|
|
"""Tests paths between all users using constrained path algorithm, |
116
|
|
|
with the ownership constraint set to B. |
117
|
|
|
""" |
118
|
|
|
self.assertTrue(self.paths_between_all_users("S10:3", {'ownership': "B"})) |
119
|
|
|
|
120
|
|
|
def test_path3_1_2(self): |
121
|
|
|
"""Tests paths between all users using constrained path algorithm, |
122
|
|
|
with the ownership constraint set to B. |
123
|
|
|
""" |
124
|
|
|
self.assertTrue(self.paths_between_all_users("User2:1", {'ownership': "B"})) |
125
|
|
|
|
126
|
|
|
def test_path4_1(self): |
127
|
|
|
"""Tests paths between all users using constrained path algorithm, |
128
|
|
|
with the reliability constraint set to 3. |
129
|
|
|
""" |
130
|
|
|
self.assertTrue(self.paths_between_all_users("S4:1", {'reliability': 3})) |
131
|
|
|
|
132
|
|
|
def test_path4_2(self): |
133
|
|
|
"""Tests paths between all users using constrained path algorithm, |
134
|
|
|
with the reliability constraint set to 3. |
135
|
|
|
""" |
136
|
|
|
self.assertTrue(self.paths_between_all_users("S5:2", {'reliability': 3})) |
137
|
|
|
|
138
|
|
|
def test_path4_3(self): |
139
|
|
|
"""Tests paths between all users using constrained path algorithm, |
140
|
|
|
with the reliability constraint set to 3. |
141
|
|
|
""" |
142
|
|
|
self.assertTrue(self.paths_between_all_users("S5:3", {'reliability': 3})) |
143
|
|
|
|
144
|
|
|
def test_path4_4(self): |
145
|
|
|
"""Tests paths between all users using constrained path algorithm, |
146
|
|
|
with the reliability constraint set to 3. |
147
|
|
|
""" |
148
|
|
|
self.assertTrue(self.paths_between_all_users("S6:1", {'reliability': 3})) |
149
|
|
|
|
150
|
|
|
def test_path5_1(self): |
151
|
|
|
"""Tests paths between all users using constrained path algorithm, |
152
|
|
|
with the reliability constraint set to 3. |
153
|
|
|
""" |
154
|
|
|
self.assertTrue(self.paths_between_all_users("S3:1", {'bandwidth': 100})) |
155
|
|
|
|
156
|
|
|
def test_path5_2(self): |
157
|
|
|
"""Tests paths between all users using constrained path algorithm, |
158
|
|
|
with the reliability constraint set to 3. |
159
|
|
|
""" |
160
|
|
|
self.assertTrue(self.paths_between_all_users("S5:1", {'bandwidth': 100})) |
161
|
|
|
|
162
|
|
|
def test_path5_3(self): |
163
|
|
|
"""Tests paths between all users using constrained path algorithm, |
164
|
|
|
with the reliability constraint set to 3. |
165
|
|
|
""" |
166
|
|
|
self.assertTrue(self.paths_between_all_users("User1:4", {'bandwidth': 100})) |
167
|
|
|
|
168
|
|
|
def test_path5_4(self): |
169
|
|
|
"""Tests paths between all users using constrained path algorithm, |
170
|
|
|
with the reliability constraint set to 3. |
171
|
|
|
""" |
172
|
|
|
self.assertTrue(self.paths_between_all_users("User4:3", {'bandwidth': 100})) |
173
|
|
|
|
174
|
|
|
def test_path9(self): |
175
|
|
|
"""Tests paths between all users using constrained path algorithm, |
176
|
|
|
with the delay constraint set to 50, the bandwidth constraint |
177
|
|
|
set to 100, the reliability constraint set to 3, and the ownership |
178
|
|
|
constraint set to 'B' |
179
|
|
|
|
180
|
|
|
Tests conducted with all but ownership flexible |
181
|
|
|
""" |
182
|
|
|
combos = combinations(["User1", "User2", "User3", "User4"], 2) |
183
|
|
|
self.initializer() |
184
|
|
|
|
185
|
|
|
for point_a, point_b in combos: |
186
|
|
|
results = self.get_path_constrained(point_a, point_b, |
187
|
|
|
base={"ownership": "B"}, |
188
|
|
|
flexible={"delay": 50, |
189
|
|
|
"bandwidth": 100, |
190
|
|
|
"reliability": 3}) |
191
|
|
|
for result in results: |
192
|
|
|
# delay = 50 checks |
193
|
|
|
if "delay" in result["metrics"]: |
194
|
|
|
for path in result["paths"]: |
195
|
|
|
self.assertNotIn("S1:1", path) |
196
|
|
|
self.assertNotIn("S2:1", path) |
197
|
|
|
self.assertNotIn("S3:1", path) |
198
|
|
|
self.assertNotIn("S5:1", path) |
199
|
|
|
self.assertNotIn("S4:2", path) |
200
|
|
|
self.assertNotIn("User1:2", path) |
201
|
|
|
self.assertNotIn("S5:5", path) |
202
|
|
|
self.assertNotIn("S8:2", path) |
203
|
|
|
self.assertNotIn("S5:6", path) |
204
|
|
|
self.assertNotIn("User1:3", path) |
205
|
|
|
self.assertNotIn("S6:3", path) |
206
|
|
|
self.assertNotIn("S9:1", path) |
207
|
|
|
self.assertNotIn("S6:4", path) |
208
|
|
|
self.assertNotIn("S9:2", path) |
209
|
|
|
self.assertNotIn("S6:5", path) |
210
|
|
|
self.assertNotIn("S10:1", path) |
211
|
|
|
self.assertNotIn("S8:5", path) |
212
|
|
|
self.assertNotIn("S9:4", path) |
213
|
|
|
self.assertNotIn("User1:4", path) |
214
|
|
|
self.assertNotIn("User4:3", path) |
215
|
|
|
|
216
|
|
|
# bandwidth = 100 checks |
217
|
|
|
if "bandwidth" in result["metrics"]: |
218
|
|
|
for path in result["paths"]: |
219
|
|
|
self.assertNotIn("S3:1", path) |
220
|
|
|
self.assertNotIn("S5:1", path) |
221
|
|
|
self.assertNotIn("User1:4", path) |
222
|
|
|
self.assertNotIn("User4:3", path) |
223
|
|
|
|
224
|
|
|
# reliability = 3 checks |
225
|
|
|
if "reliability" in result["metrics"]: |
226
|
|
|
for path in result["paths"]: |
227
|
|
|
self.assertNotIn("S4:1", path) |
228
|
|
|
self.assertNotIn("S5:2", path) |
229
|
|
|
self.assertNotIn("S5:3", path) |
230
|
|
|
self.assertNotIn("S6:1", path) |
231
|
|
|
|
232
|
|
|
# ownership = "B" checks |
233
|
|
|
self.assertIn("ownership", result["metrics"]) |
234
|
|
|
for path in result["paths"]: |
235
|
|
|
self.assertNotIn("S4:1", path) |
236
|
|
|
self.assertNotIn("S5:2", path) |
237
|
|
|
self.assertNotIn("S4:2", path) |
238
|
|
|
self.assertNotIn("User1:2", path) |
239
|
|
|
self.assertNotIn("S5:4", path) |
240
|
|
|
self.assertNotIn("S6:2", path) |
241
|
|
|
self.assertNotIn("S6:5", path) |
242
|
|
|
self.assertNotIn("S10:1", path) |
243
|
|
|
self.assertNotIn("S8:6", path) |
244
|
|
|
self.assertNotIn("S10:2", path) |
245
|
|
|
self.assertNotIn("S10:3", path) |
246
|
|
|
self.assertNotIn("User2:1", path) |
247
|
|
|
|
248
|
|
|
def test_path10(self): |
249
|
|
|
"""Tests that TypeError is generated by get_path_constrained |
250
|
|
|
|
251
|
|
|
Tests with ownership using an int type rather than string |
252
|
|
|
""" |
253
|
|
|
self.initializer() |
254
|
|
|
|
255
|
|
|
with self.assertRaises(TypeError): |
256
|
|
|
self.get_path_constrained( |
257
|
|
|
"User1", "User2", base={"ownership": 1}) |
258
|
|
|
|