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
|
|
|
|