From 8c5b4d29426feb2b009ca0e2a3fdfae830da04be Mon Sep 17 00:00:00 2001 From: Benjamin Bolte Date: Mon, 10 Jun 2024 11:43:07 -0700 Subject: [PATCH] settings test --- CONTRIBUTING.md | 10 ++++++++++ store/settings/__init__.py | 12 ++++++++---- store/settings/configs/production.yaml | 1 - tests/test_settings.py | 12 ++++++++++++ 4 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 tests/test_settings.py diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f8db537b..26291c90 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -142,3 +142,13 @@ REACT_APP_GOOGLE_CLIENT_ID=your-client-id ``` Additionally, you should set `REACT_APP_BACKEND_URL` to the URL of the FastAPI backend. This should be `http://127.0.0.1:8080` when developing locally. + +## Testing + +To run the tests, you can use the following commands: + +```bash +make test +make test-frontend # Run only the frontend tests +make test-backend # Run only the backend tests +``` diff --git a/store/settings/__init__.py b/store/settings/__init__.py index e0dea64f..5024fd4b 100644 --- a/store/settings/__init__.py +++ b/store/settings/__init__.py @@ -18,10 +18,7 @@ def _check_exists(path: Path) -> Path: return path -def _load_environment_settings() -> EnvironmentSettings: - if "ROBOLIST_ENVIRONMENT_SECRETS" in os.environ: - load_dotenv(os.environ["ROBOLIST_ENVIRONMENT_SECRETS"]) - environment = os.environ["ROBOLIST_ENVIRONMENT"] +def _load_settings(environment: str) -> EnvironmentSettings: base_dir = (Path(__file__).parent / "configs").resolve() config_path = _check_exists(base_dir / f"{environment}.yaml") config = OmegaConf.load(config_path) @@ -29,6 +26,13 @@ def _load_environment_settings() -> EnvironmentSettings: return cast(EnvironmentSettings, config) +def _load_environment_settings() -> EnvironmentSettings: + if "ROBOLIST_ENVIRONMENT_SECRETS" in os.environ: + load_dotenv(os.environ["ROBOLIST_ENVIRONMENT_SECRETS"]) + environment = os.environ["ROBOLIST_ENVIRONMENT"] + return _load_settings(environment) + + class _LazyLoadSettings(Generic[T]): def __init__(self, func: Callable[[], T]) -> None: super().__init__() diff --git a/store/settings/configs/production.yaml b/store/settings/configs/production.yaml index 26b3269e..c4969843 100644 --- a/store/settings/configs/production.yaml +++ b/store/settings/configs/production.yaml @@ -3,4 +3,3 @@ crypto: site: homepage: https://robolist.xyz image_url: https://media.robolist.xyz - api: https://robolist.xyz diff --git a/tests/test_settings.py b/tests/test_settings.py new file mode 100644 index 00000000..bf4ad456 --- /dev/null +++ b/tests/test_settings.py @@ -0,0 +1,12 @@ +"""Tests that the configurations are all valid.""" + +from pathlib import Path + +import store.settings + + +def test_all_configs_are_valid() -> None: + assert (configs_root := (Path(store.settings.__file__).parent / "configs").resolve()).exists() + assert len(config_files := list(configs_root.glob("*.yaml"))) > 0 + for config_file in config_files: + store.settings._load_settings(config_file.stem)