Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/tests/api/test_collection_list.py
Show First 20 Lines • Show All 62 Lines • ▼ Show 20 Lines | ): | ||||
url = reverse(COL_IRI, args=(coll.name,)) | url = reverse(COL_IRI, args=(coll.name,)) | ||||
response = authenticated_client.get(f"{url}?page_size=1") | response = authenticated_client.get(f"{url}?page_size=1") | ||||
assert response.status_code == status.HTTP_200_OK | assert response.status_code == status.HTTP_200_OK | ||||
data = parse_xml(BytesIO(response.content))["atom:feed"] | data = parse_xml(BytesIO(response.content))["atom:feed"] | ||||
assert ( | assert ( | ||||
data["swh:count"] == "2" | data["swh:count"] == "2" | ||||
) # total result of 2 deposits if consuming all results | ) # total result of 2 deposits if consuming all results | ||||
header_link = parse_header_links(response._headers["Link"]) | header_link = parse_header_links(response["Link"]) | ||||
assert len(header_link) == 1 # only 1 next link | assert len(header_link) == 1 # only 1 next link | ||||
expected_next = f"{url}?page=2&page_size=1" | expected_next = f"{url}?page=2&page_size=1" | ||||
assert header_link[0]["url"].endswith(expected_next) | assert header_link[0]["url"].endswith(expected_next) | ||||
assert header_link[0]["rel"] == "next" | assert header_link[0]["rel"] == "next" | ||||
# only one deposit in the response | # only one deposit in the response | ||||
deposit = data["atom:entry"] # dict as only 1 value (a-la js) | deposit = data["atom:entry"] # dict as only 1 value (a-la js) | ||||
assert isinstance(deposit, dict) | assert isinstance(deposit, dict) | ||||
assert deposit["swh:id"] == deposit_id | assert deposit["swh:id"] == deposit_id | ||||
assert deposit["swh:status"] == DEPOSIT_STATUS_PARTIAL | assert deposit["swh:status"] == DEPOSIT_STATUS_PARTIAL | ||||
# then 2nd page | # then 2nd page | ||||
response2 = authenticated_client.get(expected_next) | response2 = authenticated_client.get(expected_next) | ||||
assert response2.status_code == status.HTTP_200_OK | assert response2.status_code == status.HTTP_200_OK | ||||
data2 = parse_xml(BytesIO(response2.content))["atom:feed"] | data2 = parse_xml(BytesIO(response2.content))["atom:feed"] | ||||
assert data2["swh:count"] == "2" # still total of 2 deposits across all results | assert data2["swh:count"] == "2" # still total of 2 deposits across all results | ||||
expected_previous = f"{url}?page_size=1" | expected_previous = f"{url}?page_size=1" | ||||
header_link2 = parse_header_links(response2._headers["Link"]) | header_link2 = parse_header_links(response2["Link"]) | ||||
assert len(header_link2) == 1 # only 1 previous link | assert len(header_link2) == 1 # only 1 previous link | ||||
assert header_link2[0]["url"].endswith(expected_previous) | assert header_link2[0]["url"].endswith(expected_previous) | ||||
assert header_link2[0]["rel"] == "previous" | assert header_link2[0]["rel"] == "previous" | ||||
# only 1 deposit in the response | # only 1 deposit in the response | ||||
deposit2 = data2["atom:entry"] # dict as only 1 value (a-la js) | deposit2 = data2["atom:entry"] # dict as only 1 value (a-la js) | ||||
assert isinstance(deposit2, dict) | assert isinstance(deposit2, dict) | ||||
assert deposit2["swh:id"] == deposit_id2 | assert deposit2["swh:id"] == deposit_id2 | ||||
assert deposit2["swh:status"] == DEPOSIT_STATUS_DEPOSITED | assert deposit2["swh:status"] == DEPOSIT_STATUS_DEPOSITED | ||||
# Retrieve every deposit in one query (no page_size parameter) | # Retrieve every deposit in one query (no page_size parameter) | ||||
response3 = authenticated_client.get(url) | response3 = authenticated_client.get(url) | ||||
assert response3.status_code == status.HTTP_200_OK | assert response3.status_code == status.HTTP_200_OK | ||||
data3 = parse_xml(BytesIO(response3.content))["atom:feed"] | data3 = parse_xml(BytesIO(response3.content))["atom:feed"] | ||||
assert data3["swh:count"] == "2" # total result of 2 deposits across all results | assert data3["swh:count"] == "2" # total result of 2 deposits across all results | ||||
deposits3 = data3["atom:entry"] # list here | deposits3 = data3["atom:entry"] # list here | ||||
assert isinstance(deposits3, list) | assert isinstance(deposits3, list) | ||||
assert len(deposits3) == 2 | assert len(deposits3) == 2 | ||||
header_link3 = parse_header_links(response3._headers["Link"]) | header_link3 = parse_header_links(response3["Link"]) | ||||
assert header_link3 == [] # no pagination as all results received in one round | assert header_link3 == [] # no pagination as all results received in one round | ||||
assert deposit in deposits3 | assert deposit in deposits3 | ||||
assert deposit2 in deposits3 | assert deposit2 in deposits3 |