diff --git a/Makefile b/Makefile index 780d222..4dfb77e 100644 --- a/Makefile +++ b/Makefile @@ -58,7 +58,7 @@ docker/lint: $(DOCKER_COMPOSE) run ${APP_NAME} poetry run ruff check . docker/lint/fix: - $(DOCKER_COMPOSE) run ${APP_NAME} poetry run ruff . --fix + $(DOCKER_COMPOSE) run ${APP_NAME} poetry run ruff check . --fix docker/run: $(DOCKER_COMPOSE) run ${APP_NAME} poetry run python ${MAIN_ENTRYPOINT} diff --git a/src/config/settings.py b/src/config/settings.py index 10b5f61..bef1a34 100644 --- a/src/config/settings.py +++ b/src/config/settings.py @@ -16,6 +16,9 @@ def __init__(self, file: str = 'settings.conf'): def get(self, name: str, default_value: Any = None) -> Any: return self._get_from_section(self.env, name) or self._get_from_section('default', name) or default_value + def get_from_env(self, name: str, default_value: Any = None) -> Any: + return getenv(name, default_value) + def _get_from_section(self, section: str, var: str) -> Any: if section in self.config_parser and var in self.config_parser[section]: return self.config_parser[section][var] diff --git a/tests/config/test_settings.py b/tests/config/test_settings.py index dd66714..cb75d3b 100644 --- a/tests/config/test_settings.py +++ b/tests/config/test_settings.py @@ -39,3 +39,11 @@ def test_get_setting_value_from_test_env_with_success(self): def test_get_setting_value_from_dev_env_with_success(self): dev_settings = Settings(file='./tests/config/settings_to_test.conf') self.assertEqual(dev_settings.get('app_var'), 'dev-app-var') + + @mock.patch.dict(os.environ, {'name': 'value'}, clear=True) + def test_get_value_from_env_var_with_success(self): + self.assertEqual(self.settings.get_from_env('name'), 'value') + + @mock.patch.dict(os.environ, {'name1': 'value'}, clear=True) + def test_get_default_value_from_env_var_with_success(self): + self.assertEqual(self.settings.get_from_env('name', 'default'), 'default')