Skip to content

Commit

Permalink
make list_pages() return empty response if no crawls provided, instea…
Browse files Browse the repository at this point in the history
…d of throwing

tests: add tests for empty collection
fixes #2443
  • Loading branch information
ikreymer committed Mar 1, 2025
1 parent cb52da6 commit ca9cd07
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
8 changes: 3 additions & 5 deletions backend/btrixcloud/pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,11 +538,9 @@ async def list_pages(
crawl_ids = await self.coll_ops.get_collection_crawl_ids(
coll_id, public_or_unlisted_only
)
elif not crawl_ids:
# neither coll_id nor crawl_id, error
raise HTTPException(
status_code=400, detail="either crawl_ids or coll_id must be provided"
)

if not crawl_ids:
return [], 0

query: dict[str, object] = {
"crawl_id": {"$in": crawl_ids},
Expand Down
26 changes: 24 additions & 2 deletions backend/test/test_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,28 @@ def test_create_collection_empty_name(
assert r.status_code == 422


def test_create_empty_collection(
crawler_auth_headers, default_org_id, crawler_crawl_id, admin_crawl_id
):
r = requests.post(
f"{API_PREFIX}/orgs/{default_org_id}/collections",
headers=crawler_auth_headers,
json={
"name": "Empty Collection",
},
)
assert r.status_code == 200

r = requests.get(
f"{API_PREFIX}/orgs/{default_org_id}/collections/{_coll_id}/replay.json",
headers=crawler_auth_headers,
)
assert r.status_code == 200
data = r.json()
assert data["crawlCount"] == 0
assert data["pageCount"] == 0
assert len(data["resources"]) == 0

def test_update_collection(
crawler_auth_headers, default_org_id, crawler_crawl_id, admin_crawl_id
):
Expand Down Expand Up @@ -569,10 +591,10 @@ def test_list_collections(
)
assert r.status_code == 200
data = r.json()
assert data["total"] == 3
assert data["total"] == 4

items = data["items"]
assert len(items) == 3
assert len(items) == 4

first_coll = [coll for coll in items if coll["name"] == UPDATED_NAME][0]
assert first_coll["id"] == _coll_id
Expand Down

0 comments on commit ca9cd07

Please sign in to comment.