-
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.
Merge pull request #25 from community-of-python/vrslev-patch-6
Add env-var aliases to improve compatibility with existing internal services and pipelines
- Loading branch information
Showing
6 changed files
with
77 additions
and
22 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
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,9 +1,12 @@ | ||
from __future__ import annotations | ||
import importlib | ||
import typing | ||
from unittest.mock import AsyncMock, MagicMock | ||
|
||
import litestar | ||
import pytest | ||
|
||
import microbootstrap.settings | ||
from microbootstrap import ( | ||
FastApiPrometheusConfig, | ||
LitestarPrometheusConfig, | ||
|
@@ -26,47 +29,47 @@ def anyio_backend() -> str: | |
return "asyncio" | ||
|
||
|
||
@pytest.fixture() | ||
@pytest.fixture | ||
def default_litestar_app() -> litestar.Litestar: | ||
return litestar.Litestar() | ||
|
||
|
||
@pytest.fixture() | ||
@pytest.fixture | ||
def minimal_sentry_config() -> SentryConfig: | ||
return SentryConfig(sentry_dsn="https://[email protected]/0") | ||
|
||
|
||
@pytest.fixture() | ||
@pytest.fixture | ||
def minimal_logging_config() -> LoggingConfig: | ||
return LoggingConfig(service_debug=False) | ||
|
||
|
||
@pytest.fixture() | ||
@pytest.fixture | ||
def minimal_base_prometheus_config() -> BasePrometheusConfig: | ||
return BasePrometheusConfig() | ||
|
||
|
||
@pytest.fixture() | ||
@pytest.fixture | ||
def minimal_fastapi_prometheus_config() -> FastApiPrometheusConfig: | ||
return FastApiPrometheusConfig() | ||
|
||
|
||
@pytest.fixture() | ||
@pytest.fixture | ||
def minimal_litestar_prometheus_config() -> LitestarPrometheusConfig: | ||
return LitestarPrometheusConfig() | ||
|
||
|
||
@pytest.fixture() | ||
@pytest.fixture | ||
def minimal_swagger_config() -> SwaggerConfig: | ||
return SwaggerConfig() | ||
|
||
|
||
@pytest.fixture() | ||
def minimal_cors_config() -> SwaggerConfig: | ||
@pytest.fixture | ||
def minimal_cors_config() -> CorsConfig: | ||
return CorsConfig(cors_allowed_origins=["*"]) | ||
|
||
|
||
@pytest.fixture() | ||
@pytest.fixture | ||
def minimal_opentelemetry_config() -> OpentelemetryConfig: | ||
return OpentelemetryConfig( | ||
service_name="test-micro-service", | ||
|
@@ -77,21 +80,27 @@ def minimal_opentelemetry_config() -> OpentelemetryConfig: | |
) | ||
|
||
|
||
@pytest.fixture() | ||
@pytest.fixture | ||
def base_settings() -> BaseServiceSettings: | ||
return BaseServiceSettings() | ||
|
||
|
||
@pytest.fixture() | ||
@pytest.fixture | ||
def magic_mock() -> MagicMock: | ||
return MagicMock() | ||
|
||
|
||
@pytest.fixture() | ||
@pytest.fixture | ||
def async_mock() -> AsyncMock: | ||
return AsyncMock() | ||
|
||
|
||
@pytest.fixture() | ||
@pytest.fixture | ||
def console_writer() -> ConsoleWriter: | ||
return ConsoleWriter(writer_enabled=False) | ||
|
||
|
||
@pytest.fixture | ||
def reset_reloaded_settings_module() -> typing.Iterator[None]: | ||
yield | ||
importlib.reload(microbootstrap.settings) |
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,38 @@ | ||
import importlib | ||
|
||
import pytest | ||
|
||
import microbootstrap.settings | ||
|
||
|
||
pytestmark = [pytest.mark.usefixtures("reset_reloaded_settings_module")] | ||
|
||
|
||
@pytest.mark.parametrize("alias", ["SERVICE_NAME", "MY_SERVICE_SERVICE_NAME"]) | ||
def test_settings_service_name_aliases(monkeypatch: pytest.MonkeyPatch, alias: str) -> None: | ||
monkeypatch.setenv("ENVIRONMENT_PREFIX", "MY_SERVICE_") | ||
monkeypatch.setenv(alias, "my service") | ||
importlib.reload(microbootstrap.settings) | ||
|
||
settings = microbootstrap.settings.BaseServiceSettings() | ||
assert settings.service_name == "my service" | ||
|
||
|
||
def test_settings_service_name_default() -> None: | ||
settings = microbootstrap.settings.BaseServiceSettings() | ||
assert settings.service_name == "micro-service" | ||
|
||
|
||
@pytest.mark.parametrize("alias", ["CI_COMMIT_TAG", "MY_SERVICE_SERVICE_VERSION"]) | ||
def test_settings_service_version_aliases(monkeypatch: pytest.MonkeyPatch, alias: str) -> None: | ||
monkeypatch.setenv("ENVIRONMENT_PREFIX", "MY_SERVICE_") | ||
monkeypatch.setenv(alias, "1.2.3") | ||
importlib.reload(microbootstrap.settings) | ||
|
||
settings = microbootstrap.settings.BaseServiceSettings() | ||
assert settings.service_version == "1.2.3" | ||
|
||
|
||
def test_settings_service_version_default() -> None: | ||
settings = microbootstrap.settings.BaseServiceSettings() | ||
assert settings.service_version == "1.0.0" |