Skip to content

Commit 5cb9187

Browse files
committed
rm app_cfg
1 parent 66bc63b commit 5cb9187

File tree

3 files changed

+54
-85
lines changed

3 files changed

+54
-85
lines changed

services/web/server/tests/unit/with_dbs/03/tags/conftest.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import pytest
1111
from aioresponses import aioresponses
12+
from pytest_simcore.helpers.monkeypatch_envs import setenvs_from_dict
1213
from pytest_simcore.helpers.typing_env import EnvVarsDict
1314
from pytest_simcore.helpers.webserver_login import UserInfoDict
1415
from pytest_simcore.helpers.webserver_projects import NewProject, delete_all_projects
@@ -40,21 +41,21 @@
4041
@pytest.fixture
4142
def app_environment(
4243
monkeypatch: pytest.MonkeyPatch,
43-
app_cfg: AppConfigDict,
4444
app_environment: EnvVarsDict,
45-
monkeypatch_setenv_from_app_config: Callable[[AppConfigDict], EnvVarsDict],
4645
) -> EnvVarsDict:
47-
cfg = deepcopy(app_cfg)
48-
49-
cfg["projects"]["enabled"] = True
50-
cfg["resource_manager"][
51-
"garbage_collection_interval_seconds"
52-
] = DEFAULT_GARBAGE_COLLECTOR_INTERVAL_SECONDS # increase speed of garbage collection
53-
cfg["resource_manager"][
54-
"resource_deletion_timeout_seconds"
55-
] = DEFAULT_GARBAGE_COLLECTOR_DELETION_TIMEOUT_SECONDS # reduce deletion delay
46+
# NOTE: undos some app_environment settings
47+
monkeypatch.delenv("WEBSERVER_GARBAGE_COLLECTOR", raising=False)
48+
app_environment.pop("WEBSERVER_GARBAGE_COLLECTOR", None)
5649

57-
return app_environment | monkeypatch_setenv_from_app_config(cfg)
50+
return app_environment | setenvs_from_dict(
51+
monkeypatch,
52+
{
53+
# reduce deletion delay
54+
"RESOURCE_MANAGER_RESOURCE_TTL_S": f"{DEFAULT_GARBAGE_COLLECTOR_INTERVAL_SECONDS}",
55+
# increase speed of garbage collection
56+
"GARBAGE_COLLECTOR_INTERVAL_S": f"{DEFAULT_GARBAGE_COLLECTOR_DELETION_TIMEOUT_SECONDS}",
57+
},
58+
)
5859

5960

6061
@pytest.fixture
@@ -68,10 +69,13 @@ def client(
6869
mock_orphaned_services,
6970
redis_client, # this ensure redis is properly cleaned
7071
):
71-
# config app
7272
app = create_safe_application()
7373

74+
assert "WEBSERVER_GARBAGE_COLLECTOR" not in app_environment
75+
7476
settings = setup_settings(app)
77+
assert settings.WEBSERVER_GARBAGE_COLLECTOR is not None
78+
assert settings.WEBSERVER_PROJECTS is not None
7579
assert settings.WEBSERVER_TAGS is not None
7680

7781
# setup app

services/web/server/tests/unit/with_dbs/03/version_control/conftest.py

Lines changed: 28 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@
22
# pylint: disable=unused-argument
33
# pylint: disable=unused-variable
44

5-
import logging
65
from collections.abc import AsyncIterator, Awaitable, Callable
7-
from copy import deepcopy
86
from pathlib import Path
9-
from typing import Any
107
from unittest import mock
118
from uuid import UUID
129

@@ -21,6 +18,8 @@
2118
from models_library.utils.fastapi_encoders import jsonable_encoder
2219
from pytest_mock import MockerFixture
2320
from pytest_simcore.helpers.faker_factories import random_project
21+
from pytest_simcore.helpers.monkeypatch_envs import setenvs_from_dict
22+
from pytest_simcore.helpers.typing_env import EnvVarsDict
2423
from pytest_simcore.helpers.webserver_login import UserInfoDict
2524
from pytest_simcore.helpers.webserver_projects import NewProject
2625
from servicelib.aiohttp import status
@@ -31,7 +30,6 @@
3130
from simcore_service_webserver._meta import API_VTAG as VX
3231
from simcore_service_webserver.db.models import UserRole
3332
from simcore_service_webserver.db.plugin import APP_AIOPG_ENGINE_KEY
34-
from simcore_service_webserver.log import setup_logging
3533
from simcore_service_webserver.projects.db import ProjectDBAPI
3634
from simcore_service_webserver.projects.models import ProjectDict
3735
from tenacity.asyncio import AsyncRetrying
@@ -69,70 +67,35 @@ def catalog_subsystem_mock_override(
6967

7068

7169
@pytest.fixture
72-
def app_cfg(
73-
default_app_cfg,
74-
unused_tcp_port_factory,
70+
def app_environment(
7571
catalog_subsystem_mock_override: None,
76-
monkeypatch,
77-
) -> dict[str, Any]:
78-
"""App's configuration used for every test in this module
79-
80-
NOTE: Overrides services/web/server/tests/unit/with_dbs/conftest.py::app_cfg to influence app setup
81-
"""
82-
cfg = deepcopy(default_app_cfg)
83-
84-
monkeypatch.setenv("WEBSERVER_DEV_FEATURES_ENABLED", "1")
85-
86-
cfg["main"]["port"] = unused_tcp_port_factory()
87-
cfg["main"]["studies_access_enabled"] = True
88-
89-
exclude = {
90-
"activity",
91-
"clusters",
92-
"computation",
93-
"diagnostics",
94-
"groups",
95-
"publications",
96-
"garbage_collector",
97-
"smtp",
98-
"socketio",
99-
"storage",
100-
"studies_dispatcher",
101-
"tags",
102-
"tracing",
103-
}
104-
include = {
105-
"catalog",
106-
"db",
107-
"login",
108-
"products",
109-
"projects",
110-
"resource_manager",
111-
"rest",
112-
"users",
113-
"version_control", # MODULE UNDER TEST
114-
}
115-
116-
assert include.intersection(exclude) == set()
117-
118-
for section in include:
119-
cfg[section]["enabled"] = True
120-
for section in exclude:
121-
cfg[section]["enabled"] = False
122-
123-
# NOTE: To see logs, use pytest -s --log-cli-level=DEBUG
124-
setup_logging(
125-
level=logging.DEBUG,
126-
log_format_local_dev_enabled=True,
127-
logger_filter_mapping={},
128-
tracing_settings=None,
72+
monkeypatch: pytest.MonkeyPatch,
73+
app_environment: EnvVarsDict,
74+
) -> EnvVarsDict:
75+
76+
return app_environment | setenvs_from_dict(
77+
monkeypatch,
78+
{
79+
# exclude
80+
"WEBSERVER_ACTIVITY": "null",
81+
"WEBSERVER_CLUSTERS": "null",
82+
"WEBSERVER_COMPUTATION": "null",
83+
"WEBSERVER_DIAGNOSTICS": "null",
84+
"WEBSERVER_GROUPS": "0",
85+
"WEBSERVER_PUBLICATIONS": "0",
86+
"WEBSERVER_GARBAGE_COLLECTOR": "null",
87+
"WEBSERVER_SMTP": "null",
88+
"WEBSERVER_SOCKETIO": "0",
89+
"WEBSERVER_STORAGE": "null",
90+
"WEBSERVER_STUDIES_DISPATCHER": "null",
91+
"WEBSERVER_TAGS": "0",
92+
"WEBSERVER_TRACING": "null",
93+
# Module under test
94+
"WEBSERVER_DEV_FEATURES_ENABLED": "1",
95+
"WEBSERVER_VERSION_CONTROL": "1",
96+
},
12997
)
13098

131-
# Enforces smallest GC in the background task
132-
cfg["resource_manager"]["garbage_collection_interval_seconds"] = 1
133-
134-
return cfg
135-
13699

137100
@pytest.fixture
138101
async def user_id(logged_user: UserInfoDict) -> UserID:

services/web/server/tests/unit/with_dbs/03/version_control/test_version_control_handlers.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# pylint: disable=redefined-outer-name
22
# pylint: disable=unused-argument
33
# pylint: disable=unused-variable
4+
# pylint: disable=too-many-arguments
5+
46

57
from collections.abc import Awaitable, Callable
68
from http import HTTPStatus
@@ -23,7 +25,7 @@
2325
)
2426

2527

26-
async def assert_resp_page(
28+
async def _assert_resp_page(
2729
resp: aiohttp.ClientResponse,
2830
expected_page_cls: type[Page],
2931
expected_total: int,
@@ -38,7 +40,7 @@ async def assert_resp_page(
3840
return page
3941

4042

41-
async def assert_status_and_body(
43+
async def _assert_status_and_body(
4244
resp, expected_cls: HTTPStatus, expected_model: type[BaseModel]
4345
) -> BaseModel:
4446
data, _ = await assert_status(resp, expected_cls)
@@ -84,7 +86,7 @@ async def test_workflow(
8486
#
8587
# this project now has a repo
8688
resp = await client.get(f"/{VX}/repos/projects")
87-
page = await assert_resp_page(
89+
page = await _assert_resp_page(
8890
resp, expected_page_cls=Page[ProjectDict], expected_total=1, expected_count=1
8991
)
9092

@@ -97,8 +99,8 @@ async def test_workflow(
9799
assert CheckpointApiModel.model_validate(data) == checkpoint1
98100

99101
# TODO: GET checkpoint with tag
102+
resp = await client.get(f"/{VX}/repos/projects/{project_uuid}/checkpoints/v1")
100103
with pytest.raises(aiohttp.ClientResponseError) as excinfo:
101-
resp = await client.get(f"/{VX}/repos/projects/{project_uuid}/checkpoints/v1")
102104
resp.raise_for_status()
103105

104106
assert CheckpointApiModel.model_validate(data) == checkpoint1
@@ -114,7 +116,7 @@ async def test_workflow(
114116

115117
# LIST checkpoints
116118
resp = await client.get(f"/{VX}/repos/projects/{project_uuid}/checkpoints")
117-
page = await assert_resp_page(
119+
page = await _assert_resp_page(
118120
resp,
119121
expected_page_cls=Page[CheckpointApiModel],
120122
expected_total=1,
@@ -226,7 +228,7 @@ async def test_delete_project_and_repo(
226228

227229
# LIST
228230
resp = await client.get(f"/{VX}/repos/projects/{project_uuid}/checkpoints")
229-
await assert_resp_page(
231+
await _assert_resp_page(
230232
resp,
231233
expected_page_cls=Page[CheckpointApiModel],
232234
expected_total=1,
@@ -247,7 +249,7 @@ async def test_delete_project_and_repo(
247249

248250
# LIST empty
249251
resp = await client.get(f"/{VX}/repos/projects/{project_uuid}/checkpoints")
250-
await assert_resp_page(
252+
await _assert_resp_page(
251253
resp,
252254
expected_page_cls=Page[CheckpointApiModel],
253255
expected_total=0,

0 commit comments

Comments
 (0)