1
|
|
|
"""Module to test the schedule.py file.""" |
2
|
|
|
from unittest import TestCase |
3
|
|
|
from unittest.mock import patch, Mock |
4
|
|
|
|
5
|
|
|
from napps.kytos.mef_eline.storehouse import StoreHouse |
6
|
|
|
from tests.helpers import get_controller_mock |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
class TestStoreHouse(TestCase): |
10
|
|
|
"""Tests to verify StoreHouse class.""" |
11
|
|
|
|
12
|
|
|
def setUp(self): |
13
|
|
|
"""Execute steps before each tests.""" |
14
|
|
|
self.storehouse = StoreHouse(get_controller_mock()) |
15
|
|
|
|
16
|
|
|
def test_get_stored_box(self): |
17
|
|
|
"""Test get_stored_box method.""" |
18
|
|
|
self.storehouse.controller.buffers = Mock() |
19
|
|
|
self.storehouse.get_stored_box(1) |
20
|
|
|
self.storehouse.controller.buffers.app.put.assert_called_once() |
21
|
|
|
|
22
|
|
|
def test_create_box(self): |
23
|
|
|
"""Test get_stored_box method.""" |
24
|
|
|
self.storehouse.controller.buffers = Mock() |
25
|
|
|
self.storehouse.create_box() |
26
|
|
|
self.storehouse.controller.buffers.app.put.assert_called_once() |
27
|
|
|
|
28
|
|
|
@patch('napps.kytos.mef_eline.storehouse.log') |
29
|
|
|
def test_save_evc_callback_no_error(self, log_mock): |
30
|
|
|
# pylint: disable=protected-access |
31
|
|
|
"""Test _save_evc_callback method.""" |
32
|
|
|
self.storehouse._lock = Mock() |
33
|
|
|
data = Mock() |
34
|
|
|
data.box_id = 1 |
35
|
|
|
self.storehouse._save_evc_callback('event', data, None) |
36
|
|
|
self.storehouse._lock.release.assert_called_once() |
37
|
|
|
log_mock.error.assert_not_called() |
38
|
|
|
|
39
|
|
|
@patch('napps.kytos.mef_eline.storehouse.log') |
40
|
|
|
def test_save_evc_callback_with_error(self, log_mock): |
41
|
|
|
# pylint: disable=protected-access |
42
|
|
|
"""Test _save_evc_callback method.""" |
43
|
|
|
self.storehouse._lock = Mock() |
44
|
|
|
self.storehouse.box = Mock() |
45
|
|
|
self.storehouse.box.box_id = 1 |
46
|
|
|
data = Mock() |
47
|
|
|
data.box_id = 1 |
48
|
|
|
self.storehouse._save_evc_callback('event', data, 'error') |
49
|
|
|
self.storehouse._lock.release.assert_called_once() |
50
|
|
|
log_mock.error.assert_called_once() |
51
|
|
|
|
52
|
|
|
@patch('napps.kytos.mef_eline.storehouse.StoreHouse.get_stored_box') |
53
|
|
|
def test_get_data(self, get_stored_box_mock): |
54
|
|
|
"""Test get_data method.""" |
55
|
|
|
self.storehouse.box = Mock() |
56
|
|
|
self.storehouse.box.box_id = 2 |
57
|
|
|
self.storehouse.get_data() |
58
|
|
|
get_stored_box_mock.assert_called_once_with(2) |
59
|
|
|
|