Skip to content

Commit 99786cb

Browse files
authored
Merge pull request #31 from configcat/localfile-tests
test_reload_file + test_invalid_file
2 parents 73ec2cc + a484702 commit 99786cb

File tree

4 files changed

+52
-3
lines changed

4 files changed

+52
-3
lines changed

configcatclient/localfiledatasource.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@ def _reload_file_content(self):
3939
self._settings = data
4040
except OSError as e:
4141
log.error('Could not read the content of the file %s. %s' % (self._file_path, e))
42-
except json.decoder.JSONDecodeError as e:
42+
except ValueError as e:
4343
log.error('Could not decode json from file %s. %s' % (self._file_path, e))
4444

configcatclient/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
CONFIGCATCLIENT_VERSION = "6.0.0"
1+
CONFIGCATCLIENT_VERSION = "6.0.1"

configcatclienttests/test_local.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import logging
22
import unittest
33
from os import path
4+
import tempfile
5+
import json
6+
import time
47

58
from configcatclient import ConfigCatClient
69
from configcatclient.localdictionarydatasource import LocalDictionaryDataSource
@@ -65,6 +68,52 @@ def test_non_existent_file(self):
6568
self.assertFalse(client.get_value('enabledFeature', False))
6669
client.stop()
6770

71+
def test_reload_file(self):
72+
temp = tempfile.NamedTemporaryFile(mode="w")
73+
dictionary = {'flags': {
74+
'enabledFeature': False
75+
}}
76+
json.dump(dictionary, temp)
77+
temp.flush()
78+
79+
client = ConfigCatClient(sdk_key='test',
80+
poll_interval_seconds=0,
81+
max_init_wait_time_seconds=0,
82+
flag_overrides=LocalFileDataSource(file_path=temp.name,
83+
override_behaviour=OverrideBehaviour.LocalOnly))
84+
85+
self.assertFalse(client.get_value('enabledFeature', True))
86+
87+
time.sleep(0.5)
88+
89+
# clear the content of the temp file
90+
temp.seek(0)
91+
temp.truncate()
92+
93+
# change the temporary file
94+
dictionary['flags']['enabledFeature'] = True
95+
json.dump(dictionary, temp)
96+
temp.flush()
97+
98+
self.assertTrue(client.get_value('enabledFeature', False))
99+
100+
client.stop()
101+
102+
def test_invalid_file(self):
103+
temp = tempfile.NamedTemporaryFile(mode="w")
104+
temp.write('{"flags": {"enabledFeature": true}')
105+
temp.flush()
106+
107+
client = ConfigCatClient(sdk_key='test',
108+
poll_interval_seconds=0,
109+
max_init_wait_time_seconds=0,
110+
flag_overrides=LocalFileDataSource(file_path=temp.name,
111+
override_behaviour=OverrideBehaviour.LocalOnly))
112+
113+
self.assertFalse(client.get_value('enabledFeature', False))
114+
115+
client.stop()
116+
68117
def test_dictionary(self):
69118
dictionary = {
70119
'enabledFeature': True,

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ def parse_requirements(filename):
66
return [line for line in lines if line]
77

88

9-
configcatclient_version = '6.0.0'
9+
configcatclient_version = '6.0.1'
1010

1111
requirements = parse_requirements('requirements.txt')
1212

0 commit comments

Comments
 (0)