@@ -309,301 +309,6 @@ async def test_delete_function(
309309 assert response .status_code == status .HTTP_200_OK
310310
311311
312- async def test_register_function_job (
313- client : AsyncClient ,
314- mock_handler_in_functions_rpc_interface : Callable [[str , Any ], None ],
315- mock_project_function_job : ProjectFunctionJob ,
316- mock_registered_project_function_job : RegisteredProjectFunctionJob ,
317- auth : httpx .BasicAuth ,
318- ) -> None :
319- """Test the register_function_job endpoint."""
320-
321- mock_handler_in_functions_rpc_interface (
322- "register_function_job" , mock_registered_project_function_job
323- )
324-
325- response = await client .post (
326- f"{ API_VTAG } /function_jobs" ,
327- json = mock_project_function_job .model_dump (mode = "json" ),
328- auth = auth ,
329- )
330-
331- assert response .status_code == status .HTTP_200_OK
332- assert (
333- RegisteredProjectFunctionJob .model_validate (response .json ())
334- == mock_registered_project_function_job
335- )
336-
337-
338- async def test_get_function_job (
339- client : AsyncClient ,
340- mock_handler_in_functions_rpc_interface : Callable [[str , Any ], None ],
341- mock_registered_project_function_job : RegisteredProjectFunctionJob ,
342- auth : httpx .BasicAuth ,
343- ) -> None :
344- mock_handler_in_functions_rpc_interface (
345- "get_function_job" , mock_registered_project_function_job
346- )
347-
348- # Now, get the function job
349- response = await client .get (
350- f"{ API_VTAG } /function_jobs/{ mock_registered_project_function_job .uid } " ,
351- auth = auth ,
352- )
353- assert response .status_code == status .HTTP_200_OK
354- assert (
355- RegisteredProjectFunctionJob .model_validate (response .json ())
356- == mock_registered_project_function_job
357- )
358-
359-
360- async def test_list_function_jobs (
361- client : AsyncClient ,
362- mock_handler_in_functions_rpc_interface : Callable [[str , Any ], None ],
363- mock_registered_project_function_job : RegisteredProjectFunctionJob ,
364- auth : httpx .BasicAuth ,
365- ) -> None :
366- mock_handler_in_functions_rpc_interface (
367- "list_function_jobs" ,
368- (
369- [mock_registered_project_function_job for _ in range (5 )],
370- PageMetaInfoLimitOffset (total = 5 , count = 5 , limit = 10 , offset = 0 ),
371- ),
372- )
373-
374- # Now, list function jobs
375- response = await client .get (f"{ API_VTAG } /function_jobs" , auth = auth )
376- assert response .status_code == status .HTTP_200_OK
377- data = response .json ()["items" ]
378- assert len (data ) == 5
379- assert (
380- RegisteredProjectFunctionJob .model_validate (data [0 ])
381- == mock_registered_project_function_job
382- )
383-
384-
385- async def test_list_function_jobs_with_function_filter (
386- client : AsyncClient ,
387- mock_handler_in_functions_rpc_interface : Callable [[str , Any ], None ],
388- mock_registered_project_function_job : RegisteredProjectFunctionJob ,
389- mock_registered_project_function : RegisteredProjectFunction ,
390- auth : httpx .BasicAuth ,
391- ) -> None :
392- mock_handler_in_functions_rpc_interface (
393- "list_function_jobs" ,
394- (
395- [mock_registered_project_function_job for _ in range (5 )],
396- PageMetaInfoLimitOffset (total = 5 , count = 5 , limit = 10 , offset = 0 ),
397- ),
398- )
399-
400- # Now, list function jobs with a filter
401- response = await client .get (
402- f"{ API_VTAG } /functions/{ mock_registered_project_function .uid } /jobs" , auth = auth
403- )
404-
405- assert response .status_code == status .HTTP_200_OK
406- data = response .json ()["items" ]
407- assert len (data ) == 5
408- assert (
409- RegisteredProjectFunctionJob .model_validate (data [0 ])
410- == mock_registered_project_function_job
411- )
412-
413-
414- async def test_delete_function_job (
415- client : AsyncClient ,
416- mock_handler_in_functions_rpc_interface : Callable [[str , Any ], None ],
417- mock_registered_project_function_job : RegisteredProjectFunctionJob ,
418- auth : httpx .BasicAuth ,
419- ) -> None :
420- mock_handler_in_functions_rpc_interface ("delete_function_job" , None )
421-
422- # Now, delete the function job
423- response = await client .delete (
424- f"{ API_VTAG } /function_jobs/{ mock_registered_project_function_job .uid } " ,
425- auth = auth ,
426- )
427- assert response .status_code == status .HTTP_200_OK
428-
429-
430- async def test_register_function_job_collection (
431- client : AsyncClient ,
432- mock_handler_in_functions_rpc_interface : Callable [[str , Any ], None ],
433- auth : httpx .BasicAuth ,
434- ) -> None :
435- mock_function_job_collection = FunctionJobCollection .model_validate (
436- {
437- "title" : "Test Collection" ,
438- "description" : "A test function job collection" ,
439- "job_ids" : [str (uuid4 ()), str (uuid4 ())],
440- }
441- )
442-
443- mock_registered_function_job_collection = (
444- RegisteredFunctionJobCollection .model_validate (
445- {
446- ** mock_function_job_collection .model_dump (),
447- "uid" : str (uuid4 ()),
448- "created_at" : datetime .datetime .now (datetime .UTC ),
449- }
450- )
451- )
452-
453- mock_handler_in_functions_rpc_interface (
454- "register_function_job_collection" , mock_registered_function_job_collection
455- )
456-
457- response = await client .post (
458- f"{ API_VTAG } /function_job_collections" ,
459- json = mock_function_job_collection .model_dump (mode = "json" ),
460- auth = auth ,
461- )
462-
463- # Assert
464- assert response .status_code == status .HTTP_200_OK
465- assert (
466- RegisteredFunctionJobCollection .model_validate (response .json ())
467- == mock_registered_function_job_collection
468- )
469-
470-
471- async def test_get_function_job_collection (
472- client : AsyncClient ,
473- mock_handler_in_functions_rpc_interface : Callable [[str , Any ], None ],
474- auth : httpx .BasicAuth ,
475- ) -> None :
476- mock_registered_function_job_collection = (
477- RegisteredFunctionJobCollection .model_validate (
478- {
479- "uid" : str (uuid4 ()),
480- "title" : "Test Collection" ,
481- "description" : "A test function job collection" ,
482- "job_ids" : [str (uuid4 ()), str (uuid4 ())],
483- "created_at" : datetime .datetime .now (datetime .UTC ),
484- }
485- )
486- )
487-
488- mock_handler_in_functions_rpc_interface (
489- "get_function_job_collection" , mock_registered_function_job_collection
490- )
491-
492- response = await client .get (
493- f"{ API_VTAG } /function_job_collections/{ mock_registered_function_job_collection .uid } " ,
494- auth = auth ,
495- )
496- assert response .status_code == status .HTTP_200_OK
497- assert (
498- RegisteredFunctionJobCollection .model_validate (response .json ())
499- == mock_registered_function_job_collection
500- )
501-
502-
503- async def test_list_function_job_collections (
504- client : AsyncClient ,
505- mock_handler_in_functions_rpc_interface : Callable [[str , Any ], None ],
506- auth : httpx .BasicAuth ,
507- ) -> None :
508- mock_registered_function_job_collection = (
509- RegisteredFunctionJobCollection .model_validate (
510- {
511- "uid" : str (uuid4 ()),
512- "title" : "Test Collection" ,
513- "description" : "A test function job collection" ,
514- "job_ids" : [str (uuid4 ()), str (uuid4 ())],
515- "created_at" : datetime .datetime .now (datetime .UTC ),
516- }
517- )
518- )
519-
520- mock_handler_in_functions_rpc_interface (
521- "list_function_job_collections" ,
522- (
523- [mock_registered_function_job_collection for _ in range (5 )],
524- PageMetaInfoLimitOffset (total = 5 , count = 5 , limit = 10 , offset = 0 ),
525- ),
526- )
527-
528- response = await client .get (f"{ API_VTAG } /function_job_collections" , auth = auth )
529- assert response .status_code == status .HTTP_200_OK
530- data = response .json ()["items" ]
531- assert len (data ) == 5
532- assert (
533- RegisteredFunctionJobCollection .model_validate (data [0 ])
534- == mock_registered_function_job_collection
535- )
536-
537-
538- async def test_delete_function_job_collection (
539- client : AsyncClient ,
540- mock_handler_in_functions_rpc_interface : Callable [[str , Any ], None ],
541- mock_registered_function_job_collection : RegisteredFunctionJobCollection ,
542- auth : httpx .BasicAuth ,
543- ) -> None :
544- mock_handler_in_functions_rpc_interface ("delete_function_job_collection" , None )
545-
546- # Now, delete the function job collection
547- response = await client .delete (
548- f"{ API_VTAG } /function_job_collections/{ mock_registered_function_job_collection .uid } " ,
549- auth = auth ,
550- )
551- assert response .status_code == status .HTTP_200_OK
552- data = response .json ()
553- assert data is None
554-
555-
556- async def test_get_function_job_collection_jobs (
557- client : AsyncClient ,
558- mock_handler_in_functions_rpc_interface : Callable [[str , Any ], None ],
559- mock_registered_function_job_collection : RegisteredFunctionJobCollection ,
560- auth : httpx .BasicAuth ,
561- ) -> None :
562- mock_handler_in_functions_rpc_interface (
563- "get_function_job_collection" , mock_registered_function_job_collection
564- )
565-
566- response = await client .get (
567- f"{ API_VTAG } /function_job_collections/{ mock_registered_function_job_collection .uid } /function_jobs" ,
568- auth = auth ,
569- )
570- assert response .status_code == status .HTTP_200_OK
571- data = response .json ()
572- assert len (data ) == len (mock_registered_function_job_collection .job_ids )
573-
574-
575- async def test_list_function_job_collections_with_function_filter (
576- client : AsyncClient ,
577- mock_handler_in_functions_rpc_interface : Callable [[str , Any ], None ],
578- mock_registered_function_job_collection : RegisteredFunctionJobCollection ,
579- mock_registered_project_function : RegisteredProjectFunction ,
580- auth : httpx .BasicAuth ,
581- ) -> None :
582- mock_handler_in_functions_rpc_interface (
583- "list_function_job_collections" ,
584- (
585- [mock_registered_function_job_collection for _ in range (2 )],
586- PageMetaInfoLimitOffset (total = 5 , count = 2 , limit = 2 , offset = 1 ),
587- ),
588- )
589-
590- response = await client .get (
591- f"{ API_VTAG } /function_job_collections?function_id={ mock_registered_project_function .uid } &limit=2&offset=1" ,
592- auth = auth ,
593- )
594- assert response .status_code == status .HTTP_200_OK
595- data = response .json ()
596-
597- assert data ["total" ] == 5
598- assert data ["limit" ] == 2
599- assert data ["offset" ] == 1
600- assert len (data ["items" ]) == 2
601- assert (
602- RegisteredFunctionJobCollection .model_validate (data ["items" ][0 ])
603- == mock_registered_function_job_collection
604- )
605-
606-
607312@pytest .mark .parametrize ("user_has_execute_right" , [False , True ])
608313@pytest .mark .parametrize (
609314 "funcapi_endpoint,endpoint_inputs" , [("run" , {}), ("map" , [{}, {}])]
0 commit comments