Test Failed
Pull Request — master (#68)
by Arturo
03:45 queued 01:41
created

TestResultsEdges.test_path8()   C

Complexity

Conditions 11

Size

Total Lines 72
Code Lines 57

Duplication

Lines 22
Ratio 30.56 %

Importance

Changes 0
Metric Value
cc 11
eloc 57
nop 1
dl 22
loc 72
rs 5.1872
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

Complexity

Complex classes like build.tests.integration.test_results_edges.TestResultsEdges.test_path8() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
"""Module to test the KytosGraph in graph.py."""
2
from itertools import combinations
3
4
# Core modules to import
5
from kytos.core.link import Link
6
7
# module under test
8
from tests.integration.test_results import TestResults
9
10
11
class TestResultsEdges(TestResults):
12
    """Tests for the graph class.
13
14
    Tests to see if reflexive searches and impossible searches
15
    show correct results.
16
    """
17
18
    def test_path1(self):
19
        """Tests paths between all users using unconstrained path algorithm."""
20
        combos = combinations(["User1", "User2", "User3", "User4"], 2)
21
        self.initializer()
22
23
        valid = True
24
        for point_a, point_b in combos:
25
            results = self.get_path(point_a, point_b)
26
            if not results:
27
                valid = False
28
                break
29
30
        self.assertNotEqual(valid, False)
31
32
    def test_path12(self):
33
        """Tests paths between all users using unconstrained path algorithm."""
34
        combos = combinations(["User1", "User2", "User3", "User4", "User5"], 2)
35
        self.initializer()
36
37
        valid = True
38
        for point_a, point_b in combos:
39
            results = self.get_path(point_a, point_b)
40
            if not results:
41
                valid = False
42
                break
43
44
        self.assertEqual(valid, False)
45
46
    def test_path2(self):
47
        """Tests paths between all users using constrained path algorithm,
48
        with no constraints set.
49
        """
50
        combos = combinations(["User1", "User2", "User3", "User4"], 2)
51
        self.initializer()
52
53
        for point_a, point_b in combos:
54
            results = self.get_path_constrained(point_a, point_b)
55
            self.assertNotEqual(results, [])
56
57
    def paths_between_all_users(self, item, base=None):
58
        combos = combinations(["User1", "User2", "User3", "User4"], 2)
59
        self.initializer()
60
61
        if base is not None:
62
            value = {my_key: my_val for (my_key, my_val) in base.items()}
63
            base.update(value)
64
65
        valid = True
66
        for point_a, point_b in combos:
67
            results = self.get_path_constrained(
68
                point_a, point_b, base=base)
69
            for result in results:
70
                for path in result["paths"]:
71
                    if item in path:
72
                        valid = False
73
74
        return valid
75
76
    def test_path3_1(self):
77
        """Tests paths between all users using constrained path algorithm,
78
        with the ownership constraint set to B.
79
        """
80
        self.assertTrue(self.paths_between_all_users("S4:1", {'ownership': "B"}))
81
82
    def test_path3_2(self):
83
        """Tests paths between all users using constrained path algorithm,
84
        with the ownership constraint set to B.
85
        """
86
        self.assertTrue(self.paths_between_all_users("S5:2", {'ownership': "B"}))
87
88
    def test_path3_3(self):
89
        """Tests paths between all users using constrained path algorithm,
90
        with the ownership constraint set to B.
91
        """
92
        self.assertTrue(self.paths_between_all_users("S4:2", {'ownership': "B"}))
93
94
    def test_path3_4(self):
95
        """Tests paths between all users using constrained path algorithm,
96
        with the ownership constraint set to B.
97
        """
98
        self.assertTrue(self.paths_between_all_users("User1:2", {'ownership': "B"}))
99
100
    def test_path3_5(self):
101
        """Tests paths between all users using constrained path algorithm,
102
        with the ownership constraint set to B.
103
        """
104
        self.assertTrue(self.paths_between_all_users("S5:4", {'ownership': "B"}))
105
106
    def test_path3_6(self):
107
        """Tests paths between all users using constrained path algorithm,
108
        with the ownership constraint set to B.
109
        """
110
        self.assertTrue(self.paths_between_all_users("S6:2", {'ownership': "B"}))
111
112
    def test_path3_7(self):
113
        """Tests paths between all users using constrained path algorithm,
114
        with the ownership constraint set to B.
115
        """
116
        self.assertTrue(self.paths_between_all_users("S6:5", {'ownership': "B"}))
117
118
    def test_path3_8(self):
119
        """Tests paths between all users using constrained path algorithm,
120
        with the ownership constraint set to B.
121
        """
122
        self.assertTrue(self.paths_between_all_users("S10:1", {'ownership': "B"}))
123
124
    def test_path3_9(self):
125
        """Tests paths between all users using constrained path algorithm,
126
        with the ownership constraint set to B.
127
        """
128
        self.assertTrue(self.paths_between_all_users("S8:6", {'ownership': "B"}))
129
130
    def test_path3_1_0(self):
131
        """Tests paths between all users using constrained path algorithm,
132
        with the ownership constraint set to B.
133
        """
134
        self.assertTrue(self.paths_between_all_users("S10:2", {'ownership': "B"}))
135
136
    def test_path3_1_1(self):
137
        """Tests paths between all users using constrained path algorithm,
138
        with the ownership constraint set to B.
139
        """
140
        self.assertTrue(self.paths_between_all_users("S10:3", {'ownership': "B"}))
141
142
    def test_path3_1_2(self):
143
        """Tests paths between all users using constrained path algorithm,
144
        with the ownership constraint set to B.
145
        """
146
        self.assertTrue(self.paths_between_all_users("User2:1", {'ownership': "B"}))
147
148
    def test_path4_1(self):
149
        """Tests paths between all users using constrained path algorithm,
150
        with the reliability constraint set to 3.
151
        """
152
        self.assertTrue(self.paths_between_all_users("S4:1", {'reliability': 3}))
153
154
    def test_path4_2(self):
155
        """Tests paths between all users using constrained path algorithm,
156
        with the reliability constraint set to 3.
157
        """
158
        self.assertTrue(self.paths_between_all_users("S5:2", {'reliability': 3}))
159
160
    def test_path4_3(self):
161
        """Tests paths between all users using constrained path algorithm,
162
        with the reliability constraint set to 3.
163
        """
164
        self.assertTrue(self.paths_between_all_users("S5:3", {'reliability': 3}))
165
166
    def test_path4_4(self):
167
        """Tests paths between all users using constrained path algorithm,
168
        with the reliability constraint set to 3.
169
        """
170
        self.assertTrue(self.paths_between_all_users("S6:1", {'reliability': 3}))
171
172
    def test_path5_1(self):
173
        """Tests paths between all users using constrained path algorithm,
174
        with the reliability constraint set to 3.
175
        """
176
        self.assertTrue(self.paths_between_all_users("S3:1", {'bandwidth': 100}))
177
178
    def test_path5_2(self):
179
        """Tests paths between all users using constrained path algorithm,
180
        with the reliability constraint set to 3.
181
        """
182
        self.assertTrue(self.paths_between_all_users("S5:1", {'bandwidth': 100}))
183
184
    def test_path5_3(self):
185
        """Tests paths between all users using constrained path algorithm,
186
        with the reliability constraint set to 3.
187
        """
188
        self.assertTrue(self.paths_between_all_users("User1:4", {'bandwidth': 100}))
189
190
    def test_path5_4(self):
191
        """Tests paths between all users using constrained path algorithm,
192
        with the reliability constraint set to 3.
193
        """
194
        self.assertTrue(self.paths_between_all_users("User4:3", {'bandwidth': 100}))
195
196
    def test_path6_1(self):
197
        """Tests paths between all users using constrained path algorithm,
198
        with the delay constraint set to 50.
199
        """
200
        self.assertTrue(self.paths_between_all_users("S1:1", {'delay': 50}))
201
202
    def test_path6_2(self):
203
        """Tests paths between all users using constrained path algorithm,
204
        with the delay constraint set to 50.
205
        """
206
        self.assertTrue(self.paths_between_all_users("S2:1", {'delay': 50}))
207
208
    def test_path6_3(self):
209
        """Tests paths between all users using constrained path algorithm,
210
        with the delay constraint set to 50.
211
        """
212
        self.assertTrue(self.paths_between_all_users("S3:1", {'delay': 50}))
213
214
    def test_path6_4(self):
215
        """Tests paths between all users using constrained path algorithm,
216
        with the delay constraint set to 50.
217
        """
218
        self.assertTrue(self.paths_between_all_users("S5:1", {'delay': 50}))
219
220
    def test_path6_5(self):
221
        """Tests paths between all users using constrained path algorithm,
222
        with the delay constraint set to 50.
223
        """
224
        self.assertTrue(self.paths_between_all_users("S4:2", {'delay': 50}))
225
226
    def test_path6_6(self):
227
        """Tests paths between all users using constrained path algorithm,
228
        with the delay constraint set to 50.
229
        """
230
        self.assertTrue(self.paths_between_all_users("User1:2", {'delay': 50}))
231
232
    def test_path6_7(self):
233
        """Tests paths between all users using constrained path algorithm,
234
        with the delay constraint set to 50.
235
        """
236
        self.assertTrue(self.paths_between_all_users("S5:5", {'delay': 50}))
237
238
    def test_path6_8(self):
239
        """Tests paths between all users using constrained path algorithm,
240
        with the delay constraint set to 50.
241
        """
242
        self.assertTrue(self.paths_between_all_users("S8:2", {'delay': 50}))
243
244
    def test_path6_9(self):
245
        """Tests paths between all users using constrained path algorithm,
246
        with the delay constraint set to 50.
247
        """
248
        self.assertTrue(self.paths_between_all_users("S5:6", {'delay': 50}))
249
250
    def test_path6_1_0(self):
251
        """Tests paths between all users using constrained path algorithm,
252
        with the delay constraint set to 50.
253
        """
254
        self.assertTrue(self.paths_between_all_users("User1:3", {'delay': 50}))
255
256
    def test_path6_1_1(self):
257
        """Tests paths between all users using constrained path algorithm,
258
        with the delay constraint set to 50.
259
        """
260
        self.assertTrue(self.paths_between_all_users("S6:3", {'delay': 50}))
261
262
    def test_path6_1_2(self):
263
        """Tests paths between all users using constrained path algorithm,
264
        with the delay constraint set to 50.
265
        """
266
        self.assertTrue(self.paths_between_all_users("S9:1", {'delay': 50}))
267
268
    def test_path6_1_3(self):
269
        """Tests paths between all users using constrained path algorithm,
270
        with the delay constraint set to 50.
271
        """
272
        self.assertTrue(self.paths_between_all_users("S6:4", {'delay': 50}))
273
274
    def test_path6_1_4(self):
275
        """Tests paths between all users using constrained path algorithm,
276
        with the delay constraint set to 50.
277
        """
278
        self.assertTrue(self.paths_between_all_users("S9:2", {'delay': 50}))
279
280
    def test_path6_1_5(self):
281
        """Tests paths between all users using constrained path algorithm,
282
        with the delay constraint set to 50.
283
        """
284
        self.assertTrue(self.paths_between_all_users("S6:5", {'delay': 50}))
285
286
    def test_path6_1_6(self):
287
        """Tests paths between all users using constrained path algorithm,
288
        with the delay constraint set to 50.
289
        """
290
        self.assertTrue(self.paths_between_all_users("S6:5", {'delay': 50}))
291
292
    def test_path6_1_7(self):
293
        """Tests paths between all users using constrained path algorithm,
294
        with the delay constraint set to 50.
295
        """
296
        self.assertTrue(self.paths_between_all_users("S10:1", {'delay': 50}))
297
298
    def test_path6_1_8(self):
299
        """Tests paths between all users using constrained path algorithm,
300
        with the delay constraint set to 50.
301
        """
302
        self.assertTrue(self.paths_between_all_users("S8:5", {'delay': 50}))
303
304
    def test_path6_1_9(self):
305
        """Tests paths between all users using constrained path algorithm,
306
        with the delay constraint set to 50.
307
        """
308
        self.assertTrue(self.paths_between_all_users("S9:4", {'delay': 50}))
309
310
    def test_path6_2_0(self):
311
        """Tests paths between all users using constrained path algorithm,
312
        with the delay constraint set to 50.
313
        """
314
        self.assertTrue(self.paths_between_all_users("User1:4", {'delay': 50}))
315
316
    def test_path6_2_1(self):
317
        """Tests paths between all users using constrained path algorithm,
318
        with the delay constraint set to 50.
319
        """
320
        self.assertTrue(self.paths_between_all_users("User4:3", {'delay': 50}))
321
322
    def test_path7_1(self):
323
        """Tests paths between all users using constrained path algorithm,
324
        with the delay constraint set to 50, the bandwidth constraint set
325
        to 100, the reliability constraint set to 3, and the ownership
326
        constraint set to 'B'
327
        """
328
        # delay = 50
329
        self.assertTrue(self.paths_between_all_users("S1:1", {'delay': 50,
330
                                                              'bandwidth': 100,
331
                                                              'ownership': "B"}))
332
333
    def test_path7_2(self):
334
        """Tests paths between all users using constrained path algorithm,
335
        with the delay constraint set to 50, the bandwidth constraint set
336
        to 100, the reliability constraint set to 3, and the ownership
337
        constraint set to 'B'
338
        """
339
        # delay = 50
340
        self.assertTrue(self.paths_between_all_users("S2:1", {'delay': 50,
341
                                                              'bandwidth': 100,
342
                                                              'ownership': "B"}))
343
344
    def test_path7_3(self):
345
        """Tests paths between all users using constrained path algorithm,
346
        with the delay constraint set to 50, the bandwidth constraint set
347
        to 100, the reliability constraint set to 3, and the ownership
348
        constraint set to 'B'
349
        """
350
        # delay = 50
351
        self.assertTrue(self.paths_between_all_users("S3:1", {'delay': 50,
352
                                                              'bandwidth': 100,
353
                                                              'ownership': "B"}))
354
355
    def test_path7_4(self):
356
        """Tests paths between all users using constrained path algorithm,
357
        with the delay constraint set to 50, the bandwidth constraint set
358
        to 100, the reliability constraint set to 3, and the ownership
359
        constraint set to 'B'
360
        """
361
        # delay = 50
362
        self.assertTrue(self.paths_between_all_users("S5:1", {'delay': 50,
363
                                                              'bandwidth': 100,
364
                                                              'ownership': "B"}))
365
366
    def test_path7_5(self):
367
        """Tests paths between all users using constrained path algorithm,
368
        with the delay constraint set to 50, the bandwidth constraint set
369
        to 100, the reliability constraint set to 3, and the ownership
370
        constraint set to 'B'
371
        """
372
        # delay = 50
373
        self.assertTrue(self.paths_between_all_users("S4:2", {'delay': 50,
374
                                                              'bandwidth': 100,
375
                                                              'ownership': "B"}))
376
377
    def test_path7_6(self):
378
        """Tests paths between all users using constrained path algorithm,
379
        with the delay constraint set to 50, the bandwidth constraint set
380
        to 100, the reliability constraint set to 3, and the ownership
381
        constraint set to 'B'
382
        """
383
        # delay = 50
384
        self.assertTrue(self.paths_between_all_users("User1:2", {'delay': 50,
385
                                                                 'bandwidth': 100,
386
                                                                 'ownership': "B"}))
387
388
    def test_path7_7(self):
389
        """Tests paths between all users using constrained path algorithm,
390
        with the delay constraint set to 50, the bandwidth constraint set
391
        to 100, the reliability constraint set to 3, and the ownership
392
        constraint set to 'B'
393
        """
394
        # delay = 50
395
        self.assertTrue(self.paths_between_all_users("S5:5", {'delay': 50,
396
                                                              'bandwidth': 100,
397
                                                              'ownership': "B"}))
398
399
    def test_path7_8(self):
400
        """Tests paths between all users using constrained path algorithm,
401
        with the delay constraint set to 50, the bandwidth constraint set
402
        to 100, the reliability constraint set to 3, and the ownership
403
        constraint set to 'B'
404
        """
405
        # delay = 50
406
        self.assertTrue(self.paths_between_all_users("S8:2", {'delay': 50,
407
                                                              'bandwidth': 100,
408
                                                              'ownership': "B"}))
409
410
    def test_path7_9(self):
411
        """Tests paths between all users using constrained path algorithm,
412
        with the delay constraint set to 50, the bandwidth constraint set
413
        to 100, the reliability constraint set to 3, and the ownership
414
        constraint set to 'B'
415
        """
416
        # delay = 50
417
        self.assertTrue(self.paths_between_all_users("S5:6", {'delay': 50,
418
                                                              'bandwidth': 100,
419
                                                              'ownership': "B"}))
420
421
    def test_path7_1_0(self):
422
        """Tests paths between all users using constrained path algorithm,
423
        with the delay constraint set to 50, the bandwidth constraint set
424
        to 100, the reliability constraint set to 3, and the ownership
425
        constraint set to 'B'
426
        """
427
        # delay = 50
428
        self.assertTrue(self.paths_between_all_users("User1:3", {'delay': 50,
429
                                                                 'bandwidth': 100,
430
                                                                 'ownership': "B"}))
431
432
    def test_path7_1_1(self):
433
        """Tests paths between all users using constrained path algorithm,
434
        with the delay constraint set to 50, the bandwidth constraint set
435
        to 100, the reliability constraint set to 3, and the ownership
436
        constraint set to 'B'
437
        """
438
        # delay = 50
439
        self.assertTrue(self.paths_between_all_users("S6:3", {'delay': 50,
440
                                                              'bandwidth': 100,
441
                                                              'ownership': "B"}))
442
443
    def test_path7_1_2(self):
444
        """Tests paths between all users using constrained path algorithm,
445
        with the delay constraint set to 50, the bandwidth constraint set
446
        to 100, the reliability constraint set to 3, and the ownership
447
        constraint set to 'B'
448
        """
449
        # delay = 50
450
        self.assertTrue(self.paths_between_all_users("S9:1", {'delay': 50,
451
                                                              'bandwidth': 100,
452
                                                              'ownership': "B"}))
453
454
    def test_path7_1_3(self):
455
        """Tests paths between all users using constrained path algorithm,
456
        with the delay constraint set to 50, the bandwidth constraint set
457
        to 100, the reliability constraint set to 3, and the ownership
458
        constraint set to 'B'
459
        """
460
        # delay = 50
461
        self.assertTrue(self.paths_between_all_users("S6:4", {'delay': 50,
462
                                                              'bandwidth': 100,
463
                                                              'ownership': "B"}))
464
465
    def test_path7_1_4(self):
466
        """Tests paths between all users using constrained path algorithm,
467
        with the delay constraint set to 50, the bandwidth constraint set
468
        to 100, the reliability constraint set to 3, and the ownership
469
        constraint set to 'B'
470
        """
471
        # delay = 50
472
        self.assertTrue(self.paths_between_all_users("S9:2", {'delay': 50,
473
                                                              'bandwidth': 100,
474
                                                              'ownership': "B"}))
475
476
    def test_path7_1_5(self):
477
        """Tests paths between all users using constrained path algorithm,
478
        with the delay constraint set to 50, the bandwidth constraint set
479
        to 100, the reliability constraint set to 3, and the ownership
480
        constraint set to 'B'
481
        """
482
        # delay = 50
483
        self.assertTrue(self.paths_between_all_users("S6:5", {'delay': 50,
484
                                                              'bandwidth': 100,
485
                                                              'ownership': "B"}))
486
487
    def test_path7_1_6(self):
488
        """Tests paths between all users using constrained path algorithm,
489
        with the delay constraint set to 50, the bandwidth constraint set
490
        to 100, the reliability constraint set to 3, and the ownership
491
        constraint set to 'B'
492
        """
493
        # delay = 50
494
        self.assertTrue(self.paths_between_all_users("S10:1", {'delay': 50,
495
                                                               'bandwidth': 100,
496
                                                               'ownership': "B"}))
497
498
    def test_path7_1_7(self):
499
        """Tests paths between all users using constrained path algorithm,
500
        with the delay constraint set to 50, the bandwidth constraint set
501
        to 100, the reliability constraint set to 3, and the ownership
502
        constraint set to 'B'
503
        """
504
        # delay = 50
505
        self.assertTrue(self.paths_between_all_users("S8:5", {'delay': 50,
506
                                                              'bandwidth': 100,
507
                                                              'ownership': "B"}))
508
509
    def test_path7_1_8(self):
510
        """Tests paths between all users using constrained path algorithm,
511
        with the delay constraint set to 50, the bandwidth constraint set
512
        to 100, the reliability constraint set to 3, and the ownership
513
        constraint set to 'B'
514
        """
515
        # delay = 50
516
        self.assertTrue(self.paths_between_all_users("S9:4", {'delay': 50,
517
                                                              'bandwidth': 100,
518
                                                              'ownership': "B"}))
519
520
    def test_path7_1_9(self):
521
        """Tests paths between all users using constrained path algorithm,
522
        with the delay constraint set to 50, the bandwidth constraint set
523
        to 100, the reliability constraint set to 3, and the ownership
524
        constraint set to 'B'
525
        """
526
        # delay = 50
527
        self.assertTrue(self.paths_between_all_users("User1:4", {'delay': 50,
528
                                                                 'bandwidth': 100,
529
                                                                 'ownership': "B"}))
530
531
    def test_path7_2_0(self):
532
        """Tests paths between all users using constrained path algorithm,
533
        with the delay constraint set to 50, the bandwidth constraint set
534
        to 100, the reliability constraint set to 3, and the ownership
535
        constraint set to 'B'
536
        """
537
        # delay = 50
538
        self.assertTrue(self.paths_between_all_users("User4:3", {'delay': 50,
539
                                                                 'bandwidth': 100,
540
                                                                 'ownership': "B"}))
541
542
    def test_path7_2_1(self):
543
        """Tests paths between all users using constrained path algorithm,
544
        with the delay constraint set to 50, the bandwidth constraint set
545
        to 100, the reliability constraint set to 3, and the ownership
546
        constraint set to 'B'
547
        """
548
        # bandwidth = 100
549
        self.assertTrue(self.paths_between_all_users("S3:1", {'delay': 50,
550
                                                              'bandwidth': 100,
551
                                                              'ownership': "B"}))
552
553
    def test_path7_2_2(self):
554
        """Tests paths between all users using constrained path algorithm,
555
        with the delay constraint set to 50, the bandwidth constraint set
556
        to 100, the reliability constraint set to 3, and the ownership
557
        constraint set to 'B'
558
        """
559
        # bandwidth = 100
560
        self.assertTrue(self.paths_between_all_users("S5:1", {'delay': 50,
561
                                                              'bandwidth': 100,
562
                                                              'ownership': "B"}))
563
564
    def test_path7_2_3(self):
565
        """Tests paths between all users using constrained path algorithm,
566
        with the delay constraint set to 50, the bandwidth constraint set
567
        to 100, the reliability constraint set to 3, and the ownership
568
        constraint set to 'B'
569
        """
570
        # bandwidth = 100
571
        self.assertTrue(self.paths_between_all_users("User1:4", {'delay': 50,
572
                                                                 'bandwidth': 100,
573
                                                                 'ownership': "B"}))
574
575
    def test_path7_2_4(self):
576
        """Tests paths between all users using constrained path algorithm,
577
        with the delay constraint set to 50, the bandwidth constraint set
578
        to 100, the reliability constraint set to 3, and the ownership
579
        constraint set to 'B'
580
        """
581
        # bandwidth = 100
582
        self.assertTrue(self.paths_between_all_users("User4:3", {'delay': 50,
583
                                                                 'bandwidth': 100,
584
                                                                 'ownership': "B"}))
585
586
    def test_path7_2_5(self):
587
        """Tests paths between all users using constrained path algorithm,
588
        with the delay constraint set to 50, the bandwidth constraint set
589
        to 100, the reliability constraint set to 3, and the ownership
590
        constraint set to 'B'
591
        """
592
        # reliability = 3
593
        self.assertTrue(self.paths_between_all_users("S4:1", {'delay': 50,
594
                                                              'bandwidth': 100,
595
                                                              'ownership': "B"}))
596
597
    def test_path7_2_6(self):
598
        """Tests paths between all users using constrained path algorithm,
599
        with the delay constraint set to 50, the bandwidth constraint set
600
        to 100, the reliability constraint set to 3, and the ownership
601
        constraint set to 'B'
602
        """
603
        # reliability = 3
604
        self.assertTrue(self.paths_between_all_users("S5:2", {'delay': 50,
605
                                                              'bandwidth': 100,
606
                                                              'ownership': "B"}))
607
608
    def test_path7_2_7(self):
609
        """Tests paths between all users using constrained path algorithm,
610
        with the delay constraint set to 50, the bandwidth constraint set
611
        to 100, the reliability constraint set to 3, and the ownership
612
        constraint set to 'B'
613
        """
614
        # reliability = 3
615
        self.assertTrue(self.paths_between_all_users("S5:3", {'delay': 50,
616
                                                              'bandwidth': 100,
617
                                                              'ownership': "B"}))
618
619
    def test_path7_2_8(self):
620
        """Tests paths between all users using constrained path algorithm,
621
        with the delay constraint set to 50, the bandwidth constraint set
622
        to 100, the reliability constraint set to 3, and the ownership
623
        constraint set to 'B'
624
        """
625
        # reliability = 3
626
        self.assertTrue(self.paths_between_all_users("S6:1", {'delay': 50,
627
                                                              'bandwidth': 100,
628
                                                              'ownership': "B"}))
629
630
    def test_path7_2_9(self):
631
        """Tests paths between all users using constrained path algorithm,
632
        with the delay constraint set to 50, the bandwidth constraint set
633
        to 100, the reliability constraint set to 3, and the ownership
634
        constraint set to 'B'
635
        """
636
        # ownership = "B"
637
        self.assertTrue(self.paths_between_all_users("S4:1", {'delay': 50,
638
                                                              'bandwidth': 100,
639
                                                              'ownership': "B"}))
640
641
    def test_path7_3_0(self):
642
        """Tests paths between all users using constrained path algorithm,
643
        with the delay constraint set to 50, the bandwidth constraint set
644
        to 100, the reliability constraint set to 3, and the ownership
645
        constraint set to 'B'
646
        """
647
        # ownership = "B"
648
        self.assertTrue(self.paths_between_all_users("S5:2", {'delay': 50,
649
                                                              'bandwidth': 100,
650
                                                              'ownership': "B"}))
651
652
    def test_path7_3_1(self):
653
        """Tests paths between all users using constrained path algorithm,
654
        with the delay constraint set to 50, the bandwidth constraint set
655
        to 100, the reliability constraint set to 3, and the ownership
656
        constraint set to 'B'
657
        """
658
        # ownership = "B"
659
        self.assertTrue(self.paths_between_all_users("S4:2", {'delay': 50,
660
                                                              'bandwidth': 100,
661
                                                              'ownership': "B"}))
662
663
    def test_path7_3_2(self):
664
        """Tests paths between all users using constrained path algorithm,
665
        with the delay constraint set to 50, the bandwidth constraint set
666
        to 100, the reliability constraint set to 3, and the ownership
667
        constraint set to 'B'
668
        """
669
        # ownership = "B"
670
        self.assertTrue(self.paths_between_all_users("User1:2", {'delay': 50,
671
                                                                 'bandwidth': 100,
672
                                                                 'ownership': "B"}))
673
674
    def test_path7_3_3(self):
675
        """Tests paths between all users using constrained path algorithm,
676
        with the delay constraint set to 50, the bandwidth constraint set
677
        to 100, the reliability constraint set to 3, and the ownership
678
        constraint set to 'B'
679
        """
680
        # ownership = "B"
681
        self.assertTrue(self.paths_between_all_users("S5:4", {'delay': 50,
682
                                                              'bandwidth': 100,
683
                                                              'ownership': "B"}))
684
685
    def test_path7_3_4(self):
686
        """Tests paths between all users using constrained path algorithm,
687
        with the delay constraint set to 50, the bandwidth constraint set
688
        to 100, the reliability constraint set to 3, and the ownership
689
        constraint set to 'B'
690
        """
691
        # ownership = "B"
692
        self.assertTrue(self.paths_between_all_users("S6:2", {'delay': 50,
693
                                                              'bandwidth': 100,
694
                                                              'ownership': "B"}))
695
696
    def test_path7_3_5(self):
697
        """Tests paths between all users using constrained path algorithm,
698
        with the delay constraint set to 50, the bandwidth constraint set
699
        to 100, the reliability constraint set to 3, and the ownership
700
        constraint set to 'B'
701
        """
702
        # ownership = "B"
703
        self.assertTrue(self.paths_between_all_users("S6:5", {'delay': 50,
704
                                                              'bandwidth': 100,
705
                                                              'ownership': "B"}))
706
707
    def test_path7_3_6(self):
708
        """Tests paths between all users using constrained path algorithm,
709
        with the delay constraint set to 50, the bandwidth constraint set
710
        to 100, the reliability constraint set to 3, and the ownership
711
        constraint set to 'B'
712
        """
713
        # ownership = "B"
714
        self.assertTrue(self.paths_between_all_users("S10:1", {'delay': 50,
715
                                                               'bandwidth': 100,
716
                                                               'ownership': "B"}))
717
718
    def test_path7_3_7(self):
719
        """Tests paths between all users using constrained path algorithm,
720
        with the delay constraint set to 50, the bandwidth constraint set
721
        to 100, the reliability constraint set to 3, and the ownership
722
        constraint set to 'B'
723
        """
724
        # ownership = "B"
725
        self.assertTrue(self.paths_between_all_users("S8:6", {'delay': 50,
726
                                                              'bandwidth': 100,
727
                                                              'ownership': "B"}))
728
729
    def test_path7_3_8(self):
730
        """Tests paths between all users using constrained path algorithm,
731
        with the delay constraint set to 50, the bandwidth constraint set
732
        to 100, the reliability constraint set to 3, and the ownership
733
        constraint set to 'B'
734
        """
735
        # ownership = "B"
736
        self.assertTrue(self.paths_between_all_users("S10:2", {'delay': 50,
737
                                                               'bandwidth': 100,
738
                                                               'ownership': "B"}))
739
740
    def test_path7_3_9(self):
741
        """Tests paths between all users using constrained path algorithm,
742
        with the delay constraint set to 50, the bandwidth constraint set
743
        to 100, the reliability constraint set to 3, and the ownership
744
        constraint set to 'B'
745
        """
746
        # ownership = "B"
747
        self.assertTrue(self.paths_between_all_users("S10:3", {'delay': 50,
748
                                                               'bandwidth': 100,
749
                                                               'ownership': "B"}))
750
751
    def test_path7_4_0(self):
752
        """Tests paths between all users using constrained path algorithm,
753
        with the delay constraint set to 50, the bandwidth constraint set
754
        to 100, the reliability constraint set to 3, and the ownership
755
        constraint set to 'B'
756
        """
757
        # ownership = "B"
758
        self.assertTrue(self.paths_between_all_users("User2:1", {'delay': 50,
759
                                                                 'bandwidth': 100,
760
                                                                 'ownership': "B"}))
761
762
    def test_path8(self):
763
        """Tests paths between all users using constrained path algorithm,
764
        with the delay constraint set to 50, the bandwidth constraint
765
        set to 100, the reliability constraint set to 3, and the ownership
766
        constraint set to 'B'
767
768
        Tests conducted with flexibility enabled
769
        """
770
        combos = combinations(["User1", "User2", "User3", "User4"], 2)
771
        self.initializer()
772
773
        for point_a, point_b in combos:
774
            results = self.get_path_constrained(
775
                point_a, point_b, flexible=dict(delay=50, bandwidth=100,
776
                                                reliability=3,
777
                                                ownership="B"))
778
            for result in results:
779
                # delay = 50 checks
780 View Code Duplication
                if "delay" in result["metrics"]:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
781
                    for path in result["paths"]:
782
                        self.assertNotIn("S1:1", path)
783
                        self.assertNotIn("S2:1", path)
784
                        self.assertNotIn("S3:1", path)
785
                        self.assertNotIn("S5:1", path)
786
                        self.assertNotIn("S4:2", path)
787
                        self.assertNotIn("User1:2", path)
788
                        self.assertNotIn("S5:5", path)
789
                        self.assertNotIn("S8:2", path)
790
                        self.assertNotIn("S5:6", path)
791
                        self.assertNotIn("User1:3", path)
792
                        self.assertNotIn("S6:3", path)
793
                        self.assertNotIn("S9:1", path)
794
                        self.assertNotIn("S6:4", path)
795
                        self.assertNotIn("S9:2", path)
796
                        self.assertNotIn("S6:5", path)
797
                        self.assertNotIn("S10:1", path)
798
                        self.assertNotIn("S8:5", path)
799
                        self.assertNotIn("S9:4", path)
800
                        self.assertNotIn("User1:4", path)
801
                        self.assertNotIn("User4:3", path)
802
803
                # bandwidth = 100 checks
804
                if "bandwidth" in result["metrics"]:
805
                    for path in result["paths"]:
806
                        self.assertNotIn("S3:1", path)
807
                        self.assertNotIn("S5:1", path)
808
                        self.assertNotIn("User1:4", path)
809
                        self.assertNotIn("User4:3", path)
810
811
                # reliability = 3 checks
812
                if "reliability" in result["metrics"]:
813
                    for path in result["paths"]:
814
                        self.assertNotIn("S4:1", path)
815
                        self.assertNotIn("S5:2", path)
816
                        self.assertNotIn("S5:3", path)
817
                        self.assertNotIn("S6:1", path)
818
819
                # ownership = "B" checks
820
                if "ownership" in result["metrics"]:
821
                    for path in result["paths"]:
822
                        self.assertNotIn("S4:1", path)
823
                        self.assertNotIn("S5:2", path)
824
                        self.assertNotIn("S4:2", path)
825
                        self.assertNotIn("User1:2", path)
826
                        self.assertNotIn("S5:4", path)
827
                        self.assertNotIn("S6:2", path)
828
                        self.assertNotIn("S6:5", path)
829
                        self.assertNotIn("S10:1", path)
830
                        self.assertNotIn("S8:6", path)
831
                        self.assertNotIn("S10:2", path)
832
                        self.assertNotIn("S10:3", path)
833
                        self.assertNotIn("User2:1", path)
834
835
    def test_path9(self):
836
        """Tests paths between all users using constrained path algorithm,
837
        with the delay constraint set to 50, the bandwidth constraint
838
        set to 100, the reliability constraint set to 3, and the ownership
839
        constraint set to 'B'
840
841
        Tests conducted with all but ownership flexible
842
        """
843
        combos = combinations(["User1", "User2", "User3", "User4"], 2)
844
        self.initializer()
845
846
        for point_a, point_b in combos:
847
            results = self.get_path_constrained(point_a, point_b,
848
                                                base={"ownership": "B"},
849
                                                flexible={"delay": 50,
850
                                                          "bandwidth": 100,
851
                                                          "reliability": 3})
852
            for result in results:
853
                # delay = 50 checks
854 View Code Duplication
                if "delay" in result["metrics"]:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
855
                    for path in result["paths"]:
856
                        self.assertNotIn("S1:1", path)
857
                        self.assertNotIn("S2:1", path)
858
                        self.assertNotIn("S3:1", path)
859
                        self.assertNotIn("S5:1", path)
860
                        self.assertNotIn("S4:2", path)
861
                        self.assertNotIn("User1:2", path)
862
                        self.assertNotIn("S5:5", path)
863
                        self.assertNotIn("S8:2", path)
864
                        self.assertNotIn("S5:6", path)
865
                        self.assertNotIn("User1:3", path)
866
                        self.assertNotIn("S6:3", path)
867
                        self.assertNotIn("S9:1", path)
868
                        self.assertNotIn("S6:4", path)
869
                        self.assertNotIn("S9:2", path)
870
                        self.assertNotIn("S6:5", path)
871
                        self.assertNotIn("S10:1", path)
872
                        self.assertNotIn("S8:5", path)
873
                        self.assertNotIn("S9:4", path)
874
                        self.assertNotIn("User1:4", path)
875
                        self.assertNotIn("User4:3", path)
876
877
                # bandwidth = 100 checks
878
                if "bandwidth" in result["metrics"]:
879
                    for path in result["paths"]:
880
                        self.assertNotIn("S3:1", path)
881
                        self.assertNotIn("S5:1", path)
882
                        self.assertNotIn("User1:4", path)
883
                        self.assertNotIn("User4:3", path)
884
885
                # reliability = 3 checks
886
                if "reliability" in result["metrics"]:
887
                    for path in result["paths"]:
888
                        self.assertNotIn("S4:1", path)
889
                        self.assertNotIn("S5:2", path)
890
                        self.assertNotIn("S5:3", path)
891
                        self.assertNotIn("S6:1", path)
892
893
                # ownership = "B" checks
894
                self.assertIn("ownership", result["metrics"])
895
                for path in result["paths"]:
896
                    self.assertNotIn("S4:1", path)
897
                    self.assertNotIn("S5:2", path)
898
                    self.assertNotIn("S4:2", path)
899
                    self.assertNotIn("User1:2", path)
900
                    self.assertNotIn("S5:4", path)
901
                    self.assertNotIn("S6:2", path)
902
                    self.assertNotIn("S6:5", path)
903
                    self.assertNotIn("S10:1", path)
904
                    self.assertNotIn("S8:6", path)
905
                    self.assertNotIn("S10:2", path)
906
                    self.assertNotIn("S10:3", path)
907
                    self.assertNotIn("User2:1", path)
908
909
    def test_path10(self):
910
        """Tests that TypeError is generated by get_path_constrained
911
912
        Tests with ownership using an int type rather than string
913
        """
914
        self.initializer()
915
916
        with self.assertRaises(TypeError):
917
            self.get_path_constrained(
918
                "User1", "User2", base={"ownership": 1})
919
920
    @staticmethod
921
    def generate_topology():
922
        """Generates a predetermined topology"""
923
        switches = {}
924
        interfaces = {}
925
        links = {}
926
927
        TestResults.create_switch("S1", switches)
928
        TestResults.add_interfaces(2, switches["S1"], interfaces)
929
930
        TestResults.create_switch("S2", switches)
931
        TestResults.add_interfaces(2, switches["S2"], interfaces)
932
933
        TestResults.create_switch("S3", switches)
934
        TestResults.add_interfaces(6, switches["S3"], interfaces)
935
936
        TestResults.create_switch("S4", switches)
937
        TestResults.add_interfaces(2, switches["S4"], interfaces)
938
939
        TestResults.create_switch("S5", switches)
940
        TestResults.add_interfaces(6, switches["S5"], interfaces)
941
942
        TestResults.create_switch("S6", switches)
943
        TestResults.add_interfaces(5, switches["S6"], interfaces)
944
945
        TestResults.create_switch("S7", switches)
946
        TestResults.add_interfaces(2, switches["S7"], interfaces)
947
948
        TestResults.create_switch("S8", switches)
949
        TestResults.add_interfaces(8, switches["S8"], interfaces)
950
951
        TestResults.create_switch("S9", switches)
952
        TestResults.add_interfaces(4, switches["S9"], interfaces)
953
954
        TestResults.create_switch("S10", switches)
955
        TestResults.add_interfaces(3, switches["S10"], interfaces)
956
957
        TestResults.create_switch("S11", switches)
958
        TestResults.add_interfaces(3, switches["S11"], interfaces)
959
960
        TestResults.create_switch("User1", switches)
961
        TestResults.add_interfaces(4, switches["User1"], interfaces)
962
963
        TestResults.create_switch("User2", switches)
964
        TestResults.add_interfaces(2, switches["User2"], interfaces)
965
966
        TestResults.create_switch("User3", switches)
967
        TestResults.add_interfaces(2, switches["User3"], interfaces)
968
969
        TestResults.create_switch("User4", switches)
970
        TestResults.add_interfaces(3, switches["User4"], interfaces)
971
972
        TestResultsEdges._fill_links(links, interfaces)
973
974
        TestResultsEdges._add_metadata_to_links(links)
975
976
        return switches, links
977
978
    @staticmethod
979
    def _add_metadata_to_links(links):
980
        links["S1:1<->S2:1"].extend_metadata(
981
            {"reliability": 5, "bandwidth": 100, "delay": 105})
982
983
        links["S1:2<->User1:1"].extend_metadata(
984
            {"reliability": 5, "bandwidth": 100, "delay": 1})
985
986
        links["S2:2<->User4:1"].extend_metadata(
987
            {"reliability": 5, "bandwidth": 100, "delay": 10})
988
989
        links["S3:1<->S5:1"].extend_metadata(
990
            {"reliability": 5, "bandwidth": 10, "delay": 112})
991
992
        links["S3:2<->S7:1"].extend_metadata(
993
            {"reliability": 5, "bandwidth": 100, "delay": 1})
994
995
        links["S3:3<->S8:1"].extend_metadata(
996
            {"reliability": 5, "bandwidth": 100, "delay": 1})
997
998
        links["S3:4<->S11:1"].extend_metadata(
999
            {"reliability": 3, "bandwidth": 100, "delay": 6})
1000
1001
        links["S3:5<->User3:1"].extend_metadata(
1002
            {"reliability": 5, "bandwidth": 100, "delay": 1})
1003
1004
        links["S3:6<->User4:2"].extend_metadata(
1005
            {"reliability": 5, "bandwidth": 100, "delay": 10})
1006
1007
        links["S4:1<->S5:2"].extend_metadata(
1008
            {"reliability": 1, "bandwidth": 100, "delay": 30,
1009
             "ownership": "A"})
1010
1011
        links["S4:2<->User1:2"].extend_metadata(
1012
            {"reliability": 3, "bandwidth": 100, "delay": 110,
1013
             "ownership": "A"})
1014
1015
        links["S5:3<->S6:1"].extend_metadata(
1016
            {"reliability": 1, "bandwidth": 100, "delay": 40})
1017
1018
        links["S5:4<->S6:2"].extend_metadata(
1019
            {"reliability": 3, "bandwidth": 100, "delay": 40,
1020
             "ownership": "A"})
1021
1022
        links["S5:5<->S8:2"].extend_metadata(
1023
            {"reliability": 5, "bandwidth": 100, "delay": 112})
1024
1025
        links["S5:6<->User1:3"].extend_metadata(
1026
            {"reliability": 3, "bandwidth": 100, "delay": 60})
1027
1028
        links["S6:3<->S9:1"].extend_metadata(
1029
            {"reliability": 3, "bandwidth": 100, "delay": 60})
1030
1031
        links["S6:4<->S9:2"].extend_metadata(
1032
            {"reliability": 5, "bandwidth": 100, "delay": 62})
1033
1034
        links["S6:5<->S10:1"].extend_metadata(
1035
            {"bandwidth": 100, "delay": 108, "ownership": "A"})
1036
1037
        links["S7:2<->S8:3"].extend_metadata(
1038
            {"reliability": 5, "bandwidth": 100, "delay": 1})
1039
1040
        links["S8:4<->S9:3"].extend_metadata(
1041
            {"reliability": 3, "bandwidth": 100, "delay": 32})
1042
1043
        links["S8:5<->S9:4"].extend_metadata(
1044
            {"reliability": 3, "bandwidth": 100, "delay": 110})
1045
1046
        links["S8:6<->S10:2"].extend_metadata(
1047
            {"reliability": 5, "bandwidth": 100, "ownership": "A"})
1048
1049
        links["S8:7<->S11:2"].extend_metadata(
1050
            {"reliability": 3, "bandwidth": 100, "delay": 7})
1051
1052
        links["S8:8<->User3:2"].extend_metadata(
1053
            {"reliability": 5, "bandwidth": 100, "delay": 1})
1054
1055
        links["S10:3<->User2:1"].extend_metadata(
1056
            {"reliability": 3, "bandwidth": 100, "delay": 10,
1057
             "ownership": "A"})
1058
1059
        links["S11:3<->User2:2"].extend_metadata(
1060
            {"reliability": 3, "bandwidth": 100, "delay": 6})
1061
1062
        links["User1:4<->User4:3"].extend_metadata(
1063
            {"reliability": 5, "bandwidth": 10, "delay": 105})
1064
1065
    @staticmethod
1066
    def _fill_links(links, interfaces):
1067
        links["S1:1<->S2:1"] = Link(interfaces["S1:1"], interfaces["S2:1"])
1068
1069
        links["S1:2<->User1:1"] = Link(interfaces["S1:2"], interfaces["User1:1"])
1070
1071
        links["S2:2<->User4:1"] = Link(interfaces["S2:2"], interfaces["User4:1"])
1072
1073
        links["S3:1<->S5:1"] = Link(interfaces["S3:1"], interfaces["S5:1"])
1074
1075
        links["S3:2<->S7:1"] = Link(interfaces["S3:2"], interfaces["S7:1"])
1076
1077
        links["S3:3<->S8:1"] = Link(interfaces["S3:3"], interfaces["S8:1"])
1078
1079
        links["S3:4<->S11:1"] = Link(interfaces["S3:4"], interfaces["S11:1"])
1080
1081
        links["S3:5<->User3:1"] = Link(interfaces["S3:5"], interfaces["User3:1"])
1082
1083
        links["S3:6<->User4:2"] = Link(interfaces["S3:6"], interfaces["User4:2"])
1084
1085
        links["S4:1<->S5:2"] = Link(interfaces["S4:1"], interfaces["S5:2"])
1086
1087
        links["S4:2<->User1:2"] = Link(interfaces["S4:2"], interfaces["User1:2"])
1088
1089
        links["S5:3<->S6:1"] = Link(interfaces["S5:3"], interfaces["S6:1"])
1090
1091
        links["S5:4<->S6:2"] = Link(interfaces["S5:4"], interfaces["S6:2"])
1092
1093
        links["S5:5<->S8:2"] = Link(interfaces["S5:5"], interfaces["S8:2"])
1094
1095
        links["S5:6<->User1:3"] = Link(interfaces["S5:6"], interfaces["User1:3"])
1096
1097
        links["S6:3<->S9:1"] = Link(interfaces["S6:3"], interfaces["S9:1"])
1098
1099
        links["S6:4<->S9:2"] = Link(interfaces["S6:4"], interfaces["S9:2"])
1100
1101
        links["S6:5<->S10:1"] = Link(interfaces["S6:5"], interfaces["S10:1"])
1102
1103
        links["S7:2<->S8:3"] = Link(interfaces["S7:2"], interfaces["S8:3"])
1104
1105
        links["S8:4<->S9:3"] = Link(interfaces["S8:4"], interfaces["S9:3"])
1106
1107
        links["S8:5<->S9:4"] = Link(interfaces["S8:5"], interfaces["S9:4"])
1108
1109
        links["S8:6<->S10:2"] = Link(interfaces["S8:6"], interfaces["S10:2"])
1110
1111
        links["S8:7<->S11:2"] = Link(interfaces["S8:7"], interfaces["S11:2"])
1112
1113
        links["S8:8<->User3:2"] = Link(interfaces["S8:8"], interfaces["User3:2"])
1114
1115
        links["S10:3<->User2:1"] = Link(interfaces["S10:3"], interfaces["User2:1"])
1116
1117
        links["S11:3<->User2:2"] = Link(interfaces["S11:3"], interfaces["User2:2"])
1118
1119
        links["User1:4<->User4:3"] = Link(interfaces["User1:4"], interfaces["User4:3"])
1120