build.tests.integration.test_paths_simple   A
last analyzed

Complexity

Total Complexity 17

Size/Duplication

Total Lines 177
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 112
dl 0
loc 177
ccs 101
cts 101
cp 1
rs 10
c 0
b 0
f 0
wmc 17

10 Methods

Rating   Name   Duplication   Size   Complexity  
A TestPathsSimple.test_path_s1_s3_constrained_red() 0 10 1
A TestPathsSimple.test_path_s1_s2() 0 13 2
A TestPathsSimple.test_path_to_self() 0 10 2
A TestPathsSimple.test_path_s1_s3_constrained_blue() 0 15 2
A TestPathsSimple.test_path_s1_s4() 0 5 1
A TestPathsSimple.test_path_s1_s3_constrained_bandwidth() 0 19 2
A TestPathsSimple.test_path_s1_s2_constrained_not_owner_red() 0 15 2
A TestPathsSimple.test_path_s1_s2_constrained_not_owner_blue_red() 0 10 1
A TestPathsSimple.generate_topology() 0 41 2
A TestPathsSimple.test_path_s1_s2_constrained_not_owner_blue() 0 15 2
1
"""Module to test the KytosGraph in graph.py."""
2 1
from kytos.core.link import Link
3
4
# module under test
5
# pylint: disable=import-error
6 1
from tests.integration.test_paths import TestPaths
7
8
9 1
class TestPathsSimple(TestPaths):
10
    """Tests for the graph class.
11
12
    Tests if the paths returned have only legal edges.
13
    """
14
15 1
    def test_path_s1_s2(self):
16
        """Tests a simple, possible path"""
17 1
        self.initializer()
18
19 1
        source = "S1"
20 1
        destination = "S2"
21 1
        results = self.graph.constrained_k_shortest_paths("S1", "S2")
22
23 1
        assert results
24 1
        for result in results:
25 1
            path = result["hops"]
26 1
            assert source == path[0]
27 1
            assert destination == path[-1]
28
29 1
    def test_path_s1_s4(self):
30
        """Tests a simple, impossible path"""
31 1
        self.initializer()
32
33 1
        assert not self.graph.constrained_k_shortest_paths("S1", "S4")
34
35 1
    def test_path_to_self(self):
36
        """Tests a path to self again"""
37 1
        self.initializer()
38 1
        results = self.graph.constrained_k_shortest_paths("S1", "S1")
39
40 1
        assert results
41 1
        for result in results:
42 1
            path = result["hops"]
43 1
            assert path[0] == "S1"
44 1
            assert path[-1] == "S1"
45
46 1
    def test_path_s1_s3_constrained_red(self):
47
        """Tests path from s1 to s3 constrained ownership red"""
48 1
        self.initializer()
49
50 1
        source = "S1"
51 1
        destination = "S3"
52 1
        results = self.graph.constrained_k_shortest_paths(
53
            source, destination, mandatory_metrics={"ownership": "red"}
54
        )
55 1
        assert not results
56
57 1
    def test_path_s1_s3_constrained_blue(self):
58
        """Tests path from s1 to s3 constrained ownership blue"""
59 1
        self.initializer()
60
61 1
        source = "S1"
62 1
        destination = "S3"
63 1
        results = self.graph.constrained_k_shortest_paths(
64
            source, destination, mandatory_metrics={"ownership": "blue"}
65
        )
66 1
        assert results
67
68 1
        for result in results:
69 1
            path = result["hops"]
70 1
            assert source == path[0]
71 1
            assert destination == path[-1]
72
73 1
    def test_path_s1_s2_constrained_not_owner_red(self):
74
        """Tests path from s1 to s3 constrained not_ownership red"""
75 1
        self.initializer()
76
77 1
        source = "S1"
78 1
        destination = "S2"
79 1
        results = self.graph.constrained_k_shortest_paths(
80
            source, destination, mandatory_metrics={"not_ownership": ["red"]}
81
        )
82 1
        assert results
83
84 1
        for result in results:
85 1
            path = result["hops"]
86 1
            assert source == path[0]
87 1
            assert destination == path[-1]
88
89 1
    def test_path_s1_s2_constrained_not_owner_blue(self):
90
        """Tests path from s1 to s2 constrained not_ownership blue"""
91 1
        self.initializer()
92
93 1
        source = "S1"
94 1
        destination = "S2"
95 1
        results = self.graph.constrained_k_shortest_paths(
96
            source, destination, mandatory_metrics={"not_ownership": ["blue"]}
97
        )
98 1
        assert results
99
100 1
        for result in results:
101 1
            path = result["hops"]
102 1
            assert source == path[0]
103 1
            assert destination == path[-1]
104
105 1
    def test_path_s1_s2_constrained_not_owner_blue_red(self):
106
        """Tests path from s1 to s2 constrained not_ownership blue, red"""
107 1
        self.initializer()
108
109 1
        source = "S1"
110 1
        destination = "S2"
111 1
        results = self.graph.constrained_k_shortest_paths(
112
            source, destination, mandatory_metrics={"not_ownership": ["blue", "red"]}
113
        )
114 1
        assert not results
115
116 1
    def test_path_s1_s3_constrained_bandwidth(self):
117
        """Tests path from s1 to s3 constrained bandwdith, the best path
118
        is supposed to be via s2"""
119
120 1
        self.initializer()
121
122 1
        source = "S1"
123 1
        destination = "S3"
124 1
        results = self.graph.constrained_k_shortest_paths(
125
            source, destination, mandatory_metrics={"bandwidth": 50}
126
        )
127
128 1
        assert results
129
130 1
        for result in results:
131 1
            path = result["hops"]
132 1
            assert source == path[0]
133 1
            assert "S2" in path
134 1
            assert destination == path[-1]
135
136 1
    @staticmethod
137 1
    def generate_topology():
138
        """Generates a predetermined topology. Topology 1"""
139 1
        switches = {}
140 1
        interfaces = {}
141 1
        links = {}
142
143 1
        TestPaths.create_switch("S1", switches)
144 1
        TestPaths.add_interfaces(2, switches["S1"], interfaces)
145
146 1
        TestPaths.create_switch("S2", switches)
147 1
        TestPaths.add_interfaces(3, switches["S2"], interfaces)
148
149 1
        TestPaths.create_switch("S3", switches)
150 1
        TestPaths.add_interfaces(2, switches["S3"], interfaces)
151
152 1
        TestPaths.create_switch("S4", switches)
153 1
        TestPaths.add_interfaces(2, switches["S4"], interfaces)
154
155 1
        TestPaths.create_switch("S5", switches)
156
157 1
        links["S1:1<->S2:1"] = Link(interfaces["S1:1"], interfaces["S2:1"])
158 1
        links["S1:1<->S2:1"].extend_metadata(
159
            {"bandwidth": 50, "ownership": "red"}
160
        )
161
162 1
        links["S3:1<->S2:2"] = Link(interfaces["S3:1"], interfaces["S2:2"])
163 1
        links["S3:1<->S2:2"].extend_metadata(
164
            {"bandwidth": 51, "ownership": "blue"}
165
        )
166
167 1
        links["S1:2<->S3:2"] = Link(interfaces["S1:2"], interfaces["S3:2"])
168 1
        links["S1:2<->S3:2"].extend_metadata(
169
            {"bandwidth": 49, "ownership": "blue"}
170
        )
171
172 1
        for link in links.values():
173 1
            link.enable()
174 1
            link.activate()
175
176
        return switches, links
177