Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/tests/api/test_delete.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 | ||||
from collections import defaultdict | from collections import defaultdict | ||||
from typing import Dict, Mapping | from typing import Dict, Mapping | ||||
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 ( | from swh.deposit.config import ( | ||||
ARCHIVE_KEY, | ARCHIVE_KEY, | ||||
DEPOSIT_STATUS_DEPOSITED, | DEPOSIT_STATUS_DEPOSITED, | ||||
EDIT_IRI, | EDIT_IRI, | ||||
EM_IRI, | EM_IRI, | ||||
METADATA_KEY, | METADATA_KEY, | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | ): | ||||
assert deposit.status == DEPOSIT_STATUS_DEPOSITED | assert deposit.status == DEPOSIT_STATUS_DEPOSITED | ||||
# when | # when | ||||
update_uri = reverse(EM_IRI, args=[deposit_collection.name, deposit.id]) | update_uri = reverse(EM_IRI, args=[deposit_collection.name, deposit.id]) | ||||
response = authenticated_client.delete(update_uri) | response = authenticated_client.delete(update_uri) | ||||
# then | # then | ||||
assert response.status_code == status.HTTP_400_BAD_REQUEST | assert response.status_code == status.HTTP_400_BAD_REQUEST | ||||
assert ( | assert ( | ||||
b"You can only act on deposit with status 'partial'" in response.content | xmltodict.parse(response.content)["sword:error"]["summary"] | ||||
== "You can only act on deposit with status 'partial'" | |||||
) | ) | ||||
deposit = Deposit.objects.get(pk=deposit.id) | deposit = Deposit.objects.get(pk=deposit.id) | ||||
assert deposit is not None | assert deposit is not None | ||||
def test_delete_partial_deposit( | def test_delete_partial_deposit( | ||||
authenticated_client, deposit_collection, partial_deposit | authenticated_client, deposit_collection, partial_deposit | ||||
Show All 25 Lines | ): | ||||
deposit = complete_deposit | deposit = complete_deposit | ||||
# when | # when | ||||
url = reverse(EDIT_IRI, args=[deposit_collection.name, deposit.id]) | url = reverse(EDIT_IRI, args=[deposit_collection.name, deposit.id]) | ||||
response = authenticated_client.delete(url) | response = authenticated_client.delete(url) | ||||
# then | # then | ||||
assert response.status_code == status.HTTP_400_BAD_REQUEST | assert response.status_code == status.HTTP_400_BAD_REQUEST | ||||
assert ( | assert ( | ||||
b"You can only act on deposit with status 'partial'" in response.content | xmltodict.parse(response.content)["sword:error"]["summary"] | ||||
== "You can only act on deposit with status 'partial'" | |||||
) | ) | ||||
deposit = Deposit.objects.get(pk=deposit.id) | deposit = Deposit.objects.get(pk=deposit.id) | ||||
assert deposit is not None | assert deposit is not None |