Skip to content

Commit 42d1317

Browse files
committed
@YuryHrytsuk review: tests backwards compatiblity
1 parent 39bd21d commit 42d1317

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

services/web/server/src/simcore_service_webserver/application_settings.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,10 @@ class ApplicationSettings(BaseApplicationSettings, MixinLoggingSettings):
233233
]
234234

235235
WEBSERVER_LICENSES: Annotated[
236-
LicensesSettings | None,
236+
LicensesSettings | None | bool,
237237
Field(
238238
json_schema_extra={"auto_default_from_env": True},
239+
# NOTE: `bool` is to keep backwards compatibility
239240
),
240241
]
241242

services/web/server/tests/unit/isolated/test_application_settings.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,37 @@ def test_avoid_sensitive_info_in_public(app_settings: ApplicationSettings):
138138
assert not any("token" in key for key in app_settings.public_dict())
139139
assert not any("secret" in key for key in app_settings.public_dict())
140140
assert not any("private" in key for key in app_settings.public_dict())
141+
142+
143+
def test_backwards_compatibility_with_bool_env_vars_turned_into_objects(
144+
monkeypatch: pytest.MonkeyPatch,
145+
mock_webserver_service_environment: EnvVarsDict,
146+
):
147+
# Sometimes we turn `WEBSERVER_VAR: bool` into `WEBSERVER_VAR: VarSettings`
148+
with monkeypatch.context() as patch:
149+
patch.setenv("WEBSERVER_LICENSES", "true")
150+
151+
settings = ApplicationSettings.create_from_envs()
152+
assert settings.WEBSERVER_LICENSES is True
153+
154+
with monkeypatch.context() as patch:
155+
patch.setenv("WEBSERVER_LICENSES", "{}")
156+
patch.setenv("LICENSES_ITIS_VIP_SYNCER_ENABLED", "1")
157+
patch.setenv("LICENSES_ITIS_VIP_API_URL", "https://some-api/{category}")
158+
patch.setenv(
159+
"LICENSES_ITIS_VIP_CATEGORIES",
160+
'{"HumanWholeBody": "Humans", "HumanBodyRegion": "Humans (Region)", "AnimalWholeBody": "Animal"}',
161+
)
162+
163+
settings = ApplicationSettings.create_from_envs()
164+
assert settings.WEBSERVER_LICENSES is not None
165+
assert not isinstance(settings.WEBSERVER_LICENSES, bool)
166+
assert settings.WEBSERVER_LICENSES.LICENSES_ITIS_VIP
167+
assert settings.WEBSERVER_LICENSES.LICENSES_ITIS_VIP.LICENSES_ITIS_VIP_API_URL
168+
assert settings.WEBSERVER_LICENSES.LICENSES_ITIS_VIP_SYNCER_ENABLED
169+
170+
with monkeypatch.context() as patch:
171+
patch.setenv("WEBSERVER_LICENSES", "null")
172+
173+
settings = ApplicationSettings.create_from_envs()
174+
assert settings.WEBSERVER_LICENSES is None

0 commit comments

Comments
 (0)