33# pylint:disable=redefined-outer-name
44
55import asyncio
6+ import os
67from collections .abc import Callable
7- from pathlib import Path
88from typing import Any
99from unittest .mock import MagicMock
1010
1111import pytest
12- import yaml
1312from aiohttp .client_exceptions import ClientConnectionError
1413from aiohttp .test_utils import TestClient
1514from pytest_mock import MockerFixture
1615from pytest_simcore .helpers .assert_checks import assert_status
16+ from pytest_simcore .helpers .monkeypatch_envs import setenvs_from_dict
17+ from pytest_simcore .helpers .typing_env import EnvVarsDict
1718from servicelib .aiohttp import status
1819from servicelib .aiohttp .application import create_safe_application
1920from simcore_service_webserver .activity .plugin import setup_activity
20- from simcore_service_webserver .application_settings import setup_settings
21+ from simcore_service_webserver .application_settings import (
22+ PrometheusSettings ,
23+ setup_settings ,
24+ )
2125from simcore_service_webserver .rest .plugin import setup_rest
2226from simcore_service_webserver .security .plugin import setup_security
2327from simcore_service_webserver .session .plugin import setup_session
@@ -55,29 +59,61 @@ def mocked_monitoring_down(mocker: MockerFixture) -> None:
5559
5660
5761@pytest .fixture
58- def app_config (fake_data_dir : Path , osparc_simcore_root_dir : Path ) -> dict [str , Any ]:
59- with Path .open (fake_data_dir / "test_activity_config.yml" ) as fh :
60- content = fh .read ()
61- config = content .replace (
62- "${OSPARC_SIMCORE_REPO_ROOTDIR}" , str (osparc_simcore_root_dir )
63- )
62+ def app_environment (
63+ mock_env_devel_environment : EnvVarsDict , monkeypatch : pytest .MonkeyPatch
64+ ) -> EnvVarsDict :
65+
66+ envs = mock_env_devel_environment | setenvs_from_dict (
67+ monkeypatch ,
68+ {
69+ "LOGIN_REGISTRATION_CONFIRMATION_REQUIRED" : "True" ,
70+ "LOGIN_REGISTRATION_INVITATION_REQUIRED" : "False" ,
71+ "POSTGRES_DB" : "simcoredb" ,
72+ "POSTGRES_HOST" : "postgres" ,
73+ "POSTGRES_MAXSIZE" : "10" ,
74+ "POSTGRES_MINSIZE" : "10" ,
75+ "POSTGRES_PASSWORD" : "simcore" ,
76+ "POSTGRES_PORT" : "5432" ,
77+ "POSTGRES_USER" : "simcore" ,
78+ "PROMETHEUS_PASSWORD" : "fake" ,
79+ "PROMETHEUS_URL" : "http://prometheus:9090" ,
80+ "PROMETHEUS_USERNAME" : "fake" ,
81+ "PROMETHEUS_VTAG" : "v1" ,
82+ "SESSION_SECRET_KEY" : "REPLACE_ME_with_result__Fernet_generate_key=" ,
83+ "SMTP_HOST" : "mail.foo.com" ,
84+ "SMTP_PORT" : "25" ,
85+ "STORAGE_HOST" : "storage" ,
86+ "STORAGE_PORT" : "11111" ,
87+ "STORAGE_VTAG" : "v0" ,
88+ "WEBSERVER_LOGIN" : "null" ,
89+ "WEBSERVER_LOGLEVEL" : "DEBUG" ,
90+ "WEBSERVER_PORT" : "8080" ,
91+ "WEBSERVER_STUDIES_ACCESS_ENABLED" : "True" ,
92+ },
93+ )
94+
95+ monkeypatch .delenv ("WEBSERVER_ACTIVITY" )
96+ envs .pop ("WEBSERVER_ACTIVITY" )
6497
65- return yaml . safe_load ( config )
98+ return envs
6699
67100
68101@pytest .fixture
69102def client (
70103 event_loop : asyncio .AbstractEventLoop ,
71104 aiohttp_client : Callable ,
72- app_config : dict [str , Any ],
73105 mock_orphaned_services : MagicMock ,
74- monkeypatch_setenv_from_app_config : Callable ,
106+ app_environment : EnvVarsDict ,
75107):
76- monkeypatch_setenv_from_app_config (app_config )
108+ # app_environment are in place
109+ assert {key : os .environ [key ] for key in app_environment } == app_environment
110+ expected_activity_settings = PrometheusSettings .create_from_envs ()
111+
112+ app = create_safe_application ()
77113
78- app = create_safe_application (app_config )
114+ settings = setup_settings (app )
115+ assert expected_activity_settings == settings .WEBSERVER_ACTIVITY
79116
80- assert setup_settings (app )
81117 setup_session (app )
82118 setup_security (app )
83119 setup_rest (app )
@@ -92,7 +128,7 @@ async def test_has_login_required(client: TestClient):
92128
93129
94130async def test_monitoring_up (
95- mocked_login_required : None , mocked_monitoring : None , client
131+ mocked_login_required : None , mocked_monitoring : None , client : TestClient
96132):
97133 RUNNING_NODE_ID = "894dd8d5-de3b-4767-950c-7c3ed8f51d8c"
98134
0 commit comments