Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/tests/api/test_deposit_update_binary.py
# Copyright (C) 2017-2021 The Software Heritage developers | # Copyright (C) 2017-2021 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
"""Tests updates on EM-IRI""" | """Tests updates on EM-IRI""" | ||||
from io import BytesIO | from io import BytesIO | ||||
from django.core.files.uploadedfile import InMemoryUploadedFile | from django.core.files.uploadedfile import InMemoryUploadedFile | ||||
from django.urls import reverse_lazy as reverse | from django.urls import reverse_lazy as reverse | ||||
from rest_framework import status | from rest_framework import status | ||||
import xmltodict | |||||
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, | ||||
▲ Show 20 Lines • Show All 299 Lines • ▼ Show 20 Lines | r = put_archive( | ||||
authenticated_client, | authenticated_client, | ||||
em_iri, | em_iri, | ||||
archive2, | archive2, | ||||
HTTP_SLUG=external_id, | HTTP_SLUG=external_id, | ||||
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 ( | ||||
xmltodict.parse(r.content)["sword:error"]["summary"] | |||||
== "You can only act on deposit with status 'partial'" | |||||
) | |||||
# adding file is no longer possible since the deposit's status | # adding file is no longer possible since the deposit's status | ||||
# is ready | # is ready | ||||
r = post_archive( | r = post_archive( | ||||
authenticated_client, | authenticated_client, | ||||
em_iri, | em_iri, | ||||
archive2, | archive2, | ||||
HTTP_SLUG=external_id, | HTTP_SLUG=external_id, | ||||
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 ( | ||||
xmltodict.parse(r.content)["sword:error"]["summary"] | |||||
== "You can only act on deposit with status 'partial'" | |||||
) | |||||
# 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 = put_atom( | r = put_atom( | ||||
authenticated_client, | authenticated_client, | ||||
edit_iri, | edit_iri, | ||||
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 ( | ||||
xmltodict.parse(r.content)["sword:error"]["summary"] | |||||
== "You can only act on deposit with status 'partial'" | |||||
) | |||||
# 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 = post_atom( | r = post_atom( | ||||
authenticated_client, | authenticated_client, | ||||
se_iri, | se_iri, | ||||
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 ( | ||||
xmltodict.parse(r.content)["sword:error"]["summary"] | |||||
== "You can only act on deposit with status 'partial'" | |||||
) | |||||
archive_content = b"some content representing archive" | archive_content = b"some content representing archive" | ||||
archive = InMemoryUploadedFile( | archive = InMemoryUploadedFile( | ||||
BytesIO(archive_content), | BytesIO(archive_content), | ||||
field_name="archive0", | field_name="archive0", | ||||
name="archive0", | name="archive0", | ||||
content_type="application/zip", | content_type="application/zip", | ||||
size=len(archive_content), | size=len(archive_content), | ||||
Show All 13 Lines | ): | ||||
# deposit's status is ready | # deposit's status is ready | ||||
r = authenticated_client.put( | r = authenticated_client.put( | ||||
edit_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 ( | ||||
xmltodict.parse(r.content)["sword:error"]["summary"] | |||||
== "You can only act on deposit with status 'partial'" | |||||
) | |||||
# 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( | ||||
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 ( | ||||
xmltodict.parse(r.content)["sword:error"]["summary"] | |||||
== "You can only act on deposit with status 'partial'" | |||||
) |