Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/tests/api/test_collection_post_binary.py
Show First 20 Lines • Show All 98 Lines • ▼ Show 20 Lines | response = authenticated_client.post( | ||||
HTTP_PACKAGING="http://purl.org/net/sword/package/SimpleZip", | HTTP_PACKAGING="http://purl.org/net/sword/package/SimpleZip", | ||||
HTTP_IN_PROGRESS="false", | HTTP_IN_PROGRESS="false", | ||||
HTTP_CONTENT_DISPOSITION="attachment; filename=%s" % (sample_archive["name"],), | HTTP_CONTENT_DISPOSITION="attachment; filename=%s" % (sample_archive["name"],), | ||||
) | ) | ||||
# then | # then | ||||
response_content = parse_xml(BytesIO(response.content)) | response_content = parse_xml(BytesIO(response.content)) | ||||
assert response.status_code == status.HTTP_201_CREATED | assert response.status_code == status.HTTP_201_CREATED | ||||
deposit_id = response_content["deposit_id"] | deposit_id = response_content["swh:deposit_id"] | ||||
deposit = Deposit.objects.get(pk=deposit_id) | deposit = Deposit.objects.get(pk=deposit_id) | ||||
assert deposit.status == DEPOSIT_STATUS_DEPOSITED | assert deposit.status == DEPOSIT_STATUS_DEPOSITED | ||||
assert deposit.external_id == external_id | assert deposit.external_id == external_id | ||||
assert deposit.collection == deposit_collection | assert deposit.collection == deposit_collection | ||||
assert deposit.swhid is None | assert deposit.swhid is None | ||||
deposit_request = DepositRequest.objects.get(deposit=deposit) | deposit_request = DepositRequest.objects.get(deposit=deposit) | ||||
check_archive(sample_archive["name"], deposit_request.archive.name) | check_archive(sample_archive["name"], deposit_request.archive.name) | ||||
assert deposit_request.metadata is None | assert deposit_request.metadata is None | ||||
assert deposit_request.raw_metadata is None | assert deposit_request.raw_metadata is None | ||||
response_content = parse_xml(BytesIO(response.content)) | response_content = parse_xml(BytesIO(response.content)) | ||||
assert response_content["swh:deposit_archive"] == sample_archive["name"] | assert response_content["swh:deposit_archive"] == sample_archive["name"] | ||||
assert int(response_content["swh:deposit_id"]) == deposit.id | assert int(response_content["swh:deposit_id"]) == deposit.id | ||||
assert response_content["swh:deposit_status"] == deposit.status | assert response_content["swh:deposit_status"] == deposit.status | ||||
# deprecated tags | # deprecated tags | ||||
assert response_content["deposit_archive"] == sample_archive["name"] | assert response_content["deposit_archive"] == sample_archive["name"] | ||||
assert int(response_content["deposit_id"]) == deposit.id | assert int(response_content["swh:deposit_id"]) == deposit.id | ||||
assert response_content["deposit_status"] == deposit.status | assert response_content["deposit_status"] == deposit.status | ||||
edit_iri = reverse("edit_iri", args=[deposit_collection.name, deposit.id]) | edit_iri = reverse("edit_iri", args=[deposit_collection.name, deposit.id]) | ||||
assert response._headers["location"] == ( | assert response._headers["location"] == ( | ||||
"Location", | "Location", | ||||
"http://testserver" + edit_iri, | "http://testserver" + edit_iri, | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 194 Lines • ▼ Show 20 Lines | response = authenticated_client.post( | ||||
HTTP_IN_PROGRESS="false", | HTTP_IN_PROGRESS="false", | ||||
HTTP_CONTENT_DISPOSITION="attachment; filename=filename0", | HTTP_CONTENT_DISPOSITION="attachment; filename=filename0", | ||||
) | ) | ||||
# then | # then | ||||
assert response.status_code == status.HTTP_201_CREATED | assert response.status_code == status.HTTP_201_CREATED | ||||
response_content = parse_xml(BytesIO(response.content)) | response_content = parse_xml(BytesIO(response.content)) | ||||
deposit_id = response_content["deposit_id"] | deposit_id = response_content["swh:deposit_id"] | ||||
deposit = Deposit.objects.get(pk=deposit_id) | deposit = Deposit.objects.get(pk=deposit_id) | ||||
deposits = Deposit.objects.all() | deposits = Deposit.objects.all() | ||||
assert len(deposits) == 1 | assert len(deposits) == 1 | ||||
assert deposits[0] == deposit | assert deposits[0] == deposit | ||||
# second post | # second post | ||||
response = authenticated_client.post( | response = authenticated_client.post( | ||||
url, | url, | ||||
content_type="application/x-tar", # as zip | content_type="application/x-tar", # as zip | ||||
data=sample_archive["data"], | data=sample_archive["data"], | ||||
# + headers | # + headers | ||||
CONTENT_LENGTH=sample_archive["length"], | CONTENT_LENGTH=sample_archive["length"], | ||||
HTTP_SLUG="another-external-id", | HTTP_SLUG="another-external-id", | ||||
HTTP_CONTENT_MD5=sample_archive["md5sum"], | HTTP_CONTENT_MD5=sample_archive["md5sum"], | ||||
HTTP_PACKAGING="http://purl.org/net/sword/package/SimpleZip", | HTTP_PACKAGING="http://purl.org/net/sword/package/SimpleZip", | ||||
HTTP_IN_PROGRESS="false", | HTTP_IN_PROGRESS="false", | ||||
HTTP_CONTENT_DISPOSITION="attachment; filename=filename1", | HTTP_CONTENT_DISPOSITION="attachment; filename=filename1", | ||||
) | ) | ||||
assert response.status_code == status.HTTP_201_CREATED | assert response.status_code == status.HTTP_201_CREATED | ||||
response_content = parse_xml(BytesIO(response.content)) | response_content = parse_xml(BytesIO(response.content)) | ||||
deposit_id2 = response_content["deposit_id"] | deposit_id2 = response_content["swh:deposit_id"] | ||||
deposit2 = Deposit.objects.get(pk=deposit_id2) | deposit2 = Deposit.objects.get(pk=deposit_id2) | ||||
assert deposit != deposit2 | assert deposit != deposit2 | ||||
deposits = Deposit.objects.all().order_by("id") | deposits = Deposit.objects.all().order_by("id") | ||||
assert len(deposits) == 2 | assert len(deposits) == 2 | ||||
assert list(deposits), [deposit == deposit2] | assert list(deposits), [deposit == deposit2] | ||||
Show All 23 Lines | response = authenticated_client.post( | ||||
HTTP_IN_PROGRESS="true", | HTTP_IN_PROGRESS="true", | ||||
HTTP_CONTENT_DISPOSITION="attachment; filename=%s" % (sample_archive["name"],), | HTTP_CONTENT_DISPOSITION="attachment; filename=%s" % (sample_archive["name"],), | ||||
) | ) | ||||
# then | # then | ||||
assert response.status_code == status.HTTP_201_CREATED | assert response.status_code == status.HTTP_201_CREATED | ||||
response_content = parse_xml(BytesIO(response.content)) | response_content = parse_xml(BytesIO(response.content)) | ||||
deposit_id = response_content["deposit_id"] | deposit_id = response_content["swh:deposit_id"] | ||||
deposit = Deposit.objects.get(pk=deposit_id) | deposit = Deposit.objects.get(pk=deposit_id) | ||||
assert deposit.status == "partial" | assert deposit.status == "partial" | ||||
assert deposit.external_id == external_id | assert deposit.external_id == external_id | ||||
assert deposit.collection == deposit_collection | assert deposit.collection == deposit_collection | ||||
assert deposit.swhid is None | assert deposit.swhid is None | ||||
deposit_request = DepositRequest.objects.get(deposit=deposit) | deposit_request = DepositRequest.objects.get(deposit=deposit) | ||||
▲ Show 20 Lines • Show All 74 Lines • ▼ Show 20 Lines | response = authenticated_client.post( | ||||
HTTP_IN_PROGRESS="false", | HTTP_IN_PROGRESS="false", | ||||
HTTP_CONTENT_DISPOSITION="attachment; filename=filename0", | HTTP_CONTENT_DISPOSITION="attachment; filename=filename0", | ||||
) | ) | ||||
# then | # then | ||||
assert response.status_code == status.HTTP_201_CREATED | assert response.status_code == status.HTTP_201_CREATED | ||||
response_content = parse_xml(BytesIO(response.content)) | response_content = parse_xml(BytesIO(response.content)) | ||||
deposit_id = response_content["deposit_id"] | deposit_id = response_content["swh:deposit_id"] | ||||
deposit = Deposit.objects.get(pk=deposit_id) | deposit = Deposit.objects.get(pk=deposit_id) | ||||
assert deposit.status == DEPOSIT_STATUS_DEPOSITED | assert deposit.status == DEPOSIT_STATUS_DEPOSITED | ||||
assert deposit.external_id == external_id | assert deposit.external_id == external_id | ||||
assert deposit.collection == deposit_collection | assert deposit.collection == deposit_collection | ||||
assert deposit.swhid is None | assert deposit.swhid is None | ||||
deposit_request = DepositRequest.objects.get(deposit=deposit) | deposit_request = DepositRequest.objects.get(deposit=deposit) | ||||
▲ Show 20 Lines • Show All 117 Lines • Show Last 20 Lines |