Passed
Push — master ( 75d007...4d9626 )
by Humberto
01:10 queued 12s
created

build.tests.integration.helpers   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 29
dl 0
loc 40
rs 10
c 0
b 0
f 0
wmc 3

3 Functions

Rating   Name   Duplication   Size   Complexity  
A get_controller_mock() 0 6 1
A get_interface_mock() 0 6 1
A get_switch_mock() 0 12 1
1
"""Module to help to create Integration tests."""
2
from unittest.mock import Mock
3
4
from pyof.utils import unpack
5
from kytos.core import Controller
6
from kytos.core.config import KytosConfig
7
from kytos.core.connection import Connection, ConnectionState
8
from kytos.core.interface import Interface
9
from kytos.core.switch import Switch
10
11
12
def get_controller_mock():
13
    """Return a controller mock."""
14
    options = KytosConfig().options['daemon']
15
    controller = Controller(options)
16
    controller.log = Mock()
17
    return controller
18
19
20
def get_interface_mock(interface_name, port, *args, **kwargs):
21
    """Return a interface mock."""
22
    switch1 = get_switch_mock(0x04)
23
    switch1.connection = Mock()
24
    iface1 = Interface(interface_name, port, switch1, *args, **kwargs)
25
    return iface1
26
27
28
def get_switch_mock(of_version, connection_state=ConnectionState.NEW,
29
                    dpid="00:00:00:00:00:00:00:01"):
30
    """Return a switch mock."""
31
    switch = Switch(dpid)
32
    address = Mock()
33
    port = Mock()
34
    socket = Mock()
35
    switch.connection = Connection(address, port, socket)
36
    switch.connection.protocol.unpack = unpack
37
    switch.connection.protocol.version = of_version
38
    switch.connection.state = connection_state
39
    return switch
40