|
7 | 7 |
|
8 | 8 | import httpx |
9 | 9 | import pytest |
| 10 | +from models_library.users import UserID |
10 | 11 | from pydantic import TypeAdapter |
11 | 12 | from pytest_mock import MockType |
12 | 13 | from pytest_simcore.helpers.httpx_calls_capture_models import HttpApiCallCaptureModel |
@@ -124,3 +125,62 @@ async def test_list_all_solvers_jobs( |
124 | 125 | assert job.outputs_url is not None |
125 | 126 |
|
126 | 127 | assert mocked_backend.webserver_rpc["list_projects_marked_as_jobs"].called |
| 128 | + |
| 129 | + |
| 130 | +async def test_list_all_solvers_jobs_with_metadata_filter( |
| 131 | + auth: httpx.BasicAuth, |
| 132 | + client: httpx.AsyncClient, |
| 133 | + mocked_backend: MockBackendRouters, |
| 134 | + user_id: UserID, |
| 135 | +): |
| 136 | + """Tests the endpoint that lists all jobs across all solvers with metadata filtering.""" |
| 137 | + |
| 138 | + # Test with metadata filters |
| 139 | + metadata_filters = ["key1:val*", "key2:exactval"] |
| 140 | + |
| 141 | + # Construct query parameters with metadata.any filters |
| 142 | + params = { |
| 143 | + "limit": 10, |
| 144 | + "offset": 0, |
| 145 | + "metadata.any": metadata_filters, |
| 146 | + } |
| 147 | + |
| 148 | + # Call the endpoint with metadata filters |
| 149 | + resp = await client.get( |
| 150 | + f"/{API_VTAG}/solvers/-/releases/-/jobs", |
| 151 | + auth=auth, |
| 152 | + params=params, |
| 153 | + ) |
| 154 | + |
| 155 | + # Verify the response |
| 156 | + assert resp.status_code == status.HTTP_200_OK |
| 157 | + |
| 158 | + # Parse and validate the response |
| 159 | + jobs_page = TypeAdapter(Page[Job]).validate_python(resp.json()) |
| 160 | + |
| 161 | + # Basic assertions on the response structure |
| 162 | + assert isinstance(jobs_page.items, list) |
| 163 | + assert jobs_page.limit == 10 |
| 164 | + assert jobs_page.offset == 0 |
| 165 | + |
| 166 | + # Check that the backend was called with the correct filter parameters |
| 167 | + assert mocked_backend.webserver_rpc["list_projects_marked_as_jobs"].called |
| 168 | + |
| 169 | + # Get the call args to verify filter parameters were passed correctly |
| 170 | + call_args = mocked_backend.webserver_rpc["list_projects_marked_as_jobs"].call_args |
| 171 | + |
| 172 | + # The filter_any_custom_metadata parameter should contain our filters |
| 173 | + # The exact structure will depend on how your mocked function is called |
| 174 | + assert call_args is not None |
| 175 | + |
| 176 | + assert call_args.kwargs["product_name"] == "osparc" |
| 177 | + assert call_args.kwargs["user_id"] == user_id |
| 178 | + assert call_args.kwargs["offset"] == 0 |
| 179 | + assert call_args.kwargs["limit"] == 10 |
| 180 | + assert call_args.kwargs["filters"] |
| 181 | + |
| 182 | + # Verify the metadata filters were correctly transformed and passed |
| 183 | + assert call_args.kwargs["filters"].any_custom_metadata[0].name == "key1" |
| 184 | + assert call_args.kwargs["filters"].any_custom_metadata[0].pattern == "val*" |
| 185 | + assert call_args.kwargs["filters"].any_custom_metadata[1].name == "key2" |
| 186 | + assert call_args.kwargs["filters"].any_custom_metadata[1].pattern == "exactval" |
0 commit comments