Changeset View
Standalone View
swh/deposit/tests/api/test_deposit_update.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 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 | from django.urls import reverse | ||||
from rest_framework import status | from rest_framework import status | ||||
from swh.deposit.config import EDIT_SE_IRI, EM_IRI | from swh.deposit.config import ( | ||||
DEPOSIT_STATUS_DEPOSITED, | |||||
DEPOSIT_STATUS_PARTIAL, | |||||
EDIT_SE_IRI, | |||||
EM_IRI, | |||||
) | |||||
from swh.deposit.models import Deposit, DepositCollection, DepositRequest | from swh.deposit.models import Deposit, DepositCollection, DepositRequest | ||||
from swh.deposit.parsers import parse_xml | from swh.deposit.parsers import parse_xml | ||||
from swh.deposit.tests.common import check_archive, create_arborescence_archive | from swh.deposit.tests.common import check_archive, create_arborescence_archive | ||||
def test_replace_archive_to_deposit_is_possible( | def test_replace_archive_to_deposit_is_possible( | ||||
tmp_path, | tmp_path, | ||||
partial_deposit, | partial_deposit, | ||||
▲ Show 20 Lines • Show All 268 Lines • ▼ Show 20 Lines | ): | ||||
assert requests[0].raw_metadata == expected_raw_meta0 | assert requests[0].raw_metadata == expected_raw_meta0 | ||||
assert requests[1].raw_metadata == data_atom_entry | assert requests[1].raw_metadata == data_atom_entry | ||||
# check we did not touch the other parts | # check we did not touch the other parts | ||||
requests_archive1 = DepositRequest.objects.filter(deposit=deposit, type="archive") | requests_archive1 = DepositRequest.objects.filter(deposit=deposit, type="archive") | ||||
assert len(requests_archive1) == 1 + 1, "New deposit request metadata got added" | assert len(requests_archive1) == 1 + 1, "New deposit request metadata got added" | ||||
def test_post_metadata_empty_post_finalize_deposit_ok( | |||||
authenticated_client, | |||||
deposit_collection, | |||||
partial_deposit_with_metadata, | |||||
atom_dataset, | |||||
): | |||||
"""Empty atom post entry with header in-progress to false transitions deposit to | |||||
moranegg: I actually don't get which scenario is tested.
Let's see:
empty atom is the xml -> no xml file? | |||||
Done Inline ActionsI'm testing the conditional in the deposit_update.py code above (which is orange in You can check that the blue near the scrollbar which says 'alright, we passed [1] not covered in the previous diffs i opened, which adds coverage to some ardumont: I'm testing the conditional in the `deposit_update.py` code above (which is orange in
another… | |||||
'deposited' status | |||||
Response: 200 | |||||
""" | |||||
deposit = partial_deposit_with_metadata | |||||
Not Done Inline Actionschecking that the deposit is still in-progress moranegg: checking that the deposit is still in-progress | |||||
Done Inline Actionsyes, but the assert is enough to say as much. ardumont: yes, but the assert is enough to say as much. | |||||
assert deposit.status == DEPOSIT_STATUS_PARTIAL | |||||
update_uri = reverse(EDIT_SE_IRI, args=[deposit_collection.name, deposit.id]) | |||||
response = authenticated_client.post( | |||||
update_uri, | |||||
content_type="application/atom+xml;type=entry", | |||||
data="", | |||||
size=0, | |||||
HTTP_IN_PROGRESS=False, | |||||
) | |||||
assert response.status_code == status.HTTP_200_OK | |||||
deposit = Deposit.objects.get(pk=deposit.id) | |||||
Not Done Inline Actionshere it's deposited. moranegg: here it's `deposited`.
So there was an update for a `partial` deposit with only metadata. right? | |||||
Done Inline ActionsIt did not do anything but transitions the status from partial to deposited (the deposit already has the necessary archive and metadata). ardumont: It did not do anything but transitions the status from partial to deposited (the deposit… | |||||
assert deposit.status == DEPOSIT_STATUS_DEPOSITED | |||||
def test_add_metadata_to_unknown_deposit( | def test_add_metadata_to_unknown_deposit( | ||||
deposit_collection, authenticated_client, atom_dataset | deposit_collection, authenticated_client, atom_dataset | ||||
): | ): | ||||
"""Replacing metadata to unknown deposit should return a 404 response | """Replacing metadata to unknown deposit should return a 404 response | ||||
""" | """ | ||||
unknown_deposit_id = 1000 | unknown_deposit_id = 1000 | ||||
try: | try: | ||||
▲ Show 20 Lines • Show All 225 Lines • Show Last 20 Lines |
I actually don't get which scenario is tested.
Let's see:
empty atom is the xml -> no xml file?
it's a POST (so not an update, so for now it can't be just metadata).
header is in-progress
Clarify in docstring