def test_locations_yaml_chain_multi(): os.environ['FOO'] = '1' os.environ['BAR'] = '2' os.environ['BAZ'] = '3' os.environ['TEST_SETTINGS'] = 'tests.data.settings1' config = Config(chain=True) config.locations = [ Location.from_env_keys(['FOO', 'BAR', 'BAZ']), Location.from_python('tests.data.settings2'), Location.from_env_python('TEST_SETTINGS'), ] assert config.data.FOO == '1' assert config.data.BAR == '2' assert config.data.BAZ == '3' assert config.data.CELERY_RESULT_BACKEND == 'amqp' assert config.data.CACHES['default']['BACKEND'] == \ 'django.core.cache.backends.memcached.MemcachedCache' assert 'south' in config.data.INSTALLED_APPS assert config.data.USE_TZ == True assert config.data.custom_show_toolbar() == True # testing extension assert config.data.EXTRA1 == 1 assert config.data.EXTRA2 == 2
def test_locations_yaml_chain_multi(): os.environ['FOO'] = '1' os.environ['BAR'] = '2' os.environ['BAZ'] = '3' os.environ['TEST_SETTINGS'] = './tests/data/settings1.yaml' config = Config(chain=True) config.locations = [ Location.from_env_keys(['FOO', 'BAR', 'BAZ']), Location.from_env_path('TEST_SETTINGS'), Location.from_path('./tests/data/settings2.yaml') ] assert config.data.FOO == '1' assert config.data.BAR == '2' assert config.data.BAZ == '3' assert config.data.name == 'Ollie' assert config.data.occupation == 'Cat' assert config.data.Sound == 'Meow' assert config.data['foo.bar.baz']['name'] == 'lucy' # testing extension assert config.data.extra1 == 1 assert config.data.extra2 == 1
def test_locations_json_chain_multi(): os.environ['FOO'] = '1' os.environ['BAR'] = '2' os.environ['BAZ'] = '3' os.environ['TEST_SETTINGS'] = './tests/data/settings1.json' config = Config(chain=True) config.locations = [ Location.from_env_keys(['FOO', 'BAR', 'BAZ']), Location.from_env_path('TEST_SETTINGS'), Location.from_path('./tests/data/settings2.json') ] assert config.data.FOO == '1' assert config.data.BAR == '2' assert config.data.BAZ == '3' assert config.data.name == 'Ollie' assert config.data.occupation == 'Cat' assert config.data.Sound == 'Meow' assert config.data['foo.bar.baz']['name'] == 'lucy' # testing extension assert config.data.extra1 == 1 assert config.data.extra2 == 1 #testing attribute dict assert config.data.extra3.foo.bar.baz == 'lucy'
def test_locations_configparser_chain_multi(): os.environ['FOO'] = '1' os.environ['BAR'] = '2' os.environ['BAZ'] = '3' os.environ['TEST_SETTINGS'] = './tests/data/settings1.ini' config = Config(chain=True) config.locations = [ Location.from_env_keys(['FOO', 'BAR', 'BAZ']), Location.from_env_path('TEST_SETTINGS'), Location.from_path('./tests/data/settings2.ini') ] assert config.data.FOO == '1' assert config.data.BAR == '2' assert config.data.BAZ == '3' assert config.data.section1['foo'] == '1' assert config.data.section1['bar'] == '2' assert config.data.section1['baz'] == '3' assert config.data.section2['dog'] == 'lucy' assert config.data.section2['cat'] == 'ollie' assert config.data.section3['zap'] == '1' assert config.data.section3['qux'] == '2' assert config.data.section3['quux'] == '3' assert config.data.section4['lucy'] == 'dog' assert config.data.section4['ollie'] == 'cat'
def test_locations_yaml_first(): config = Config() config.locations = [Location.from_path('./tests/data/settings1.yaml')] assert config.data.name == 'Lucy' assert config.data.occupation == 'Dog' assert config.data.Sound == 'Woof' assert config.data['foo.bar.baz']['name'] == 'ollie'
def test_locations_env_keys_chain_replace(): defaults = {'FOO': '20'} os.environ['FOO'] = '1' config = Config(defaults=defaults, chain=True) config.locations = [Location.from_env_keys(['FOO'])] assert config.data.FOO == '1'
def test_locations_json_first(): config = Config() config.locations = [Location.from_path('./tests/data/settings1.json')] assert config.data.name == 'Lucy' assert config.data.occupation == 'Dog' assert config.data.Sound == 'Woof' assert config.data['foo.bar.baz']['name'] == 'ollie'
def test_locations_dict_first(): config = Config() config.locations = [ Location.from_dict({'name': 'Lucy'}), Location.from_dict({'name': 'Ollie'}), ] assert config.data.name == 'Lucy'
def test_missing_env_key_with_defaults(): defaults = {'ZAF': 'ducks'} config = Config(chain=True, defaults=defaults) config.locations = [ Location.from_env_keys(['ZAF']), ] assert config.data.ZAF == 'ducks'
def test_locations_configparser_first(): config = Config() config.locations = [Location.from_path('./tests/data/settings1.ini')] assert config.data.section1['foo'] == '1' assert config.data.section1['bar'] == '2' assert config.data.section1['baz'] == '3' assert config.data.section2['dog'] == 'lucy' assert config.data.section2['cat'] == 'ollie'
def test_locations_yaml_first_env(): os.environ['TEST_SETTINGS'] = './tests/data/settings1.yaml' config = Config() config.locations = [Location.from_env_path('TEST_SETTINGS')] assert config.data.name == 'Lucy' assert config.data.occupation == 'Dog' assert config.data.Sound == 'Woof' assert config.data['foo.bar.baz']['name'] == 'ollie'
def test_locations_dict_chain(): config = Config(chain=True) config.locations = [ Location.from_dict({'name': 'Lucy'}), Location.from_dict({'nombre': 'Ollie'}), ] assert config.data.name == 'Lucy' assert config.data.nombre == 'Ollie'
def test_locations_env_keys_first_extend(): defaults = {'FOO': '20'} os.environ['FOO'] = '1' config = Config(defaults=defaults) config.locations = [Location.from_env_keys(['FOO'])] config.extend({'BAR': 2}) assert config.data.FOO == '1' assert config.data.BAR == 2
def load_config(overrides): config = Config(chain=True, defaults=defaults) config.locations = [ Location.from_env_keys(env_keys), Location.from_path(user_config), Location.from_path(local_config), Location.from_dict(overrides), ] return config
def test_locations_configparser_first_env(): os.environ['TEST_SETTINGS'] = './tests/data/settings1.ini' config = Config() config.locations = [Location.from_env_path('TEST_SETTINGS')] assert config.data.section1['foo'] == '1' assert config.data.section1['bar'] == '2' assert config.data.section1['baz'] == '3' assert config.data.section2['dog'] == 'lucy' assert config.data.section2['cat'] == 'ollie'
def test_locations_python_first(): config = Config() config.locations = [Location.from_python('tests.data.settings1')] assert config.data.CELERY_RESULT_BACKEND == 'amqp' assert config.data.CACHES['default']['BACKEND'] == \ 'django.core.cache.backends.memcached.MemcachedCache' assert 'south' in config.data.INSTALLED_APPS assert config.data.USE_TZ == True assert config.data.custom_show_toolbar() == True
def test_locations_json_first_multi_fail(): os.environ['TEST_SETTINGS'] = './tests/data/notfound' config = Config() config.locations = [ Location.from_env_path('TEST_SETTINGS'), Location.from_path('./tests/data/settings1.json')] assert config.data.name == 'Lucy' assert config.data.occupation == 'Dog' assert config.data.Sound == 'Woof' assert config.data['foo.bar.baz']['name'] == 'ollie'
def test_locations_yaml_first_multi(): os.environ['TEST_SETTINGS'] = './tests/data/settings2.yaml' config = Config() config.locations = [ Location.from_env_path('TEST_SETTINGS'), Location.from_path('./tests/data/settings1.yaml')] assert config.data.name == 'Ollie' assert config.data.occupation == 'Cat' assert config.data.Sound == 'Meow' assert config.data['foo.bar.baz']['name'] == 'lucy'
def test_locations_json_first_multi(): os.environ['TEST_SETTINGS'] = './tests/data/settings2.json' config = Config() config.locations = [ Location.from_env_path('TEST_SETTINGS'), Location.from_path('./tests/data/settings1.json') ] assert config.data.name == 'Ollie' assert config.data.occupation == 'Cat' assert config.data.Sound == 'Meow' assert config.data['foo.bar.baz']['name'] == 'lucy'
def test_locations_json_first_multi_fail(): os.environ['TEST_SETTINGS'] = './tests/data/notfound' config = Config() config.locations = [ Location.from_env_path('TEST_SETTINGS'), Location.from_path('./tests/data/settings1.json') ] assert config.data.name == 'Lucy' assert config.data.occupation == 'Dog' assert config.data.Sound == 'Woof' assert config.data['foo.bar.baz']['name'] == 'ollie'
def test_locations_json_first_env(): os.environ['TEST_SETTINGS'] = './tests/data/settings1.json' config = Config() config.locations = [Location.from_env_path('TEST_SETTINGS')] assert config.data.name == 'Lucy' assert config.data.occupation == 'Dog' assert config.data.Sound == 'Woof' assert config.data['foo.bar.baz']['name'] == 'ollie' # attribute dict test assert config.data['foo.bar.baz'].name == 'ollie' assert config.data.extra3.foo.bar.baz == 'lucy'
def test_locations_env_keys(): os.environ['FOO'] = '1' os.environ['BAR'] = '2' os.environ['BAZ'] = '3' config = Config() config.locations = [Location.from_env_keys(['FOO', 'BAR', 'BAZ'])] assert config.data.FOO == '1' assert config.data.BAR == '2' assert config.data.BAZ == '3' assert config.data['FOO'] == '1' assert config.data['BAR'] == '2' assert config.data['BAZ'] == '3'
def test_locations_configparser_first_multi(): os.environ['TEST_SETTINGS'] = './tests/data/settings2.ini' config = Config() config.locations = [ Location.from_env_path('TEST_SETTINGS'), Location.from_path('./tests/data/settings1.ini') ] assert config.data.section3['zap'] == '1' assert config.data.section3['qux'] == '2' assert config.data.section3['quux'] == '3' assert config.data.section4['lucy'] == 'dog' assert config.data.section4['ollie'] == 'cat'
def test_locations_python_first_multi_defaults(): os.environ['TEST_SETTINGS'] = 'tests.data.notfound1' config = Config(defaults={ 'name': 'lorem', 'occupation': 'ipsum', 'Sound': 'latin'}) config.locations = [ Location.from_env_python('TEST_SETTINGS'), Location.from_python('tests.data.notfound2')] assert config.data.name == 'lorem' assert config.data.occupation == 'ipsum' assert config.data.Sound == 'latin'
def test_locations_python_first_multi(): os.environ['TEST_SETTINGS'] = 'tests.data.settings2' config = Config() config.locations = [ Location.from_env_python('TEST_SETTINGS'), Location.from_python('tests.data.settings1')] assert config.data.CELERY_RESULT_BACKEND == 'foo' assert config.data.CACHES['default']['BACKEND'] == 'bar' assert 'zap' in config.data.INSTALLED_APPS assert config.data.USE_TZ == False assert config.data.custom_show_toolbar() == False
def test_locations_python_first_multi(): os.environ['TEST_SETTINGS'] = 'tests.data.settings2' config = Config() config.locations = [ Location.from_env_python('TEST_SETTINGS'), Location.from_python('tests.data.settings1') ] assert config.data.CELERY_RESULT_BACKEND == 'foo' assert config.data.CACHES['default']['BACKEND'] == 'bar' assert 'zap' in config.data.INSTALLED_APPS assert config.data.USE_TZ == False assert config.data.custom_show_toolbar() == False
def test_locations_python_first_multi_fail(): os.environ['TEST_SETTINGS'] = 'tests.data.notfound' config = Config() config.locations = [ Location.from_env_python('TEST_SETTINGS'), Location.from_python('tests.data.settings1')] assert config.data.CELERY_RESULT_BACKEND == 'amqp' assert config.data.CACHES['default']['BACKEND'] == \ 'django.core.cache.backends.memcached.MemcachedCache' assert 'south' in config.data.INSTALLED_APPS assert config.data.USE_TZ == True assert config.data.custom_show_toolbar() == True
def test_locations_configparser_first_multi_keys(): os.environ['FOO'] = '1' os.environ['BAR'] = '2' os.environ['BAZ'] = '3' config = Config() config.locations = [ Location.from_env_keys(['FOO', 'BAR', 'BAZ']), Location.from_env_path('TEST_SETTINGS'), Location.from_path('./tests/data/notfound2') ] assert config.data.FOO == '1' assert config.data.BAR == '2' assert config.data.BAZ == '3'
def test_locations_python_first_multi_keys(): os.environ['FOO'] = '1' os.environ['BAR'] = '2' os.environ['BAZ'] = '3' config = Config() config.locations = [ Location.from_env_keys(['FOO', 'BAR', 'BAZ']), Location.from_env_python('TEST_SETTINGS_NOT_FOUND'), Location.from_python('tests.data.notfound2') ] assert config.data.FOO == '1' assert config.data.BAR == '2' assert config.data.BAZ == '3'
def test_locations_yaml_first_multi_keys(): os.environ['FOO'] = '1' os.environ['BAR'] = '2' os.environ['BAZ'] = '3' config = Config() config.locations = [ Location.from_env_keys(['FOO', 'BAR', 'BAZ']), Location.from_env_path('TEST_SETTINGS'), Location.from_path('./tests/data/notfound2') ] assert config.data.FOO == '1' assert config.data.BAR == '2' assert config.data.BAZ == '3'
def test_locations_configparser_first_multi_defaults(): os.environ['TEST_SETTINGS'] = './tests/data/notfound1' config = Config(defaults={ 'name': 'lorem', 'occupation': 'ipsum', 'Sound': 'latin' }) config.locations = [ Location.from_env_path('TEST_SETTINGS'), Location.from_path('./tests/data/notfound2') ] assert config.data.name == 'lorem' assert config.data.occupation == 'ipsum' assert config.data.Sound == 'latin'
def test_locations_python_first_multi_fail(): os.environ['TEST_SETTINGS'] = 'tests.data.notfound' config = Config() config.locations = [ Location.from_env_python('TEST_SETTINGS'), Location.from_python('tests.data.settings1') ] assert config.data.CELERY_RESULT_BACKEND == 'amqp' assert config.data.CACHES['default']['BACKEND'] == \ 'django.core.cache.backends.memcached.MemcachedCache' assert 'south' in config.data.INSTALLED_APPS assert config.data.USE_TZ == True assert config.data.custom_show_toolbar() == True
def test_locations_env_keys_chain(): defaults = {'foo': 'bar'} os.environ['FOO'] = '1' os.environ['BAR'] = '2' os.environ['BAZ'] = '3' config = Config(defaults=defaults, chain=True) config.locations = [Location.from_env_keys(['FOO', 'BAR', 'BAZ'])] assert config.data.FOO == '1' assert config.data.BAR == '2' assert config.data.BAZ == '3' assert config.data.foo == 'bar' assert config.data['FOO'] == '1' assert config.data['BAR'] == '2' assert config.data['BAZ'] == '3' assert config.data['foo'] == 'bar'
def test_config_init_yaml(): config = Config() assert config is not None
def test_config_init_json(): config = Config() assert config is not None
def test_config_init_yaml_defaults(): defaults = {'foo': 'bar'} config = Config(defaults=defaults) assert config.data.foo == 'bar'
from confypy import Config, Location settings = Config() settings.locations = [ Location.from_env_path('BURN_CONFIG') ]
def test_config_defaults_get(): defaults = {'foo': 'bar'} config = Config(defaults=defaults) assert config.data.get('foo', 22) == 'bar' assert config.data.get('bar', 22) == 22