Skip to content

Commit 8b25a9e

Browse files
committed
feat: implement get_service_ports method in CatalogService and add corresponding tests
1 parent 1ba60c3 commit 8b25a9e

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

services/api-server/src/simcore_service_api_server/services_rpc/catalog.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from fastapi import Depends
55
from models_library.api_schemas_catalog.services import LatestServiceGet, ServiceGetV2
6+
from models_library.api_schemas_catalog.services_ports import ServicePortGet
67
from models_library.products import ProductName
78
from models_library.rest_pagination import (
89
DEFAULT_NUMBER_OF_ITEMS_PER_PAGE,
@@ -113,3 +114,33 @@ async def get(
113114
service_key=name,
114115
service_version=version,
115116
)
117+
118+
@_exception_mapper(
119+
rpc_exception_map={
120+
CatalogItemNotFoundError: ProgramOrSolverOrStudyNotFoundError,
121+
CatalogForbiddenError: ServiceForbiddenAccessError,
122+
ValidationError: InvalidInputError,
123+
}
124+
)
125+
async def get_service_ports(
126+
self,
127+
*,
128+
product_name: ProductName,
129+
user_id: UserID,
130+
service_key: ServiceKey,
131+
service_version: ServiceVersion,
132+
) -> list[ServicePortGet]:
133+
"""Gets service ports (inputs and outputs) for a specific service version
134+
135+
Raises:
136+
ProgramOrSolverOrStudyNotFoundError: service not found in catalog
137+
ServiceForbiddenAccessError: no access rights to read this service
138+
InvalidInputError: invalid input parameters
139+
"""
140+
return await catalog_rpc.get_service_ports(
141+
self._client,
142+
product_name=product_name,
143+
user_id=user_id,
144+
service_key=service_key,
145+
service_version=service_version,
146+
)

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@ def get_mock_rabbitmq_rpc_client():
9696
autospec=True,
9797
side_effect=side_effects.list_my_service_history_paginated,
9898
),
99+
"get_service_ports": mocker.patch.object(
100+
catalog_rpc,
101+
"get_service_ports",
102+
autospec=True,
103+
side_effect=side_effects.get_service_ports,
104+
),
99105
}
100106
app.dependency_overrides.pop(get_rabbitmq_rpc_client)
101107

services/api-server/tests/unit/test_services_catalog.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,23 @@ async def test_catalog_service_read_solvers(
7676
assert solver.id == selected_solver.id
7777
assert solver.version == oldest_release.version
7878

79+
# Step 4: Get service ports for the solver
80+
ports = await catalog_service.get_service_ports(
81+
product_name=product_name,
82+
user_id=user_id,
83+
service_key=selected_solver.id,
84+
service_version=oldest_release.version,
85+
)
86+
87+
# Verify ports are returned and contain both inputs and outputs
88+
assert ports, "Service ports should not be empty"
89+
assert any(port.kind == "input" for port in ports), "Should contain input ports"
90+
assert any(port.kind == "output" for port in ports), "Should contain output ports"
91+
7992
# checks calls to rpc
8093
mocked_rpc_catalog_service_api["list_services_paginated"].assert_called_once()
8194
mocked_rpc_catalog_service_api[
8295
"list_my_service_history_paginated"
8396
].assert_called_once()
8497
mocked_rpc_catalog_service_api["get_service"].assert_called_once()
98+
mocked_rpc_catalog_service_api["get_service_ports"].assert_called_once()

0 commit comments

Comments
 (0)