3030from models_library .groups import EVERYONE_GROUP_ID
3131from models_library .products import ProductName
3232from models_library .rest_ordering import OrderBy , OrderDirection
33+ from models_library .rest_pagination import PageMetaInfoLimitOffset
3334from pytest_simcore .helpers .webserver_users import UserInfoDict
3435from servicelib .rabbitmq .rpc_interfaces .webserver .v1 import WebServerRpcClient
3536
@@ -294,6 +295,7 @@ async def test_list_functions_mixed_user(
294295 user_id = logged_user ["id" ],
295296 product_name = osparc_product_name ,
296297 read = True ,
298+ write = True ,
297299 )
298300 other_functions , _ = await webserver_rpc_client .functions .list_functions (
299301 pagination_limit = 10 ,
@@ -314,38 +316,48 @@ async def test_list_functions_mixed_user(
314316 ],
315317)
316318@pytest .mark .parametrize (
317- "test_pagination_limit, test_pagination_offset" ,
319+ "test_pagination_limit, test_pagination_offset, total_number_functions " ,
318320 [
319- (5 , 0 ),
320- (2 , 2 ),
321- (12 , 4 ),
321+ (5 , 0 , 10 ),
322+ (2 , 2 , 10 ),
323+ (12 , 4 , 10 ),
322324 ],
323325)
324326async def test_list_functions_with_pagination_ordering (
325327 client : TestClient ,
326328 add_user_function_api_access_rights : None ,
327329 webserver_rpc_client : WebServerRpcClient ,
328330 create_fake_function_obj : Callable [[FunctionClass ], ProjectFunction ],
329- clean_functions : None ,
330331 osparc_product_name : ProductName ,
331332 logged_user : UserInfoDict ,
332333 order_by : OrderBy | None ,
333334 test_pagination_limit : int ,
334335 test_pagination_offset : int ,
336+ total_number_functions : int ,
337+ clean_functions : None ,
335338):
339+ # Making sure functions are empty before we start
340+ assert await webserver_rpc_client .functions .list_functions (
341+ pagination_limit = 1 ,
342+ pagination_offset = 0 ,
343+ user_id = logged_user ["id" ],
344+ product_name = osparc_product_name ,
345+ ) == (
346+ [],
347+ PageMetaInfoLimitOffset (limit = 1 , total = 0 , offset = 0 , count = 0 ),
348+ )
336349 # Register multiple functions
337- TOTAL_FUNCTIONS = 10
338350 registered_functions = [
339351 await webserver_rpc_client .functions .register_function (
340352 function = create_fake_function_obj (FunctionClass .PROJECT ),
341353 user_id = logged_user ["id" ],
342354 product_name = osparc_product_name ,
343355 )
344- for _ in range (TOTAL_FUNCTIONS )
356+ for _ in range (total_number_functions )
345357 ]
346358
347359 # List functions with pagination
348- functions , page_info = await webserver_rpc_client .functions .list_functions (
360+ listed_functions , page_info = await webserver_rpc_client .functions .list_functions (
349361 pagination_limit = test_pagination_limit ,
350362 pagination_offset = test_pagination_offset ,
351363 user_id = logged_user ["id" ],
@@ -354,23 +366,26 @@ async def test_list_functions_with_pagination_ordering(
354366 )
355367
356368 # Assert the list contains the correct number of functions
357- assert len (functions ) == min (
358- test_pagination_limit , max (0 , TOTAL_FUNCTIONS - test_pagination_offset )
369+ assert len (listed_functions ) == min (
370+ test_pagination_limit , max (0 , total_number_functions - test_pagination_offset )
359371 )
360- assert all (f .uid in [rf .uid for rf in registered_functions ] for f in functions )
361- assert page_info .count == len (functions )
362- assert page_info .total == TOTAL_FUNCTIONS
372+
373+ assert all (
374+ f .uid in [rf .uid for rf in registered_functions ] for f in listed_functions
375+ )
376+ assert page_info .count == len (listed_functions )
377+ assert page_info .total == total_number_functions
363378
364379 # Verify the functions are sorted correctly based on the order_by parameter
365380 if order_by :
366381 field = order_by .field
367382 direction = order_by .direction
368383 sorted_functions = sorted (
369- functions ,
384+ listed_functions ,
370385 key = lambda f : getattr (f , field ),
371386 reverse = (direction == OrderDirection .DESC ),
372387 )
373- assert functions == sorted_functions
388+ assert listed_functions == sorted_functions
374389
375390
376391@pytest .mark .parametrize (
0 commit comments