22# pylint: disable=unused-argument
33
44import datetime
5- from uuid import uuid4
5+ from uuid import UUID , uuid4
66
77import pytest
88from aiohttp .test_utils import TestClient
99from common_library .users_enums import UserRole
10+ from faker import Faker
1011from models_library .api_schemas_webserver .functions import (
1112 ProjectFunction ,
1213 ProjectFunctionJob ,
1314)
14- from models_library .functions import FunctionJobCollection , FunctionJobStatus
15+ from models_library .functions import (
16+ FunctionClass ,
17+ FunctionJobCollection ,
18+ FunctionJobStatus ,
19+ RegisteredProjectFunctionJob ,
20+ )
1521from models_library .functions_errors import (
1622 FunctionJobIDNotFoundError ,
1723 FunctionJobReadAccessDeniedError ,
2834pytest_simcore_core_services_selection = ["rabbit" ]
2935
3036
37+ _faker = Faker ()
38+
39+
3140@pytest .mark .parametrize (
3241 "user_role" ,
3342 [UserRole .USER ],
@@ -57,6 +66,7 @@ async def test_register_get_delete_function_job(
5766 project_job_id = uuid4 (),
5867 inputs = {"input1" : "value1" },
5968 outputs = {"output1" : "result1" },
69+ job_creation_task_id = None ,
6070 )
6171
6272 # Register the function job
@@ -183,6 +193,7 @@ async def test_list_function_jobs(
183193 project_job_id = uuid4 (),
184194 inputs = {"input1" : "value1" },
185195 outputs = {"output1" : "result1" },
196+ job_creation_task_id = None ,
186197 )
187198
188199 # Register the function job
@@ -244,6 +255,7 @@ async def test_list_function_jobs_filtering(
244255 project_job_id = uuid4 (),
245256 inputs = {"input1" : "value1" },
246257 outputs = {"output1" : "result1" },
258+ job_creation_task_id = None ,
247259 )
248260 # Register the function job
249261 first_registered_function_jobs .append (
@@ -262,6 +274,7 @@ async def test_list_function_jobs_filtering(
262274 project_job_id = uuid4 (),
263275 inputs = {"input1" : "value1" },
264276 outputs = {"output1" : "result1" },
277+ job_creation_task_id = None ,
265278 )
266279 # Register the function job
267280 second_registered_function_jobs .append (
@@ -381,6 +394,7 @@ async def test_find_cached_function_jobs(
381394 project_job_id = uuid4 (),
382395 inputs = {"input1" : value if value < 4 else 1 },
383396 outputs = {"output1" : "result1" },
397+ job_creation_task_id = None ,
384398 )
385399
386400 # Register the function job
@@ -421,6 +435,70 @@ async def test_find_cached_function_jobs(
421435 assert cached_jobs is None
422436
423437
438+ @pytest .mark .parametrize (
439+ "user_role" ,
440+ [UserRole .USER ],
441+ )
442+ async def test_patch_registered_function_jobs (
443+ client : TestClient ,
444+ rpc_client : RabbitMQRPCClient ,
445+ add_user_function_api_access_rights : None ,
446+ logged_user : UserInfoDict ,
447+ other_logged_user : UserInfoDict ,
448+ osparc_product_name : ProductName ,
449+ mock_function : ProjectFunction ,
450+ clean_functions : None ,
451+ ):
452+
453+ registered_function = await functions_rpc .register_function (
454+ rabbitmq_rpc_client = rpc_client ,
455+ function = mock_function ,
456+ user_id = logged_user ["id" ],
457+ product_name = osparc_product_name ,
458+ )
459+
460+ function_job = ProjectFunctionJob (
461+ function_uid = registered_function .uid ,
462+ title = "Test Function Job" ,
463+ description = "A test function job" ,
464+ project_job_id = None ,
465+ inputs = {"input1" : _faker .pyint (min_value = 0 , max_value = 1000 )},
466+ outputs = {"output1" : "result1" },
467+ job_creation_task_id = None ,
468+ )
469+
470+ # Register the function job
471+ registered_job = await functions_rpc .register_function_job (
472+ rabbitmq_rpc_client = rpc_client ,
473+ function_job = function_job ,
474+ user_id = logged_user ["id" ],
475+ product_name = osparc_product_name ,
476+ )
477+
478+ added_data = {"job_creation_task_id" : f"{ uuid4 ()} " }
479+ registered_job_dict = registered_job .model_dump ()
480+ registered_job_dict .update (** added_data )
481+ registered_job = RegisteredProjectFunctionJob .model_validate (registered_job_dict )
482+
483+ registered_job = await functions_rpc .patch_registered_function_job (
484+ rabbitmq_rpc_client = rpc_client ,
485+ user_id = logged_user ["id" ],
486+ product_name = osparc_product_name ,
487+ registered_function_job = registered_job ,
488+ )
489+ assert registered_job .function_class == FunctionClass .PROJECT
490+ assert registered_job .job_creation_task_id == added_data ["job_creation_task_id" ]
491+
492+ added_data .update (project_job_id = f"{ uuid4 ()} " )
493+
494+ registered_job_dict = registered_job .model_dump ()
495+ registered_job_dict .update (** added_data )
496+ registered_job = RegisteredProjectFunctionJob .model_validate (registered_job_dict )
497+ assert registered_job .function_class == FunctionClass .PROJECT
498+ assert registered_job .job_creation_task_id == added_data ["job_creation_task_id" ]
499+ assert registered_job .project_job_id == UUID (added_data ["project_job_id" ])
500+
501+
424502@pytest .mark .parametrize (
425503 "user_role" ,
426504 [UserRole .USER ],
@@ -448,6 +526,7 @@ async def test_update_function_job_status(
448526 project_job_id = uuid4 (),
449527 inputs = {"input1" : "value1" },
450528 outputs = {"output1" : "result1" },
529+ job_creation_task_id = None ,
451530 )
452531
453532 # Register the function job
@@ -507,6 +586,7 @@ async def test_update_function_job_outputs(
507586 project_job_id = uuid4 (),
508587 inputs = {"input1" : "value1" },
509588 outputs = None ,
589+ job_creation_task_id = None ,
510590 )
511591
512592 # Register the function job
0 commit comments