Exemplo n.º 1
0
def test_lazy_format_class():
    value = Lazy("{this[FOO]}/bar")
    settings = {"FOO": "foo"}
    assert value(settings) == "foo/bar"
    assert str(value) == value.value
    assert repr(value) == "'@{value.formatter} {value.value}'".format(
        value=value)
Exemplo n.º 2
0
def test_unparse():
    """Assert bare types are reversed cast"""
    assert unparse_conf_data("teste") == "teste"
    assert unparse_conf_data(123) == "@int 123"
    assert unparse_conf_data(123.4) == "@float 123.4"
    assert unparse_conf_data(False) == "@bool False"
    assert unparse_conf_data(True) == "@bool True"
    assert unparse_conf_data(["a", "b"]) == '@json ["a", "b"]'
    assert unparse_conf_data({"name": "Bruno"}) == '@json {"name": "Bruno"}'
    assert unparse_conf_data(None) == "@none "
    assert unparse_conf_data(Lazy("{foo}")) == "@format {foo}"
Exemplo n.º 3
0
        env="development",
        must_exist=True,
        when=Validator("BASE_IMAGE",
                       must_exist=True,
                       env=settings.ENV_FOR_DYNACONF),
    ),
    Validator(
        "IMAGE_4",
        "IMAGE_5",
        env=("development", "production"),
        must_exist=True,
        when=Validator("BASE_IMAGE",
                       must_exist=False,
                       env=settings.ENV_FOR_DYNACONF),
    ),
    Validator(
        "PORT",
        must_exist=True,
        ne=8000,
        when=Validator("MYSQL_HOST", eq="localhost"),
    ),
    Validator("A_DICT.NESTED_1.NESTED_2.NESTED_3.NESTED_4",
              must_exist=True,
              eq=1),
    Validator("A_DICT.NESTED_1.NOT.YET.LOADED", must_exist=True, eq=1),
    Validator("FOOBAR", default=Lazy(formatter=lambda x, **y: str(x))),
)

# Validate settings except those that we don't want to validate yet
settings.validators.validate(exclude="A_DICT.NESTED_1.NOT")
Exemplo n.º 4
0
def test_try_to_encode():
    value = Lazy("{this[FOO]}/bar")
    assert try_to_encode(value) == "@format {this[FOO]}/bar"
Exemplo n.º 5
0
def test_lazy_format_is_json_serializable():
    value = Lazy("{this[FOO]}/bar")
    assert (
        json.dumps({"val": value}, cls=DynaconfEncoder)
        == '{"val": "@format {this[FOO]}/bar"}'
    )
Exemplo n.º 6
0
def test_lazy_format_class_jinja():
    value = Lazy("{{this['FOO']}}/bar", formatter=Formatters.jinja_formatter)
    settings = {"FOO": "foo"}
    assert value(settings) == "foo/bar"