Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/tests/api/test_deposit_update_binary.py
Show All 12 Lines | |||||
from swh.deposit.config import COL_IRI, DEPOSIT_STATUS_DEPOSITED, EM_IRI, SE_IRI | from swh.deposit.config import COL_IRI, DEPOSIT_STATUS_DEPOSITED, EM_IRI, SE_IRI | ||||
from swh.deposit.models import Deposit, DepositRequest | from swh.deposit.models import Deposit, DepositRequest | ||||
from swh.deposit.parsers import parse_xml | from swh.deposit.parsers import parse_xml | ||||
from swh.deposit.tests.common import ( | from swh.deposit.tests.common import ( | ||||
check_archive, | check_archive, | ||||
create_arborescence_archive, | create_arborescence_archive, | ||||
post_archive, | post_archive, | ||||
post_atom, | |||||
put_archive, | put_archive, | ||||
put_atom, | |||||
) | ) | ||||
def test_post_deposit_binary_and_post_to_add_another_archive( | def test_post_deposit_binary_and_post_to_add_another_archive( | ||||
authenticated_client, deposit_collection, sample_archive, tmp_path | authenticated_client, deposit_collection, sample_archive, tmp_path | ||||
): | ): | ||||
"""Updating a deposit should return a 201 with receipt | """Updating a deposit should return a 201 with receipt | ||||
▲ Show 20 Lines • Show All 88 Lines • ▼ Show 20 Lines | ): | ||||
assert len(list(requests)) == 1 | assert len(list(requests)) == 1 | ||||
check_archive(sample_archive["name"], requests[0].archive.name) | check_archive(sample_archive["name"], requests[0].archive.name) | ||||
# we have no metadata for that deposit | # we have no metadata for that deposit | ||||
requests = list(DepositRequest.objects.filter(deposit=deposit, type="metadata")) | requests = list(DepositRequest.objects.filter(deposit=deposit, type="metadata")) | ||||
assert len(requests) == 0 | assert len(requests) == 0 | ||||
response = authenticated_client.post( | response = post_atom( | ||||
authenticated_client, | |||||
reverse(SE_IRI, args=[deposit_collection.name, deposit.id]), | reverse(SE_IRI, args=[deposit_collection.name, deposit.id]), | ||||
content_type="application/atom+xml;type=entry", | |||||
data=atom_dataset["entry-data1"], | data=atom_dataset["entry-data1"], | ||||
HTTP_SLUG=deposit.external_id, | HTTP_SLUG=deposit.external_id, | ||||
HTTP_IN_PROGRESS=True, | HTTP_IN_PROGRESS=True, | ||||
) | ) | ||||
requests = list(DepositRequest.objects.filter(deposit=deposit, type="metadata")) | requests = list(DepositRequest.objects.filter(deposit=deposit, type="metadata")) | ||||
assert len(requests) == 1 | assert len(requests) == 1 | ||||
▲ Show 20 Lines • Show All 198 Lines • ▼ Show 20 Lines | r = post_archive( | ||||
HTTP_IN_PROGRESS="false", | HTTP_IN_PROGRESS="false", | ||||
) | ) | ||||
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 = put_atom( | ||||
authenticated_client, | |||||
edit_iri, | edit_iri, | ||||
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 = post_atom( | ||||
authenticated_client, | |||||
se_iri, | se_iri, | ||||
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 40 Lines |