| 
1 | 1 | # pylint: disable=redefined-outer-name  | 
2 | 2 | # pylint: disable=unused-argument  | 
3 | 3 | # pylint: disable=unused-variable  | 
4 |  | - | 
5 |  | -import logging  | 
6 |  | -from copy import deepcopy  | 
7 |  | -from typing import Any  | 
8 |  | - | 
 | 4 | +# pylint: disable=too-many-arguments  | 
9 | 5 | import pytest  | 
 | 6 | +from pytest_simcore.helpers.monkeypatch_envs import setenvs_from_dict  | 
 | 7 | +from pytest_simcore.helpers.typing_env import EnvVarsDict  | 
10 | 8 | from simcore_postgres_database.models.users import UserRole  | 
11 |  | -from simcore_service_webserver.log import setup_logging  | 
12 | 9 | 
 
  | 
13 | 10 | 
 
  | 
14 | 11 | @pytest.fixture  | 
15 | 12 | def user_role() -> UserRole:  | 
16 |  | -    # TODO: user rights still not in place  | 
17 | 13 |     return UserRole.TESTER  | 
18 | 14 | 
 
  | 
19 | 15 | 
 
  | 
20 | 16 | @pytest.fixture  | 
21 |  | -def app_cfg(default_app_cfg, unused_tcp_port_factory, monkeypatch) -> dict[str, Any]:  | 
22 |  | -    """App's configuration used for every test in this module  | 
23 |  | -
  | 
24 |  | -    NOTE: Overrides services/web/server/tests/unit/with_dbs/conftest.py::app_cfg to influence app setup  | 
25 |  | -    """  | 
26 |  | -    cfg = deepcopy(default_app_cfg)  | 
27 |  | - | 
28 |  | -    monkeypatch.setenv("WEBSERVER_DEV_FEATURES_ENABLED", "1")  | 
29 |  | - | 
30 |  | -    cfg["main"]["port"] = unused_tcp_port_factory()  | 
31 |  | -    cfg["main"]["studies_access_enabled"] = True  | 
32 |  | - | 
33 |  | -    exclude = {  | 
34 |  | -        "activity",  | 
35 |  | -        "clusters",  | 
36 |  | -        "computation",  | 
37 |  | -        "diagnostics",  | 
38 |  | -        "garbage_collector",  | 
39 |  | -        "groups",  | 
40 |  | -        "publications",  | 
41 |  | -        "smtp",  | 
42 |  | -        "socketio",  | 
43 |  | -        "storage",  | 
44 |  | -        "studies_dispatcher",  | 
45 |  | -        "tags",  | 
46 |  | -        "tracing",  | 
47 |  | -    }  | 
48 |  | -    include = {  | 
49 |  | -        "catalog",  | 
50 |  | -        "db",  | 
51 |  | -        "login",  | 
52 |  | -        "meta_modeling",  # MODULE UNDER TEST  | 
53 |  | -        "products",  | 
54 |  | -        "projects",  | 
55 |  | -        "redis",  | 
56 |  | -        "resource_manager",  | 
57 |  | -        "rest",  | 
58 |  | -        "users",  | 
59 |  | -        "version_control",  | 
60 |  | -    }  | 
61 |  | - | 
62 |  | -    assert include.intersection(exclude) == set()  | 
63 |  | - | 
64 |  | -    for section in include:  | 
65 |  | -        cfg[section]["enabled"] = True  | 
66 |  | -    for section in exclude:  | 
67 |  | -        cfg[section]["enabled"] = False  | 
68 |  | - | 
69 |  | -    # NOTE: To see logs, use pytest -s --log-cli-level=DEBUG  | 
70 |  | -    setup_logging(  | 
71 |  | -        level=logging.DEBUG,  | 
72 |  | -        log_format_local_dev_enabled=True,  | 
73 |  | -        logger_filter_mapping={},  | 
74 |  | -        tracing_settings=None,  | 
 | 17 | +def app_environment(  | 
 | 18 | +    monkeypatch: pytest.MonkeyPatch,  | 
 | 19 | +    app_environment: EnvVarsDict,  | 
 | 20 | +) -> EnvVarsDict:  | 
 | 21 | +    return app_environment | setenvs_from_dict(  | 
 | 22 | +        monkeypatch,  | 
 | 23 | +        {  | 
 | 24 | +            # exclude  | 
 | 25 | +            "WEBSERVER_ACTIVITY": "null",  | 
 | 26 | +            "WEBSERVER_CLUSTERS": "null",  | 
 | 27 | +            "WEBSERVER_COMPUTATION": "null",  | 
 | 28 | +            "WEBSERVER_DIAGNOSTICS": "null",  | 
 | 29 | +            "WEBSERVER_GROUPS": "0",  | 
 | 30 | +            "WEBSERVER_PUBLICATIONS": "0",  | 
 | 31 | +            "WEBSERVER_GARBAGE_COLLECTOR": "null",  | 
 | 32 | +            "WEBSERVER_SMTP": "null",  | 
 | 33 | +            "WEBSERVER_SOCKETIO": "0",  | 
 | 34 | +            "WEBSERVER_STORAGE": "null",  | 
 | 35 | +            "WEBSERVER_STUDIES_DISPATCHER": "null",  | 
 | 36 | +            "WEBSERVER_TAGS": "0",  | 
 | 37 | +            "WEBSERVER_TRACING": "null",  | 
 | 38 | +            # Module under test  | 
 | 39 | +            "WEBSERVER_DEV_FEATURES_ENABLED": "1",  | 
 | 40 | +            "WEBSERVER_VERSION_CONTROL": "1",  | 
 | 41 | +            "WEBSERVER_META_MODELING": "1",  | 
 | 42 | +        },  | 
75 | 43 |     )  | 
76 |  | - | 
77 |  | -    # Enforces smallest GC in the background task  | 
78 |  | -    cfg["resource_manager"]["garbage_collection_interval_seconds"] = 1  | 
79 |  | - | 
80 |  | -    return cfg  | 
0 commit comments