8000 init · optimizely/python-sdk@3cdb51f · GitHub
[go: up one dir, main page]

Skip to content

Commit 3cdb51f

Browse files
committed
init
1 parent b6c2c63 commit 3cdb51f

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

optimizely/config_manager.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ def _set_config(self, datafile):
130130
return
131131

132132
self._config = config
133-
self.optimizely_config = OptimizelyConfigService(config).get_config()
133+
if self.optimizely_config is not None:
134+
self.optimizely_config = OptimizelyConfigService(self._config).get_config()
134135
self.notification_center.send_notifications(enums.NotificationTypes.OPTIMIZELY_CONFIG_UPDATE)
135136
self.logger.debug(
136137
'Received new datafile and updated config. '
@@ -146,6 +147,12 @@ def get_config(self):
146147

147148
return self._config
148149

150+
def get_optimizely_config(self):
151+
if self.optimizely_config is None:
152+
self.optimizely_config = OptimizelyConfigService(self._config).get_config()
153+
154+
return self.optimizely_config
155+
149156

150157
class PollingConfigManager(StaticConfigManager):
151158
""" Config manager that polls for the datafile and updated ProjectConfig based on an update interval. """

optimizely/optimizely.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -944,7 +944,7 @@ def get_optimizely_config(self):
944944

945945
# Customized Config Manager may not have optimizely_config defined.
946946
if hasattr(self.config_manager, 'optimizely_config'):
947-
return self.config_manager.optimizely_config
947+
return self.config_manager.get_optimizely_config()
948948

949949
return OptimizelyConfigService(project_config).get_config()
950950

tests/test_config_manager.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def test_set_config__success(self):
7777
mock_notification_center.send_notifications.assert_called_once_with('OPTIMIZELY_CONFIG_UPDATE')
7878

7979
self.assertIsInstance(
80-
project_config_manager.optimizely_config,
80+
project_config_manager.get_optimizely_config(),
8181
optimizely_config.OptimizelyConfig
8282
)
8383

@@ -99,7 +99,7 @@ def test_set_config__twice__with_same_content(self):
9999
)
100100
self.assertEqual(1, mock_logger.debug.call_count)
101101
mock_notification_center.send_notifications.assert_called_once_with('OPTIMIZELY_CONFIG_UPDATE')
102-
self.assertEqual(1, mock_opt_service.call_count)
102+
self.assertEqual(0, mock_opt_service.call_count)
103103

104104
mock_logger.reset_mock()
105105
mock_notification_center.reset_mock()
@@ -128,7 +128,7 @@ def test_set_config__twice__with_diff_content(self):
128128
)
129129
self.assertEqual(1, mock_logger.debug.call_count)
130130
mock_notification_center.send_notifications.assert_called_once_with('OPTIMIZELY_CONFIG_UPDATE')
131-
self.assertEqual('1', project_config_manager.optimizely_config.revision)
131+
self.assertEqual('1', project_config_manager.get_optimizely_config().revision)
132132

133133
mock_logger.reset_mock()
134134
mock_notification_center.reset_mock()
@@ -141,7 +141,7 @@ def test_set_config__twice__with_diff_content(self):
141141
)
142142
self.assertEqual(1, mock_logger.debug.call_count)
143143
mock_notification_center.send_notifications.assert_called_once_with('OPTIMIZELY_CONFIG_UPDATE')
144-
self.assertEqual('42', project_config_manager.optimizely_config.revision)
144+
self.assertEqual('42', project_config_manager.get_optimizely_config().revision)
145145

146146
def test_set_config__schema_validation(self):
147147
""" Test set_config calls or does not call schema validation based on skip_json_validation value. """

0 commit comments

Comments
 (0)
0