Exemplo n.º 1
0
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
Exemplo n.º 2
0
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
Exemplo n.º 3
0
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'
Exemplo n.º 4
0
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'
Exemplo n.º 5
0
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
Exemplo n.º 6
0
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'
Exemplo n.º 7
0
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'
Exemplo n.º 8
0
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'
Exemplo n.º 9
0
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'
Exemplo n.º 10
0
def test_locations_dict_first():

    config = Config()
    config.locations = [
    Location.from_dict({'name': 'Lucy'}),
    Location.from_dict({'name': 'Ollie'}),
    ]

    assert config.data.name == 'Lucy'
Exemplo n.º 11
0
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'
Exemplo n.º 12
0
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'
Exemplo n.º 13
0
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'
Exemplo n.º 14
0
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'
Exemplo n.º 15
0
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'
Exemplo n.º 16
0
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'
Exemplo n.º 17
0
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
Exemplo n.º 18
0
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
Exemplo n.º 19
0
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'
Exemplo n.º 20
0
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
Exemplo n.º 21
0
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'
Exemplo n.º 22
0
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'
Exemplo n.º 23
0
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
Exemplo n.º 24
0
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'
Exemplo n.º 25
0
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'
Exemplo n.º 26
0
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'
Exemplo n.º 27
0
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'
Exemplo n.º 28
0
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'
Exemplo n.º 29
0
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'
Exemplo n.º 30
0
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'
Exemplo n.º 31
0
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'
Exemplo n.º 32
0
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'
Exemplo n.º 33
0
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
Exemplo n.º 34
0
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
Exemplo n.º 35
0
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
Exemplo n.º 36
0
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'
Exemplo n.º 37
0
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'
Exemplo n.º 38
0
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'
Exemplo n.º 39
0
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'
Exemplo n.º 40
0
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'
Exemplo n.º 41
0
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
Exemplo n.º 42
0
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'
Exemplo n.º 43
0
def test_config_init_yaml():
    config = Config()
    assert config is not None
Exemplo n.º 44
0
def test_config_init_json():
    config = Config()
    assert config is not None
Exemplo n.º 45
0
def test_config_init_yaml_defaults():
    defaults = {'foo': 'bar'}
    config = Config(defaults=defaults)
    assert config.data.foo == 'bar'
Exemplo n.º 46
0
from confypy import Config, Location

settings = Config()
settings.locations = [
    Location.from_env_path('BURN_CONFIG')
]
Exemplo n.º 47
0
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