Example #1
0
    def test_as_dict(self, mock_envfile):
        settings = Settings(env_prefix="PREFIX_")
        settings.load_dotenv_file(mock_envfile)

        as_dict = settings.as_dict()
        assert as_dict == settings._config
        assert isinstance(as_dict, dict)
Example #2
0
    def test_load_environment_does_not_load_unprefixed_vars(
            self, mock_environment):
        settings = Settings(env_prefix="PREFIX_")
        settings.load_env()

        with pytest.raises(AttributeError):
            settings.USER
    def test_load_environment_with_override_keys(self, mock_environment,
                                                 override_keys_function):
        settings = Settings("PREFIX_", "OVERRIDE_", override_keys_function)
        settings.load_env()

        assert settings.DEBUG is False
        assert settings.HASH == {"dict": "test"}
    def test_override_keys_function_not_callable_raises_warning(
            self, mock_environment):
        settings = Settings("PREFIX_", "OVERRIDE_", ["KEY"])
        settings.load_env()

        with pytest.warns(NotCallableWarning):
            assert settings.DEBUG is True
Example #5
0
    def test_load_envfile_with_prefix_strips_out_prefix(self, mock_envfile):
        settings = Settings(env_prefix="PREFIX_")
        settings.load_dotenv_file(mock_envfile)

        with pytest.raises(AttributeError):
            settings.PREFIX_DEBUG

        assert settings.DEBUG is True
Example #6
0
 def test_override_keys_reverse_lookup(self, mock_environment, mocker):
     settings = Settings("PREFIX_", "OVERRIDE_", override_keys_function, override_keys_reverse_lookup=True)
     mocker.patch.object(settings, "override_keys_function")
     settings.override_keys_function.return_value = ("KEY1", "KEY2")
     settings.load_env()
     assert settings.VALUE_1 == "key2-value-1"
     assert settings.VALUE_2 == "key1-value-2"
     assert settings.VALUE_3 == "default-value-3"
Example #7
0
 def test_override_keys_function_preserves_order_of_overrides(self, mock_environment, mocker):
     settings = Settings("PREFIX_", "OVERRIDE_", override_keys_function)
     mocker.patch.object(settings, "override_keys_function")
     settings.override_keys_function.return_value = ("KEY1", "KEY2")
     settings.load_env()
     assert settings.VALUE_1 == "key1-value-1"
     assert settings.VALUE_2 == "key1-value-2"
     assert settings.VALUE_3 == "default-value-3"
    def test_load_environment_with_prefix_strips_out_prefix(self, mock_environment):
        settings = Settings(env_prefix="PREFIX_")
        settings.load_env()

        with pytest.raises(AttributeError):
            settings.PREFIX_DEBUG

        assert settings.DEBUG is True
Example #9
0
    def test_override_keys_function_does_not_return_list_or_set_raises_warning(self, mock_environment, mocker):
        settings = Settings("PREFIX_", "OVERRIDE_", override_keys_function)
        mocker.patch.object(settings, "override_keys_function")
        settings.override_keys_function.return_value = "KEY1, KEY2"
        settings.load_env()

        with pytest.warns(UnsupportedSetTypeWarning):
            assert settings.HASH == {"dict": "test"}
            assert settings.DEBUG is True
Example #10
0
    def test_load_envfile_with_prefix(self, mock_envfile):
        settings = Settings(env_prefix="PREFIX_")
        settings.load_dotenv_file(mock_envfile)

        assert settings.DEBUG is True
        assert settings.ESCAPED_HASH == {"dict": "test"}
        assert settings.UNESCAPED_HASH == {"dict": "test"}
        assert settings.MULTILINE_KEY == (
            "===BEGIN PUBLIC CERTIFICATE=== \n" " it is a certificate value \n" "===END PUBLIC CERTIFICATE==="
        )
Example #11
0
    def test_missing_missing_override_key_from_callable_raises_warning(self, mock_environment, mocker):
        settings = Settings("PREFIX_", "OVERRIDE_", override_keys_function)
        mocker.patch.object(settings, "override_keys_function")
        settings.override_keys_function.return_value = ["MISSING_KEY"]
        settings.load_env()

        with pytest.warns(MissingOverrideKeysWarning):
            assert settings.DEBUG is True

        settings.override_keys_function.return_value = []
        assert settings.HASH == {"dict": "test"}
        assert settings.DEBUG is True
Example #12
0
    def test_prefix_gets_stripped_once_only(self, mock_environment):
        settings = Settings(env_prefix="PREFIX_")
        settings.load_env()

        assert settings.SOME_KEY_PREFIX_REPEATED == "nested"
Example #13
0
    def test_load_environment_with_prefix(self, mock_environment):
        settings = Settings(env_prefix="PREFIX_")
        settings.load_env()

        assert settings.DEBUG is True
        assert settings.HASH == {"dict": "test"}
Example #14
0
def settings():
    settings = Settings(env_prefix="PREFIX_")
    settings.load_env()

    return settings
Example #15
0
    def test_prefix_gets_stripped_once_only(self, mock_envfile):
        settings = Settings(env_prefix="PREFIX_")
        settings.load_dotenv_file(mock_envfile)

        assert settings.SOME_KEY_PREFIX_REPEATED == "nested"
Example #16
0
    def test_load_envfile_does_not_load_unprefixed_vars(self, mock_envfile):
        settings = Settings(env_prefix="PREFIX_")
        settings.load_dotenv_file(mock_envfile)

        with pytest.raises(AttributeError):
            settings.USER