|
3 | 3 | # pylint: disable=unused-variable |
4 | 4 | # pylint: disable=too-many-arguments |
5 | 5 |
|
| 6 | +from datetime import timedelta |
6 | 7 | from uuid import UUID |
7 | 8 |
|
| 9 | +import arrow |
8 | 10 | import pytest |
9 | 11 | from aiohttp.test_utils import TestClient |
10 | 12 | from common_library.users_enums import UserRole |
|
13 | 15 | _projects_db as projects_service_repository, |
14 | 16 | ) |
15 | 17 | 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 |
17 | 19 |
|
18 | 20 |
|
19 | 21 | @pytest.fixture |
@@ -52,7 +54,7 @@ async def test_patch_project( |
52 | 54 | ): |
53 | 55 | assert client.app |
54 | 56 |
|
55 | | - # Thie will change after in patched_project |
| 57 | + # This will change after in patched_project |
56 | 58 | assert user_project["creationDate"] == user_project["lastChangeDate"] |
57 | 59 |
|
58 | 60 | # Patch valid project |
@@ -103,3 +105,60 @@ async def test_delete_project( |
103 | 105 | await projects_service_repository.delete_project( |
104 | 106 | client.app, project_uuid=non_existent_project_uuid |
105 | 107 | ) |
| 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