44
55import re
66import urllib .parse
7- from unittest .mock import MagicMock
87
98import pytest
10- from aiohttp import web
119from aiohttp .test_utils import TestClient
1210from aioresponses import aioresponses as AioResponsesMock
1311from faker import Faker
14- from models_library .api_schemas_catalog .services import LatestServiceGet , ServiceGetV2
12+ from models_library .api_schemas_catalog .services import ServiceGetV2
1513from models_library .api_schemas_webserver .catalog import (
1614 CatalogServiceGet ,
1715 CatalogServiceUpdate ,
1816)
19- from models_library .products import ProductName
2017from models_library .rest_pagination import Page
21- from models_library .rpc_pagination import PageLimitInt , PageRpc
22- from models_library .services_types import ServiceKey , ServiceVersion
23- from models_library .users import UserID
2418from models_library .utils .fastapi_encoders import jsonable_encoder
25- from pydantic import NonNegativeInt , TypeAdapter
26- from pytest_mock import MockerFixture
19+ from pydantic import TypeAdapter
20+ from pytest_mock import MockerFixture , MockType
2721from pytest_simcore .helpers .assert_checks import assert_status
22+ from pytest_simcore .helpers .catalog_rpc_server import CatalogRpcSideEffects
2823from pytest_simcore .helpers .faker_factories import random_icon_url
2924from pytest_simcore .helpers .monkeypatch_envs import setenvs_from_dict
3025from pytest_simcore .helpers .typing_env import EnvVarsDict
@@ -50,86 +45,25 @@ def app_environment(
5045
5146
5247@pytest .fixture
53- def mocked_rpc_catalog_service_api (mocker : MockerFixture ) -> dict [str , MagicMock ]:
54- async def _list (
55- app : web .Application ,
56- * ,
57- product_name : ProductName ,
58- user_id : UserID ,
59- limit : PageLimitInt ,
60- offset : NonNegativeInt ,
61- ):
62- assert app
63- assert product_name
64- assert user_id
65-
66- items = TypeAdapter (list [LatestServiceGet ]).validate_python (
67- LatestServiceGet .model_json_schema ()["examples" ],
68- )
69- total_count = len (items )
70-
71- return PageRpc [LatestServiceGet ].create (
72- items [offset : offset + limit ],
73- total = total_count ,
74- limit = limit ,
75- offset = offset ,
76- )
48+ def mocked_rpc_catalog_service_api (mocker : MockerFixture ) -> dict [str , MockType ]:
7749
78- async def _get (
79- app : web .Application ,
80- * ,
81- product_name : ProductName ,
82- user_id : UserID ,
83- service_key : ServiceKey ,
84- service_version : ServiceVersion ,
85- ):
86- assert app
87- assert product_name
88- assert user_id
89-
90- got = ServiceGetV2 .model_validate (
91- ServiceGetV2 .model_json_schema ()["examples" ][0 ]
92- )
93- got .version = service_version
94- got .key = service_key
95-
96- return got
97-
98- async def _update (
99- app : web .Application ,
100- * ,
101- product_name : ProductName ,
102- user_id : UserID ,
103- service_key : ServiceKey ,
104- service_version : ServiceVersion ,
105- update : CatalogServiceUpdate ,
106- ):
107- assert app
108- assert product_name
109- assert user_id
110-
111- got = ServiceGetV2 .model_validate (
112- ServiceGetV2 .model_json_schema ()["examples" ][0 ]
113- )
114- got .version = service_version
115- got .key = service_key
116- return got .model_copy (update = update .model_dump (exclude_unset = True ))
50+ side_effects = CatalogRpcSideEffects ()
11751
11852 return {
11953 "list_services_paginated" : mocker .patch (
12054 "simcore_service_webserver.catalog._service.catalog_rpc.list_services_paginated" ,
12155 autospec = True ,
122- side_effect = _list ,
56+ side_effect = side_effects . list_services_paginated ,
12357 ),
12458 "get_service" : mocker .patch (
12559 "simcore_service_webserver.catalog._service.catalog_rpc.get_service" ,
12660 autospec = True ,
127- side_effect = _get ,
61+ side_effect = side_effects . get_service ,
12862 ),
12963 "update_service" : mocker .patch (
13064 "simcore_service_webserver.catalog._service.catalog_rpc.update_service" ,
13165 autospec = True ,
132- side_effect = _update ,
66+ side_effect = side_effects . update_service ,
13367 ),
13468 }
13569
@@ -141,7 +75,7 @@ async def _update(
14175async def test_list_services_latest (
14276 client : TestClient ,
14377 logged_user : UserInfoDict ,
144- mocked_rpc_catalog_service_api : dict [str , MagicMock ],
78+ mocked_rpc_catalog_service_api : dict [str , MockType ],
14579):
14680 assert client .app
14781 assert client .app .router
@@ -359,7 +293,7 @@ async def test_get_compatible_outputs_given_target_inptuts(
359293async def test_get_and_patch_service (
360294 client : TestClient ,
361295 logged_user : UserInfoDict ,
362- mocked_rpc_catalog_service_api : dict [str , MagicMock ],
296+ mocked_rpc_catalog_service_api : dict [str , MockType ],
363297 faker : Faker ,
364298):
365299 assert client .app
@@ -426,7 +360,7 @@ async def test_get_and_patch_service(
426360async def test_tags_in_services (
427361 client : TestClient ,
428362 logged_user : UserInfoDict ,
429- mocked_rpc_catalog_service_api : dict [str , MagicMock ],
363+ mocked_rpc_catalog_service_api : dict [str , MockType ],
430364):
431365 assert client .app
432366 assert client .app .router
0 commit comments