uploads api: support filtering uploads by collectionId (#969)

tests: add collection filter test
This commit is contained in:
Ilya Kreymer 2023-07-09 10:54:30 -07:00 committed by GitHub
parent a640f58657
commit f1bce310d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 83 additions and 44 deletions

View File

@ -278,6 +278,7 @@ def init_uploads_api(app, mdb, users, crawl_manager, orgs, user_dep):
userid: Optional[UUID4] = None,
name: Optional[str] = None,
description: Optional[str] = None,
collectionId: Optional[UUID4] = None,
sortBy: Optional[str] = "finished",
sortDirection: Optional[int] = -1,
):
@ -288,6 +289,7 @@ def init_uploads_api(app, mdb, users, crawl_manager, orgs, user_dep):
description=description,
page_size=pageSize,
page=page,
collection_id=collectionId,
sort_by=sortBy,
sort_direction=sortDirection,
type_="upload",

View File

@ -79,6 +79,87 @@ def test_get_stream_upload(admin_auth_headers, default_org_id):
assert r.status_code == 200
def test_upload_form(admin_auth_headers, default_org_id):
with open(os.path.join(curr_dir, "data", "example.wacz"), "rb") as fh:
data = fh.read()
files = [
("uploads", ("test.wacz", data, "application/octet-stream")),
("uploads", ("test-2.wacz", data, "application/octet-stream")),
("uploads", ("test.wacz", data, "application/octet-stream")),
]
r = requests.put(
f"{API_PREFIX}/orgs/{default_org_id}/uploads/formdata?name=test2.wacz",
headers=admin_auth_headers,
files=files,
)
assert r.status_code == 200
assert r.json()["added"]
global upload_id_2
upload_id_2 = r.json()["id"]
def test_list_uploads(admin_auth_headers, default_org_id):
r = requests.get(
f"{API_PREFIX}/orgs/{default_org_id}/uploads",
headers=admin_auth_headers,
)
results = r.json()
assert len(results["items"]) > 1
found = None
for res in results["items"]:
if res["id"] == upload_id_2:
found = res
assert found
assert found["name"] == "test2.wacz"
assert "files" not in res
assert "resources" not in res
def test_collection_uploads(admin_auth_headers, default_org_id):
# Create collection with one upload
r = requests.post(
f"{API_PREFIX}/orgs/{default_org_id}/collections",
headers=admin_auth_headers,
json={
"crawlIds": [upload_id],
"name": "My Test Coll",
},
)
print(r.json())
assert r.status_code == 200
data = r.json()
coll_id = data["id"]
assert data["added"]
# Test uploads filtered by collection
r = requests.get(
f"{API_PREFIX}/orgs/{default_org_id}/uploads?collectionId={coll_id}",
headers=admin_auth_headers,
)
results = r.json()
assert len(results["items"]) == 1
assert results["items"][0]["id"] == upload_id
# Delete Collection
r = requests.delete(
f"{API_PREFIX}/orgs/{default_org_id}/collections/{coll_id}",
headers=admin_auth_headers,
)
assert r.status_code == 200
assert r.json()["success"]
def test_get_upload_replay_json(admin_auth_headers, default_org_id):
r = requests.get(
f"{API_PREFIX}/orgs/{default_org_id}/uploads/{upload_id}/replay.json",
@ -224,50 +305,6 @@ def test_delete_stream_upload_2(admin_auth_headers, default_org_id):
assert r.json()["deleted"] == True
def test_upload_form(admin_auth_headers, default_org_id):
with open(os.path.join(curr_dir, "data", "example.wacz"), "rb") as fh:
data = fh.read()
files = [
("uploads", ("test.wacz", data, "application/octet-stream")),
("uploads", ("test-2.wacz", data, "application/octet-stream")),
("uploads", ("test.wacz", data, "application/octet-stream")),
]
r = requests.put(
f"{API_PREFIX}/orgs/{default_org_id}/uploads/formdata?name=test2.wacz",
headers=admin_auth_headers,
files=files,
)
assert r.status_code == 200
assert r.json()["added"]
global upload_id_2
upload_id_2 = r.json()["id"]
def test_list_form_upload(admin_auth_headers, default_org_id):
r = requests.get(
f"{API_PREFIX}/orgs/{default_org_id}/uploads",
headers=admin_auth_headers,
)
results = r.json()
assert len(results["items"]) > 0
found = None
for res in results["items"]:
if res["id"] == upload_id_2:
found = res
assert found
assert found["name"] == "test2.wacz"
assert "files" not in res
assert "resources" not in res
def test_verify_from_upload_resource_count(admin_auth_headers, default_org_id):
r = requests.get(