Ejemplo n.º 1
0
def test_using_env(tmpdir):
    load(settings, filename=TOML)
    assert settings.HOST == "prodserver.com"

    tmpfile = tmpdir.mkdir("sub").join("test_using_env.toml")
    tmpfile.write(TOML)
    with settings.using_env("DEVELOPMENT", filename=str(tmpfile)):
        assert settings.HOST == "devserver.com"
    assert settings.HOST == "prodserver.com"
Ejemplo n.º 2
0
def test_envless():
    settings = LazySettings()
    ini = """
    a = "a,b"
    colors__white__code = '#FFFFFF'
    COLORS__white__name = 'white'
    """
    load(settings, filename=ini)
    assert settings.a == "a,b"
    assert settings.COLORS.white.code == "#FFFFFF"
    assert settings.COLORS.white.name == "white"
Ejemplo n.º 3
0
def test_load_dunder():
    """Test load with dunder settings"""
    toml = """
    a = "a,b"
    [foo]
    colors__gray__code = '#CCCCCC'
    COLORS__gray__name = 'Gray'
    """
    load(settings, filename=toml, env="FOO")
    assert settings.COLORS.gray.code == "#CCCCCC"
    assert settings.COLORS.gray.name == "Gray"
Ejemplo n.º 4
0
def test_load_single_key():
    """Test loading a single key"""
    toml = """
    [foo]
    bar = "blaz"
    zaz = "naz"
    """
    load(settings, filename=toml, namespace='FOO', key='bar')
    assert settings.BAR == 'blaz'
    assert settings.exists('BAR') is True
    assert settings.exists('ZAZ') is False
Ejemplo n.º 5
0
def test_prefix():
    settings = LazySettings(filter_strategy=PrefixFilter("prefix"))
    ini = """
    prefix_a = "a,b"
    prefix_colors__white__code = '#FFFFFF'
    COLORS__white__name = 'white'
    """
    load(settings, filename=ini)
    assert settings.a == "a,b"
    assert settings.COLORS.white.code == "#FFFFFF"
    with pytest.raises(AttributeError):
        settings.COLORS.white.name
Ejemplo n.º 6
0
def test_load_from_multiple_toml():
    """Assert loads from TOML string"""
    load(settings, filename=TOMLS)
    assert settings.HOST == "othertoml.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=TOMLS, env="DEVELOPMENT")
    assert settings.PORT == 8080
    assert settings.HOST == "othertoml.com"
    load(settings, filename=TOMLS)
    assert settings.HOST == "othertoml.com"
    assert settings.PASSWORD == 123456
    load(settings, filename=TOML, env="DEVELOPMENT")
    assert settings.PORT == 8080
    assert settings.HOST == "devserver.com"
    load(settings, filename=TOML)
    assert settings.HOST == "prodserver.com"
    assert settings.PASSWORD == 11111
Ejemplo n.º 7
0
def test_load_from_multiple_toml():
    """Assert loads from TOML string"""
    load(settings, filename=TOMLS)
    assert settings.HOST == 'othertoml.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=TOMLS, env='DEVELOPMENT')
    assert settings.PORT == 8080
    assert settings.HOST == 'othertoml.com'
    load(settings, filename=TOMLS)
    assert settings.HOST == 'othertoml.com'
    assert settings.PASSWORD == 123456
    load(settings, filename=TOML, env='DEVELOPMENT')
    assert settings.PORT == 8080
    assert settings.HOST == 'devserver.com'
    load(settings, filename=TOML)
    assert settings.HOST == 'prodserver.com'
    assert settings.PASSWORD == 11111
Ejemplo n.º 8
0
def test_load_single_key():
    """Test loading a single key"""
    toml = """
    a = "a,b"
    [foo]
    bar = "blaz"
    ZAZ = "naz"
    lowerkey = 'hello'
    UPPERKEY = 'world'
    """
    load(settings, filename=toml, env="FOO", key="bar")
    assert settings.BAR == "blaz"
    assert settings.exists("BAR") is True
    assert settings.exists("ZAZ") is False
    load(settings, filename=toml, env="FOO", key="ZAZ")
    assert settings.ZAZ == "naz"
    load(settings, filename=toml, env="FOO", key="LOWERKEY")
    assert settings.LOWERKEY == "hello"
    load(settings, filename=toml, env="FOO", key="upperkey")
    assert settings.UPPERKEY == "world"
Ejemplo n.º 9
0
def test_load_from_toml():
    """Assert loads from TOML string"""
    load(settings, filename=TOML)
    assert settings.HOST == 'server.com'
    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=TOML, namespace='DEVELOPMENT')
    assert settings.HOST == 'dev_server.com'
    load(settings, filename=TOML)
    assert settings.HOST == 'server.com'
Ejemplo n.º 10
0
def test_cleaner():
    load(settings, filename=TOML)
    assert settings.HOST == 'server.com'
    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=TOML, namespace='DEVELOPMENT')
    assert settings.HOST == 'dev_server.com'
    load(settings, filename=TOML)
    assert settings.HOST == 'server.com'
    clean(settings, settings.namespace)
Ejemplo n.º 11
0
def test_load_from_toml():
    """Assert loads from TOML string"""
    load(settings, filename=TOML)
    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=TOML, env='DEVELOPMENT')
    assert settings.HOST == 'devserver.com'
    load(settings, filename=TOML)
    assert settings.HOST == 'prodserver.com'
Ejemplo n.º 12
0
def test_load_from_toml():
    """Assert loads from TOML string"""
    load(settings, filename=TOML)
    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=TOML, env="DEVELOPMENT")
    assert settings.HOST == "devserver.com"
    load(settings, filename=TOML)
    assert settings.HOST == "prodserver.com"
Ejemplo n.º 13
0
def test_cleaner():
    load(settings, filename=TOML)
    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=TOML, env="DEVELOPMENT")
    assert settings.HOST == "devserver.com"
    load(settings, filename=TOML)
    assert settings.HOST == "prodserver.com"

    settings.clean()
    with pytest.raises(AttributeError):
        assert settings.HOST == "prodserver.com"
Ejemplo n.º 14
0
def test_cleaner():
    load(settings, filename=TOML)
    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=TOML, env='DEVELOPMENT')
    assert settings.HOST == 'devserver.com'
    load(settings, filename=TOML)
    assert settings.HOST == 'prodserver.com'

    settings.clean()
    with pytest.raises(AttributeError):
        assert settings.HOST == 'prodserver.com'
Ejemplo n.º 15
0
def test_no_filename_is_none():
    """Assert if passed no filename return is None"""
    assert load(settings) is None
Ejemplo n.º 16
0
def test_key_error_on_invalid_namespace():
    """Assert error raised if namespace is not found in TOML"""
    with pytest.raises(KeyError):
        load(settings, filename=TOML, namespace='FOOBAR', silent=False)
Ejemplo n.º 17
0
def test_no_key_error_on_invalid_namespace():
    """Assert error raised if namespace is not found in TOML"""
    load(settings, filename=TOML, namespace='FOOBAR', silent=True)
Ejemplo n.º 18
0
def test_no_key_error_on_invalid_env():
    """Assert error raised if env is not found in TOML"""
    load(settings, filename=TOML, env="FOOBAR", silent=True)
Ejemplo n.º 19
0
def test_key_error_on_invalid_env():
    """Assert error raised if env is not found in TOML"""
    with pytest.raises(KeyError):
        load(settings, filename=TOML, env="FOOBAR", silent=False)
Ejemplo n.º 20
0
def test_multiple_filenames():
    load(settings, filename="a.toml,b.tml,c.toml,d.tml")
Ejemplo n.º 21
0
def test_prefix_is_not_str_raises():
    with pytest.raises(TypeError):
        toml_loader.load(LazySettings(filter_strategy=PrefixFilter(int)))
    with pytest.raises(TypeError):
        toml_loader.load(LazySettings(filter_strategy=PrefixFilter(True)))
Ejemplo n.º 22
0
def test_empty_value():
    load(settings, filename="")