diff --git a/configcatclient/localfiledatasource.py b/configcatclient/localfiledatasource.py index 9f5c0b7..d6120e8 100644 --- a/configcatclient/localfiledatasource.py +++ b/configcatclient/localfiledatasource.py @@ -39,6 +39,6 @@ def _reload_file_content(self): self._settings = data except OSError as e: log.error('Could not read the content of the file %s. %s' % (self._file_path, e)) - except json.decoder.JSONDecodeError as e: + except ValueError as e: log.error('Could not decode json from file %s. %s' % (self._file_path, e)) diff --git a/configcatclient/version.py b/configcatclient/version.py index 9e5cb12..2519168 100644 --- a/configcatclient/version.py +++ b/configcatclient/version.py @@ -1 +1 @@ -CONFIGCATCLIENT_VERSION = "6.0.0" +CONFIGCATCLIENT_VERSION = "6.0.1" diff --git a/configcatclienttests/test_local.py b/configcatclienttests/test_local.py index 6823729..1c1e2f0 100644 --- a/configcatclienttests/test_local.py +++ b/configcatclienttests/test_local.py @@ -1,6 +1,9 @@ import logging import unittest from os import path +import tempfile +import json +import time from configcatclient import ConfigCatClient from configcatclient.localdictionarydatasource import LocalDictionaryDataSource @@ -65,6 +68,52 @@ def test_non_existent_file(self): self.assertFalse(client.get_value('enabledFeature', False)) client.stop() + def test_reload_file(self): + temp = tempfile.NamedTemporaryFile(mode="w") + dictionary = {'flags': { + 'enabledFeature': False + }} + json.dump(dictionary, temp) + temp.flush() + + client = ConfigCatClient(sdk_key='test', + poll_interval_seconds=0, + max_init_wait_time_seconds=0, + flag_overrides=LocalFileDataSource(file_path=temp.name, + override_behaviour=OverrideBehaviour.LocalOnly)) + + self.assertFalse(client.get_value('enabledFeature', True)) + + time.sleep(0.5) + + # clear the content of the temp file + temp.seek(0) + temp.truncate() + + # change the temporary file + dictionary['flags']['enabledFeature'] = True + json.dump(dictionary, temp) + temp.flush() + + self.assertTrue(client.get_value('enabledFeature', False)) + + client.stop() + + def test_invalid_file(self): + temp = tempfile.NamedTemporaryFile(mode="w") + temp.write('{"flags": {"enabledFeature": true}') + temp.flush() + + client = ConfigCatClient(sdk_key='test', + poll_interval_seconds=0, + max_init_wait_time_seconds=0, + flag_overrides=LocalFileDataSource(file_path=temp.name, + override_behaviour=OverrideBehaviour.LocalOnly)) + + self.assertFalse(client.get_value('enabledFeature', False)) + + client.stop() + def test_dictionary(self): dictionary = { 'enabledFeature': True, diff --git a/setup.py b/setup.py index 05f5938..fe323d0 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ def parse_requirements(filename): return [line for line in lines if line] -configcatclient_version = '6.0.0' +configcatclient_version = '6.0.1' requirements = parse_requirements('requirements.txt')