How to use the dynaconf.loaders.ini_loader.load function in dynaconf

To help you get started, weā€™ve selected a few dynaconf examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rochacbruno / dynaconf / tests / test_ini_loader.py View on Github external
def test_load_from_ini():
    """Assert loads from INI string"""
    load(settings, filename=INI)
    assert settings.HOST == "prodserver.com"
    assert settings.PORT == 8080
    assert settings.ALIST == ["item1", "item2", 23]
    assert settings.SERVICE["url"] == "service.com"
    assert settings.SERVICE.url == "service.com"
    assert settings.SERVICE.port == 80
    assert settings.SERVICE.auth.password == "qwerty"
    assert settings.SERVICE.auth.test == 1234
    load(settings, filename=INI, env="DEVELOPMENT")
    assert settings.HOST == "devserver.com"
    load(settings, filename=INI)
    assert settings.HOST == "prodserver.com"
    assert settings.PORT == 8080
github rochacbruno / dynaconf / tests / test_ini_loader.py View on Github external
assert settings.HOST == "otherini.com"
    assert settings.PASSWORD == 123456
    assert settings.SECRET == 42.0
    assert settings.PORT == 8080
    assert settings.SERVICE["url"] == "service.com"
    assert settings.SERVICE.url == "service.com"
    assert settings.SERVICE.port == 80
    assert settings.SERVICE.auth.password == "qwerty"
    assert settings.SERVICE.auth.test == 1234
    load(settings, filename=INIS, env="DEVELOPMENT")
    assert settings.PORT == 8080
    assert settings.HOST == "otherini.com"
    load(settings, filename=INIS)
    assert settings.HOST == "otherini.com"
    assert settings.PASSWORD == 123456
    load(settings, filename=INI, env="DEVELOPMENT")
    assert settings.PORT == 8080
    assert settings.HOST == "devserver.com"
    load(settings, filename=INI)
    assert settings.HOST == "prodserver.com"
    assert settings.PASSWORD == 11111
github rochacbruno / dynaconf / tests / test_ini_loader.py View on Github external
def test_cleaner():
    load(settings, filename=INI)
    assert settings.HOST == "prodserver.com"
    assert settings.PORT == 8080
    assert settings.ALIST == ["item1", "item2", 23]
    assert settings.SERVICE["url"] == "service.com"
    assert settings.SERVICE.url == "service.com"
    assert settings.SERVICE.port == 80
    assert settings.SERVICE.auth.password == "qwerty"
    assert settings.SERVICE.auth.test == 1234
    load(settings, filename=INI, env="DEVELOPMENT")
    assert settings.HOST == "devserver.com"
    load(settings, filename=INI)
    assert settings.HOST == "prodserver.com"

    settings.clean()
    with pytest.raises(AttributeError):
        assert settings.HOST == "prodserver.com"
github rochacbruno / dynaconf / tests / test_ini_loader.py View on Github external
def test_using_env(tmpdir):
    load(settings, filename=INI)
    assert settings.HOST == "prodserver.com"

    tmpfile = tmpdir.mkdir("sub").join("test_using_env.ini")
    tmpfile.write(INI)
    with settings.using_env("DEVELOPMENT", filename=str(tmpfile)):
        assert settings.HOST == "devserver.com"
    assert settings.HOST == "prodserver.com"
github rochacbruno / dynaconf / tests / test_ini_loader.py View on Github external
def test_load_from_multiple_ini():
    """Assert loads from INI string"""
    load(settings, filename=INIS)
    assert settings.HOST == "otherini.com"
    assert settings.PASSWORD == 123456
    assert settings.SECRET == 42.0
    assert settings.PORT == 8080
    assert settings.SERVICE["url"] == "service.com"
    assert settings.SERVICE.url == "service.com"
    assert settings.SERVICE.port == 80
    assert settings.SERVICE.auth.password == "qwerty"
    assert settings.SERVICE.auth.test == 1234
    load(settings, filename=INIS, env="DEVELOPMENT")
    assert settings.PORT == 8080
    assert settings.HOST == "otherini.com"
    load(settings, filename=INIS)
    assert settings.HOST == "otherini.com"
    assert settings.PASSWORD == 123456
    load(settings, filename=INI, env="DEVELOPMENT")
github rochacbruno / dynaconf / tests / test_ini_loader.py View on Github external
def test_no_key_error_on_invalid_env():
    """Assert error raised if env is not found in INI"""
    load(settings, filename=INI, env="FOOBAR", silent=True)
github rochacbruno / dynaconf / tests / test_ini_loader.py View on Github external
def test_multiple_filenames():
    load(settings, filename="a.ini,b.ini,c.conf,d.properties")
github rochacbruno / dynaconf / tests / test_ini_loader.py View on Github external
"""Test loading a single key"""
    ini = """
    a = "a,b"
    [foo]
    bar = "blaz"
    ZAZ = "naz"
    lowerkey = 'hello'
    UPPERKEY = 'world'
    """
    load(settings, filename=ini, env="FOO", key="bar")
    assert settings.BAR == "blaz"
    assert settings.exists("BAR") is True
    assert settings.exists("ZAZ") is False
    load(settings, filename=ini, env="FOO", key="ZAZ")
    assert settings.ZAZ == "naz"
    load(settings, filename=ini, env="FOO", key="LOWERKEY")
    assert settings.LOWERKEY == "hello"
    load(settings, filename=ini, env="FOO", key="upperkey")
    assert settings.UPPERKEY == "world"
github rochacbruno / dynaconf / tests / test_ini_loader.py View on Github external
def test_empty_value():
    load(settings, filename="")
github rochacbruno / dynaconf / tests / test_ini_loader.py View on Github external
def test_key_error_on_invalid_env():
    """Assert error raised if env is not found in INI"""
    with pytest.raises(KeyError):
        load(settings, filename=INI, env="FOOBAR", silent=False)