Completed
Pull Request — master (#76)
by
unknown
02:23
created

build.tests.unit.test_flow   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 25
dl 0
loc 42
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A TestFlowFactory.test_from_of_flow_stats() 0 12 1
A TestFlowFactory.setUp() 0 17 2
1
"""Module to test flow methods."""
2
from unittest import TestCase
3
from unittest.mock import MagicMock, patch
4
5
from kytos.lib.helpers import get_switch_mock, get_connection_mock
6
7
8
# pylint: disable=protected-access, too-many-public-methods
9
class TestFlowFactory(TestCase):
10
    """Test the FlowFactory class."""
11
12
    def setUp(self):
13
        """Execute steps before each tests.
14
        Set the server_name_url from kytos/of_core
15
        """
16
        self.switch_v0x01 = get_switch_mock("00:00:00:00:00:00:00:01")
17
        self.switch_v0x04 = get_switch_mock("00:00:00:00:00:00:00:02")
18
        self.switch_v0x01.connection = get_connection_mock(
19
            0x01, get_switch_mock("00:00:00:00:00:00:00:03"))
20
        self.switch_v0x04.connection = get_connection_mock(
21
            0x04, get_switch_mock("00:00:00:00:00:00:00:04"))
22
23
        patch('kytos.core.helpers.run_on_thread', lambda x: x).start()
24
        # pylint: disable=bad-option-value
25
        from napps.kytos.of_core.flow import FlowFactory
26
        self.addCleanup(patch.stopall)
27
28
        self.napp = FlowFactory()
29
30
    @patch('napps.kytos.of_core.flow.v0x01')
31
    @patch('napps.kytos.of_core.flow.v0x04')
32
    def test_from_of_flow_stats(self, *args):
33
        """Test from_of_flow_stats."""
34
        (mock_flow_v0x04, mock_flow_v0x01) = args
35
        mock_stats = MagicMock()
36
37
        self.napp.from_of_flow_stats(mock_stats, self.switch_v0x01)
38
        mock_flow_v0x01.flow.Flow.from_of_flow_stats.assert_called()
39
40
        self.napp.from_of_flow_stats(mock_stats, self.switch_v0x04)
41
        mock_flow_v0x04.flow.Flow.from_of_flow_stats.assert_called()
42