Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
from pytest_mock import MockerFixture
from pytest_simcore.helpers.typing_mock import HandlerMockFactory
from simcore_service_api_server._meta import API_VERSION
from simcore_service_api_server.api.dependencies.webserver_rpc import (
get_wb_api_rpc_client,
)
from simcore_service_api_server.services_rpc.wb_api_server import WbApiRpcClient

# Fake response based on values from 05_licensed_items.json
EXPECTED_LICENSED_ITEMS = [
Expand Down Expand Up @@ -141,15 +137,9 @@ class DummyRpcClient:
async def mock_wb_api_server_rpc(
app: FastAPI,
mocker: MockerFixture,
mocked_app_rpc_dependencies: None,
mock_handler_in_licenses_rpc_interface: HandlerMockFactory,
) -> None:
from servicelib.rabbitmq.rpc_interfaces.webserver.v1 import ( # noqa: PLC0415
WebServerRpcClient,
)

app.dependency_overrides[get_wb_api_rpc_client] = lambda: WbApiRpcClient(
_rpc_client=mocker.MagicMock(spec=WebServerRpcClient),
)

mock_handler_in_licenses_rpc_interface(
"get_licensed_items", return_value=EXPECTED_LICENSED_ITEMS_PAGE
Expand Down
6 changes: 3 additions & 3 deletions services/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ services:
# WEBSERVER_SERVER_HOST
WEBSERVER_HOST: ${WEBSERVER_HOST}
WEBSERVER_PORT: ${WEBSERVER_PORT}
WEBSERVER_RPC_NAMESPACE: ${WEBSERVER_HOST}
WEBSERVER_RPC_NAMESPACE: webserver

# WEBSERVER / -> index.html
WEBSERVER_FRONTEND: ${WEBSERVER_FRONTEND}
Expand Down Expand Up @@ -953,7 +953,7 @@ services:

WEBSERVER_HOST: ${WEBSERVER_HOST}
WEBSERVER_PORT: ${WEBSERVER_PORT}
WEBSERVER_RPC_NAMESPACE: ${WEBSERVER_HOST}
WEBSERVER_RPC_NAMESPACE: webserver

DIRECTOR_V2_HOST: ${DIRECTOR_V2_HOST}
DIRECTOR_V2_PORT: ${DIRECTOR_V2_PORT}
Expand Down Expand Up @@ -1104,7 +1104,7 @@ services:
WEBSERVER_PRODUCTS: ${WB_GC_PRODUCTS}
WEBSERVER_PROJECTS: ${WB_GC_PROJECTS}
WEBSERVER_PUBLICATIONS: ${WB_GC_PUBLICATIONS}
WEBSERVER_RPC_NAMESPACE: ${WEBSERVER_HOST}
WEBSERVER_RPC_NAMESPACE: webserver
WEBSERVER_SCICRUNCH: ${WB_GC_SCICRUNCH}
WEBSERVER_SOCKETIO: ${WB_GC_SOCKETIO}
WEBSERVER_STATICWEB: ${WB_GC_STATICWEB}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
# pylint:disable=no-name-in-module

import json
import logging
from typing import Annotated

import pytest
from aiohttp import web
from common_library.json_serialization import json_dumps
from models_library.rpc.webserver import DEFAULT_WEBSERVER_RPC_NAMESPACE
from pydantic import Field, HttpUrl, TypeAdapter
from pytest_simcore.helpers.monkeypatch_envs import setenvs_from_dict
from pytest_simcore.helpers.typing_env import EnvVarsDict
Expand All @@ -18,6 +20,8 @@
setup_settings,
)

_logger = logging.getLogger(__name__)


@pytest.fixture
def app_settings(
Expand Down Expand Up @@ -230,3 +234,50 @@ def test_valid_application_settings(mock_webserver_service_environment: EnvVarsD
assert settings

assert settings == ApplicationSettings.create_from_envs()


@pytest.fixture
def mock_service_environment(
docker_compose_service_environment_dict,
service_name: str,
monkeypatch: pytest.MonkeyPatch,
) -> EnvVarsDict:
# NOTE: the name of the service in real deploys are not necessarily the ones we have here in the docker-compose
# Typically they include prefixes with the deployment name e.g. master-webserver or staging-webserver instead of just webserver
_logger.info("Mocking envs for service: %s", service_name)

assert docker_compose_service_environment_dict
return setenvs_from_dict(monkeypatch, {**docker_compose_service_environment_dict})


@pytest.mark.parametrize(
"service_name", ["webserver", "wb-db-event-listener", "wb-garbage-collector"]
)
def test_webserver_rpc_namespace_must_be_default(mock_service_environment: EnvVarsDict):
# NOTE: This requirement will change when https://github.com/ITISFoundation/osparc-simcore/issues/8448 is implemented
settings = ApplicationSettings.create_from_envs()
assert settings

assert settings.WEBSERVER_RPC_NAMESPACE == DEFAULT_WEBSERVER_RPC_NAMESPACE


@pytest.mark.parametrize("service_name", ["wb-api-server"])
def test_webserver_rpc_namespace_must_be_non_default(
mock_service_environment: EnvVarsDict,
env_devel_dict: EnvVarsDict,
):
settings = ApplicationSettings.create_from_envs()
assert settings

assert settings.WEBSERVER_RPC_NAMESPACE != DEFAULT_WEBSERVER_RPC_NAMESPACE
assert env_devel_dict["WB_API_WEBSERVER_HOST"] == settings.WEBSERVER_RPC_NAMESPACE


@pytest.mark.parametrize("service_name", ["wb-auth"])
def test_webserver_rpc_namespace_must_be_disabled(
mock_service_environment: EnvVarsDict,
):
settings = ApplicationSettings.create_from_envs()
assert settings

assert settings.WEBSERVER_RPC_NAMESPACE is None
Loading