Skip to content

Commit 7732c67

Browse files
committed
api-server tests fixture
1 parent 33347b9 commit 7732c67

File tree

7 files changed

+40
-34
lines changed

7 files changed

+40
-34
lines changed

packages/pytest-simcore/src/pytest_simcore/helpers/webserver_rpc_server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
class WebserverRpcSideEffects:
1616
# pylint: disable=no-self-use
1717

18-
@validate_call(config=dict(arbitrary_types_allowed=True))
18+
@validate_call(config={"arbitrary_types_allowed": True})
1919
async def mark_project_as_job(
2020
self,
2121
rpc_client: RabbitMQRPCClient,

services/api-server/tests/unit/api_solvers/conftest.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def solver_version() -> str:
3232

3333

3434
@pytest.fixture
35-
def mocked_webserver_service_api(
35+
def mocked_webserver_rest_api(
3636
app: FastAPI,
3737
mocked_webserver_service_api_base: MockRouter,
3838
patch_webserver_long_running_project_tasks: Callable[[MockRouter], MockRouter],
@@ -46,11 +46,17 @@ def mocked_webserver_service_api(
4646

4747

4848
@pytest.fixture
49-
def mocked_rpc_webserver_service_api(
49+
def mocked_webserver_rpc_api(
5050
app: FastAPI, mocker: MockerFixture
5151
) -> dict[str, MockType]:
52-
# from simcore_service_api_server.services_rpc.wb_api_server import projects_rpc
5352
from servicelib.rabbitmq.rpc_interfaces.webserver import projects as projects_rpc
53+
from simcore_service_api_server.services_rpc import wb_api_server
54+
55+
# NOTE: mock_missing_plugins patches `setup_rabbitmq`
56+
try:
57+
wb_api_server.WbApiRpcClient.get_from_app_state(app)
58+
except AttributeError:
59+
wb_api_server.setup(app, mocker.MagicMock())
5460

5561
settings: ApplicationSettings = app.state.settings
5662
assert settings.API_SERVER_WEBSERVER
@@ -67,7 +73,7 @@ def mocked_rpc_webserver_service_api(
6773

6874

6975
@pytest.fixture
70-
def mocked_catalog_service_api(
76+
def mocked_catalog_rest_api(
7177
app: FastAPI,
7278
mocked_catalog_service_api_base: MockRouter,
7379
catalog_service_openapi_specs: dict[str, Any],
@@ -113,7 +119,7 @@ def mocked_catalog_service_api(
113119

114120

115121
@pytest.fixture
116-
async def mocked_directorv2_service(
122+
async def mocked_directorv2_rest_api(
117123
mocked_directorv2_service_api_base,
118124
) -> AsyncIterable[MockRouter]:
119125
stop_time: Final[datetime] = datetime.now() + timedelta(seconds=5)

services/api-server/tests/unit/api_solvers/test_api_routers_solvers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
@pytest.mark.skip(reason="Still under development. Currently using fake implementation")
1919
async def test_list_solvers(
2020
client: httpx.AsyncClient,
21-
mocked_catalog_service_api: MockRouter,
21+
mocked_catalog_rest_api: MockRouter,
2222
mocker: MockFixture,
2323
):
2424
warn = mocker.patch.object(
@@ -63,7 +63,7 @@ async def test_list_solvers(
6363

6464

6565
async def test_list_solver_ports(
66-
mocked_catalog_service_api: MockRouter,
66+
mocked_catalog_rest_api: MockRouter,
6767
client: httpx.AsyncClient,
6868
auth: httpx.BasicAuth,
6969
):

services/api-server/tests/unit/api_solvers/test_api_routers_solvers_jobs.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,10 @@ async def test_run_solver_job(
204204
client: httpx.AsyncClient,
205205
directorv2_service_openapi_specs: dict[str, Any],
206206
catalog_service_openapi_specs: dict[str, Any],
207-
mocked_catalog_service_api: MockRouter,
207+
mocked_catalog_rest_api: MockRouter,
208208
mocked_directorv2_service_api: MockRouter,
209-
mocked_webserver_service_api: MockRouter,
210-
mocked_rpc_webserver_service_api: dict[str, MockType],
209+
mocked_webserver_rest_api: MockRouter,
210+
mocked_webserver_rpc_api: dict[str, MockType],
211211
auth: httpx.BasicAuth,
212212
project_id: str,
213213
solver_key: str,
@@ -280,7 +280,7 @@ async def test_run_solver_job(
280280
),
281281
)
282282

283-
mocked_webserver_service_api.post(
283+
mocked_webserver_rest_api.post(
284284
path__regex=r"^/v0/computations/[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-(3|4|5)[0-9a-fA-F]{3}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}:start$",
285285
name="webserver_start_job",
286286
).respond(
@@ -319,7 +319,7 @@ async def test_run_solver_job(
319319
if "boot-options" in e
320320
)
321321

322-
mocked_catalog_service_api.get(
322+
mocked_catalog_rest_api.get(
323323
# path__regex=r"/services/(?P<service_key>[\w-]+)/(?P<service_version>[0-9\.]+)",
324324
path=f"/v0/services/{solver_key}/{solver_version}",
325325
name="get_service_v0_services__service_key___service_version__get",
@@ -355,9 +355,9 @@ async def test_run_solver_job(
355355
)
356356
assert resp.status_code == status.HTTP_201_CREATED
357357

358-
assert mocked_webserver_service_api["create_projects"].called
359-
assert mocked_webserver_service_api["get_task_status"].called
360-
assert mocked_webserver_service_api["get_task_result"].called
358+
assert mocked_webserver_rest_api["create_projects"].called
359+
assert mocked_webserver_rest_api["get_task_status"].called
360+
assert mocked_webserver_rest_api["get_task_result"].called
361361

362362
job = Job.model_validate(resp.json())
363363

services/api-server/tests/unit/api_solvers/test_api_routers_solvers_jobs_delete.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ class MockedBackendApiDict(TypedDict):
3333

3434
@pytest.fixture
3535
def mocked_backend_services_apis_for_delete_non_existing_project(
36-
mocked_webserver_service_api: MockRouter,
37-
mocked_rpc_webserver_service_api: dict[str, MockType],
36+
mocked_webserver_rest_api: MockRouter,
37+
mocked_webserver_rpc_api: dict[str, MockType],
3838
project_tests_dir: Path,
3939
) -> MockedBackendApiDict:
4040
mock_name = "delete_project_not_found.json"
@@ -51,12 +51,12 @@ def _response(request: httpx.Request, project_id: str):
5151
status_code=capture.status_code, json=capture.response_body
5252
)
5353

54-
mocked_webserver_service_api.delete(
54+
mocked_webserver_rest_api.delete(
5555
path__regex=rf"/projects/(?P<project_id>{UUID_RE_BASE})$",
5656
name="delete_project",
5757
).mock(side_effect=_response)
5858

59-
return MockedBackendApiDict(webserver=mocked_webserver_service_api, catalog=None)
59+
return MockedBackendApiDict(webserver=mocked_webserver_rest_api, catalog=None)
6060

6161

6262
@pytest.mark.acceptance_test(
@@ -86,9 +86,9 @@ async def test_delete_non_existing_solver_job(
8686

8787
@pytest.fixture
8888
def mocked_backend_services_apis_for_create_and_delete_solver_job(
89-
mocked_webserver_service_api: MockRouter,
90-
mocked_rpc_webserver_service_api: dict[str, MockType],
91-
mocked_catalog_service_api: MockRouter,
89+
mocked_webserver_rest_api: MockRouter,
90+
mocked_webserver_rpc_api: dict[str, MockType],
91+
mocked_catalog_rest_api: MockRouter,
9292
project_tests_dir: Path,
9393
) -> MockedBackendApiDict:
9494
mock_name = "on_create_job.json"
@@ -101,22 +101,22 @@ def mocked_backend_services_apis_for_create_and_delete_solver_job(
101101
capture = captures[0]
102102
assert capture.host == "catalog"
103103
assert capture.method == "GET"
104-
mocked_catalog_service_api.request(
104+
mocked_catalog_rest_api.request(
105105
method=capture.method, path=capture.path, name="get_service" # GET service
106106
).respond(status_code=capture.status_code, json=capture.response_body)
107107

108108
capture = captures[-1]
109109
assert capture.host == "webserver"
110110
assert capture.method == "DELETE"
111111

112-
mocked_webserver_service_api.delete(
112+
mocked_webserver_rest_api.delete(
113113
path__regex=rf"/projects/(?P<project_id>{UUID_RE_BASE})$",
114114
name="delete_project",
115115
).respond(status_code=capture.status_code, json=capture.response_body)
116116

117117
return MockedBackendApiDict(
118-
catalog=mocked_catalog_service_api,
119-
webserver=mocked_webserver_service_api,
118+
catalog=mocked_catalog_rest_api,
119+
webserver=mocked_webserver_rest_api,
120120
)
121121

122122

services/api-server/tests/unit/api_solvers/test_api_routers_solvers_jobs_logs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ async def test_log_streaming(
9898
solver_version: str,
9999
fake_log_distributor,
100100
fake_project_for_streaming: ProjectGet,
101-
mocked_directorv2_service: MockRouter,
101+
mocked_directorv2_rest_api: MockRouter,
102102
disconnect: bool,
103103
):
104104

services/api-server/tests/unit/api_solvers/test_api_routers_solvers_jobs_metadata.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ def _as_path_regex(initial_path: str):
3838

3939
@pytest.fixture
4040
def mocked_backend(
41-
mocked_webserver_service_api: MockRouter,
42-
mocked_rpc_webserver_service_api: dict[str, MockType],
43-
mocked_catalog_service_api: MockRouter,
41+
mocked_webserver_rest_api: MockRouter,
42+
mocked_webserver_rpc_api: dict[str, MockType],
43+
mocked_catalog_rest_api: MockRouter,
4444
project_tests_dir: Path,
4545
) -> MockedBackendApiDict:
4646
mock_name = "for_test_get_and_update_job_metadata.json"
@@ -54,7 +54,7 @@ def mocked_backend(
5454

5555
capture = captures["get_service"]
5656
assert capture.host == "catalog"
57-
mocked_catalog_service_api.request(
57+
mocked_catalog_rest_api.request(
5858
method=capture.method,
5959
path=capture.path,
6060
name=capture.name,
@@ -68,7 +68,7 @@ def mocked_backend(
6868
assert capture.host == "webserver"
6969
capture_path_regex = _as_path_regex(capture.path.removeprefix("/v0"))
7070

71-
route = mocked_webserver_service_api.request(
71+
route = mocked_webserver_rest_api.request(
7272
method=capture.method,
7373
path__regex=capture_path_regex,
7474
name=capture.name,
@@ -88,7 +88,7 @@ def mocked_backend(
8888
)
8989

9090
return MockedBackendApiDict(
91-
webserver=mocked_webserver_service_api, catalog=mocked_catalog_service_api
91+
webserver=mocked_webserver_rest_api, catalog=mocked_catalog_rest_api
9292
)
9393

9494

0 commit comments

Comments
 (0)