File tree Expand file tree Collapse file tree 2 files changed +43
-0
lines changed
Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Original file line number Diff line number Diff line change 44from pyobas .daemons import BaseDaemon
55from pyobas .utils import PingAlive
66
7+ DEFAULT_PERIOD_SECONDS = 60
8+
79
810class CollectorDaemon (BaseDaemon ):
911 """Implementation of a daemon of Collector type. Note that it requires
@@ -16,6 +18,8 @@ class CollectorDaemon(BaseDaemon):
1618 """
1719
1820 def _setup (self ):
21+ if self ._configuration .get ("collector_period" ) is None :
22+ self ._configuration .set ("collector_period" , DEFAULT_PERIOD_SECONDS )
1923 icon_path = self ._configuration .get ("collector_icon_filepath" )
2024 icon_name = self ._configuration .get ("collector_id" ) + ".png"
2125 with open (icon_path , "rb" ) as icon_file_handle :
Original file line number Diff line number Diff line change 1+ import unittest
2+ from unittest .mock import mock_open , patch
3+
4+ from pyobas .configuration import Configuration
5+ from pyobas .daemons import CollectorDaemon
6+ from pyobas .daemons .collector_daemon import DEFAULT_PERIOD_SECONDS
7+
8+
9+ class TestCollectorDaemon (unittest .TestCase ):
10+ @patch ("pyobas.apis.DocumentManager.upsert" )
11+ @patch ("pyobas.apis.CollectorManager.create" )
12+ @patch ("builtins.open" , new_callable = mock_open , read_data = "data" )
13+ @patch ("pyobas.utils.PingAlive.start" )
14+ def test_when_no_period_config_provided_set_default_period (
15+ self ,
16+ mock_ping_alive ,
17+ mock_open_local ,
18+ mock_collector_create ,
19+ mock_document_upsert ,
20+ ):
21+ mock_ping_alive .return_value = None
22+ mock_collector_create .return_value = {}
23+ mock_document_upsert .return_value = {}
24+ config = Configuration (
25+ config_hints = {
26+ "openbas_url" : {"data" : "fake" },
27+ "openbas_token" : {"data" : "fake" },
28+ "collector_id" : {"data" : "fake id" },
29+ }
30+ )
31+ collector = CollectorDaemon (config )
32+
33+ collector ._setup ()
34+
35+ self .assertEqual (config .get ("collector_period" ), DEFAULT_PERIOD_SECONDS )
36+
37+
38+ if __name__ == "__main__" :
39+ unittest .main ()
You can’t perform that action at this time.
0 commit comments