Skip to content

Commit 34db9ca

Browse files
committed
Make job listing test more complex
1 parent b455ca7 commit 34db9ca

File tree

2 files changed

+53
-36
lines changed

2 files changed

+53
-36
lines changed

services/api-server/src/simcore_service_api_server/api/routes/studies_jobs.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,8 @@ async def create_study_job(
130130
user_id: Annotated[PositiveInt, Depends(get_current_user_id)],
131131
product_name: Annotated[str, Depends(get_product_name)],
132132
hidden: Annotated[bool, Query()] = True, # noqa: FBT002
133-
x_simcore_parent_project_uuid: ProjectID | None = Header( # noqa: B008
134-
default=None
135-
),
136-
x_simcore_parent_node_id: NodeID | None = Header(default=None), # noqa: B008
133+
x_simcore_parent_project_uuid: Annotated[ProjectID | None, Header()] = None,
134+
x_simcore_parent_node_id: Annotated[NodeID | None, Header()] = None,
137135
) -> Job:
138136
"""
139137
hidden -- if True (default) hides project from UI

services/api-server/tests/unit/api_functions/test_api_routers_function_jobs.py

Lines changed: 51 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -115,47 +115,66 @@ async def test_list_function_jobs(
115115

116116
async def test_list_function_jobs_with_job_id_filter(
117117
client: AsyncClient,
118-
mock_handler_in_functions_rpc_interface: Callable[[str, Any], MockType],
118+
mock_handler_in_functions_rpc_interface: Callable[[str], MockType],
119119
mock_registered_project_function_job: RegisteredProjectFunctionJob,
120120
user_id: UserID,
121121
product_name: ProductName,
122122
auth: httpx.BasicAuth,
123123
) -> None:
124124

125-
mocked_list_function_jobs = mock_handler_in_functions_rpc_interface(
125+
PAGE_SIZE = 3
126+
TOTAL_SIZE = 10
127+
128+
def mocked_list_function_jobs(offset: int, limit: int):
129+
start = offset
130+
end = offset + limit
131+
items = [
132+
mock_registered_project_function_job
133+
for _ in range(start, min(end, TOTAL_SIZE))
134+
]
135+
return items, PageMetaInfoLimitOffset(
136+
total=TOTAL_SIZE, count=len(items), limit=limit, offset=offset
137+
)
138+
139+
mock_list_function_jobs = mock_handler_in_functions_rpc_interface(
126140
"list_function_jobs",
127-
(
128-
[mock_registered_project_function_job for _ in range(3)],
129-
PageMetaInfoLimitOffset(total=5, count=3, limit=3, offset=1),
130-
),
131-
)
132-
response = await client.get(
133-
f"{API_VTAG}/function_jobs",
134-
params={
135-
"function_job_ids": [str(mock_registered_project_function_job.uid)],
136-
"limit": 3,
137-
"offset": 1,
138-
},
139-
auth=auth,
140-
)
141-
mocked_list_function_jobs.assert_called_once_with(
142-
ANY, # Dummy rpc client
143-
filter_by_function_job_ids=[mock_registered_project_function_job.uid],
144-
filter_by_function_job_collection_id=None,
145-
filter_by_function_id=None,
146-
pagination_offset=1,
147-
pagination_limit=3,
148-
product_name=product_name,
149-
user_id=user_id,
150-
)
151-
assert response.status_code == status.HTTP_200_OK
152-
data = response.json()["items"]
153-
assert len(data) == 3
154-
assert (
155-
RegisteredProjectFunctionJob.model_validate(data[0])
156-
== mock_registered_project_function_job
157141
)
158142

143+
mock_list_function_jobs.side_effect = lambda *args, **kwargs: ( # noqa: ARG005
144+
mocked_list_function_jobs(
145+
kwargs.get("pagination_offset", 0),
146+
kwargs.get("pagination_limit", PAGE_SIZE),
147+
)
148+
)
149+
for page in range((TOTAL_SIZE + PAGE_SIZE - 1) // PAGE_SIZE):
150+
offset = page * PAGE_SIZE
151+
response = await client.get(
152+
f"{API_VTAG}/function_jobs",
153+
params={
154+
"function_job_ids": [str(mock_registered_project_function_job.uid)],
155+
"limit": PAGE_SIZE,
156+
"offset": offset,
157+
},
158+
auth=auth,
159+
)
160+
mock_list_function_jobs.assert_called_with(
161+
ANY, # Dummy rpc client
162+
filter_by_function_job_ids=[mock_registered_project_function_job.uid],
163+
filter_by_function_job_collection_id=None,
164+
filter_by_function_id=None,
165+
pagination_offset=offset,
166+
pagination_limit=PAGE_SIZE,
167+
product_name=product_name,
168+
user_id=user_id,
169+
)
170+
assert response.status_code == status.HTTP_200_OK
171+
data = response.json()["items"]
172+
assert len(data) == min(PAGE_SIZE, TOTAL_SIZE - offset)
173+
assert (
174+
RegisteredProjectFunctionJob.model_validate(data[0])
175+
== mock_registered_project_function_job
176+
)
177+
159178

160179
@pytest.mark.parametrize("job_status", ["SUCCESS", "FAILED", "STARTED"])
161180
async def test_get_function_job_status(

0 commit comments

Comments
 (0)