|
1
|
|
|
"""Module to help to create Integration tests.""" |
|
2
|
1 |
|
from unittest.mock import Mock |
|
3
|
|
|
|
|
4
|
1 |
|
from kytos.core import Controller |
|
5
|
1 |
|
from kytos.core.config import KytosConfig |
|
6
|
1 |
|
from kytos.core.connection import Connection, ConnectionState |
|
7
|
1 |
|
from kytos.core.interface import Interface |
|
8
|
1 |
|
from kytos.core.switch import Switch |
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
1 |
|
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
|
1 |
|
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
|
1 |
|
switch = Switch(dpid) |
|
23
|
1 |
|
address = Mock() |
|
24
|
1 |
|
port = Mock() |
|
25
|
1 |
|
socket = Mock() |
|
26
|
1 |
|
switch.connection = Connection(address, port, socket) |
|
27
|
1 |
|
switch.connection.protocol.version = of_version |
|
28
|
1 |
|
switch.connection.state = connection_state |
|
29
|
1 |
|
return switch |
|
30
|
|
|
|
|
31
|
|
|
|
|
32
|
1 |
|
def get_interface_mock(interface_name, port, *args, **kwargs): |
|
33
|
|
|
"""Return a interface mock.""" |
|
34
|
1 |
|
switch = get_switch_mock(0x04) |
|
35
|
1 |
|
switch.connection = Mock() |
|
36
|
1 |
|
switch.connection.protocol.version = 0x04 |
|
37
|
1 |
|
iface = Interface(interface_name, port, switch, *args, **kwargs) |
|
38
|
|
|
return iface |
|
39
|
|
|
|