Completed
Pull Request — master (#69)
by Gleyberson
03:04 queued 51s
created

build.tests.integration.helpers   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

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

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
6
from kytos.core import Controller
7
from kytos.core.config import KytosConfig
8
from kytos.core.connection import Connection, ConnectionState
9
from kytos.core.interface import Interface
10
from kytos.core.switch import Switch
11
12
13
def get_controller_mock():
14
    """Return a controller mock."""
15
    options = KytosConfig().options['daemon']
16
    controller = Controller(options)
17
    controller.log = Mock()
18
    return controller
19
20
21
def get_interface_mock(interface_name, port, *args, **kwargs):
22
    """Return a interface mock."""
23
    switch1 = get_switch_mock(0x04)
24
    switch1.connection = Mock()
25
    iface1 = Interface(interface_name, port, switch1, *args, **kwargs)
26
    return iface1
27
28
29
def get_switch_mock(of_version, connection_state=ConnectionState.NEW,
30
                    dpid="00:00:00:00:00:00:00:01"):
31
    """Return a switch mock."""
32
    switch = Switch(dpid)
33
    address = Mock()
34
    port = Mock()
35
    socket = Mock()
36
    switch.connection = Connection(address, port, socket)
37
    switch.connection.protocol.unpack = unpack
38
    switch.connection.protocol.version = of_version
39
    switch.connection.state = connection_state
40
    return switch
41