-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: support for env vars reading in config
- Loading branch information
Michael Panchenko
committed
Feb 24, 2023
1 parent
3b1d60c
commit dd534d9
Showing
5 changed files
with
80 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"env_var_entry": "env:THIS_EXISTS", "empty_env_var_entry": "env:THIS_EXISTS_NOT"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,55 @@ | ||
import os | ||
|
||
import pytest | ||
|
||
from accsr.config import ConfigProviderBase, DefaultDataConfiguration | ||
from accsr.remote_storage import RemoteStorageConfig | ||
|
||
|
||
class __Configuration(DefaultDataConfiguration): | ||
# has to be kept in sync with resources/config.json | ||
@property | ||
def env_var_entry(self): | ||
return self._get_non_empty_entry("env_var_entry") | ||
|
||
@property | ||
def empty_env_var_entry(self): | ||
return self._get_non_empty_entry("empty_env_var_entry") | ||
|
||
|
||
class ConfigProvider(ConfigProviderBase[__Configuration]): | ||
pass | ||
|
||
|
||
_config_provider = ConfigProvider() | ||
|
||
|
||
@pytest.fixture() | ||
def test_config(test_resources, reload=False): | ||
return _config_provider.get_config(reload=reload, config_directory=test_resources) | ||
|
||
|
||
def test_storage_config_repr_does_not_include_secret(): | ||
""" | ||
Ensure that str representation of storage config does not leak secret. | ||
Regression test for issue #6. | ||
""" | ||
cfg = RemoteStorageConfig( | ||
"provider", "key", "bucket", "secretkey", "region", "host", "1234", "base_path" | ||
"provider", "key", "bucket", "secretkey", "region", "host", 1234, "base_path" | ||
) | ||
|
||
assert cfg.secret not in repr(cfg) | ||
assert cfg.secret not in str(cfg) | ||
|
||
|
||
class TestConfig: | ||
def test_env_var_retrieval(self, test_config): | ||
os.environ["THIS_EXISTS"] = "env_entry" | ||
assert test_config.env_var_entry == "env_entry" | ||
|
||
def test_empty_env_var_raises(self, test_config): | ||
os.environ.pop("THIS_EXISTS_NOT", None) | ||
with pytest.raises(KeyError) as e: | ||
test_config.empty_env_var_entry | ||
assert "THIS_EXISTS_NOT" in str(e) |