1
|
|
|
"""Module to test the main napp file.""" |
2
|
|
|
from unittest import TestCase |
3
|
|
|
from unittest.mock import Mock |
4
|
|
|
|
5
|
|
|
from kytos.core import Controller |
6
|
|
|
from kytos.core.config import KytosConfig |
7
|
|
|
|
8
|
|
|
from napps.kytos.flow_manager.main import Main |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
class TestMain(TestCase): |
12
|
|
|
"""Test the Main class.""" |
13
|
|
|
|
14
|
|
|
def setUp(self): |
15
|
|
|
"""Execute steps before each tests. |
16
|
|
|
""" |
17
|
|
|
self.napp = Main(self.get_controller_mock()) |
18
|
|
|
|
19
|
|
|
@staticmethod |
20
|
|
|
def get_controller_mock(): |
21
|
|
|
"""Return a controller mock.""" |
22
|
|
|
options = KytosConfig().options['daemon'] |
23
|
|
|
controller = Controller(options) |
24
|
|
|
controller.log = Mock() |
25
|
|
|
return controller |
26
|
|
|
|
27
|
|
|
def test_add_flow_mod_sent_ok(self): |
28
|
|
|
self.napp._flow_mods_sent_max_size = 3 |
29
|
|
|
flow = Mock() |
30
|
|
|
xid = '12345' |
31
|
|
|
initial_len = len(self.napp._flow_mods_sent) |
32
|
|
|
self.napp._add_flow_mod_sent(xid, flow) |
33
|
|
|
|
34
|
|
|
assert len(self.napp._flow_mods_sent) == initial_len + 1 |
35
|
|
|
assert self.napp._flow_mods_sent.get(xid, None) == flow |
36
|
|
|
|
37
|
|
|
def test_add_flow_mod_sent_overlimit(self): |
38
|
|
|
self.napp._flow_mods_sent_max_size = 5 |
39
|
|
|
xid = '23456' |
40
|
|
|
while len(self.napp._flow_mods_sent) < 5: |
41
|
|
|
xid += '1' |
42
|
|
|
flow = Mock() |
43
|
|
|
self.napp._add_flow_mod_sent(xid, flow) |
44
|
|
|
|
45
|
|
|
xid = '90876' |
46
|
|
|
flow = Mock() |
47
|
|
|
initial_len = len(self.napp._flow_mods_sent) |
48
|
|
|
self.napp._add_flow_mod_sent(xid, flow) |
49
|
|
|
|
50
|
|
|
assert len(self.napp._flow_mods_sent) == initial_len |
51
|
|
|
assert self.napp._flow_mods_sent.get(xid, None) == flow |
52
|
|
|
|