Passed
Push — master ( 05dde9...905e13 )
by Humberto
01:22 queued 10s
created

test_main.TestMain.get_controller_mock()   A

Complexity

Conditions 1

Size

Total Lines 7
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

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