@@ -51,14 +51,15 @@ def mock_function() -> dict[str, Any]:
5151
5252
5353@pytest .mark .parametrize (
54- "user_role,add_user_function_api_access_rights,expected_register,expected_get,expected_list,expected_delete,expected_get2" ,
54+ "user_role,add_user_function_api_access_rights,expected_register,expected_get,expected_list,expected_update, expected_delete,expected_get2" ,
5555 [
5656 (
5757 UserRole .USER ,
5858 True ,
5959 status .HTTP_201_CREATED ,
6060 status .HTTP_200_OK ,
6161 status .HTTP_200_OK ,
62+ status .HTTP_200_OK ,
6263 status .HTTP_204_NO_CONTENT ,
6364 status .HTTP_404_NOT_FOUND ,
6465 ),
@@ -70,6 +71,7 @@ def mock_function() -> dict[str, Any]:
7071 status .HTTP_403_FORBIDDEN ,
7172 status .HTTP_403_FORBIDDEN ,
7273 status .HTTP_403_FORBIDDEN ,
74+ status .HTTP_403_FORBIDDEN ,
7375 ),
7476 ],
7577 indirect = ["add_user_function_api_access_rights" ],
@@ -81,11 +83,13 @@ async def test_function_workflow(
8183 expected_register : HTTPStatus ,
8284 expected_get : HTTPStatus ,
8385 expected_list : HTTPStatus ,
86+ expected_update : HTTPStatus ,
8487 expected_delete : HTTPStatus ,
8588 expected_get2 : HTTPStatus ,
8689 add_user_function_api_access_rights : AsyncIterator [None ],
8790 request : pytest .FixtureRequest ,
8891) -> None :
92+ # Register a new function
8993 url = client .app .router ["register_function" ].url_for ()
9094 response = await client .post (url , json = mock_function )
9195 data , error = await assert_status (response , expected_status_code = expected_register )
@@ -96,15 +100,17 @@ async def test_function_workflow(
96100 assert returned_function .uid is not None
97101 returned_function_uid = returned_function .uid
98102
103+ # Get the registered function
99104 url = client .app .router ["get_function" ].url_for (
100- function_id = str ( returned_function_uid )
105+ function_id = f" { returned_function_uid } "
101106 )
102107 response = await client .get (url )
103108 data , error = await assert_status (response , expected_get )
104109 if not error :
105110 retrieved_function = RegisteredProjectFunctionGet .model_validate (data )
106111 assert retrieved_function .uid == returned_function .uid
107112
113+ # List existing functions
108114 url = client .app .router ["list_functions" ].url_for ()
109115 response = await client .get (url )
110116 data , error = await assert_status (response , expected_list )
@@ -115,14 +121,31 @@ async def test_function_workflow(
115121 assert len (retrieved_functions ) == 1
116122 assert retrieved_functions [0 ].uid == returned_function_uid
117123
124+ # Update existing function
125+ new_title = "Test Function (edited)"
126+ new_description = "A test function (edited)"
127+ url = client .app .router ["update_function" ].url_for (
128+ function_id = f"{ returned_function_uid } "
129+ )
130+ response = await client .patch (
131+ url , json = {"title" : new_title , "description" : new_description }
132+ )
133+ data , error = await assert_status (response , expected_update )
134+ if not error :
135+ updated_function = RegisteredProjectFunctionGet .model_validate (data )
136+ assert updated_function .title == new_title
137+ assert updated_function .description == new_description
138+
139+ # Delete existing function
118140 url = client .app .router ["delete_function" ].url_for (
119- function_id = str ( returned_function_uid )
141+ function_id = f" { returned_function_uid } "
120142 )
121143 response = await client .delete (url )
122144 data , error = await assert_status (response , expected_delete )
123145
146+ # Check if the function was effectively deleted
124147 url = client .app .router ["get_function" ].url_for (
125- function_id = str ( returned_function_uid )
148+ function_id = f" { returned_function_uid } "
126149 )
127150 response = await client .get (url )
128151 data , error = await assert_status (response , expected_get2 )
0 commit comments