Passed
Pull Request — master (#76)
by
unknown
02:24
created

TestUtils.setUp()   A

Complexity

Conditions 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nop 1
1
"""Test v0x04.utils 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
from napps.kytos.of_core.v0x04.utils import (send_desc_request, say_hello,
7
                                             send_port_request, send_echo,
8
                                             send_set_config,
9
                                             handle_features_reply)
10
11
from tests.helpers import get_controller_mock
12
13
14
class TestUtils(TestCase):
15
    """Test utils."""
16
17
    def setUp(self):
18
        """Execute steps before each tests."""
19
        self.mock_controller = get_controller_mock()
20
        self.mock_switch = get_switch_mock('00:00:00:00:00:00:00:01', 'v0x04')
21
        self.mock_connection = get_connection_mock('v0x04', self.mock_switch)
22
23
    @patch('napps.kytos.of_core.v0x04.utils.emit_message_out')
24
    def test_send_desc_request(self, mock_emit_message_out):
25
        """Test send_desc_request."""
26
        send_desc_request(self.mock_controller, self.mock_switch)
27
        mock_emit_message_out.assert_called()
28
29
    @patch('napps.kytos.of_core.v0x04.utils.emit_message_out')
30
    def test_port_request(self, mock_emit_message_out):
31
        """Test send_desc_request."""
32
        send_port_request(self.mock_controller, self.mock_switch)
33
        mock_emit_message_out.assert_called()
34
35
    def test_handle_features_reply(self):
36
        """test Handle features reply."""
37
        mock_controller = MagicMock()
38
        mock_controller.get_switch_or_create.return_value = self.mock_switch
39
        response = handle_features_reply(mock_controller, MagicMock())
40
        self.assertEqual(self.mock_switch, response)
41
        self.assertEqual(self.mock_switch.update_features.call_count, 1)
42
43
    @patch('napps.kytos.of_core.v0x04.utils.emit_message_out')
44
    def test_send_echo(self, mock_emit_message_out):
45
        """Test send_echo."""
46
        send_echo(self.mock_controller, self.mock_switch)
47
        mock_emit_message_out.assert_called()
48
49
    @patch('napps.kytos.of_core.v0x04.utils.emit_message_out')
50
    def test_set_config(self, mock_emit_message_out):
51
        """Test set_config."""
52
        send_set_config(self.mock_controller, self.mock_switch)
53
        mock_emit_message_out.assert_called()
54
55
    @patch('napps.kytos.of_core.v0x04.utils.emit_message_out')
56
    def test_say_hello(self, mock_emit_message_out):
57
        """Test say_hello."""
58
        say_hello(self.mock_controller, self.mock_switch)
59
        mock_emit_message_out.assert_called()
60