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

get_controller_mock()   A

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 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