@@ -74,72 +74,6 @@ async def test_list_tasks_api_happy_path(py_api: httpx.AsyncClient) -> None:
7474 assert "OpenML100" in task ["tag" ]
7575
7676
77- @pytest .mark .parametrize (
78- ("limit" , "offset" , "expected_status" , "expected_max_results" ),
79- [
80- (- 10 , 0 , HTTPStatus .NOT_FOUND , 0 ), # negative limit clamped to 0 -> No results
81- (5 , - 10 , HTTPStatus .OK , 5 ), # negative offset clamped to 0 -> First 5 results
82- ],
83- ids = ["negative_limit" , "negative_offset" ],
84- )
85- async def test_list_tasks_negative_pagination_safely_clamped (
86- limit : int ,
87- offset : int ,
88- expected_status : int ,
89- expected_max_results : int ,
90- py_api : httpx .AsyncClient ,
91- ) -> None :
92- """Negative pagination values are safely clamped to 0 instead of causing 500 errors.
93-
94- A limit clamped to 0 raises NoResultsError, which the API maps to HTTP 404.
95- An offset clamped to 0 simply returns the first page of results (200 OK).
96-
97- Note: This remains an HTTP-level (py_api) test to ensure end-to-end safety is
98- preserved.
99- """
100- response = await py_api .post (
101- "/tasks/list" ,
102- json = {"pagination" : {"limit" : limit , "offset" : offset }},
103- )
104- assert response .status_code == expected_status
105- if expected_status == HTTPStatus .OK :
106- body = response .json ()
107- assert len (body ) <= expected_max_results
108- # Compare to a baseline with offset=0 to prove it was correctly clamped
109- baseline = await py_api .post (
110- "/tasks/list" ,
111- json = {"pagination" : {"limit" : limit , "offset" : 0 }},
112- )
113- assert baseline .status_code == HTTPStatus .OK
114- assert [t ["task_id" ] for t in body ] == [t ["task_id" ] for t in baseline .json ()]
115- else :
116- error = response .json ()
117- assert error ["type" ] == NoResultsError .uri
118-
119-
120- @pytest .mark .parametrize (
121- ("pagination_override" , "expected_field" ),
122- [
123- ({"limit" : "abc" , "offset" : 0 }, "limit" ), # Invalid type
124- ({"limit" : 5 , "offset" : "xyz" }, "offset" ), # Invalid type
125- ],
126- ids = ["bad_limit_type" , "bad_offset_type" ],
127- )
128- async def test_list_tasks_invalid_pagination_type (
129- pagination_override : dict [str , Any ], expected_field : str , py_api : httpx .AsyncClient
130- ) -> None :
131- """Invalid pagination types return 422 Unprocessable Entity."""
132- response = await py_api .post (
133- "/tasks/list" ,
134- json = {"pagination" : pagination_override },
135- )
136- assert response .status_code == HTTPStatus .UNPROCESSABLE_ENTITY
137- # Verify that the error points to the correct field
138- error = response .json ()["errors" ][0 ]
139- assert error ["loc" ][- 2 :] == ["pagination" , expected_field ]
140- assert error ["type" ] in {"type_error.integer" , "int_parsing" , "int_type" }
141-
142-
14377@pytest .mark .parametrize (
14478 "value" ,
14579 ["1...2" , "abc" ],
0 commit comments