This repository has been archived by the owner on Sep 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: use constants for test/local env checks.
We are starting to amass a bit of functionality that is condition upon the environment setting. E.g., sentry init disabled by default in test and local environments, alternate logging config if environment is local, and server reloading automatically configured for local environment. So, it makes sense to have a bit more structure around these checks. Closes #244
- Loading branch information
1 parent
ef00c0b
commit 6c07154
Showing
8 changed files
with
55 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
"""Application constants.""" | ||
from __future__ import annotations | ||
|
||
from starlite_saqlalchemy.settings import app | ||
from starlite_saqlalchemy.utils import case_insensitive_string_compare | ||
|
||
IS_TEST_ENVIRONMENT = case_insensitive_string_compare(app.ENVIRONMENT, app.TEST_ENVIRONMENT_NAME) | ||
"""Flag indicating if the application is running in a test environment.""" | ||
|
||
IS_LOCAL_ENVIRONMENT = case_insensitive_string_compare(app.ENVIRONMENT, app.LOCAL_ENVIRONMENT_NAME) | ||
"""Flag indicating if application is running in local development mode.""" |
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
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 |
---|---|---|
@@ -1,27 +1,33 @@ | ||
"""Tests for scripts.py.""" | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
import pytest | ||
|
||
from starlite_saqlalchemy import settings | ||
from starlite_saqlalchemy.scripts import determine_reload_dirs, determine_should_reload | ||
from starlite_saqlalchemy import scripts, settings | ||
from starlite_saqlalchemy.testing import modify_settings | ||
|
||
if TYPE_CHECKING: | ||
from pytest import MonkeyPatch | ||
|
||
|
||
@pytest.mark.parametrize(("reload", "expected"), [(None, True), (True, True), (False, False)]) | ||
def test_uvicorn_config_auto_reload_local(reload: bool | None, expected: bool) -> None: | ||
def test_uvicorn_config_auto_reload_local( | ||
reload: bool | None, expected: bool, monkeypatch: MonkeyPatch | ||
) -> None: | ||
"""Test that setting ENVIRONMENT to 'local' triggers auto reload.""" | ||
with modify_settings( | ||
(settings.app, {"ENVIRONMENT": "local"}), (settings.server, {"RELOAD": reload}) | ||
): | ||
assert determine_should_reload() is expected | ||
monkeypatch.setattr(scripts, "IS_LOCAL_ENVIRONMENT", True) | ||
with modify_settings((settings.server, {"RELOAD": reload})): | ||
assert scripts.determine_should_reload() is expected | ||
|
||
|
||
@pytest.mark.parametrize("reload", [True, False]) | ||
def test_uvicorn_config_reload_dirs(reload: bool) -> None: | ||
"""Test that RELOAD_DIRS is only used when RELOAD is enabled.""" | ||
if not reload: | ||
assert determine_reload_dirs(reload) is None | ||
assert scripts.determine_reload_dirs(reload) is None | ||
else: | ||
reload_dirs = determine_reload_dirs(reload) | ||
reload_dirs = scripts.determine_reload_dirs(reload) | ||
assert reload_dirs is not None | ||
assert reload_dirs == settings.server.RELOAD_DIRS |