Skip to content

Commit 9f4da63

Browse files
committed
updates datcore-adapter
1 parent 41dd763 commit 9f4da63

File tree

3 files changed

+75
-25
lines changed

3 files changed

+75
-25
lines changed

services/datcore-adapter/src/simcore_service_datcore_adapter/core/settings.py

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from functools import cached_property
22
from typing import Annotated
33

4+
from common_library.basic_types import DEFAULT_FACTORY
45
from models_library.basic_types import BootModeEnum, LogLevel
56
from pydantic import AliasChoices, Field, TypeAdapter, field_validator
67
from pydantic.networks import AnyUrl
@@ -34,32 +35,39 @@ class ApplicationSettings(BaseApplicationSettings, MixinLoggingSettings):
3435
),
3536
] = LogLevel.INFO
3637

37-
PENNSIEVE: PennsieveSettings = Field(
38-
json_schema_extra={"auto_default_from_env": True}
39-
)
38+
PENNSIEVE: Annotated[
39+
PennsieveSettings, Field(json_schema_extra={"auto_default_from_env": True})
40+
]
4041

41-
DATCORE_ADAPTER_LOG_FORMAT_LOCAL_DEV_ENABLED: bool = Field(
42-
default=False,
43-
validation_alias=AliasChoices(
44-
"DATCORE_ADAPTER_LOG_FORMAT_LOCAL_DEV_ENABLED",
45-
"LOG_FORMAT_LOCAL_DEV_ENABLED",
42+
DATCORE_ADAPTER_LOG_FORMAT_LOCAL_DEV_ENABLED: Annotated[
43+
bool,
44+
Field(
45+
validation_alias=AliasChoices(
46+
"DATCORE_ADAPTER_LOG_FORMAT_LOCAL_DEV_ENABLED",
47+
"LOG_FORMAT_LOCAL_DEV_ENABLED",
48+
),
49+
description="Enables local development log format. WARNING: make sure it is disabled if you want to have structured logs!",
4650
),
47-
description="Enables local development log format. WARNING: make sure it is disabled if you want to have structured logs!",
48-
)
49-
DATCORE_ADAPTER_LOG_FILTER_MAPPING: dict[
50-
LoggerName, list[MessageSubstring]
51-
] = Field(
52-
default_factory=dict,
53-
validation_alias=AliasChoices(
54-
"DATCORE_ADAPTER_LOG_FILTER_MAPPING", "LOG_FILTER_MAPPING"
51+
] = False
52+
DATCORE_ADAPTER_LOG_FILTER_MAPPING: Annotated[
53+
dict[LoggerName, list[MessageSubstring]],
54+
Field(
55+
default_factory=dict,
56+
validation_alias=AliasChoices(
57+
"DATCORE_ADAPTER_LOG_FILTER_MAPPING", "LOG_FILTER_MAPPING"
58+
),
59+
description="is a dictionary that maps specific loggers (such as 'uvicorn.access' or 'gunicorn.access') to a list of log message patterns that should be filtered out.",
5560
),
56-
description="is a dictionary that maps specific loggers (such as 'uvicorn.access' or 'gunicorn.access') to a list of log message patterns that should be filtered out.",
57-
)
61+
] = DEFAULT_FACTORY
62+
5863
DATCORE_ADAPTER_PROMETHEUS_INSTRUMENTATION_ENABLED: bool = True
59-
DATCORE_ADAPTER_TRACING: TracingSettings | None = Field(
60-
description="settings for opentelemetry tracing",
61-
json_schema_extra={"auto_default_from_env": True},
62-
)
64+
DATCORE_ADAPTER_TRACING: Annotated[
65+
TracingSettings | None,
66+
Field(
67+
description="settings for opentelemetry tracing",
68+
json_schema_extra={"auto_default_from_env": True},
69+
),
70+
]
6371

6472
@cached_property
6573
def debug(self) -> bool:

services/datcore-adapter/tests/unit/conftest.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def pennsieve_mock_dataset_packages(mocks_dir: Path) -> dict[str, Any]:
6565

6666
@pytest.fixture()
6767
def minimal_app(
68-
app_envs: None,
68+
app_environment: None,
6969
) -> FastAPI:
7070
from simcore_service_datcore_adapter.main import the_app
7171

@@ -79,7 +79,7 @@ def client(minimal_app: FastAPI) -> TestClient:
7979

8080

8181
@pytest.fixture
82-
def app_envs(
82+
def app_environment(
8383
mock_env_devel_environment: EnvVarsDict, monkeypatch: pytest.MonkeyPatch
8484
) -> EnvVarsDict:
8585
return setenvs_from_dict(
@@ -93,7 +93,7 @@ def app_envs(
9393

9494
@pytest.fixture()
9595
async def initialized_app(
96-
app_envs: None, minimal_app: FastAPI
96+
app_environment: None, minimal_app: FastAPI
9797
) -> AsyncIterator[FastAPI]:
9898
async with LifespanManager(minimal_app):
9999
yield minimal_app
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# pylint: disable=unused-variable
2+
# pylint: disable=unused-argument
3+
# pylint: disable=redefined-outer-name
4+
5+
6+
import pytest
7+
from pytest_simcore.helpers.monkeypatch_envs import (
8+
EnvVarsDict,
9+
delenvs_from_dict,
10+
setenvs_from_dict,
11+
)
12+
from simcore_service_datcore_adapter.core.settings import ApplicationSettings
13+
14+
15+
@pytest.fixture
16+
def app_environment(
17+
monkeypatch: pytest.MonkeyPatch,
18+
app_environment: EnvVarsDict,
19+
external_envfile_dict: EnvVarsDict,
20+
) -> EnvVarsDict:
21+
"""
22+
NOTE: To run against repo.config in osparc-config repo
23+
24+
ln -s /path/to/osparc-config/deployments/mydeploy.com/repo.config .secrets
25+
pytest --external-envfile=.secrets tests/unit/test_core_settings.py
26+
27+
"""
28+
if external_envfile_dict:
29+
delenvs_from_dict(monkeypatch, app_environment, raising=False)
30+
return setenvs_from_dict(
31+
monkeypatch,
32+
{**external_envfile_dict},
33+
)
34+
return app_environment
35+
36+
37+
def test_unit_app_environment(app_environment: EnvVarsDict):
38+
assert app_environment
39+
settings = ApplicationSettings.create_from_envs()
40+
print("captured settings: \n", settings.model_dump_json(indent=2, warnings="none"))
41+
42+
assert settings.PENNSIEVE

0 commit comments

Comments
 (0)