Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/tests/api/test_delete.py
# Copyright (C) 2017-2019 The Software Heritage developers | # Copyright (C) 2017-2019 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 | from django.urls import reverse | ||||
from rest_framework import status | from rest_framework import status | ||||
from swh.deposit.config import ( | from swh.deposit.config import ( | ||||
ARCHIVE_KEY, | ARCHIVE_KEY, | ||||
DEPOSIT_STATUS_DEPOSITED, | DEPOSIT_STATUS_DEPOSITED, | ||||
EDIT_SE_IRI, | EDIT_IRI, | ||||
EM_IRI, | EM_IRI, | ||||
METADATA_KEY, | METADATA_KEY, | ||||
) | ) | ||||
from swh.deposit.models import Deposit, DepositRequest | from swh.deposit.models import Deposit, DepositRequest | ||||
def count_deposit_request_types(deposit_requests) -> Mapping[str, int]: | def count_deposit_request_types(deposit_requests) -> Mapping[str, int]: | ||||
deposit_request_types = defaultdict(int) # type: Dict[str, int] | deposit_request_types = defaultdict(int) # type: Dict[str, int] | ||||
▲ Show 20 Lines • Show All 70 Lines • ▼ Show 20 Lines | |||||
): | ): | ||||
"""Delete deposit should return a 204 response | """Delete deposit should return a 204 response | ||||
""" | """ | ||||
# given | # given | ||||
deposit = partial_deposit | deposit = partial_deposit | ||||
# when | # when | ||||
url = reverse(EDIT_SE_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_204_NO_CONTENT | assert response.status_code == status.HTTP_204_NO_CONTENT | ||||
deposit_requests = list(DepositRequest.objects.filter(deposit=deposit)) | deposit_requests = list(DepositRequest.objects.filter(deposit=deposit)) | ||||
assert deposit_requests == [] | assert deposit_requests == [] | ||||
deposits = list(Deposit.objects.filter(pk=deposit.id)) | deposits = list(Deposit.objects.filter(pk=deposit.id)) | ||||
assert deposits == [] | assert deposits == [] | ||||
def test_delete_on_edit_se_iri_cannot_delete_non_partial_deposit( | def test_delete_on_edit_iri_cannot_delete_non_partial_deposit( | ||||
authenticated_client, deposit_collection, complete_deposit | authenticated_client, deposit_collection, complete_deposit | ||||
): | ): | ||||
"""Delete !partial deposit should return a 400 response | """Delete !partial deposit should return a 400 response | ||||
""" | """ | ||||
# given | # given | ||||
deposit = complete_deposit | deposit = complete_deposit | ||||
# when | # when | ||||
url = reverse(EDIT_SE_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 | b"You can only act on deposit with status 'partial'" in response.content | ||||
) | ) | ||||
deposit = Deposit.objects.get(pk=deposit.id) | deposit = Deposit.objects.get(pk=deposit.id) | ||||
assert deposit is not None | assert deposit is not None |