Example #1
0
    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()
Example #2
0
    def test_simple_file(self):
        client = ConfigCatClient(
            sdk_key='test',
            poll_interval_seconds=0,
            max_init_wait_time_seconds=0,
            flag_overrides=LocalFileDataSource(
                file_path=path.join(LocalTests.script_dir, 'test-simple.json'),
                override_behaviour=OverrideBehaviour.LocalOnly))

        self.assertTrue(client.get_value('enabledFeature', False))
        self.assertFalse(client.get_value('disabledFeature', True))
        self.assertEqual(5, client.get_value('intSetting', 0))
        self.assertEqual(3.14, client.get_value('doubleSetting', 0.0))
        self.assertEqual('test', client.get_value('stringSetting', ''))
        client.stop()
Example #3
0
    def test_remote_over_local(self, mock_get):
        dictionary = {'fakeKey': True, 'nonexisting': True}

        client = ConfigCatClient(
            sdk_key='test',
            poll_interval_seconds=0,
            max_init_wait_time_seconds=0,
            flag_overrides=LocalDictionaryDataSource(
                source=dictionary,
                override_behaviour=OverrideBehaviour.RemoteOverLocal))
        client.force_refresh()

        self.assertFalse(client.get_value('fakeKey', True))
        self.assertTrue(client.get_value('nonexisting', False))
        client.stop()
Example #4
0
 def test_non_existent_file(self):
     client = ConfigCatClient(
         sdk_key='test',
         poll_interval_seconds=0,
         max_init_wait_time_seconds=0,
         flag_overrides=LocalFileDataSource(
             file_path='non_existent.json',
             override_behaviour=OverrideBehaviour.LocalOnly))
     self.assertFalse(client.get_value('enabledFeature', False))
     client.stop()
Example #5
0
    def test_dictionary(self):
        dictionary = {
            'enabledFeature': True,
            'disabledFeature': False,
            'intSetting': 5,
            'doubleSetting': 3.14,
            'stringSetting': 'test'
        }

        client = ConfigCatClient(
            sdk_key='test',
            poll_interval_seconds=0,
            max_init_wait_time_seconds=0,
            flag_overrides=LocalDictionaryDataSource(
                source=dictionary,
                override_behaviour=OverrideBehaviour.LocalOnly))

        self.assertTrue(client.get_value('enabledFeature', False))
        self.assertFalse(client.get_value('disabledFeature', True))
        self.assertEqual(5, client.get_value('intSetting', 0))
        self.assertEqual(3.14, client.get_value('doubleSetting', 0.0))
        self.assertEqual('test', client.get_value('stringSetting', ''))
        client.stop()
Example #6
0
    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()