Exemplo n.º 1
0
def test_get_fresh():
    assert settings.MUSTBEFRESH == 'first'
    os.environ['DYNACONF_MUSTBEFRESH'] = 'second'
    with pytest.raises(AssertionError):
        # fresh should now be second
        assert settings.exists('MUSTBEFRESH')
        assert settings.get_fresh('MUSTBEFRESH') == 'first'

    assert settings.get_fresh('MUSTBEFRESH') == 'second'

    os.environ['DYNACONF_THISMUSTEXIST'] = '@int 1'
    # must tnot exist yet (not loaded)
    assert settings.exists('THISMUSTEXIST') is False
    # must exist because fresh will call loaders
    assert settings.exists('THISMUSTEXIST', fresh=True) is True
    # loaders run only once
    assert settings.get('THISMUSTEXIST') == 1

    os.environ['DYNACONF_THISMUSTEXIST'] = '@int 23'
    del os.environ['DYNACONF_THISMUSTEXIST']
    # this should error because envvar got cleaned
    # but it is not, so cleaners should be fixed
    assert settings.get_fresh('THISMUSTEXIST') is None
    with pytest.raises(AttributeError):
        settings.THISMUSTEXIST
    with pytest.raises(KeyError):
        settings['THISMUSTEXIST']

    os.environ['DYNACONF_THISMUSTEXIST'] = '@int 23'
    os.environ['BLARG_THISMUSTEXIST'] = '@int 99'
    # namespace switch is deleting the variable
    with settings.using_namespace('BLARG'):
        assert settings.get('THISMUSTEXIST') == 99

    assert settings.get('THISMUSTEXIST') == 23
Exemplo n.º 2
0
from dynaconf import settings
from dynaconf.loaders import vault_loader

vault_loader.write(settings, {'SECRET': 'vault_works'})

with settings.using_namespace('dev'):
    vault_loader.write(settings, {'SECRET': 'vault_works_in_dev'})
Exemplo n.º 3
0
print("\nThe list is:")
print(settings.ALIST)
print(len(settings.ALIST))
print(type(settings.ALIST))

print("\nThe dict is:")
print(settings.ADICT)
print(settings.ADICT.keys())
print(type(settings.ADICT))


print("\nThe value that may not exist can have a default :")
print(settings.get('FOO', default='bar'))

print("\nNamespaces Support :")
with settings.using_namespace('PROJECT1'):
    print("\nThe host for project1 :")
    print(settings.HOSTNAME)

print("\nThe host for default :")
print(settings.HOSTNAME)

print("\nNamespaces Support :")
with settings.using_namespace('PROJECT1'):
    print("\nThe host for project1 :")
    print(settings.HOSTNAME)

print("\nThe host for default :")
print(settings.HOSTNAME)

print(settings.WORKS)
Exemplo n.º 4
0
from dynaconf import settings

print(settings.YAML)
print(settings.HOST)
print(settings.PORT)


# using development: namespace values for context
with settings.using_namespace('DEVELOPMENT'):
    print(settings.ENVIRONMENT)
    print(settings.HOST)

# back to default dynaconf: namespace
print(settings.get('ENVIRONMENT'))
print(settings.HOST)