@@ -54,6 +54,7 @@ async def _new_project(
5454 product_name : str ,
5555 tests_data_dir : Path ,
5656 project_data : dict [str , Any ],
57+ as_template : bool = False ,
5758):
5859 """returns a project for the given user"""
5960 assert client .app
@@ -63,6 +64,7 @@ async def _new_project(
6364 user_id ,
6465 product_name = product_name ,
6566 default_project_json = tests_data_dir / "fake-template-projects.isan.2dplot.json" ,
67+ as_template = as_template ,
6668 )
6769
6870
@@ -505,3 +507,85 @@ async def test_list_projects_for_specific_folder_id(
505507 _assert_response_data (
506508 data , 1 , 0 , 1 , f"/v0/projects?folder_id={ setup_folders_db } &offset=0&limit=20" , 1
507509 )
510+
511+
512+ @pytest .mark .parametrize (* standard_user_role ())
513+ async def test_list_and_patch_projects_with_template_type (
514+ client : TestClient ,
515+ logged_user : UserDict ,
516+ expected : ExpectedResponse ,
517+ fake_project : ProjectDict ,
518+ tests_data_dir : Path ,
519+ osparc_product_name : str ,
520+ project_db_cleaner ,
521+ mock_catalog_api_get_services_for_user_in_product ,
522+ ):
523+ projects_type = [
524+ "STANDARD" ,
525+ "STANDARD" ,
526+ "STANDARD" ,
527+ "TEMPLATE" ,
528+ "TEMPLATE" ,
529+ ]
530+ for _type in projects_type :
531+ project_data = deepcopy (fake_project )
532+ await _new_project (
533+ client ,
534+ logged_user ["id" ],
535+ osparc_product_name ,
536+ tests_data_dir ,
537+ project_data ,
538+ as_template = _type == "TEMPLATE" ,
539+ )
540+
541+ base_url = client .app .router ["list_projects" ].url_for ()
542+ # Now we will test listing with type=user
543+ query_parameters = {"type" : "user" }
544+ url = base_url .with_query (** query_parameters )
545+
546+ resp = await client .get (f"{ url } " )
547+ data = await resp .json ()
548+
549+ assert resp .status == 200
550+ _assert_response_data (data , 3 , 0 , 3 , "/v0/projects?type=user&offset=0&limit=20" , 3 )
551+
552+ # Now we will test listing with type=all
553+ query_parameters = {"type" : "all" }
554+ url = base_url .with_query (** query_parameters )
555+
556+ resp = await client .get (f"{ url } " )
557+ data = await resp .json ()
558+
559+ assert resp .status == 200
560+ _assert_response_data (data , 5 , 0 , 5 , "/v0/projects?type=all&offset=0&limit=20" , 5 )
561+
562+ # Now we will test listing with type=template
563+ query_parameters = {"type" : "template" }
564+ url = base_url .with_query (** query_parameters )
565+
566+ resp = await client .get (f"{ url } " )
567+ data = await resp .json ()
568+
569+ assert resp .status == 200
570+ _assert_response_data (
571+ data , 2 , 0 , 2 , "/v0/projects?type=template&offset=0&limit=20" , 2
572+ )
573+
574+ # Now we will test listing with type=user and template_type=null
575+ query_parameters = {"type" : "user" , "template_type" : "null" }
576+ url = base_url .with_query (** query_parameters )
577+
578+ resp = await client .get (f"{ url } " )
579+ data = await resp .json ()
580+
581+ assert resp .status == 200
582+ _assert_response_data (
583+ data , 3 , 0 , 3 , "/v0/projects?type=user&template_type=null&offset=0&limit=20" , 3
584+ )
585+
586+ # Now we will test listing with incompatible type and template_type
587+ query_parameters = {"type" : "user" , "template_type" : "TEMPLATE" }
588+ url = base_url .with_query (** query_parameters )
589+ resp = await client .get (f"{ url } " )
590+ data = await resp .json ()
591+ assert resp .status == 422
0 commit comments