get_controller_mock()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 6
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

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