From 152401edb9af54b0840a98821aab6ee64f7ed06c Mon Sep 17 00:00:00 2001 From: FarhanAnjum-opti Date: Thu, 19 Feb 2026 21:18:26 +0600 Subject: [PATCH 1/2] fix: update PollingConfigManager initialization requirements and enhance tests for url handling --- optimizely/config_manager.py | 5 +---- tests/test_config_manager.py | 32 +++++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/optimizely/config_manager.py b/optimizely/config_manager.py index 3dce2741..28e71848 100644 --- a/optimizely/config_manager.py +++ b/optimizely/config_manager.py @@ -204,7 +204,7 @@ def __init__( skip_json_validation: Optional[bool] = False, retries: Optional[int] = 3, ): - """ Initialize config manager. One of sdk_key or datafile has to be set to be able to use. + """ Initialize config manager. One of sdk_key or url is required if datafile is not provided. Args: sdk_key: Optional string uniquely identifying the datafile. If not provided, datafile must @@ -236,9 +236,6 @@ def __init__( ) self._sdk_key = sdk_key or self._sdk_key - if self._sdk_key is None: - raise optimizely_exceptions.InvalidInputException(enums.Errors.MISSING_SDK_KEY) - self.datafile_url = self.get_datafile_url( self._sdk_key, url, url_template or self.DATAFILE_URL_TEMPLATE ) diff --git a/tests/test_config_manager.py b/tests/test_config_manager.py index 1930520e..0e8cb7b3 100644 --- a/tests/test_config_manager.py +++ b/tests/test_config_manager.py @@ -224,12 +224,34 @@ def test_init__no_sdk_key_no_datafile__fails(self, _): """ Test that initialization fails if there is no sdk_key or datafile provided. """ self.assertRaisesRegex( optimizely_exceptions.InvalidInputException, - enums.Errors.MISSING_SDK_KEY, + 'Must provide at least one of sdk_key or url.', config_manager.PollingConfigManager, sdk_key=None, datafile=None, ) + def test_init__url_only__succeeds(self, _): + """ Test that initialization succeeds when only url is provided (no sdk_key). """ + test_url = 'https://mydatafiles.com/my_datafile.json' + test_headers = {'Last-Modified': 'New Time'} + test_datafile = json.dumps(self.config_dict_with_features) + test_response = requests.Response() + test_response.status_code = 200 + test_response.headers = test_headers + test_response._content = test_datafile + + with mock.patch('requests.Session.get', return_value=test_response) as mock_request: + project_config_manager = config_manager.PollingConfigManager(url=test_url) + project_config_manager.stop() + + mock_request.assert_called_once_with( + test_url, + headers={}, + timeout=enums.ConfigManager.REQUEST_TIMEOUT + ) + self.assertEqual(test_url, project_config_manager.datafile_url) + self.assertIsInstance(project_config_manager.get_config(), project_config.ProjectConfig) + def test_get_datafile_url__no_sdk_key_no_url_raises(self, _): """ Test that get_datafile_url raises exception if no sdk_key or url is provided. """ self.assertRaisesRegex( @@ -273,6 +295,14 @@ def test_get_datafile_url__sdk_key_and_template_provided(self, _): expected_url, config_manager.PollingConfigManager.get_datafile_url(test_sdk_key, None, test_url_template), ) + def test_get_datafile_url__url_provided(self, _): + """ Test get_datafile_url when only url is provided (no sdk_key). """ + test_url = 'www.myoptimizelydatafiles.com/my_key.json' + # url_template is ignored when url is provided + self.assertEqual( + test_url, config_manager.PollingConfigManager.get_datafile_url(None, test_url, None), + ) + def test_get_datafile_url__url_and_template_provided(self, _): """ Test get_datafile_url when url and url_template are provided. """ test_url_template = 'www.optimizelydatafiles.com/{sdk_key}.json' From f18f1671261b0de7ef807f8a03e199f6a6cd5ab7 Mon Sep 17 00:00:00 2001 From: FarhanAnjum-opti Date: Thu, 19 Feb 2026 21:24:03 +0600 Subject: [PATCH 2/2] fix: clarify initialization requirements for PollingConfigManager --- optimizely/config_manager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/optimizely/config_manager.py b/optimizely/config_manager.py index 28e71848..21c74973 100644 --- a/optimizely/config_manager.py +++ b/optimizely/config_manager.py @@ -204,7 +204,7 @@ def __init__( skip_json_validation: Optional[bool] = False, retries: Optional[int] = 3, ): - """ Initialize config manager. One of sdk_key or url is required if datafile is not provided. + """ Initialize config manager. One of sdk_key or datafile has to be set to be able to use. Args: sdk_key: Optional string uniquely identifying the datafile. If not provided, datafile must