Test Failed
Pull Request — master (#42)
by Gleyberson
02:13
created

build.tests.helpers   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 31
dl 0
loc 42
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A get_topology_mock() 0 32 1
1
"""Module to help to create tests."""
2
from unittest.mock import MagicMock
3
4
from kytos.core.connection import (Connection, ConnectionProtocol,
5
                                   ConnectionState)
6
from kytos.lib.helpers import (get_interface_mock, get_link_mock,
7
                               get_switch_mock)
8
9
10
def get_topology_mock():
11
    """Create a default topology."""
12
    switch_a = get_switch_mock("00:00:00:00:00:00:00:01", 0x04)
13
    switch_b = get_switch_mock("00:00:00:00:00:00:00:02", 0x04)
14
    switch_c = get_switch_mock("00:00:00:00:00:00:00:03", 0x01)
15
16
    interface_a1 = get_interface_mock("s1-eth1", 1, switch_a)
17
    interface_a2 = get_interface_mock("s1-eth2", 2, switch_a)
18
19
    interface_b1 = get_interface_mock("s2-eth1", 1, switch_b)
20
    interface_b2 = get_interface_mock("s2-eth2", 2, switch_b)
21
22
    interface_c1 = get_interface_mock("s3-eth1", 1, switch_c)
23
    interface_c2 = get_interface_mock("s3-eth2", 2, switch_c)
24
25
    switch_a.interfaces = {interface_a1.id: interface_a1,
26
                           interface_a2.id: interface_a2}
27
    switch_b.interfaces = {interface_b1.id: interface_b1,
28
                           interface_b2.id: interface_b2}
29
    switch_c.interfaces = {interface_c1.id: interface_c1,
30
                           interface_c2.id: interface_c2}
31
32
    link_1 = get_link_mock(interface_a1, interface_b1)
33
    link_2 = get_link_mock(interface_a2, interface_c1)
34
    link_3 = get_link_mock(interface_b2, interface_c2)
35
36
    topology = MagicMock()
37
    topology.links = {"1": link_1, "2": link_2, "3": link_3}
38
    topology.switches = {switch_a.dpid: switch_a,
39
                         switch_b.dpid: switch_b,
40
                         switch_c.dpid: switch_c}
41
    return topology
42