Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F7123899
D4049.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Subscribers
None
D4049.diff
View Options
diff --git a/swh/deposit/api/deposit_update.py b/swh/deposit/api/deposit_update.py
--- a/swh/deposit/api/deposit_update.py
+++ b/swh/deposit/api/deposit_update.py
@@ -139,8 +139,8 @@
"""Add new metadata/archive to existing deposit.
source:
- - http://swordapp.github.io/SWORDv2-Profile/SWORDProfile.html#protocoloperations_addingcontent_metadata # noqa
- - http://swordapp.github.io/SWORDv2-Profile/SWORDProfile.html#protocoloperations_addingcontent_multipart # noqa
+ - http://swordapp.github.io/SWORDv2-Profile/SWORDProfile.html#protocoloperations_addingcontent_metadata
+ - http://swordapp.github.io/SWORDv2-Profile/SWORDProfile.html#protocoloperations_addingcontent_multipart
This also deals with an empty post corner case to finalize a
deposit.
@@ -153,16 +153,13 @@
For the empty post case, this returns a 200.
- """
+ """ # noqa
assert deposit_id is not None
if request.content_type.startswith("multipart/"):
- return (
- status.HTTP_201_CREATED,
- EM_IRI,
- self._multipart_upload(
- request, headers, collection_name, deposit_id=deposit_id
- ),
+ data = self._multipart_upload(
+ request, headers, collection_name, deposit_id=deposit_id
)
+ return (status.HTTP_201_CREATED, EM_IRI, data)
# check for final empty post
# source: http://swordapp.github.io/SWORDv2-Profile/SWORDProfile.html
# #continueddeposit_complete
@@ -170,11 +167,10 @@
data = self._empty_post(request, headers, collection_name, deposit_id)
return (status.HTTP_200_OK, EDIT_SE_IRI, data)
- return (
- status.HTTP_201_CREATED,
- EM_IRI,
- self._atom_entry(request, headers, collection_name, deposit_id=deposit_id),
+ data = self._atom_entry(
+ request, headers, collection_name, deposit_id=deposit_id
)
+ return (status.HTTP_201_CREATED, EM_IRI, data)
def process_delete(self, req, collection_name: str, deposit_id: int) -> Dict:
"""Delete the container (deposit).
diff --git a/swh/deposit/tests/api/test_deposit_update.py b/swh/deposit/tests/api/test_deposit_update.py
--- a/swh/deposit/tests/api/test_deposit_update.py
+++ b/swh/deposit/tests/api/test_deposit_update.py
@@ -230,6 +230,70 @@
assert set(requests_archive0) == set(requests_archive1)
+def test_add_both_archive_and_metadata_to_deposit(
+ authenticated_client,
+ deposit_collection,
+ partial_deposit_with_metadata,
+ atom_dataset,
+ sample_archive,
+):
+ """Scenario: Add both a new archive and new metadata to a partial deposit is ok
+
+ Response: 201
+
+ """
+ deposit = partial_deposit_with_metadata
+ requests = DepositRequest.objects.filter(deposit=deposit, type="metadata")
+ assert len(requests) == 1
+
+ requests_archive0 = DepositRequest.objects.filter(deposit=deposit, type="archive")
+ assert len(requests_archive0) == 1
+
+ update_uri = reverse(EDIT_SE_IRI, args=[deposit_collection.name, deposit.id])
+ archive = InMemoryUploadedFile(
+ BytesIO(sample_archive["data"]),
+ field_name=sample_archive["name"],
+ name=sample_archive["name"],
+ content_type="application/x-tar",
+ size=sample_archive["length"],
+ charset=None,
+ )
+
+ data_atom_entry = atom_dataset["entry-data1"]
+ atom_entry = InMemoryUploadedFile(
+ BytesIO(data_atom_entry.encode("utf-8")),
+ field_name="atom0",
+ name="atom0",
+ content_type='application/atom+xml; charset="utf-8"',
+ size=len(data_atom_entry),
+ charset="utf-8",
+ )
+
+ update_uri = reverse(EDIT_SE_IRI, args=[deposit_collection.name, deposit.id])
+ response = authenticated_client.post(
+ update_uri,
+ format="multipart",
+ data={"archive": archive, "atom_entry": atom_entry,},
+ )
+
+ assert response.status_code == status.HTTP_201_CREATED
+ requests = DepositRequest.objects.filter(deposit=deposit, type="metadata").order_by(
+ "id"
+ )
+
+ assert len(requests) == 1 + 1, "New deposit request archive got added"
+ expected_raw_meta0 = atom_dataset["entry-data0"] % (
+ deposit.external_id.encode("utf-8")
+ )
+ # a new one was added
+ assert requests[0].raw_metadata == expected_raw_meta0
+ assert requests[1].raw_metadata == data_atom_entry
+
+ # check we did not touch the other parts
+ requests_archive1 = DepositRequest.objects.filter(deposit=deposit, type="archive")
+ assert len(requests_archive1) == 1 + 1, "New deposit request metadata got added"
+
+
def test_add_metadata_to_unknown_deposit(
deposit_collection, authenticated_client, atom_dataset
):
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Dec 20 2024, 5:55 AM (11 w, 3 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3216700
Attached To
D4049: test: Update missing scenario on update metadata with multipart (post)
Event Timeline
Log In to Comment