44# pylint: disable=unused-variable
55# type: ignore
66
7+ from collections .abc import AsyncIterator
78from copy import deepcopy
89from http import HTTPStatus
10+ from pathlib import Path
911from typing import Any
1012
1113import pytest
1719 MyServiceGet ,
1820 MyServicesRpcBatchGet ,
1921)
20- from models_library .api_schemas_webserver .projects import ProjectPatch
21- from models_library .products import ProductName
2222from models_library .services_history import ServiceRelease
2323from pytest_mock import MockerFixture
2424from pytest_simcore .helpers .assert_checks import assert_status
25+ from pytest_simcore .helpers .webserver_projects import NewProject
2526from pytest_simcore .helpers .webserver_users import UserInfoDict
2627from servicelib .aiohttp import status
2728from servicelib .rabbitmq import RPCServerError
2829from simcore_service_webserver .db .models import UserRole
29- from simcore_service_webserver .projects import _projects_service
3030from simcore_service_webserver .projects .models import ProjectDict
3131from yarl import URL
3232
@@ -337,7 +337,7 @@ async def test_accessible_for_one_service(
337337 expected_url = client .app .router ["get_project_services_access_for_gid" ].url_for (
338338 project_id = project_id
339339 )
340- assert URL (f"/v0/projects/{ project_id } /nodes/-/services" ) == expected_url
340+ assert URL (f"/v0/projects/{ project_id } /nodes/-/services:access " ) == expected_url
341341
342342 resp = await client .get (
343343 f"/v0/projects/{ project_id } /nodes/-/services:access?for_gid={ for_gid } "
@@ -595,28 +595,41 @@ async def test_get_project_services_service_unavailable(
595595 assert not data
596596
597597
598+ @pytest .fixture
599+ async def empty_project (
600+ client ,
601+ fake_project : dict ,
602+ logged_user : dict ,
603+ tests_data_dir : Path ,
604+ osparc_product_name : str ,
605+ ) -> AsyncIterator [dict ]:
606+ fake_project ["prjOwner" ] = logged_user ["name" ]
607+ fake_project ["workbench" ] = {}
608+ async with NewProject (
609+ fake_project ,
610+ client .app ,
611+ user_id = logged_user ["id" ],
612+ product_name = osparc_product_name ,
613+ tests_data_dir = tests_data_dir ,
614+ ) as project :
615+ yield project
616+
617+
598618@pytest .mark .parametrize ("user_role" , [UserRole .USER ])
599619async def test_get_project_services_empty_project (
600620 client : TestClient ,
601- user_project : ProjectDict ,
621+ empty_project : ProjectDict ,
602622 mocker : MockerFixture ,
603- logged_user : UserInfoDict ,
604- default_product_name : ProductName ,
605623):
606- #
607- # Clear the project's workbench to make it empty
608- # Update the project in the database to have an empty workbench
609- await _projects_service .patch_project_for_user (
610- client .app ,
611- user_id = logged_user ["id" ],
612- project_uuid = user_project ["uuid" ],
613- project_patch = ProjectPatch (workbench = {}),
614- product_name = default_product_name ,
615- client_session_id = None ,
616- )
624+ # NOTE: Tests bug described in https://github.com/ITISFoundation/osparc-simcore/pull/8501
625+ assert empty_project ["workbench" ] == {}
617626
618- mocker .patch (
619- "simcore_service_webserver.catalog._service.catalog_rpc.batch_get_my_services" ,
627+ # MOCK CATALOG TO RAISE IF CALLED (it should not be called)
628+ from simcore_service_webserver .catalog ._service import catalog_rpc # noqa: PLC0415
629+
630+ mocker .patch .object (
631+ catalog_rpc ,
632+ "batch_get_my_services" ,
620633 spec = True ,
621634 side_effect = ValueError (
622635 "Bad request: cannot batch-get an empty list of name-ids"
@@ -625,14 +638,17 @@ async def test_get_project_services_empty_project(
625638
626639 assert client .app
627640
628- project_id = user_project ["uuid" ]
641+ # ACT
642+ project_id = empty_project ["uuid" ]
629643
630644 expected_url = client .app .router ["get_project_services" ].url_for (
631645 project_id = project_id
632646 )
633647 assert URL (f"/v0/projects/{ project_id } /nodes/-/services" ) == expected_url
634648
635649 resp = await client .get (f"/v0/projects/{ project_id } /nodes/-/services" )
650+
651+ # ASSERT
636652 data , _ = await assert_status (resp , status .HTTP_200_OK )
637653
638654 assert data == {
0 commit comments