@@ -115,47 +115,66 @@ async def test_list_function_jobs(
115115
116116async 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" ])
161180async def test_get_function_job_status (
0 commit comments