Skip to content

Commit

Permalink
tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
pcrespov committed Nov 6, 2024
1 parent 176c8b6 commit f4c101c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,9 @@ async def list_(
) -> tuple[int, list[FolderDB]]:
"""
content_of_folder_id - Used to filter in which folder we want to list folders. None means root folder.
trashed - If set to true, it returns folders **explicitly** trashed, if false then non-trashed folders.
"""
assert not (
assert not ( # nosec
user_id is not None and workspace_id is not None
), "Both user_id and workspace_id cannot be provided at the same time. Please provide only one."

Expand All @@ -122,7 +123,10 @@ async def list_(

if trashed is not None:
base_query = base_query.where(
folders_v2.c.trashed_at.is_not(None)
(
(folders_v2.c.trashed_at.is_not(None))
& (folders_v2.c.trashed_explicitly.is_(True))
)
if trashed
else folders_v2.c.trashed_at.is_(None)
)
Expand Down
27 changes: 21 additions & 6 deletions services/web/server/tests/unit/with_dbs/03/test_trash.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,9 @@ async def test_trash_folder_with_content(
assert page.meta.total == 1
assert page.data[0] == subfolder

resp = await client.get("/v0/projects")
resp = await client.get(
"/v0/projects", params={"folder_id": f"{subfolder.folder_id}"}
)
await assert_status(resp, status.HTTP_200_OK)
page = Page[ProjectListItem].parse_obj(await resp.json())
assert page.meta.total == 1
Expand All @@ -327,9 +329,11 @@ async def test_trash_folder_with_content(
await assert_status(resp, status.HTTP_200_OK)
page = Page[FolderGet].parse_obj(await resp.json())
assert page.meta.total == 0
assert page.data[0].folder_id == subfolder.folder_id

resp = await client.get("/v0/projects", params={"filters": '{"trashed": true}'})
resp = await client.get(
"/v0/projects",
params={"filters": '{"trashed": true}', "folder_id": f"{subfolder.folder_id}"},
)
await assert_status(resp, status.HTTP_200_OK)
page = Page[ProjectListItem].parse_obj(await resp.json())
assert page.meta.total == 0
Expand All @@ -347,7 +351,7 @@ async def test_trash_folder_with_content(

resp = await client.get(f"/v0/projects/{project_uuid}")
data, _ = await assert_status(resp, status.HTTP_200_OK)
got = FolderGet.parse_obj(data)
got = ProjectGet.parse_obj(data)
assert got.trashed_at is not None

# UNTRASH folder
Expand All @@ -360,7 +364,18 @@ async def test_trash_folder_with_content(
page = Page[FolderGet].parse_obj(await resp.json())
assert page.meta.total == 0

resp = await client.get("/v0/projects", params={"filters": '{"trashed": true}'})
resp = await client.get(
"/v0/folders",
params={"filters": '{"trashed": true}', "folder_id": f"{folder.folder_id}"},
)
await assert_status(resp, status.HTTP_200_OK)
page = Page[FolderGet].parse_obj(await resp.json())
assert page.meta.total == 0

resp = await client.get(
"/v0/projects",
params={"filters": '{"trashed": true}', "folder_id": f"{subfolder.folder_id}"},
)
await assert_status(resp, status.HTTP_200_OK)
page = Page[ProjectListItem].parse_obj(await resp.json())
assert page.meta.total == 0
Expand All @@ -378,5 +393,5 @@ async def test_trash_folder_with_content(

resp = await client.get(f"/v0/projects/{project_uuid}")
data, _ = await assert_status(resp, status.HTTP_200_OK)
got = FolderGet.parse_obj(data)
got = ProjectGet.parse_obj(data)
assert got.trashed_at is None

0 comments on commit f4c101c

Please sign in to comment.