Passed
Pull Request — master (#58)
by
unknown
02:11
created

TestResultsMetadata.test_path1()   B

Complexity

Conditions 6

Size

Total Lines 20
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 15
nop 1
dl 0
loc 20
rs 8.6666
c 0
b 0
f 0
1
"""Module to test the KytosGraph in graph.py."""
2
3
# module under test
4
from tests.integration.test_results import TestResults
5
6
7
class TestResultsMetadata(TestResults):
8
    """Tests for the graph class.
9
10
    Tests if the metadata in search result edges have passing values.
11
    """
12
13
    def test_path1(self):
14
        """Tests to see if the edges used in the paths of the result set
15
        do not have poor reliability"""
16
        reliabilities = []
17
        requirements = {"reliability": 3}
18
        poor_reliability = 1
19
20
        result = self.get_path_constrained("User1", "User2", base=requirements)
21
22
        if result:
23
            for path in result[0]["paths"]:
24
                for i in range(1, len(path)):
25
                    endpoint_a = path[i - 1]
26
                    endpoint_b = path[i]
27
                    meta_data = self.graph.get_link_metadata(
28
                        endpoint_a, endpoint_b)
29
                    if meta_data and "reliability" in meta_data.keys():
30
                        reliabilities.append(meta_data["reliability"])
31
32
        self.assertNotIn(poor_reliability, reliabilities)
33
34
    def test_path2(self):
35
        """Tests to see if the edges used in the paths from User 1 to User 2
36
        have less than 30 delay."""
37
        delays = []
38
        requirements = {"delay": 29}
39
40
        result = self.get_path_constrained(
41
            "User1", "User2", base=requirements)
42
43
        if result:
44
            for path in result[0]["paths"]:
45
                for i in range(1, len(path)):
46
                    endpoint_a = path[i - 1]
47
                    endpoint_b = path[i]
48
                    meta_data = self.graph.get_link_metadata(
49
                        endpoint_a, endpoint_b)
50
                    if meta_data and "delay" in meta_data.keys():
51
                        delays.append(meta_data["delay"])
52
53
        for delay in delays:
54
            self.assertEqual(delay > requirements["delay"], False)
55
56
    def test_path3(self):
57
        """Tests to see if the edges used in the paths from User 1 to User 2
58
        have at least 20 bandwidth."""
59
        bandwidths = []
60
        requirements = {"bandwidth": 20}
61
62
        result = self.get_path_constrained(
63
            "User1", "User2", base=requirements)
64
65
        if result:
66
            for path in result[0]["paths"]:
67
                for i in range(1, len(path)):
68
                    endpoint_a = path[i - 1]
69
                    endpoint_b = path[i]
70
                    meta_data = self.graph.get_link_metadata(
71
                        endpoint_a, endpoint_b)
72
                    if meta_data and "bandwidth" in meta_data.keys():
73
                        bandwidths.append(meta_data["bandwidth"])
74
75
        for bandwidth in bandwidths:
76
            self.assertEqual(bandwidth < requirements["bandwidth"], False)
77
78
    def test_path4(self):
79
        """Tests to see if the edges used in the paths from User 1 to User 2
80
        have at least 20 bandwidth and under 30 delay."""
81
        bandwidths = []
82
        delays = []
83
        requirements = {"bandwidth": 20, "delay": 29}
84
85
        result = self.get_path_constrained(
86
            "User1", "User2", base=requirements)
87
88
        if result:
89
            for path in result[0]["paths"]:
90
                for i in range(1, len(path)):
91
                    endpoint_a = path[i - 1]
92
                    endpoint_b = path[i]
93
                    meta_data = self.graph.get_link_metadata(
94
                        endpoint_a, endpoint_b)
95
                    if meta_data and "bandwidth" in meta_data.keys():
96
                        bandwidths.append(meta_data["bandwidth"])
97
                    elif meta_data and "delay" in meta_data.keys():
98
                        delays.append(meta_data["delay"])
99
100
        for bandwidth in bandwidths:
101
            self.assertEqual(bandwidth < requirements["bandwidth"], False)
102
103
        for delay in delays:
104
            self.assertEqual(delay > requirements["delay"], False)
105
106
    @staticmethod
107
    def generate_topology():
108
        """Generates a predetermined topology"""
109
        switches = {}
110
        interfaces = {}
111
        links = {}
112
113
        TestResults.create_switch("User1", switches)
114
        TestResults.add_interfaces(3, switches["User1"], interfaces)
115
116
        TestResults.create_switch("S2", switches)
117
        TestResults.add_interfaces(2, switches["S2"], interfaces)
118
119
        TestResults.create_switch("User2", switches)
120
        TestResults.add_interfaces(3, switches["User2"], interfaces)
121
122
        TestResults.create_switch("S4", switches)
123
        TestResults.add_interfaces(4, switches["S4"], interfaces)
124
125
        TestResults.create_switch("S5", switches)
126
        TestResults.add_interfaces(2, switches["S5"], interfaces)
127
128
        TestResults.create_link("User1:1", "S2:1", interfaces, links)
129
        TestResults.create_link("User1:2", "S5:1", interfaces, links)
130
        TestResults.create_link("User1:3", "S4:1", interfaces, links)
131
        TestResults.create_link("S2:2", "User2:1", interfaces, links)
132
        TestResults.create_link("User2:2", "S4:2", interfaces, links)
133
        TestResults.create_link("S5:2", "S4:3", interfaces, links)
134
        TestResults.create_link("User2:3", "S4:4", interfaces, links)
135
136
        TestResults.add_metadata_to_link(
137
            "User1:1", "S2:1", {
138
                "reliability": 3, "ownership": "B", "delay": 30,
139
                "bandwidth": 20}, links)
140
        TestResults.add_metadata_to_link(
141
            "User1:2", "S5:1", {
142
                "reliability": 1, "ownership": "A", "delay": 5,
143
                "bandwidth": 50}, links)
144
        TestResults.add_metadata_to_link(
145
            "User1:3", "S4:1", {
146
                "reliability": 3, "ownership": "A", "delay": 60,
147
                "bandwidth": 10}, links)
148
        TestResults.add_metadata_to_link(
149
            "S2:2", "User2:1", {
150
                "reliability": 3, "ownership": "B", "delay": 30,
151
                "bandwidth": 20}, links)
152
        TestResults.add_metadata_to_link(
153
            "User2:2", "S4:2", {
154
                "reliability": 3, "ownership": "B", "delay": 30,
155
                "bandwidth": 10}, links)
156
        TestResults.add_metadata_to_link(
157
            "S5:2", "S4:3", {
158
                "reliability": 1, "ownership": "A", "delay": 10,
159
                "bandwidth": 50}, links)
160
        TestResults.add_metadata_to_link(
161
            "User2:3", "S4:4", {
162
                "reliability": 3, "ownership": "A", "delay": 29,
163
                "bandwidth": 20}, links)
164
165
        return (switches, links)
166