Пример #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
Пример #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
Пример #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'
Пример #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'
Пример #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
Пример #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'
Пример #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'
Пример #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'
Пример #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'
Пример #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'
Пример #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'
Пример #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'
Пример #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'
Пример #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'
Пример #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'
Пример #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'
Пример #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
Пример #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
Пример #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'
Пример #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
Пример #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'
Пример #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'
Пример #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
Пример #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'
Пример #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'
Пример #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'
Пример #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'
Пример #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'
Пример #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'
Пример #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'
Пример #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'
Пример #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'
Пример #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
Пример #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
Пример #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
Пример #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'
Пример #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'
Пример #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'
Пример #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'
Пример #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'
Пример #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
Пример #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'
Пример #43
0
def test_config_init_yaml():
    config = Config()
    assert config is not None
Пример #44
0
def test_config_init_json():
    config = Config()
    assert config is not None
Пример #45
0
def test_config_init_yaml_defaults():
    defaults = {'foo': 'bar'}
    config = Config(defaults=defaults)
    assert config.data.foo == 'bar'
Пример #46
0
from confypy import Config, Location

settings = Config()
settings.locations = [
    Location.from_env_path('BURN_CONFIG')
]
Пример #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