Skip to content

Commit fb16e05

Browse files
committed
fixing tests
1 parent 001a4dd commit fb16e05

File tree

3 files changed

+13
-17
lines changed

3 files changed

+13
-17
lines changed

packages/models-library/src/models_library/api_schemas_webserver/projects.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
)
3737
from ..workspaces import WorkspaceID
3838
from ._base import EmptyModel, InputSchema, OutputSchema
39-
from .groups import GroupID
4039
from .permalinks import ProjectPermalink
4140

4241

@@ -99,10 +98,6 @@ class ProjectGet(OutputSchema):
9998
folder_id: FolderID | None
10099

101100
trashed_at: datetime | None
102-
trashed_by: Annotated[
103-
GroupID | None,
104-
Field(description="Primary group ID of the user who trashed this item"),
105-
]
106101

107102
_empty_description = field_validator("description", mode="before")(
108103
none_to_empty_str_pre_validator

services/web/server/src/simcore_service_webserver/projects/_crud_api_read.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
"""
77

88
from aiohttp import web
9-
from models_library.api_schemas_webserver._base import OutputSchema
109
from models_library.api_schemas_webserver.projects import ProjectListItem
1110
from models_library.folders import FolderID, FolderQuery, FolderScope
1211
from models_library.projects import ProjectID
@@ -27,13 +26,12 @@
2726
from .models import ProjectDict, ProjectTypeAPI
2827

2928

30-
async def _append_fields(
29+
async def _append_item(
3130
request: web.Request,
3231
*,
3332
user_id: UserID,
3433
project: ProjectDict,
3534
is_template: bool,
36-
model_schema_cls: type[OutputSchema],
3735
):
3836
# state
3937
await projects_api.add_project_states_for_user(
@@ -47,7 +45,7 @@ async def _append_fields(
4745
await update_or_pop_permalink_in_project(request, project)
4846

4947
# validate
50-
return model_schema_cls.model_validate(project).data(exclude_unset=True)
48+
return ProjectListItem.from_model(project).data(exclude_unset=True)
5149

5250

5351
async def list_projects( # pylint: disable=too-many-arguments
@@ -128,12 +126,11 @@ async def list_projects( # pylint: disable=too-many-arguments
128126

129127
projects: list[ProjectDict] = await logged_gather(
130128
*(
131-
_append_fields(
129+
_append_item(
132130
request,
133131
user_id=user_id,
134132
project=prj,
135133
is_template=prj_type == ProjectTypeDB.TEMPLATE,
136-
model_schema_cls=ProjectListItem,
137134
)
138135
for prj, prj_type in zip(db_projects, db_project_types, strict=False)
139136
),
@@ -182,12 +179,11 @@ async def list_projects_full_depth(
182179

183180
projects: list[ProjectDict] = await logged_gather(
184181
*(
185-
_append_fields(
182+
_append_item(
186183
request,
187184
user_id=user_id,
188185
project=prj,
189186
is_template=prj_type == ProjectTypeDB.TEMPLATE,
190-
model_schema_cls=ProjectListItem,
191187
)
192188
for prj, prj_type in zip(db_projects, db_project_types, strict=False)
193189
),

services/web/server/tests/conftest.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from aiohttp.test_utils import TestClient
1919
from common_library.json_serialization import json_dumps
2020
from faker import Faker
21+
from models_library.api_schemas_webserver.projects import ProjectGet
2122
from models_library.projects import ProjectID
2223
from models_library.projects_nodes_io import NodeID
2324
from models_library.projects_state import ProjectState
@@ -216,7 +217,7 @@ async def _setup(
216217
project_data: ProjectDict = {}
217218
expected_data: ProjectDict = {
218219
"classifiers": [],
219-
"accessRights": [],
220+
"accessRights": {},
220221
"tags": [],
221222
"lastChangeDate": None,
222223
"creationDate": None,
@@ -235,12 +236,16 @@ async def _setup(
235236
"trashedAt": None,
236237
}
237238
if from_study:
238-
# access rights are replaced
239-
expected_data = deepcopy(from_study)
240-
expected_data["accessRights"] = {}
239+
from_study_wo_access_rights = deepcopy(from_study)
240+
from_study_wo_access_rights.pop("accessRights")
241+
expected_data = {**expected_data, **from_study_wo_access_rights}
241242
if not as_template:
242243
expected_data["name"] = f"{from_study['name']} (Copy)"
243244

245+
expected_data = ProjectGet.from_model(expected_data).model_dump(
246+
mode="json", by_alias=True
247+
)
248+
244249
if not from_study or project:
245250
assert NEW_PROJECT.request_payload
246251
project_data = deepcopy(NEW_PROJECT.request_payload)

0 commit comments

Comments
 (0)