Test Failed
Pull Request — master (#58)
by
unknown
07:38
created

build.tests.unit.test_search_results1   A

Complexity

Total Complexity 19

Size/Duplication

Total Lines 138
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 93
dl 0
loc 138
rs 10
c 0
b 0
f 0
wmc 19

14 Methods

Rating   Name   Duplication   Size   Complexity  
A TestSearchResults1.test_constrained_path2() 0 5 1
A TestSearchResults1.test_constrained_path3() 0 5 1
A TestSearchResults1.test_constrained_path5() 0 6 2
A TestSearchResults1.test_path4() 0 5 1
A TestSearchResults1.test_path2() 0 5 1
A TestSearchResults1.test_path3() 0 5 1
A TestSearchResults1.test_constrained_path1() 0 5 1
A TestSearchResults1.test_constrained_path4() 0 5 1
A TestSearchResults1.test_path1() 0 5 1
A TestSearchResults1.test_constrained_path8() 0 7 2
A TestSearchResults1.generate_topology() 0 34 1
A TestSearchResults1.test_constrained_path9() 0 6 2
A TestSearchResults1.test_constrained_path6() 0 7 2
A TestSearchResults1.test_constrained_path7() 0 6 2
1
"""Module to test the KytosGraph in graph.py."""
2
from unittest import TestCase
3
from unittest.mock import Mock
4
5
import networkx as nx
6
from kytos.core.interface import Interface
7
from kytos.core.link import Link
8
# Core modules to import
9
from kytos.core.switch import Switch
10
11
# module under test
12
from graph import KytosGraph
13
from tests.unit.test_search_results import TestSearchResults
14
15
16
class TestSearchResults1(TestSearchResults):
17
    '''Tests for the graph class.'''
18
19
    def test_path1(self):
20
        """Tests a simple, definetly possible path"""
21
        self.setup()
22
        results = self.get_path("S1", "S2")
23
        self.assertNotEqual(results, [])
24
25
    def test_constrained_path1(self):
26
        """Tests a simple, definetly possible path"""
27
        self.setup()
28
        results = self.get_path_constrained("S1", "S2")
29
        self.assertNotEqual(results, [])
30
31
    def test_path2(self):
32
        """Tests a simple, impossible path"""
33
        self.setup()
34
        results = self.get_path("S1", "S4")
35
        self.assertEqual(results, [])
36
37
    def test_constrained_path2(self):
38
        """Tests a simple, impossible path"""
39
        self.setup()
40
        results = self.get_path_constrained("S1", "S4")
41
        self.assertEqual(results, [])
42
43
    def test_path3(self):
44
        """Tests a path to self"""
45
        self.setup()
46
        results = self.get_path("S4", "S4")
47
        self.assertNotEqual(results, [])
48
49
    def test_constrained_path3(self):
50
        """Tests a path to self"""
51
        self.setup()
52
        results = self.get_path_constrained("S4", "S4")
53
        self.assertNotEqual(results, [])
54
55
    def test_path4(self):
56
        """Tests a path to self again"""
57
        self.setup()
58
        results = self.get_path("S1", "S1")
59
        self.assertNotEqual(results, [])
60
61
    def test_constrained_path4(self):
62
        """Tests a path to self again"""
63
        self.setup()
64
        results = self.get_path_constrained("S1", "S1")
65
        self.assertNotEqual(results, [])
66
67
    def test_constrained_path5(self):
68
        """Tests constrained path"""
69
        self.setup()
70
        results = self.get_path_constrained("S1", "S3", 0, bandwidth=50)
71
        for result in results:
72
            self.assertNotIn(['S1', 'S1:2', 'S3:2', 'S3'], result["paths"])
73
74
    def test_constrained_path6(self):
75
        """Tests constrained path"""
76
        self.setup()
77
        results = self.get_path_constrained("S1", "S2", 0, ownership="red")
78
        for result in results:
79
            self.assertNotIn(['S1', 'S1:2', 'S3:2', 'S3',
80
                              'S3:1', 'S2:2', 'S2'], result["paths"])
81
82
    def test_constrained_path7(self):
83
        """Tests constrained path"""
84
        self.setup()
85
        results = self.get_path_constrained("S1", "S2", 0, ownership="blue")
86
        for result in results:
87
            self.assertNotIn(['S1', 'S1:1', 'S2:1', 'S2'], result["paths"])
88
89
    def test_constrained_path8(self):
90
        """Tests constrained path, to self AGAIN"""
91
        self.setup()
92
        results = self.get_path_constrained("S5", "S5", 0, ownership="blue")
93
        for result in results:
94
            self.assertNotEqual([], result["paths"])
95
            self.assertIn(['S5'], result["paths"])
96
97
    def test_constrained_path9(self):
98
        """Tests constrained path"""
99
        self.setup()
100
        results = self.get_path_constrained("S1", "S2", 1, ownership="blue")
101
        for result in results:
102
            self.assertNotIn(['S1', 'S1:1', 'S2:1', 'S2'], result["paths"])
103
104
    @staticmethod
105
    def generate_topology():
106
        """Generates a predetermined topology"""
107
        switches = {}
108
        interfaces = {}
109
        links = {}
110
111
        TestSearchResults.create_switch("S1", switches)
112
        TestSearchResults.add_interfaces(2, switches["S1"], interfaces)
113
114
        TestSearchResults.create_switch("S2", switches)
115
        TestSearchResults.add_interfaces(3, switches["S2"], interfaces)
116
117
        TestSearchResults.create_switch("S3", switches)
118
        TestSearchResults.add_interfaces(2, switches["S3"], interfaces)
119
120
        TestSearchResults.create_switch("S4", switches)
121
        TestSearchResults.add_interfaces(2, switches["S4"], interfaces)
122
123
        TestSearchResults.create_switch("S5", switches)
124
125
        links["S1:1<->S2:1"] = Link(interfaces["S1:1"], interfaces["S2:1"])
126
        links["S1:1<->S2:1"].extend_metadata(
127
            {"bandwidth": 50, "ownership": "red"})
128
129
        links["S3:1<->S2:2"] = Link(interfaces["S3:1"], interfaces["S2:2"])
130
        links["S3:1<->S2:2"].extend_metadata(
131
            {"bandwidth": 51, "ownership": "blue"})
132
133
        links["S1:2<->S3:2"] = Link(interfaces["S1:2"], interfaces["S3:2"])
134
        links["S1:2<->S3:2"].extend_metadata(
135
            {"bandwidth": 49, "ownership": "blue"})
136
137
        return (switches, links)
138