1
|
|
|
"""Test v0x01.utils methods.""" |
2
|
|
|
from unittest import TestCase |
3
|
|
|
from unittest.mock import MagicMock, patch, PropertyMock |
4
|
|
|
|
5
|
|
|
from kytos.lib.helpers import get_switch_mock, get_connection_mock |
6
|
|
|
from napps.kytos.of_core.v0x01.utils import (send_desc_request, send_echo, |
7
|
|
|
say_hello, send_set_config, |
8
|
|
|
handle_features_reply) |
9
|
|
|
|
10
|
|
|
from tests.helpers import get_controller_mock |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
class TestUtils(TestCase): |
14
|
|
|
"""Test utils.""" |
15
|
|
|
|
16
|
|
|
def setUp(self): |
17
|
|
|
"""Execute steps before each tests.""" |
18
|
|
|
self.mock_controller = get_controller_mock() |
19
|
|
|
self.mock_switch = get_switch_mock('00:00:00:00:00:00:00:01', 'v0x01') |
20
|
|
|
self.mock_connection = get_connection_mock('v0x01', self.mock_switch) |
21
|
|
|
|
22
|
|
|
@patch('napps.kytos.of_core.v0x01.utils.emit_message_out') |
23
|
|
|
def test_send_desc_request(self, mock_emit_message_out): |
24
|
|
|
"""Test send_desc_request.""" |
25
|
|
|
send_desc_request(self.mock_controller, self.mock_switch) |
26
|
|
|
mock_emit_message_out.assert_called() |
27
|
|
|
|
28
|
|
|
def test_handle_features_reply(self): |
29
|
|
|
"""test Handle features reply.""" |
30
|
|
|
mock_controller = MagicMock() |
31
|
|
|
mock_event = MagicMock() |
32
|
|
|
mock_features = MagicMock() |
33
|
|
|
type(mock_features).ports = PropertyMock(return_value=[MagicMock()]) |
34
|
|
|
type(mock_event).content = PropertyMock(side_effect=[{'message': |
35
|
|
|
mock_features}]) |
36
|
|
|
mock_controller.get_switch_or_create.return_value = self.mock_switch |
37
|
|
|
response = handle_features_reply(mock_controller, mock_event) |
38
|
|
|
self.assertEqual(self.mock_switch, response) |
39
|
|
|
self.assertEqual(self.mock_switch.update_features.call_count, 1) |
40
|
|
|
|
41
|
|
|
@patch('napps.kytos.of_core.v0x01.utils.emit_message_out') |
42
|
|
|
def test_send_echo(self, mock_emit_message_out): |
43
|
|
|
"""Test send_echo.""" |
44
|
|
|
send_echo(self.mock_controller, self.mock_switch) |
45
|
|
|
mock_emit_message_out.assert_called() |
46
|
|
|
|
47
|
|
|
@patch('napps.kytos.of_core.v0x01.utils.emit_message_out') |
48
|
|
|
def test_set_config(self, mock_emit_message_out): |
49
|
|
|
"""Test set_config.""" |
50
|
|
|
send_set_config(self.mock_controller, self.mock_switch) |
51
|
|
|
mock_emit_message_out.assert_called() |
52
|
|
|
|
53
|
|
|
@patch('napps.kytos.of_core.v0x01.utils.emit_message_out') |
54
|
|
|
def test_say_hello(self, mock_emit_message_out): |
55
|
|
|
"""Test say_hello.""" |
56
|
|
|
say_hello(self.mock_controller, self.mock_switch) |
57
|
|
|
mock_emit_message_out.assert_called() |
58
|
|
|
|