def test__django_keys__initialization(): """ Tests that DjangoKeys instance is constructed correctly. """ keys = DjangoKeys(EXAMPLE1_ENV_PATH) assert keys.str("DOMAIN") == "example.org" assert keys.str("ADMIN_EMAIL") == "*****@*****.**" assert keys.str("ROOT_URL") == "example.org/app" assert keys.str("HELLO") == "nobody answers back"
def test__django_keys__overwriting_env_variables__allowed(): """ If overwrite=True, environment variable can be overwritten by .env. """ with use_environment_variable('MY_EXAMPLE_VAR_6274', 'original'): keys = DjangoKeys(DJANGOKEYS_OVERWRITING_ENV_PATH) assert keys.str('MY_EXAMPLE_VAR_6274', overwrite=True) == "overwritten"
def test__django_keys__overwriting_env_variables__disallowed(): """ If overwrite=False, environment variable cannot be overwritten by .env. """ with use_environment_variable('DK_TEST_KEY', 'value'): keys = DjangoKeys(EMPTY_ENV_PATH) assert keys.str('DK_TEST_KEY') == "value"
def test__django_keys_str__regular_string(): """ A string is interpreted as is. """ keys = DjangoKeys(DJANGOKEYS_ACCESSING_TYPES_ENV_PATH) assert keys.str("STR_VALUE") == "helLo WOrld"
def test__django_keys_str__empty_string(): """ An empty value is interpreted as an empty string. """ keys = DjangoKeys(DJANGOKEYS_ACCESSING_TYPES_ENV_PATH) assert keys.str("EMPTY_VALUE") == ""
def test__django_keys_str__not_found(): """ An appropriate exception is raised when env var is not set. """ keys = DjangoKeys(DJANGOKEYS_ACCESSING_TYPES_ENV_PATH) with pytest.raises(EnvironmentVariableNotFound): keys.str("DOES_NOT_EXIST")