Skip to content

Commit ad6e4d6

Browse files
committed
fix tests
1 parent 118b576 commit ad6e4d6

File tree

2 files changed

+64
-4
lines changed

2 files changed

+64
-4
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import logging
2+
from collections.abc import Callable
23
from datetime import datetime
3-
from typing import Callable, cast
4+
from typing import cast
45

56
import sqlalchemy as sa
67
from aiohttp import web
@@ -28,7 +29,7 @@
2829
_logger = logging.getLogger(__name__)
2930

3031

31-
PROJECT_DB_COLS = get_columns_from_db_model( # noqa: RUF012
32+
PROJECT_DB_COLS = get_columns_from_db_model(
3233
# NOTE: MD: I intentionally didn't include the workbench. There is a special interface
3334
# for the workbench, and at some point, this column should be removed from the table.
3435
# The same holds true for access_rights/ui/classifiers/quality, but we have decided to proceed step by step.

services/web/server/tests/unit/with_dbs/02/test_projects_repository.py

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
# pylint: disable=unused-variable
44
# pylint: disable=too-many-arguments
55

6+
from datetime import timedelta
67
from uuid import UUID
78

9+
import arrow
810
import pytest
911
from aiohttp.test_utils import TestClient
1012
from common_library.users_enums import UserRole
@@ -13,7 +15,7 @@
1315
_projects_db as projects_service_repository,
1416
)
1517
from simcore_service_webserver.projects.exceptions import ProjectNotFoundError
16-
from simcore_service_webserver.projects.models import ProjectDict
18+
from simcore_service_webserver.projects.models import ProjectDBGet, ProjectDict
1719

1820

1921
@pytest.fixture
@@ -52,7 +54,7 @@ async def test_patch_project(
5254
):
5355
assert client.app
5456

55-
# Thie will change after in patched_project
57+
# This will change after in patched_project
5658
assert user_project["creationDate"] == user_project["lastChangeDate"]
5759

5860
# Patch valid project
@@ -103,3 +105,60 @@ async def test_delete_project(
103105
await projects_service_repository.delete_project(
104106
client.app, project_uuid=non_existent_project_uuid
105107
)
108+
109+
110+
@pytest.fixture
111+
async def trashed_project(
112+
client: TestClient,
113+
logged_user: UserInfoDict,
114+
user_project: ProjectDict,
115+
) -> ProjectDBGet:
116+
assert client.app
117+
118+
# Patch project to be trashed
119+
trashed_at = arrow.utcnow().datetime
120+
patch_data = {
121+
"trashed": trashed_at,
122+
"trashed_by": logged_user["id"],
123+
"trashed_explicitly": True,
124+
}
125+
return await projects_service_repository.patch_project(
126+
client.app,
127+
project_uuid=user_project["uuid"],
128+
new_partial_project_data=patch_data,
129+
)
130+
131+
132+
async def test_list_trashed_projects(client: TestClient, trashed_project: ProjectDBGet):
133+
assert client.app
134+
135+
(
136+
total_count,
137+
trashed_projects,
138+
) = await projects_service_repository.list_trashed_projects(
139+
client.app,
140+
trashed_explicitly=True,
141+
trashed_before=arrow.utcnow().datetime + timedelta(days=1),
142+
)
143+
144+
assert total_count == 1
145+
assert len(trashed_projects) == 1
146+
assert trashed_projects[0] == trashed_project
147+
148+
149+
async def test_get_trashed_by_primary_gid(
150+
client: TestClient,
151+
logged_user: UserInfoDict,
152+
trashed_project: ProjectDBGet,
153+
):
154+
assert client.app
155+
156+
# Get trashed by primary gid
157+
trashed_by_primary_gid = (
158+
await projects_service_repository.get_trashed_by_primary_gid(
159+
client.app,
160+
projects_uuid=trashed_project.uuid,
161+
)
162+
)
163+
164+
assert trashed_by_primary_gid == logged_user["primary_gid"]

0 commit comments

Comments
 (0)