Skip to content

Commit 74dd364

Browse files
committed
drafts test
1 parent 232db3a commit 74dd364

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed

services/web/server/tests/unit/with_dbs/03/trash/test_trash_service.py

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,100 @@ async def test_trash_service__delete_expired_trash(
120120
async with _client_session_with_user(client, other_user):
121121
resp = await client.get(f"/v0/projects/{other_user_project_id}")
122122
await assert_status(resp, status.HTTP_404_NOT_FOUND)
123+
124+
125+
async def test_trash_nested_folders_and_projects(
126+
client: TestClient,
127+
logged_user: UserInfoDict,
128+
user_project: ProjectDict,
129+
other_user: UserInfoDict,
130+
other_user_project: ProjectDict,
131+
mocked_catalog: None,
132+
mocked_director_v2: None,
133+
):
134+
assert client.app
135+
assert logged_user["id"] != other_user["id"]
136+
137+
# Create folders hierarchy for logged_user
138+
resp = await client.post("/v0/folders", json={"name": "Root Folder"})
139+
data, _ = await assert_status(resp, status.HTTP_201_CREATED)
140+
logged_user_root_folder = data
141+
142+
resp = await client.post(
143+
"/v0/folders",
144+
json={
145+
"name": "Sub Folder",
146+
"parentFolderId": logged_user_root_folder["folderId"],
147+
},
148+
)
149+
data, _ = await assert_status(resp, status.HTTP_201_CREATED)
150+
logged_user_sub_folder = data
151+
152+
# Move project to subfolder
153+
resp = await client.put(
154+
f"/v0/projects/{user_project['uuid']}/folders/{logged_user_sub_folder['folderId']}"
155+
)
156+
await assert_status(resp, status.HTTP_204_NO_CONTENT)
157+
158+
# Trash root folders
159+
resp = await client.post(f"/v0/folders/{logged_user_root_folder['folderId']}:trash")
160+
await assert_status(resp, status.HTTP_204_NO_CONTENT)
161+
162+
# Create folders hierarchy for other_user
163+
async with _client_session_with_user(client, other_user):
164+
resp = await client.post("/v0/folders", json={"name": "Root Folder"})
165+
data, _ = await assert_status(resp, status.HTTP_201_CREATED)
166+
other_user_root_folder = data
167+
168+
resp = await client.post(
169+
"/v0/folders",
170+
json={
171+
"name": "Sub Folder",
172+
"parentFolderId": other_user_root_folder["folderId"],
173+
},
174+
)
175+
data, _ = await assert_status(resp, status.HTTP_201_CREATED)
176+
other_user_sub_folder = data
177+
178+
# Move project to subfolder
179+
resp = await client.put(
180+
f"/v0/projects/{other_user_project['uuid']}/folders/{other_user_sub_folder['folderId']}"
181+
)
182+
await assert_status(resp, status.HTTP_204_NO_CONTENT)
183+
184+
# Trash root folders
185+
resp = await client.post(
186+
f"/v0/folders/{logged_user_root_folder['folderId']}:trash"
187+
)
188+
await assert_status(resp, status.HTTP_204_NO_CONTENT)
189+
190+
async with _client_session_with_user(client, other_user):
191+
resp = await client.post(
192+
f"/v0/folders/{other_user_root_folder['folderId']}:trash"
193+
)
194+
await assert_status(resp, status.HTTP_204_NO_CONTENT)
195+
196+
# UNDER TEST
197+
await trash_service.delete_expired_trash_as_admin(client.app)
198+
199+
async with _client_session_with_user(client, logged_user):
200+
# Verify logged_user's resources are gone
201+
resp = await client.get(f"/v0/folders/{logged_user_root_folder['folderId']}")
202+
await assert_status(resp, status.HTTP_404_NOT_FOUND)
203+
204+
resp = await client.get(f"/v0/folders/{logged_user_sub_folder['folderId']}")
205+
await assert_status(resp, status.HTTP_404_NOT_FOUND)
206+
207+
resp = await client.get(f"/v0/projects/{user_project['uuid']}")
208+
await assert_status(resp, status.HTTP_404_NOT_FOUND)
209+
210+
# Verify other_user's resources are gone
211+
async with _client_session_with_user(client, other_user):
212+
resp = await client.get(f"/v0/folders/{other_user_root_folder['folderId']}")
213+
await assert_status(resp, status.HTTP_404_NOT_FOUND)
214+
215+
resp = await client.get(f"/v0/folders/{other_user_sub_folder['folderId']}")
216+
await assert_status(resp, status.HTTP_404_NOT_FOUND)
217+
218+
resp = await client.get(f"/v0/projects/{other_user_project['uuid']}")
219+
await assert_status(resp, status.HTTP_404_NOT_FOUND)

0 commit comments

Comments
 (0)