Skip to content

Commit b472bbf

Browse files
committed
extends test
1 parent 20c4040 commit b472bbf

File tree

1 file changed

+38
-19
lines changed

1 file changed

+38
-19
lines changed

services/web/server/tests/unit/with_dbs/03/test_trash.py

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,15 @@ def mocked_catalog(
3636
@pytest.mark.acceptance_test(
3737
"For https://github.com/ITISFoundation/osparc-simcore/pull/6579"
3838
)
39+
@pytest.mark.parametrize("is_trash_service_running", [False, True])
3940
async def test_trash_projects(
4041
client: TestClient,
4142
logged_user: UserInfoDict,
4243
user_project: ProjectDict,
4344
mocked_catalog: None,
4445
director_v2_service_mock: aioresponses,
4546
mocker: MockerFixture,
47+
is_trash_service_running: bool,
4648
):
4749
assert client.app
4850

@@ -57,7 +59,7 @@ async def test_trash_projects(
5759
)
5860
mocker.patch(
5961
"simcore_service_webserver.projects._trash_api.director_v2_api.is_pipeline_running",
60-
returns=False,
62+
return_value=is_trash_service_running,
6163
autospec=True,
6264
)
6365

@@ -87,34 +89,51 @@ async def test_trash_projects(
8789
# TRASH
8890
trashing_at = arrow.utcnow().datetime
8991
resp = await client.post(f"/v0/projects/{project_uuid}:trash")
90-
await assert_status(resp, status.HTTP_204_NO_CONTENT)
92+
_, error = await assert_status(
93+
resp,
94+
status.HTTP_409_CONFLICT
95+
if is_trash_service_running
96+
else status.HTTP_204_NO_CONTENT,
97+
)
98+
99+
could_not_trash = is_trash_service_running
100+
101+
if could_not_trash:
102+
assert error["status"] == status.HTTP_409_CONFLICT
103+
assert "Current study is in use" in error["message"]
91104

92105
# GET
93106
resp = await client.get(f"/v0/projects/{project_uuid}")
94107
data, _ = await assert_status(resp, status.HTTP_200_OK)
95108
got = ProjectGet.parse_obj(data)
96109
assert got.uuid == project_uuid
97110

98-
assert got.trashed_at
99-
assert trashing_at < got.trashed_at
100-
assert got.trashed_at < arrow.utcnow().datetime
111+
if could_not_trash:
112+
assert got.trashed_at is None
113+
else:
114+
assert got.trashed_at
115+
assert trashing_at < got.trashed_at
116+
assert got.trashed_at < arrow.utcnow().datetime
101117

102118
# LIST trashed
103119
resp = await client.get("/v0/projects", params={"filters": '{"trashed": true}'})
104120
await assert_status(resp, status.HTTP_200_OK)
105121

106122
page = Page[ProjectListItem].parse_obj(await resp.json())
107-
assert page.meta.total == 1
108-
assert page.data[0].uuid == project_uuid
109-
110-
# UNTRASH
111-
resp = await client.post(f"/v0/projects/{project_uuid}:untrash")
112-
data, _ = await assert_status(resp, status.HTTP_204_NO_CONTENT)
113-
114-
# GET
115-
resp = await client.get(f"/v0/projects/{project_uuid}")
116-
data, _ = await assert_status(resp, status.HTTP_200_OK)
117-
got = ProjectGet.parse_obj(data)
118-
119-
assert got.uuid == project_uuid
120-
assert got.trashed_at is None
123+
if could_not_trash:
124+
assert page.meta.total == 0
125+
else:
126+
assert page.meta.total == 1
127+
assert page.data[0].uuid == project_uuid
128+
129+
# UNTRASH
130+
resp = await client.post(f"/v0/projects/{project_uuid}:untrash")
131+
data, _ = await assert_status(resp, status.HTTP_204_NO_CONTENT)
132+
133+
# GET
134+
resp = await client.get(f"/v0/projects/{project_uuid}")
135+
data, _ = await assert_status(resp, status.HTTP_200_OK)
136+
got = ProjectGet.parse_obj(data)
137+
138+
assert got.uuid == project_uuid
139+
assert got.trashed_at is None

0 commit comments

Comments
 (0)