|
1
|
|
|
"""Module to test the storehouse client.""" |
|
2
|
|
|
from unittest import TestCase |
|
3
|
|
|
from unittest.mock import MagicMock, patch |
|
4
|
|
|
|
|
5
|
|
|
from tests.unit.helpers import get_controller_mock |
|
6
|
|
|
|
|
7
|
|
|
|
|
8
|
|
|
# pylint: disable=too-many-public-methods |
|
9
|
|
|
class TestStoreHouse(TestCase): |
|
10
|
|
|
"""Test the Main class.""" |
|
11
|
|
|
# pylint: disable=too-many-public-methods |
|
12
|
|
|
|
|
13
|
|
|
def setUp(self): |
|
14
|
|
|
"""Execute steps before each tests. |
|
15
|
|
|
|
|
16
|
|
|
Set the server_name_url_url from kytos/topology |
|
17
|
|
|
""" |
|
18
|
|
|
self.server_name_url = 'http://localhost:8181/api/kytos/topology' |
|
19
|
|
|
|
|
20
|
|
|
patch('kytos.core.helpers.run_on_thread', lambda x: x).start() |
|
21
|
|
|
from napps.kytos.topology.storehouse import StoreHouse |
|
22
|
|
|
self.addCleanup(patch.stopall) |
|
23
|
|
|
|
|
24
|
|
|
self.napp = StoreHouse(get_controller_mock()) |
|
25
|
|
|
|
|
26
|
|
|
@patch('napps.kytos.topology.storehouse.StoreHouse.get_stored_box') |
|
27
|
|
|
def test_get_persistence_data(self, mock_get_stored_box): |
|
28
|
|
|
"""Test get_data.""" |
|
29
|
|
|
mock_box = MagicMock() |
|
30
|
|
|
response = self.napp.get_persistence_data() |
|
31
|
|
|
self.assertEqual(response, {}) |
|
32
|
|
|
|
|
33
|
|
|
self.napp.box = mock_box |
|
34
|
|
|
self.napp.get_persistence_data() |
|
35
|
|
|
mock_get_stored_box.assert_called() |
|
36
|
|
|
|
|
37
|
|
|
@patch('napps.kytos.topology.storehouse.KytosEvent') |
|
38
|
|
|
@patch('kytos.core.buffers.KytosEventBuffer.put') |
|
39
|
|
|
def test_create_persistence_box(self, *args): |
|
40
|
|
|
"""Test create_box.""" |
|
41
|
|
|
(mock_buffers_put, mock_event) = args |
|
42
|
|
|
self.napp.create_persistence_box() |
|
43
|
|
|
mock_event.assert_called() |
|
44
|
|
|
mock_buffers_put.assert_called() |
|
45
|
|
|
|
|
46
|
|
|
# pylint: disable = protected-access |
|
47
|
|
|
@patch('napps.kytos.topology.storehouse.StoreHouse.get_stored_box') |
|
48
|
|
|
@patch('napps.kytos.topology.storehouse.StoreHouse.create_persistence_box') |
|
49
|
|
|
def test_get_or_create_a_box_from_list_of_boxes(self, *args): |
|
50
|
|
|
"""Test create_box.""" |
|
51
|
|
|
(mock_create_box, mock_get_stored_box) = args |
|
52
|
|
|
mock_event = MagicMock() |
|
53
|
|
|
mock_data = MagicMock() |
|
54
|
|
|
mock_error = MagicMock() |
|
55
|
|
|
self.napp._get_or_create_a_box_from_list_of_boxes(mock_event, |
|
56
|
|
|
mock_data, |
|
57
|
|
|
mock_error) |
|
58
|
|
|
mock_get_stored_box.assert_called() |
|
59
|
|
|
self.napp._get_or_create_a_box_from_list_of_boxes(mock_event, |
|
60
|
|
|
None, |
|
61
|
|
|
mock_error) |
|
62
|
|
|
mock_create_box.assert_called() |
|
63
|
|
|
|
|
64
|
|
|
@patch('napps.kytos.topology.storehouse.KytosEvent') |
|
65
|
|
|
@patch('kytos.core.buffers.KytosEventBuffer.put') |
|
66
|
|
|
def test_get_stored_box(self, *args): |
|
67
|
|
|
"""Test get_stored_box.""" |
|
68
|
|
|
(mock_buffers_put, mock_event) = args |
|
69
|
|
|
mock_box = MagicMock() |
|
70
|
|
|
self.napp.get_stored_box(mock_box) |
|
71
|
|
|
mock_event.assert_called() |
|
72
|
|
|
mock_buffers_put.assert_called() |
|
73
|
|
|
|
|
74
|
|
|
@patch('napps.kytos.topology.storehouse.KytosEvent') |
|
75
|
|
|
@patch('kytos.core.buffers.KytosEventBuffer.put') |
|
76
|
|
|
def test_save_status(self, *args): |
|
77
|
|
|
"""Test save_status.""" |
|
78
|
|
|
(mock_buffers_put, mock_event) = args |
|
79
|
|
|
mock_status = MagicMock() |
|
80
|
|
|
self.napp.save_status(mock_status) |
|
81
|
|
|
mock_event.assert_called() |
|
82
|
|
|
mock_buffers_put.assert_called() |
|
83
|
|
|
|