2424
2525
2626class StaticConfigManagerTest (base .BaseTest ):
27+ def test_init__invalid_logger_fails (self ):
28+ """ Test that initialization fails if logger is invalid. """
29+ class InvalidLogger (object ):
30+ pass
31+ with self .assertRaisesRegexp (optimizely_exceptions .InvalidInputException ,
32+ 'Provided "logger" is in an invalid format.' ):
33+ config_manager .StaticConfigManager (logger = InvalidLogger ())
34+
35+ def test_init__invalid_error_handler_fails (self ):
36+ """ Test that initialization fails if error_handler is invalid. """
37+ class InvalidErrorHandler (object ):
38+ pass
39+ with self .assertRaisesRegexp (optimizely_exceptions .InvalidInputException ,
40+ 'Provided "error_handler" is in an invalid format.' ):
41+ config_manager .StaticConfigManager (error_handler = InvalidErrorHandler ())
42+
43+ def test_init__invalid_notification_center_fails (self ):
44+ """ Test that initialization fails if notification_center is invalid. """
45+ class InvalidNotificationCenter (object ):
46+ pass
47+ with self .assertRaisesRegexp (optimizely_exceptions .InvalidInputException ,
48+ 'Provided "notification_center" is in an invalid format.' ):
49+ config_manager .StaticConfigManager (notification_center = InvalidNotificationCenter ())
50+
2751 def test_set_config__success (self ):
2852 """ Test set_config when datafile is valid. """
2953 test_datafile = json .dumps (self .config_dict_with_features )
3054 mock_logger = mock .Mock ()
3155 mock_notification_center = mock .Mock ()
32- project_config_manager = config_manager .StaticConfigManager (datafile = test_datafile ,
33- logger = mock_logger ,
34- notification_center = mock_notification_center )
56+
57+ with mock .patch ('optimizely.config_manager.BaseConfigManager._validate_instantiation_options' ):
58+ project_config_manager = config_manager .StaticConfigManager (datafile = test_datafile ,
59+ logger = mock_logger ,
60+ notification_center = mock_notification_center )
3561
3662 project_config_manager ._set_config (test_datafile )
3763 mock_logger .debug .assert_called_with ('Received new datafile and updated config. '
@@ -43,9 +69,11 @@ def test_set_config__twice(self):
4369 test_datafile = json .dumps (self .config_dict_with_features )
4470 mock_logger = mock .Mock ()
4571 mock_notification_center = mock .Mock ()
46- project_config_manager = config_manager .StaticConfigManager (datafile = test_datafile ,
47- logger = mock_logger ,
48- notification_center = mock_notification_center )
72+
73+ with mock .patch ('optimizely.config_manager.BaseConfigManager._validate_instantiation_options' ):
74+ project_config_manager = config_manager .StaticConfigManager (datafile = test_datafile ,
75+ logger = mock_logger ,
76+ notification_center = mock_notification_center )
4977
5078 project_config_manager ._set_config (test_datafile )
5179 mock_logger .debug .assert_called_with ('Received new datafile and updated config. '
@@ -71,16 +99,16 @@ def test_set_config__schema_validation(self):
7199 # Note: set_config is called in __init__ itself.
72100 with mock .patch ('optimizely.helpers.validator.is_datafile_valid' ,
73101 return_value = True ) as mock_validate_datafile :
74- config_manager .StaticConfigManager (datafile = test_datafile ,
75- logger = mock_logger )
102+ config_manager .StaticConfigManager (datafile = test_datafile ,
103+ logger = mock_logger )
76104 mock_validate_datafile .assert_called_once_with (test_datafile )
77105
78106 # Test that schema is not validated if skip_json_validation option is set to True.
79107 with mock .patch ('optimizely.helpers.validator.is_datafile_valid' ,
80108 return_value = True ) as mock_validate_datafile :
81- config_manager .StaticConfigManager (datafile = test_datafile ,
82- logger = mock_logger ,
83- skip_json_validation = True )
109+ config_manager .StaticConfigManager (datafile = test_datafile ,
110+ logger = mock_logger ,
111+ skip_json_validation = True )
84112 mock_validate_datafile .assert_not_called ()
85113
86114 def test_set_config__unsupported_datafile_version (self ):
@@ -90,9 +118,10 @@ def test_set_config__unsupported_datafile_version(self):
90118 mock_logger = mock .Mock ()
91119 mock_notification_center = mock .Mock ()
92120
93- project_config_manager = config_manager .StaticConfigManager (datafile = test_datafile ,
94- logger = mock_logger ,
95- notification_center = mock_notification_center )
121+ with mock .patch ('optimizely.config_manager.BaseConfigManager._validate_instantiation_options' ):
122+ project_config_manager = config_manager .StaticConfigManager (datafile = test_datafile ,
123+ logger = mock_logger ,
124+ notification_center = mock_notification_center )
96125
97126 invalid_version_datafile = self .config_dict_with_features .copy ()
98127 invalid_version_datafile ['version' ] = 'invalid_version'
@@ -111,9 +140,10 @@ def test_set_config__invalid_datafile(self):
111140 mock_logger = mock .Mock ()
112141 mock_notification_center = mock .Mock ()
113142
114- project_config_manager = config_manager .StaticConfigManager (datafile = test_datafile ,
115- logger = mock_logger ,
116- notification_center = mock_notification_center )
143+ with mock .patch ('optimizely.config_manager.BaseConfigManager._validate_instantiation_options' ):
144+ project_config_manager = config_manager .StaticConfigManager (datafile = test_datafile ,
145+ logger = mock_logger ,
146+ notification_center = mock_notification_center )
117147
118148 # Call set_config with invalid content
119149 project_config_manager ._set_config ('invalid_datafile' )
@@ -220,7 +250,7 @@ def test_set_last_modified(self, _):
220250 def test_fetch_datafile (self , _ ):
221251 """ Test that fetch_datafile sets config and last_modified based on response. """
222252 with mock .patch ('optimizely.config_manager.PollingConfigManager.fetch_datafile' ):
223- project_config_manager = config_manager .PollingConfigManager (sdk_key = 'some_key' )
253+ project_config_manager = config_manager .PollingConfigManager (sdk_key = 'some_key' )
224254 expected_datafile_url = 'https://cdn.optimizely.com/datafiles/some_key.json'
225255 test_headers = {
226256 'Last-Modified' : 'New Time'
@@ -249,6 +279,6 @@ def test_fetch_datafile(self, _):
249279 def test_is_running (self , _ ):
250280 """ Test that polling thread is running after instance of PollingConfigManager is created. """
251281 with mock .patch ('optimizely.config_manager.PollingConfigManager.fetch_datafile' ) as mock_fetch_datafile :
252- project_config_manager = config_manager .PollingConfigManager (sdk_key = 'some_key' )
253- self .assertTrue (project_config_manager .is_running )
282+ project_config_manager = config_manager .PollingConfigManager (sdk_key = 'some_key' )
283+ self .assertTrue (project_config_manager .is_running )
254284 mock_fetch_datafile .assert_called_with ()
0 commit comments