Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/tests/api/test_collection_post_binary.py
Show First 20 Lines • Show All 117 Lines • ▼ Show 20 Lines | ): | ||||
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["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["deposit_id"]) == deposit.id | ||||
assert response_content["deposit_status"] == deposit.status | assert response_content["deposit_status"] == deposit.status | ||||
edit_se_iri = reverse("edit_se_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_se_iri, | "http://testserver" + edit_iri, | ||||
) | ) | ||||
def test_post_deposit_binary_failure_unsupported_packaging_header( | def test_post_deposit_binary_failure_unsupported_packaging_header( | ||||
authenticated_client, deposit_collection, sample_archive | authenticated_client, deposit_collection, sample_archive | ||||
): | ): | ||||
"""Bin deposit without supported content_disposition header returns 400 | """Bin deposit without supported content_disposition header returns 400 | ||||
▲ Show 20 Lines • Show All 321 Lines • ▼ Show 20 Lines | ): | ||||
deposit_request = DepositRequest.objects.get(deposit=deposit) | deposit_request = DepositRequest.objects.get(deposit=deposit) | ||||
assert deposit_request.deposit == deposit | assert deposit_request.deposit == deposit | ||||
check_archive("filename0", deposit_request.archive.name) | check_archive("filename0", deposit_request.archive.name) | ||||
# updating/adding is forbidden | # updating/adding is forbidden | ||||
# uri to update the content | # uri to update the content | ||||
edit_se_iri = reverse("edit_se_iri", args=[deposit_collection.name, deposit_id]) | edit_iri = reverse("edit_iri", args=[deposit_collection.name, deposit_id]) | ||||
se_iri = reverse("se_iri", args=[deposit_collection.name, deposit_id]) | |||||
em_iri = reverse("em_iri", args=[deposit_collection.name, deposit_id]) | em_iri = reverse("em_iri", args=[deposit_collection.name, deposit_id]) | ||||
# Testing all update/add endpoint should fail | # Testing all update/add endpoint should fail | ||||
# since the status is ready | # since the status is ready | ||||
archive2 = create_arborescence_archive( | archive2 = create_arborescence_archive( | ||||
tmp_path, "archive2", "file2", b"some content in file 2" | tmp_path, "archive2", "file2", b"some content in file 2" | ||||
) | ) | ||||
Show All 30 Lines | ): | ||||
) | ) | ||||
assert r.status_code == status.HTTP_400_BAD_REQUEST | assert r.status_code == status.HTTP_400_BAD_REQUEST | ||||
assert b"You can only act on deposit with status 'partial'" in r.content | assert b"You can only act on deposit with status 'partial'" in r.content | ||||
# replacing metadata is no longer possible since the deposit's | # replacing metadata is no longer possible since the deposit's | ||||
# status is ready | # status is ready | ||||
r = authenticated_client.put( | r = authenticated_client.put( | ||||
edit_se_iri, | edit_iri, | ||||
content_type="application/atom+xml;type=entry", | content_type="application/atom+xml;type=entry", | ||||
data=atom_dataset["entry-data-deposit-binary"], | data=atom_dataset["entry-data-deposit-binary"], | ||||
CONTENT_LENGTH=len(atom_dataset["entry-data-deposit-binary"]), | CONTENT_LENGTH=len(atom_dataset["entry-data-deposit-binary"]), | ||||
HTTP_SLUG=external_id, | HTTP_SLUG=external_id, | ||||
) | ) | ||||
assert r.status_code == status.HTTP_400_BAD_REQUEST | assert r.status_code == status.HTTP_400_BAD_REQUEST | ||||
assert b"You can only act on deposit with status 'partial'" in r.content | assert b"You can only act on deposit with status 'partial'" in r.content | ||||
# adding new metadata is no longer possible since the | # adding new metadata is no longer possible since the | ||||
# deposit's status is ready | # deposit's status is ready | ||||
r = authenticated_client.post( | r = authenticated_client.post( | ||||
edit_se_iri, | se_iri, | ||||
content_type="application/atom+xml;type=entry", | content_type="application/atom+xml;type=entry", | ||||
data=atom_dataset["entry-data-deposit-binary"], | data=atom_dataset["entry-data-deposit-binary"], | ||||
CONTENT_LENGTH=len(atom_dataset["entry-data-deposit-binary"]), | CONTENT_LENGTH=len(atom_dataset["entry-data-deposit-binary"]), | ||||
HTTP_SLUG=external_id, | HTTP_SLUG=external_id, | ||||
) | ) | ||||
assert r.status_code == status.HTTP_400_BAD_REQUEST | assert r.status_code == status.HTTP_400_BAD_REQUEST | ||||
assert b"You can only act on deposit with status 'partial'" in r.content | assert b"You can only act on deposit with status 'partial'" in r.content | ||||
Show All 15 Lines | atom_entry = InMemoryUploadedFile( | ||||
content_type='application/atom+xml; charset="utf-8"', | content_type='application/atom+xml; charset="utf-8"', | ||||
size=len(atom_dataset["entry-data-deposit-binary"]), | size=len(atom_dataset["entry-data-deposit-binary"]), | ||||
charset="utf-8", | charset="utf-8", | ||||
) | ) | ||||
# replacing multipart metadata is no longer possible since the | # replacing multipart metadata is no longer possible since the | ||||
# deposit's status is ready | # deposit's status is ready | ||||
r = authenticated_client.put( | r = authenticated_client.put( | ||||
edit_se_iri, | edit_iri, | ||||
format="multipart", | format="multipart", | ||||
data={"archive": archive, "atom_entry": atom_entry,}, | data={"archive": archive, "atom_entry": atom_entry,}, | ||||
) | ) | ||||
assert r.status_code == status.HTTP_400_BAD_REQUEST | assert r.status_code == status.HTTP_400_BAD_REQUEST | ||||
assert b"You can only act on deposit with status 'partial'" in r.content | assert b"You can only act on deposit with status 'partial'" in r.content | ||||
# adding new metadata is no longer possible since the | # adding new metadata is no longer possible since the | ||||
# deposit's status is ready | # deposit's status is ready | ||||
r = authenticated_client.post( | r = authenticated_client.post( | ||||
edit_se_iri, | se_iri, | ||||
format="multipart", | format="multipart", | ||||
data={"archive": archive, "atom_entry": atom_entry,}, | data={"archive": archive, "atom_entry": atom_entry,}, | ||||
) | ) | ||||
assert r.status_code == status.HTTP_400_BAD_REQUEST | assert r.status_code == status.HTTP_400_BAD_REQUEST | ||||
assert b"You can only act on deposit with status 'partial'" in r.content | assert b"You can only act on deposit with status 'partial'" in r.content |