def test__django_keys_str__empty_string(): """ An empty value cannot be used as Django's secret key. """ with use_environment_variable('SECRET_KEY', ''): keys = DjangoKeys(EMPTY_ENV_PATH) with pytest.raises(ValueIsEmpty): keys.secret_key('SECRET_KEY')
def test__django_keys_bool__alternative_false_values(): """ Alternative values of False are interpreted correctly. """ keys = DjangoKeys(DJANGOKEYS_ACCESSING_TYPES_ENV_PATH) assert not keys.bool("BOOL_VALUE_FALSE_F") assert not keys.bool("BOOL_VALUE_FALSE_0") assert not keys.bool("BOOL_VALUE_FALSE_N") assert not keys.bool("BOOL_VALUE_FALSE_NO")
def test__django_keys_bool__alternative_true_values(): """ Alternative values of True are interpreted correctly. """ keys = DjangoKeys(DJANGOKEYS_ACCESSING_TYPES_ENV_PATH) assert keys.bool("BOOL_VALUE_TRUE_T") assert keys.bool("BOOL_VALUE_TRUE_1") assert keys.bool("BOOL_VALUE_TRUE_Y") assert keys.bool("BOOL_VALUE_TRUE_YES")
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_bool__invalid(): """ A random string of characters cannot be interpreted as a bool. """ keys = DjangoKeys(DJANGOKEYS_ACCESSING_TYPES_ENV_PATH) with pytest.raises(ValueTypeMismatch): keys.bool("BOOL_VALUE_INVALID")
def test__django_keys_secret_key__not_found(): """ An appropriate exception is raised when env var is not set. """ keys = DjangoKeys(EMPTY_ENV_PATH) with pytest.raises(EnvironmentVariableNotFound): keys.secret_key("DOES_NOT_EXIST")
def test__django_keys_int__random_characters(): """ A random string of characters cannot be interpreted as an int. """ keys = DjangoKeys(DJANGOKEYS_ACCESSING_TYPES_ENV_PATH) with pytest.raises(ValueTypeMismatch): keys.int("INT_VALUE_INVALID")
def test__django_keys_int__float(): """ A float value cannot be interpreted as an int. """ keys = DjangoKeys(DJANGOKEYS_ACCESSING_TYPES_ENV_PATH) with pytest.raises(ValueTypeMismatch): keys.int("INT_VALUE_FLOAT")
def test__django_keys_int_regular_int(): """ A regular integer is interpreted as an int. """ keys = DjangoKeys(DJANGOKEYS_ACCESSING_TYPES_ENV_PATH) assert keys.int("INT_VALUE") == 5
def test__django_keys_int__empty(): """ An empty value cannot be interpreted as an int. """ keys = DjangoKeys(DJANGOKEYS_ACCESSING_TYPES_ENV_PATH) with pytest.raises(ValueIsEmpty): keys.int("EMPTY_VALUE")
def test__django_keys_int__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.int("DOES_NOT_EXIST")
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__regular_string(): """ A string of characters can be used as Django's secret key. """ with use_environment_variable('SECRET_KEY', 'abcDE12345'): keys = DjangoKeys(EMPTY_ENV_PATH) assert keys.secret_key("SECRET_KEY") == "abcDE12345"
def test__django_keys_bool__regular_false(): """ 'False' is interpreted correctly. """ keys = DjangoKeys(DJANGOKEYS_ACCESSING_TYPES_ENV_PATH) assert not keys.bool("BOOL_VALUE_FALSE")
def test__django_keys_bool__regular_true(): """ 'True' is interpreted correctly. """ keys = DjangoKeys(DJANGOKEYS_ACCESSING_TYPES_ENV_PATH) assert keys.bool("BOOL_VALUE_TRUE")
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_report_problems(): """ placeholder """ keys = DjangoKeys(EMPTY_ENV_PATH) keys.report_problems() # this method does nothing yet
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_str__empty_string(): """ An empty value is interpreted as an empty string. """ keys = DjangoKeys(DJANGOKEYS_ACCESSING_TYPES_ENV_PATH) assert keys.str("EMPTY_VALUE") == ""