Passed
Pull Request — master (#51)
by Vinicius
06:36
created

test_main.TestMain.test_empty()   A

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
"""Test Main methods."""
2
3 1
from unittest.mock import AsyncMock, MagicMock, patch
4 1
from napps.kytos.telemetry_int.main import Main
5 1
from napps.kytos.telemetry_int import utils
6 1
from kytos.lib.helpers import get_controller_mock
7 1
from kytos.core.events import KytosEvent
8
9
10 1
class TestMain:
11
    """Tests for the Main class."""
12
13 1
    def setup_method(self):
14
        """Setup."""
15 1
        patch("kytos.core.helpers.run_on_thread", lambda x: x).start()
16
        # pylint: disable=import-outside-toplevel
17 1
        controller = get_controller_mock()
18 1
        self.napp = Main(controller)
19
20 1
    async def test_on_flow_mod_error(self, monkeypatch) -> None:
21
        """Test on_flow_mod_error."""
22 1
        api_mock, flow = AsyncMock(), MagicMock()
23 1
        flow.cookie = 0xA800000000000001
24 1
        monkeypatch.setattr(
25
            "napps.kytos.telemetry_int.main.api",
26
            api_mock,
27
        )
28 1
        api_mock.get_evc.return_value = {
29
            utils.get_id_from_cookie(flow.cookie): {
30
                "metadata": {"telemetry": {"enabled": True}}
31
            }
32
        }
33 1
        self.napp.int_manager.remove_int_flows = AsyncMock()
34
35 1
        event = KytosEvent(content={"flow": flow, "error_command": "add"})
36 1
        await self.napp.on_flow_mod_error(event)
37
38 1
        assert api_mock.get_evc.call_count == 1
39 1
        assert api_mock.get_stored_flows.call_count == 1
40 1
        assert api_mock.add_evcs_metadata.call_count == 1
41
        assert self.napp.int_manager.remove_int_flows.call_count == 1
42