Completed
Pull Request — master (#58)
by
unknown
02:26
created

build.tests.unit.test_results_simple   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 49
dl 0
loc 76
rs 10
c 0
b 0
f 0
wmc 8

6 Methods

Rating   Name   Duplication   Size   Complexity  
A TestResultsSimple.test_path1() 0 4 1
A TestResultsSimple.test_path4() 0 7 2
A TestResultsSimple.generate_topology() 0 34 1
A TestResultsSimple.test_path5() 0 7 2
A TestResultsSimple.test_path2() 0 4 1
A TestResultsSimple.test_path3() 0 4 1
1
"""Module to test the KytosGraph in graph.py."""
2
from kytos.core.link import Link
3
4
# module under test
5
from tests.unit.test_results import TestResults
6
7
8
class TestResultsSimple(TestResults):
9
    """Tests for the graph class."""
10
11
    def test_path1(self):
12
        """Tests a simple, possible path"""
13
        results = self.get_path_constrained("S1", "S2")
14
        self.assertNotEqual(results, [])
15
16
    def test_path2(self):
17
        """Tests a simple, impossible path"""
18
        results = self.get_path_constrained("S1", "S4")
19
        self.assertEqual(results, [])
20
21
    def test_path3(self):
22
        """Tests a path to self again"""
23
        results = self.get_path_constrained("S1", "S1")
24
        self.assertNotEqual(results, [])
25
26
    def test_path4(self):
27
        """Tests constrained path to self again"""
28
        results = self.get_path_constrained(
29
            "S5", "S5", base={"ownership": "blue"})
30
        for result in results:
31
            self.assertNotEqual([], result["paths"])
32
            self.assertIn(['S5'], result["paths"])
33
34
    def test_path5(self):
35
        """Tests constrained path to self again"""
36
        results = self.get_path_constrained(
37
            "S5", "S5", flexible={"priority": 5})
38
        for result in results:
39
            self.assertNotEqual([], result["paths"])
40
            self.assertIn(['S5'], result["paths"])
41
42
    @staticmethod
43
    def generate_topology():
44
        """Generates a predetermined topology"""
45
        switches = {}
46
        interfaces = {}
47
        links = {}
48
49
        TestResults.create_switch("S1", switches)
50
        TestResults.add_interfaces(2, switches["S1"], interfaces)
51
52
        TestResults.create_switch("S2", switches)
53
        TestResults.add_interfaces(3, switches["S2"], interfaces)
54
55
        TestResults.create_switch("S3", switches)
56
        TestResults.add_interfaces(2, switches["S3"], interfaces)
57
58
        TestResults.create_switch("S4", switches)
59
        TestResults.add_interfaces(2, switches["S4"], interfaces)
60
61
        TestResults.create_switch("S5", switches)
62
63
        links["S1:1<->S2:1"] = Link(interfaces["S1:1"], interfaces["S2:1"])
64
        links["S1:1<->S2:1"].extend_metadata(
65
            {"bandwidth": 50, "ownership": "red"})
66
67
        links["S3:1<->S2:2"] = Link(interfaces["S3:1"], interfaces["S2:2"])
68
        links["S3:1<->S2:2"].extend_metadata(
69
            {"bandwidth": 51, "ownership": "blue"})
70
71
        links["S1:2<->S3:2"] = Link(interfaces["S1:2"], interfaces["S3:2"])
72
        links["S1:2<->S3:2"].extend_metadata(
73
            {"bandwidth": 49, "ownership": "blue"})
74
75
        return (switches, links)
76