Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
found = settings.get(key)
assert found == getattr(settings, key)
assert (
found == value
), "expected: {key}: [{value}] found: [{found}]".format(**locals())
assertions = {
"HOST": "prod_server.com",
"PORT": 5000,
"ENVIRONMENT": "this is production",
}
for key, value in assertions.items():
found = settings.from_env("production").get(key)
assert found == getattr(settings.from_env("production"), key)
assert (
found == value
), "expected: {key}: [{value}] found: [{found}]".format(**locals())
"PORT": 5000,
"USERNAME": "admin",
"PASSWORD": "Secret",
"LEVELS": ["debug", "info", "warning"],
"MONEY": 500.5,
"AGE": 42,
"ENABLED": True,
"WORKS": "toml_example in prod env",
"CUSTOM": "this is custom from [production]",
"TEST_LOADERS": {"dev": "test_dev", "prod": "test_prod"},
}
for key, value in assertions.items():
found = settings.from_env("production").get(key)
assert found == getattr(settings.from_env("production"), key)
assert (
found == value
), "expected: {key}: [{value}] found: [{found}]".format(**locals())
assert found == getattr(settings, key)
assert (
found == value
), "expected: {key}: [{value}] found: [{found}]".format(**locals())
assertions = {
"HOST": "prod_server.com",
"PORT": 5000,
"ENVIRONMENT": "this is production",
}
for key, value in assertions.items():
found = settings.from_env("production").get(key)
assert found == getattr(settings.from_env("production"), key)
assert (
found == value
), "expected: {key}: [{value}] found: [{found}]".format(**locals())
for key, value in assertions.items():
found = settings.get(key)
assert found == getattr(settings, key)
assert (
found == value
), "expected: {key}: [{value}] found: [{found}]".format(**locals())
print("production")
print(settings.from_env("production").VAR1)
print(settings.from_env("production").VAR2)
assertions = {"VAR1": "var1_prod", "VAR2": "var2_prod"}
for key, value in assertions.items():
found = settings.from_env("production").get(key)
assert found == getattr(settings.from_env("production"), key)
assert (
found == value
), "expected: {key}: [{value}] found: [{found}]".format(**locals())
"HOST": "prod_server.com from toml",
"PORT": 5000,
"USERNAME": "admin",
"PASSWORD": "Secret",
"LEVELS": ["debug", "info", "warning"],
"MONEY": 500.5,
"AGE": 42,
"ENABLED": True,
"WORKS": "toml_example in prod env",
"CUSTOM": "this is custom from [production]",
"TEST_LOADERS": {"dev": "test_dev", "prod": "test_prod"},
}
for key, value in assertions.items():
found = settings.from_env("production").get(key)
assert found == getattr(settings.from_env("production"), key)
assert (
found == value
), "expected: {key}: [{value}] found: [{found}]".format(**locals())
"HOST": "prod_server.com from yaml",
"PORT": 5000,
"USERNAME": "admin",
"PASSWORD": "Secret",
"LEVELS": ["debug", "info", "warning"],
"MONEY": 500.5,
"AGE": 42,
"ENABLED": True,
"WORKS": "yaml_example in prod env",
"CUSTOM": "this is custom from [production]",
"TEST_LOADERS": {"dev": "test_dev", "prod": "test_prod"},
}
for key, value in assertions.items():
found = settings.from_env("production").get(key)
assert found == getattr(settings.from_env("production"), key)
assert (
found == value
), "expected: {key}: [{value}] found: [{found}]".format(**locals())
from dynaconf import settings
print(settings.FOO) # noqa
# >>> 'foo_is_default'
with settings.using_env("development"):
assert settings.SECRET == "redis_works_in_development", settings.SECRET
assert settings.FOO == "foo_is_default"
available_envs = ["default", "development", "production"]
all_secrets = []
for env in available_envs:
env_settings = settings.from_env(env)
assert env_settings.SECRET == "redis_works_in_{0}".format(
env
), env_settings.SECRET
assert env_settings.FOO == "foo_is_default", env_settings.FOO
all_secrets.append(env_settings.SECRET)
print(available_envs)
print(all_secrets)
print(settings.VAR2)
assertions = {"VAR1": "var1_dev", "VAR2": "var2_dev"}
for key, value in assertions.items():
found = settings.get(key)
assert found == getattr(settings, key)
assert (
found == value
), "expected: {key}: [{value}] found: [{found}]".format(**locals())
print("production")
print(settings.from_env("production").VAR1)
print(settings.from_env("production").VAR2)
assertions = {"VAR1": "var1_prod", "VAR2": "var2_prod"}
for key, value in assertions.items():
found = settings.from_env("production").get(key)
assert found == getattr(settings.from_env("production"), key)
assert (
found == value
), "expected: {key}: [{value}] found: [{found}]".format(**locals())