Added warning to information collector
This commit is contained in:
1 parent
c34dc7fdd3
commit
956ade4d03
3 files changed
+82
No files matched your search
@@ -0,0 +1,45 @@
|
||||
from pathlib import Path
|
||||
import sys
|
||||
import unittest
|
||||
from unittest.mock import Mock
|
||||
|
||||
sys.path[:0] = [str(Path(__file__).resolve().parents[1] / 'apps'),
|
||||
str(Path(__file__).resolve().parents[1] / 'apps/ad_toolbox')]
|
||||
|
||||
from informationscollector import InformationsCollector
|
||||
|
||||
|
||||
class WarningCollectorTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.app = object.__new__(InformationsCollector)
|
||||
self.app.warning_list = []
|
||||
self.app.warning_count_sensor = Mock()
|
||||
self.app.warning_count_sensor.get_state.return_value = '2'
|
||||
|
||||
def test_warning_is_counted_and_exposed_in_attributes(self):
|
||||
self.app.on_log_warning(
|
||||
'example', None, 'WARNING', None, 'Something happened', {}
|
||||
)
|
||||
|
||||
self.app.warning_count_sensor.set_state.assert_called_once_with(
|
||||
state=3,
|
||||
attributes={
|
||||
'last_warning': 'Something happened',
|
||||
'warning_list': ['Something happened'],
|
||||
},
|
||||
)
|
||||
|
||||
def test_warning_reset_clears_count_and_attributes(self):
|
||||
self.app.warning_list = ['Old warning']
|
||||
|
||||
self.app.on_reset_warning_count(None, None, None, None, {})
|
||||
|
||||
self.assertEqual(self.app.warning_list, [])
|
||||
self.app.warning_count_sensor.set_state.assert_called_once_with(
|
||||
state=0,
|
||||
attributes={'last_warning': '', 'warning_list': []},
|
||||
)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user