Beispiel #1
0
    def __init__(self):

        if "CONFIGCAT_TEST_TOKEN" in os.environ:
            configcat_token = os.environ["CONFIGCAT_TEST_TOKEN"]
        else:
            configcat_token = "NgLYCNlqy0GD2zYrTE_p_w/GNzk7N3Sa0KzKJrhdqfUQw"

        self.configcat_client = configcatclient.create_client(configcat_token)
 def test_force_refresh(self):
     client = configcatclient.create_client(_SDK_KEY)
     self.assertEqual('This text came from ConfigCat',
                      client.get_value('keySampleText', 'default value'))
     client.force_refresh()
     self.assertEqual('This text came from ConfigCat',
                      client.get_value('keySampleText', 'default value'))
     client.stop()
Beispiel #3
0
def test_joke():
    if "CONFIGCAT_TEST_TOKEN" in os.environ:
        configcat_token = os.environ["CONFIGCAT_TEST_TOKEN"]
    else:
        configcat_token = "NgLYCNlqy0GD2zYrTE_p_w/GNzk7N3Sa0KzKJrhdqfUQw"

    configcat_client = configcatclient.create_client(configcat_token)

    new_joke_flag = configcat_client.get_value('newjoke', False)

    if new_joke_flag:
        assert "¿Por qué las focas del circo miran...?" == SpanishJoke().joke()
    else:
        assert "¿En que se parecen...?" == SpanishJoke().joke()
Beispiel #4
0
    def _test_matrix(self, file_path, sdk_key, type):
        script_dir = path.dirname(__file__)
        file_path = path.join(script_dir, file_path)

        with open(file_path, 'r') as f:
            content = f.readlines()

        # CSV header
        header = content[0].rstrip()
        setting_keys = header.split(';')[4:]
        custom_key = header.split(';')[3]
        content.pop(0)

        client = configcatclient.create_client(sdk_key)
        errors = ''
        for line in content:
            user_descriptor = line.rstrip().split(';')

            user_object = None
            if user_descriptor[0] is not None and user_descriptor[0] != '##null##':
                email = None
                country = None
                custom = None

                identifier = user_descriptor[0]

                if user_descriptor[1] is not None and user_descriptor[1] != '' and user_descriptor[1] != '##null##':
                    email = user_descriptor[1]

                if user_descriptor[2] is not None and user_descriptor[2] != '' and user_descriptor[2] != '##null##':
                    country = user_descriptor[2]

                if user_descriptor[3] is not None and user_descriptor[3] != '' and user_descriptor[3] != '##null##':
                    custom = {custom_key: user_descriptor[3]}

                user_object = User(identifier, email, country, custom)

            i = 0
            for setting_key in setting_keys:
                value = client.get_variation_id(setting_key, None, user_object) if type == self.variation_test_type \
                    else client.get_value(setting_key, None, user_object)
                if str(value) != str(user_descriptor[i + 4]):
                    errors += 'Identifier: ' + user_descriptor[0] + '. SettingKey: ' + setting_key + \
                              '. Expected: ' + str(user_descriptor[i + 4]) + '. Result: ' + str(value) + '.\n'
                i += 1

        self.assertEqual('', errors)
        client.stop()
Beispiel #5
0
    def test_concurrency_process(self):
        client = configcatclient.create_client(
            'PKDVCLf-Hq-h-kCzMp-L7Q/psuH7BGHoUmdONrzzUOY7A')
        value = client.get_value('keySampleText', False, User('key'))
        print("'keySampleText' value from ConfigCat: " + str(value))

        p1 = multiprocessing.Process(target=_manual_force_refresh,
                                     args=(client, ))
        p2 = multiprocessing.Process(target=_manual_force_refresh,
                                     args=(client, ))
        p1.start()
        p2.start()
        p1.join()
        p2.join()

        client.stop()
Beispiel #6
0
"""
You should install the ConfigCat-Client package before using this sample project
pip install configcat-client
"""

import configcatclient
import logging
from configcatclient.user import User

logging.basicConfig(level=logging.DEBUG)

if __name__ == '__main__':
    # Initialize the ConfigCatClient with an SDK Key.
    client = configcatclient.create_client(
        'PKDVCLf-Hq-h-kCzMp-L7Q/psuH7BGHoUmdONrzzUOY7A')

    # In the project there is a 'keySampleText' setting with the following rules:
    # 1. If the User's country is Hungary, the value should be 'Dog'
    # 2. If the User's custom property - SubscriptionType - is unlimited, the value should be 'Lion'
    # 3. In other cases there is a percentage rollout configured with 50% 'Falcon' and 50% 'Horse' rules.
    # 4. There is also a default value configured: 'Cat'

    # 1. As the passed User's country is Hungary this will print 'Dog'
    my_setting_value = client.get_value('keySampleText', 'default value',
                                        User('key', country='Hungary'))
    print("'keySampleText' value from ConfigCat: " + str(my_setting_value))

    # 2. As the passed User's custom attribute - SubscriptionType - is unlimited this will print 'Lion'
    my_setting_value = client.get_value(
        'keySampleText', 'default value',
        User('key', custom={'SubscriptionType': 'unlimited'}))
Beispiel #7
0
 def test_wrong_user_object(self):
     client = configcatclient.create_client('PKDVCLf-Hq-h-kCzMp-L7Q/psuH7BGHoUmdONrzzUOY7A')
     setting_value = client.get_value('stringContainsDogDefaultCat', 'Lion', {'Email': '*****@*****.**'})
     self.assertEqual('Cat', setting_value)
     client.stop()
 def test_get_all_values(self):
     client = configcatclient.create_client(_SDK_KEY)
     all_values = client.get_all_values()
     self.assertEqual(5, len(all_values))
     self.assertEqual('This text came from ConfigCat',
                      all_values['keySampleText'])
 def test_get_all_keys(self):
     client = configcatclient.create_client(_SDK_KEY)
     keys = client.get_all_keys()
     self.assertEqual(5, len(keys))
     self.assertTrue('keySampleText' in keys)
 def test_without_sdk_key(self):
     try:
         configcatclient.create_client(None)
         self.fail('Expected ConfigCatClientException')
     except ConfigCatClientException:
         pass
Beispiel #11
0
"""
You should install the ConfigCat-Client package before using this sample project
pip install configcat-client
"""

import configcatclient
import logging
from configcatclient.user import User

# Info level logging helps to inspect the feature flag evaluation process.
# Use the default warning level to avoid too detailed logging in your application.
logging.basicConfig(level=logging.INFO)

if __name__ == '__main__':
    # Initialize the ConfigCatClient with an SDK Key.
    client = configcatclient.create_client(
        'PKDVCLf-Hq-h-kCzMp-L7Q/HhOWfwVtZ0mb30i9wi17GQ')

    # Creating a user object to identify your user (optional).
    userObject = User('Some UserID',
                      email='*****@*****.**',
                      custom={'version': '1.0.0'})

    value = client.get_value('isPOCFeatureEnabled', False, userObject)
    print("'isPOCFeatureEnabled' value from ConfigCat: " + str(value))

    client.stop()
Beispiel #12
0
class WebappConfig(AppConfig):
    name = 'webapp'
    configcat_client = configcatclient.create_client(
        'PKDVCLf-Hq-h-kCzMp-L7Q/psuH7BGHoUmdONrzzUOY7A')