Passed
Pull Request — master (#63)
by Gleyberson
02:00
created

build.tests.helpers.get_connection_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 2
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
"""Module to help to create tests."""
2
from unittest.mock import MagicMock, Mock
3
4
from kytos.core import Controller
5
from kytos.core.config import KytosConfig
6
from kytos.core.connection import Connection
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_interface_mock(interface_name, port, *args, **kwargs):
20
    """Return a interface mock."""
21
    switch = get_switch_mock(0x04)
22
    switch.connection = Mock()
23
    iface = Interface(interface_name, port, switch, *args, **kwargs)
24
    return iface
25
26
27
def get_switch_mock(dpid):
28
    """Return a switch mock."""
29
    return Switch(dpid)
30
31
32
def get_connection_mock(of_version, target_switch):
33
    """Return a connection mock."""
34
    connection = Connection(Mock(), Mock(), Mock())
35
    connection.switch = target_switch
36
    connection.protocol.version = of_version
37
    return connection
38
39
40
def get_kytos_event_mock(**kwargs):
41
    """Return a kytos event mock."""
42
    destination = kwargs.get('destination')
43
    message = kwargs.get('message')
44
    source = kwargs.get('source')
45
46
    event = MagicMock()
47
    event.source = source
48
    event.content = {'destination': destination,
49
                     'message': message}
50
    return event
51