Skip to content

Commit

Permalink
settings test
Browse files Browse the repository at this point in the history
  • Loading branch information
codekansas committed Jun 10, 2024
1 parent 158ef56 commit 8c5b4d2
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
10 changes: 10 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
12 changes: 8 additions & 4 deletions store/settings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,21 @@ 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)
config = OmegaConf.merge(OmegaConf.structured(EnvironmentSettings), config)
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__()
Expand Down
1 change: 0 additions & 1 deletion store/settings/configs/production.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ crypto:
site:
homepage: https://robolist.xyz
image_url: https://media.robolist.xyz
api: https://robolist.xyz
12 changes: 12 additions & 0 deletions tests/test_settings.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 8c5b4d2

Please sign in to comment.