2323from packaging import version
2424from pydantic import EmailStr , HttpUrl , TypeAdapter
2525from pytest_simcore .helpers .catalog_services import CreateFakeServiceDataCallable
26- from pytest_simcore .helpers .faker_factories import random_project
26+ from pytest_simcore .helpers .faker_factories import random_project , random_project_node
2727from pytest_simcore .helpers .postgres_tools import insert_and_get_row_lifespan
2828from simcore_postgres_database .models .projects import ProjectType , projects
29+ from simcore_postgres_database .models .projects_nodes import projects_nodes
2930from simcore_service_catalog .models .services_db import (
3031 ServiceAccessRightsDB ,
3132 ServiceDBFilters ,
@@ -812,21 +813,41 @@ async def test_list_services_from_published_templates(
812813 type = ProjectType .TEMPLATE ,
813814 published = True ,
814815 prj_owner = user ["id" ],
815- workbench = {
816- "node-1" : {
817- "key" : "simcore/services/dynamic/jupyterlab" ,
818- "version" : "1.0.0" ,
819- },
820- "node-2" : {
821- "key" : "simcore/services/frontend/file-picker" ,
822- "version" : "1.0.0" ,
823- },
824- },
825816 ),
826817 pk_col = projects .c .uuid ,
827818 pk_value = "template-1" ,
828819 )
829820 )
821+ await stack .enter_async_context (
822+ insert_and_get_row_lifespan (
823+ sqlalchemy_async_engine ,
824+ table = projects_nodes ,
825+ values = random_project_node (
826+ node_id = "node-1.1" ,
827+ project_uuid = "template-1" ,
828+ key = "simcore/services/dynamic/jupyterlab" ,
829+ version = "1.0.0" ,
830+ label = "jupyterlab" ,
831+ ),
832+ pk_col = projects_nodes .c .node_id ,
833+ pk_value = "node-1.1" ,
834+ )
835+ )
836+ await stack .enter_async_context (
837+ insert_and_get_row_lifespan (
838+ sqlalchemy_async_engine ,
839+ table = projects_nodes ,
840+ values = random_project_node (
841+ node_id = "node-1.2" ,
842+ project_uuid = "template-1" ,
843+ key = "simcore/services/frontend/file-picker" ,
844+ version = "1.0.0" ,
845+ label = "file-picker" ,
846+ ),
847+ pk_col = projects_nodes .c .node_id ,
848+ pk_value = "node-1.2" ,
849+ )
850+ )
830851 await stack .enter_async_context (
831852 insert_and_get_row_lifespan (
832853 sqlalchemy_async_engine ,
@@ -836,17 +857,26 @@ async def test_list_services_from_published_templates(
836857 type = ProjectType .TEMPLATE ,
837858 published = False ,
838859 prj_owner = user ["id" ],
839- workbench = {
840- "node-1" : {
841- "key" : "simcore/services/dynamic/some-service" ,
842- "version" : "2.0.0" ,
843- },
844- },
845860 ),
846861 pk_col = projects .c .uuid ,
847862 pk_value = "template-2" ,
848863 )
849864 )
865+ await stack .enter_async_context (
866+ insert_and_get_row_lifespan (
867+ sqlalchemy_async_engine ,
868+ table = projects_nodes ,
869+ values = random_project_node (
870+ node_id = "node-2.1" ,
871+ project_uuid = "template-2" ,
872+ key = "simcore/services/dynamic/some-service" ,
873+ version = "2.0.0" ,
874+ label = "some-service" ,
875+ ),
876+ pk_col = projects_nodes .c .node_id ,
877+ pk_value = "node-2.1" ,
878+ )
879+ )
850880
851881 # Act: Call the method
852882 services = await projects_repo .list_services_from_published_templates ()
@@ -874,21 +904,41 @@ async def test_list_services_from_published_templates_with_invalid_service(
874904 type = ProjectType .TEMPLATE ,
875905 published = True ,
876906 prj_owner = user ["id" ],
877- workbench = {
878- "node-1" : {
879- "key" : "simcore/services/frontend/file-picker" ,
880- "version" : "1.0.0" ,
881- },
882- "node-2" : {
883- "key" : "simcore/services/dynamic/invalid-service" ,
884- "version" : "invalid" ,
885- },
886- },
887907 ),
888908 pk_col = projects .c .uuid ,
889909 pk_value = "template-1" ,
890910 )
891911 )
912+ await stack .enter_async_context (
913+ insert_and_get_row_lifespan (
914+ sqlalchemy_async_engine ,
915+ table = projects_nodes ,
916+ values = random_project_node (
917+ node_id = "node-1.1" ,
918+ project_uuid = "template-1" ,
919+ key = "simcore/services/frontend/file-picker" ,
920+ version = "1.0.0" ,
921+ label = "file-picker" ,
922+ ),
923+ pk_col = projects_nodes .c .node_id ,
924+ pk_value = "node-1.1" ,
925+ )
926+ )
927+ await stack .enter_async_context (
928+ insert_and_get_row_lifespan (
929+ sqlalchemy_async_engine ,
930+ table = projects_nodes ,
931+ values = random_project_node (
932+ node_id = "node-1.2" ,
933+ project_uuid = "template-1" ,
934+ key = "simcore/services/dynamic/invalid-service" ,
935+ version = "invalid" , # NOTE: invalid version
936+ label = "invalid-service" ,
937+ ),
938+ pk_col = projects_nodes .c .node_id ,
939+ pk_value = "node-1.2" ,
940+ )
941+ )
892942
893943 # Act: Call the method and capture logs
894944 with caplog .at_level (logging .WARNING ):
@@ -897,7 +947,7 @@ async def test_list_services_from_published_templates_with_invalid_service(
897947 # Assert: Validate the results
898948 assert len (services ) == 0 # No valid services should be returned
899949 assert (
900- "service {'key': ' simcore/services/dynamic/invalid-service', 'version': ' invalid'} could not be validated"
950+ "service with key= simcore/services/dynamic/invalid-service and version= invalid could not be validated"
901951 in caplog .text
902952 )
903953
0 commit comments