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

build.tests.unit.test_results_simple   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 54
dl 0
loc 81
rs 10
c 0
b 0
f 0
wmc 8

6 Methods

Rating   Name   Duplication   Size   Complexity  
A TestResultsSimple.test_path1() 0 5 1
A TestResultsSimple.test_path4() 0 8 2
A TestResultsSimple.generate_topology() 0 34 1
A TestResultsSimple.test_path5() 0 8 2
A TestResultsSimple.test_path2() 0 5 1
A TestResultsSimple.test_path3() 0 5 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
        self.setup()
14
        results = self.get_path_constrained("S1", "S2")
15
        self.assertNotEqual(results, [])
16
17
    def test_path2(self):
18
        """Tests a simple, impossible path"""
19
        self.setup()
20
        results = self.get_path_constrained("S1", "S4")
21
        self.assertEqual(results, [])
22
23
    def test_path3(self):
24
        """Tests a path to self again"""
25
        self.setup()
26
        results = self.get_path_constrained("S1", "S1")
27
        self.assertNotEqual(results, [])
28
29
    def test_path4(self):
30
        """Tests constrained path to self again"""
31
        self.setup()
32
        results = self.get_path_constrained(
33
            "S5", "S5", base={"ownership": "blue"})
34
        for result in results:
35
            self.assertNotEqual([], result["paths"])
36
            self.assertIn(['S5'], result["paths"])
37
38
    def test_path5(self):
39
        """Tests constrained path to self again"""
40
        self.setup()
41
        results = self.get_path_constrained(
42
            "S5", "S5", flexible={"priority": 5})
43
        for result in results:
44
            self.assertNotEqual([], result["paths"])
45
            self.assertIn(['S5'], result["paths"])
46
47
    @staticmethod
48
    def generate_topology():
49
        """Generates a predetermined topology"""
50
        switches = {}
51
        interfaces = {}
52
        links = {}
53
54
        TestResults.create_switch("S1", switches)
55
        TestResults.add_interfaces(2, switches["S1"], interfaces)
56
57
        TestResults.create_switch("S2", switches)
58
        TestResults.add_interfaces(3, switches["S2"], interfaces)
59
60
        TestResults.create_switch("S3", switches)
61
        TestResults.add_interfaces(2, switches["S3"], interfaces)
62
63
        TestResults.create_switch("S4", switches)
64
        TestResults.add_interfaces(2, switches["S4"], interfaces)
65
66
        TestResults.create_switch("S5", switches)
67
68
        links["S1:1<->S2:1"] = Link(interfaces["S1:1"], interfaces["S2:1"])
69
        links["S1:1<->S2:1"].extend_metadata(
70
            {"bandwidth": 50, "ownership": "red"})
71
72
        links["S3:1<->S2:2"] = Link(interfaces["S3:1"], interfaces["S2:2"])
73
        links["S3:1<->S2:2"].extend_metadata(
74
            {"bandwidth": 51, "ownership": "blue"})
75
76
        links["S1:2<->S3:2"] = Link(interfaces["S1:2"], interfaces["S3:2"])
77
        links["S1:2<->S3:2"].extend_metadata(
78
            {"bandwidth": 49, "ownership": "blue"})
79
80
        return (switches, links)
81