Fix replay.json 400 response for empty collection (#2445)
- fix #2443 - don't throw error in list_pages() if no crawls provided, just return empty list - ensure an empty collection returns 200 on replay.json, add tests
This commit is contained in:
		
							parent
							
								
									2e86ee3fcc
								
							
						
					
					
						commit
						2263745df3
					
				| @ -538,11 +538,9 @@ class PageOps: | |||||||
|             crawl_ids = await self.coll_ops.get_collection_crawl_ids( |             crawl_ids = await self.coll_ops.get_collection_crawl_ids( | ||||||
|                 coll_id, public_or_unlisted_only |                 coll_id, public_or_unlisted_only | ||||||
|             ) |             ) | ||||||
|         elif not crawl_ids: | 
 | ||||||
|             # neither coll_id nor crawl_id, error |         if not crawl_ids: | ||||||
|             raise HTTPException( |             return [], 0 | ||||||
|                 status_code=400, detail="either crawl_ids or coll_id must be provided" |  | ||||||
|             ) |  | ||||||
| 
 | 
 | ||||||
|         query: dict[str, object] = { |         query: dict[str, object] = { | ||||||
|             "crawl_id": {"$in": crawl_ids}, |             "crawl_id": {"$in": crawl_ids}, | ||||||
|  | |||||||
| @ -155,6 +155,38 @@ def test_create_collection_empty_name( | |||||||
|     assert r.status_code == 422 |     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 | ||||||
|  |     coll_id = r.json()["id"] | ||||||
|  | 
 | ||||||
|  |     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 | ||||||
|  | 
 | ||||||
|  |     # Delete the empty collection | ||||||
|  |     r = requests.delete( | ||||||
|  |         f"{API_PREFIX}/orgs/{default_org_id}/collections/{coll_id}", | ||||||
|  |         headers=crawler_auth_headers, | ||||||
|  |     ) | ||||||
|  |     assert r.status_code == 200 | ||||||
|  |     assert r.json()["success"] | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| def test_update_collection( | def test_update_collection( | ||||||
|     crawler_auth_headers, default_org_id, crawler_crawl_id, admin_crawl_id |     crawler_auth_headers, default_org_id, crawler_crawl_id, admin_crawl_id | ||||||
| ): | ): | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user