Passed
Push — master ( 5bb45b...07a00f )
by Humberto
02:40
created

TestStoreHouse.test_get_data()   A

Complexity

Conditions 1

Size

Total Lines 14
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

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