fix public collections endpoint returning 404 when not public (#1052)

tests: add tests for public collections endpoint when collection is public and when not
This commit is contained in:
Ilya Kreymer 2023-08-04 10:29:13 -07:00 committed by GitHub
parent 7ff57ce6b5
commit 8d0a4f2ca9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 3 deletions

View File

@ -156,6 +156,9 @@ class CollectionOps:
query["isPublic"] = True
result = await self.collections.find_one(query)
if not result:
return None
if resources:
result["resources"] = await self.get_collection_crawl_resources(
coll_id, org

View File

@ -249,9 +249,7 @@ def test_get_collection(crawler_auth_headers, default_org_id):
assert data["tags"] == ["wr-test-2", "wr-test-1"]
def test_get_collection_replay(
crawler_auth_headers, default_org_id, crawler_crawl_id, admin_crawl_id
):
def test_get_collection_replay(crawler_auth_headers, default_org_id):
r = requests.get(
f"{API_PREFIX}/orgs/{default_org_id}/collections/{_coll_id}/replay.json",
headers=crawler_auth_headers,
@ -276,6 +274,48 @@ def test_get_collection_replay(
assert resource["size"]
def test_collection_public(crawler_auth_headers, default_org_id):
r = requests.get(
f"{API_PREFIX}/orgs/{default_org_id}/collections/{_coll_id}/public/replay.json",
headers=crawler_auth_headers,
)
assert r.status_code == 404
# make public
r = requests.patch(
f"{API_PREFIX}/orgs/{default_org_id}/collections/{_coll_id}",
headers=crawler_auth_headers,
json={
"isPublic": True,
},
)
assert r.status_code == 200
assert r.json()["updated"]
r = requests.get(
f"{API_PREFIX}/orgs/{default_org_id}/collections/{_coll_id}/public/replay.json",
headers=crawler_auth_headers,
)
assert r.status_code == 200
assert r.headers["Access-Control-Allow-Origin"] == "*"
assert r.headers["Access-Control-Allow-Headers"] == "*"
# make private again
r = requests.patch(
f"{API_PREFIX}/orgs/{default_org_id}/collections/{_coll_id}",
headers=crawler_auth_headers,
json={
"isPublic": False,
},
)
r = requests.get(
f"{API_PREFIX}/orgs/{default_org_id}/collections/{_coll_id}/public/replay.json",
headers=crawler_auth_headers,
)
assert r.status_code == 404
def test_add_upload_to_collection(crawler_auth_headers, default_org_id):
with open(os.path.join(curr_dir, "data", "example.wacz"), "rb") as fh:
r = requests.put(