Passed
Pull Request — master (#108)
by
unknown
02:28
created

build.tests.unit.test_storehouse   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 42
dl 0
loc 65
rs 10
c 0
b 0
f 0
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A TestStoreHouse.test_save_status() 0 9 1
A TestStoreHouse.test_create_box() 0 8 1
A TestStoreHouse.test_get_data() 0 10 1
A TestStoreHouse.test_get_stored_box() 0 9 1
A TestStoreHouse.setUp() 0 12 2
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_data(self, mock_get_stored_box):
28
        """Test get_data."""
29
        mock_box = MagicMock()
30
        response = self.napp.get_data()
31
        self.assertEqual(response, {})
32
33
        self.napp.box = mock_box
34
        self.napp.get_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_box(self, *args):
40
        """Test create_box."""
41
        (mock_buffers_put, mock_event) = args
42
        self.napp.create_box()
43
        mock_event.assert_called()
44
        mock_buffers_put.assert_called()
45
46
    @patch('napps.kytos.topology.storehouse.KytosEvent')
47
    @patch('kytos.core.buffers.KytosEventBuffer.put')
48
    def test_get_stored_box(self, *args):
49
        """Test get_stored_box."""
50
        (mock_buffers_put, mock_event) = args
51
        mock_box = MagicMock()
52
        self.napp.get_stored_box(mock_box)
53
        mock_event.assert_called()
54
        mock_buffers_put.assert_called()
55
56
    @patch('napps.kytos.topology.storehouse.KytosEvent')
57
    @patch('kytos.core.buffers.KytosEventBuffer.put')
58
    def test_save_status(self, *args):
59
        """Test save_status."""
60
        (mock_buffers_put, mock_event) = args
61
        mock_status = MagicMock()
62
        self.napp.save_status(mock_status)
63
        mock_event.assert_called()
64
        mock_buffers_put.assert_called()
65