| 
3 | 3 | # pylint:disable=no-name-in-module  | 
4 | 4 | 
 
  | 
5 | 5 | import json  | 
 | 6 | +import logging  | 
6 | 7 | from typing import Annotated  | 
7 | 8 | 
 
  | 
8 | 9 | import pytest  | 
9 | 10 | from aiohttp import web  | 
10 | 11 | from common_library.json_serialization import json_dumps  | 
 | 12 | +from models_library.rpc.webserver import DEFAULT_WEBSERVER_RPC_NAMESPACE  | 
11 | 13 | from pydantic import Field, HttpUrl, TypeAdapter  | 
12 | 14 | from pytest_simcore.helpers.monkeypatch_envs import setenvs_from_dict  | 
13 | 15 | from pytest_simcore.helpers.typing_env import EnvVarsDict  | 
 | 
18 | 20 |     setup_settings,  | 
19 | 21 | )  | 
20 | 22 | 
 
  | 
 | 23 | +_logger = logging.getLogger(__name__)  | 
 | 24 | + | 
21 | 25 | 
 
  | 
22 | 26 | @pytest.fixture  | 
23 | 27 | def app_settings(  | 
@@ -230,3 +234,50 @@ def test_valid_application_settings(mock_webserver_service_environment: EnvVarsD  | 
230 | 234 |     assert settings  | 
231 | 235 | 
 
  | 
232 | 236 |     assert settings == ApplicationSettings.create_from_envs()  | 
 | 237 | + | 
 | 238 | + | 
 | 239 | +@pytest.fixture  | 
 | 240 | +def mock_service_environment(  | 
 | 241 | +    docker_compose_service_environment_dict,  | 
 | 242 | +    service_name: str,  | 
 | 243 | +    monkeypatch: pytest.MonkeyPatch,  | 
 | 244 | +) -> EnvVarsDict:  | 
 | 245 | +    # NOTE: the name of the service in real deploys are not necessarily the ones we have here in the docker-compose  | 
 | 246 | +    # Typically they include prefixes with the deployment name e.g. master-webserver or staging-webserver instead of just webserver  | 
 | 247 | +    _logger.info("Mocking envs for service: %s", service_name)  | 
 | 248 | + | 
 | 249 | +    assert docker_compose_service_environment_dict  | 
 | 250 | +    return setenvs_from_dict(monkeypatch, {**docker_compose_service_environment_dict})  | 
 | 251 | + | 
 | 252 | + | 
 | 253 | +@pytest.mark.parametrize(  | 
 | 254 | +    "service_name", ["webserver", "wb-db-event-listener", "wb-garbage-collector"]  | 
 | 255 | +)  | 
 | 256 | +def test_webserver_rpc_namespace_must_be_default(mock_service_environment: EnvVarsDict):  | 
 | 257 | +    # NOTE: This requirement will change when https://github.com/ITISFoundation/osparc-simcore/issues/8448  is implemented  | 
 | 258 | +    settings = ApplicationSettings.create_from_envs()  | 
 | 259 | +    assert settings  | 
 | 260 | + | 
 | 261 | +    assert settings.WEBSERVER_RPC_NAMESPACE == DEFAULT_WEBSERVER_RPC_NAMESPACE  | 
 | 262 | + | 
 | 263 | + | 
 | 264 | +@pytest.mark.parametrize("service_name", ["wb-api-server"])  | 
 | 265 | +def test_webserver_rpc_namespace_must_be_non_default(  | 
 | 266 | +    mock_service_environment: EnvVarsDict,  | 
 | 267 | +    env_devel_dict: EnvVarsDict,  | 
 | 268 | +):  | 
 | 269 | +    settings = ApplicationSettings.create_from_envs()  | 
 | 270 | +    assert settings  | 
 | 271 | + | 
 | 272 | +    assert settings.WEBSERVER_RPC_NAMESPACE != DEFAULT_WEBSERVER_RPC_NAMESPACE  | 
 | 273 | +    assert env_devel_dict["WB_API_WEBSERVER_HOST"] == settings.WEBSERVER_RPC_NAMESPACE  | 
 | 274 | + | 
 | 275 | + | 
 | 276 | +@pytest.mark.parametrize("service_name", ["wb-auth"])  | 
 | 277 | +def test_webserver_rpc_namespace_must_be_disabled(  | 
 | 278 | +    mock_service_environment: EnvVarsDict,  | 
 | 279 | +):  | 
 | 280 | +    settings = ApplicationSettings.create_from_envs()  | 
 | 281 | +    assert settings  | 
 | 282 | + | 
 | 283 | +    assert settings.WEBSERVER_RPC_NAMESPACE is None  | 
0 commit comments