Esempio n. 1
0
def test_set_from_env_no_env_w_default():
    scope = {}
    settings_manager = SettingsManager(scope)
    assert os.environ.get("TEST_SETTING") is None
    settings_manager.set_from_env("TEST_SETTING", default="default")
    assert scope["TEST_SETTING"] == "default"
Esempio n. 2
0
File: example.py Progetto: 20c/confu
from confu.util import SettingsManager

# using local scope g
g = {}
settings_manager = SettingsManager(g)
settings_manager.set_option("TEST_SETTING", "world")
print(g["TEST_SETTING"])

# using Global scope
settings_manager = SettingsManager(globals())
settings_manager.set_option("TEST_SETTING", "world")
print(TEST_SETTING)

# setting from env
os.environ["ENV_SETTING"] = "my_setting"  # setting env variable
settings_manager.set_from_env("ENV_SETTING")
print(ENV_SETTING)

# setting boolean
settings_manager.set_bool("BOOL_SETTING", False)
print(BOOL_SETTING)

# setting boolean overriden from env var from env
os.environ["ENV_BOOL"] = "True"  # setting env variable
settings_manager.set_bool("ENV_BOOL", False)
print(ENV_BOOL)

# setting int from env
os.environ["ENV_INT"] = "123"  # setting env variable
settings_manager.set_option("ENV_INT", None, envvar_type=int)
print(ENV_INT)
Esempio n. 3
0
def test_set_from_env(envvar_fixture):
    scope = {}
    settings_manager = SettingsManager(scope)
    settings_manager.set_from_env("TEST_SETTING")
    assert scope["TEST_SETTING"] == "world"
Esempio n. 4
0
    settings_manager.set_bool("DEBUG", True)
else:
    settings_manager.set_bool("DEBUG", False)

# look for mainsite/settings/${RELEASE_ENV}.py and load if it exists
env_file = os.path.join(os.path.dirname(__file__), f"{RELEASE_ENV}.py")
try_include(env_file)

print_debug(f"Release env is '{RELEASE_ENV}'")

settings_manager.set_option(
    "PACKAGE_VERSION",
    read_file(os.path.join(BASE_DIR, "etc/VERSION")).strip())

# Contact email, from address, support email
settings_manager.set_from_env("SERVER_EMAIL")

# django secret key
settings_manager.set_from_env("SECRET_KEY")

# database
settings_manager.set_option("DATABASE_ENGINE", "postgresql_psycopg2")

settings_manager.set_from_env("DATABASE_HOST", "")
settings_manager.set_from_env("DATABASE_PORT", "")
settings_manager.set_from_env("DATABASE_NAME", "devicectl")
settings_manager.set_from_env("DATABASE_USER", "devicectl")
settings_manager.set_from_env("DATABASE_PASSWORD", "")

# Django config
ALLOWED_HOSTS = ["*"]