diff --git a/docs/metadata.rst b/docs/metadata.rst --- a/docs/metadata.rst +++ b/docs/metadata.rst @@ -38,11 +38,6 @@ www.url-example.com -- **the external\_identifier** *MAY* be provided as an identifier - -- **the external\_identifier** *SHOULD* match the Slug external-identifier in - the header - - **the description** of the software deposit *SHOULD* be provided [codemeta:description]: short or long description of the software @@ -63,7 +58,6 @@ Awesome Compiler urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a - 1785io25c695 2017-10-07T15:17:08Z some awesome author @@ -78,7 +72,6 @@ xmlns:codemeta="https://doi.org/10.5063/SCHEMA/CODEMETA-2.0"> Awesome Compiler urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a - 1785io25c695 1785io25c695 origin url other identifier, DOI, ARK @@ -140,7 +133,6 @@ Awesome Compiler hal urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a - %s hal-01587361 doi:10.5281/zenodo.438684 The assignment problem diff --git a/docs/specs/metadata_example.xml b/docs/specs/metadata_example.xml --- a/docs/specs/metadata_example.xml +++ b/docs/specs/metadata_example.xml @@ -7,7 +7,6 @@ hal@ccsd.cnrs.fr hal - hal-01243573 The assignment problem https://hal.archives-ouvertes.fr/hal-01243573 other identifier, DOI, ARK diff --git a/docs/specs/spec-meta-deposit.rst b/docs/specs/spec-meta-deposit.rst --- a/docs/specs/spec-meta-deposit.rst +++ b/docs/specs/spec-meta-deposit.rst @@ -48,7 +48,6 @@ hal@ccsd.cnrs.fr hal - hal-01243573 The assignment problem https://hal.archives-ouvertes.fr/hal-01243573 other identifier, DOI, ARK diff --git a/docs/specs/spec-sparse-deposit.rst b/docs/specs/spec-sparse-deposit.rst --- a/docs/specs/spec-sparse-deposit.rst +++ b/docs/specs/spec-sparse-deposit.rst @@ -44,7 +44,6 @@ hal@ccsd.cnrs.fr hal - hal-01243573 The assignment problem https://hal.archives-ouvertes.fr/hal-01243573 other identifier, DOI, ARK diff --git a/docs/user-manual.rst b/docs/user-manual.rst --- a/docs/user-manual.rst +++ b/docs/user-manual.rst @@ -102,7 +102,6 @@ Verifiable online voting system belenios belenios-01243065 - test-01243065 https://gitlab.inria.fr/belenios/belenios test Online voting diff --git a/swh/deposit/api/common.py b/swh/deposit/api/common.py --- a/swh/deposit/api/common.py +++ b/swh/deposit/api/common.py @@ -250,7 +250,6 @@ "check-deposit", collection=deposit.collection.name, deposit_id=deposit.id, - retries_left=3, ) check_task_id = scheduler.create_tasks([task])[0]["id"] deposit.check_task_id = check_task_id @@ -773,6 +772,18 @@ "If the body is empty, there is no metadata.", ) + if ( + "atom:external_identifier" in metadata + and metadata["atom:external_identifier"] != headers.slug + ): + # TODO: When clients stopped using it, raise this error + # even when they are equal. + raise DepositError( + BAD_REQUEST, + "The 'external_identifier' tag is deprecated, " + "the Slug header should be used instead.", + ) + # Determine if we are in the metadata-only deposit case try: swhid = parse_swh_reference(metadata) @@ -781,20 +792,14 @@ PARSING_ERROR, "Invalid SWHID reference", str(e), ) - if swhid is not None: - external_id = metadata.get("external_identifier", headers.slug) - else: - slug = headers.slug - if check_slug_is_present and not slug: - raise_missing_slug_error() - - external_id = metadata.get("external_identifier", slug) + if swhid is None and check_slug_is_present and not headers.slug: + raise_missing_slug_error() deposit = self._deposit_put( request, deposit_id=deposit_id, in_progress=headers.in_progress, - external_id=external_id, + external_id=headers.slug, ) if swhid is not None: @@ -1003,7 +1008,7 @@ class APIPost(APIBase, metaclass=ABCMeta): - """Mixin for class to support POST method. + """Mixin for class to support DELETE method. """ diff --git a/swh/deposit/tests/api/test_collection.py b/swh/deposit/tests/api/test_collection.py --- a/swh/deposit/tests/api/test_collection.py +++ b/swh/deposit/tests/api/test_collection.py @@ -115,7 +115,7 @@ response = authenticated_client.post( reverse(COL_IRI, args=[deposit_collection.name]), content_type="application/atom+xml;type=entry", - data=atom_dataset["entry-data0"] % deposit.external_id, + data=atom_dataset["entry-data0"], HTTP_SLUG=deposit.external_id, ) @@ -145,7 +145,7 @@ response = authenticated_client.post( reverse(COL_IRI, args=[deposit_collection.name]), content_type="application/atom+xml;type=entry", - data=atom_dataset["entry-data0"] % deposit.external_id, + data=atom_dataset["entry-data0"], HTTP_SLUG=deposit.external_id, ) @@ -176,7 +176,7 @@ response = authenticated_client.post( reverse(COL_IRI, args=[deposit_collection.name]), content_type="application/atom+xml;type=entry", - data=atom_dataset["entry-data0"] % deposit.external_id, + data=atom_dataset["entry-data0"], HTTP_SLUG=deposit.external_id, ) diff --git a/swh/deposit/tests/api/test_collection_post_atom.py b/swh/deposit/tests/api/test_collection_post_atom.py --- a/swh/deposit/tests/api/test_collection_post_atom.py +++ b/swh/deposit/tests/api/test_collection_post_atom.py @@ -116,6 +116,29 @@ assert response.status_code == status.HTTP_400_BAD_REQUEST +def test_post_deposit_atom_with_external_identifier( + authenticated_client, deposit_collection, atom_dataset +): + """Posting an atom entry without a slug header should return a 400 + + """ + url = reverse(COL_IRI, args=[deposit_collection.name]) + + # when + response = authenticated_client.post( + url, + content_type="application/atom+xml;type=entry", + data=atom_dataset["error-with-external-identifier"], + # + headers + HTTP_IN_PROGRESS="false", + HTTP_SLUG="something", + ) + + print(response.content) + assert b"The 'external_identifier' tag is deprecated" in response.content + assert response.status_code == status.HTTP_400_BAD_REQUEST + + def test_post_deposit_atom_unknown_collection(authenticated_client, atom_dataset): """Posting an atom entry to an unknown collection should return a 404 @@ -146,7 +169,7 @@ with pytest.raises(Deposit.DoesNotExist): Deposit.objects.get(external_id=external_id) - atom_entry_data = atom_dataset["entry-data0"] % external_id + atom_entry_data = atom_dataset["entry-data0"] # when response = authenticated_client.post( @@ -187,7 +210,7 @@ with pytest.raises(Deposit.DoesNotExist): Deposit.objects.get(external_id=external_id) - atom_entry_data = atom_dataset["codemeta-sample"] % external_id + atom_entry_data = atom_dataset["codemeta-sample"] # when response = authenticated_client.post( reverse(COL_IRI, args=[deposit_collection.name]), @@ -292,9 +315,7 @@ deposit_requests = DepositRequest.objects.filter(deposit=deposit) assert len(deposit_requests) == 1 - atom_entry_data = atom_dataset["entry-data-minimal"] % external_id.encode( - "utf-8" - ) # noqa + atom_entry_data = atom_dataset["entry-data-minimal"] for link in response_content["atom:link"]: if link["@rel"] == "http://purl.org/net/sword/terms/add": @@ -312,7 +333,7 @@ ) # then - assert response.status_code == status.HTTP_201_CREATED + assert response.status_code == status.HTTP_201_CREATED, response.content response_content = parse_xml(BytesIO(response.content)) deposit_id = int(response_content["swh:deposit_id"]) 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 @@ -111,7 +111,7 @@ """ # given deposit = partial_deposit_with_metadata - raw_metadata0 = atom_dataset["entry-data0"] % deposit.external_id.encode("utf-8") + raw_metadata0 = atom_dataset["entry-data0"] requests_meta = DepositRequest.objects.filter(deposit=deposit, type="metadata") assert len(requests_meta) == 1 @@ -236,9 +236,7 @@ ) assert len(requests) == 2 - expected_raw_meta0 = atom_dataset["entry-data0"] % ( - deposit.external_id.encode("utf-8") - ) + expected_raw_meta0 = atom_dataset["entry-data0"] # a new one was added assert requests[0].raw_metadata == expected_raw_meta0 assert requests[1].raw_metadata == atom_entry @@ -301,9 +299,7 @@ ) assert len(requests) == 1 + 1, "New deposit request archive got added" - expected_raw_meta0 = atom_dataset["entry-data0"] % ( - deposit.external_id.encode("utf-8") - ) + expected_raw_meta0 = atom_dataset["entry-data0"] # a new one was added assert requests[0].raw_metadata == expected_raw_meta0 assert requests[1].raw_metadata == data_atom_entry @@ -518,7 +514,7 @@ """ # given deposit = partial_deposit_with_metadata - raw_metadata0 = atom_dataset["entry-data0"] % deposit.external_id.encode("utf-8") + raw_metadata0 = atom_dataset["entry-data0"] requests_meta = DepositRequest.objects.filter(deposit=deposit, type="metadata") assert len(requests_meta) == 1 diff --git a/swh/deposit/tests/conftest.py b/swh/deposit/tests/conftest.py --- a/swh/deposit/tests/conftest.py +++ b/swh/deposit/tests/conftest.py @@ -317,7 +317,7 @@ response = authenticated_client.post( reverse(SE_IRI, args=[collection_name, deposit.id]), content_type="application/atom+xml;type=entry", - data=atom_dataset["entry-data0"] % deposit.external_id.encode("utf-8"), + data=atom_dataset["entry-data0"], HTTP_SLUG=deposit.external_id, HTTP_IN_PROGRESS="true", ) diff --git a/swh/deposit/tests/data/atom/codemeta-sample.xml b/swh/deposit/tests/data/atom/codemeta-sample.xml --- a/swh/deposit/tests/data/atom/codemeta-sample.xml +++ b/swh/deposit/tests/data/atom/codemeta-sample.xml @@ -2,7 +2,6 @@ - %s hal-01587361 https://hal.inria.fr/hal-01587361 https://hal.inria.fr/hal-01587361/document diff --git a/swh/deposit/tests/data/atom/entry-data-minimal.xml b/swh/deposit/tests/data/atom/entry-data-minimal.xml --- a/swh/deposit/tests/data/atom/entry-data-minimal.xml +++ b/swh/deposit/tests/data/atom/entry-data-minimal.xml @@ -1,4 +1,4 @@ - %s + Awesome Compiler diff --git a/swh/deposit/tests/data/atom/entry-data0.xml b/swh/deposit/tests/data/atom/entry-data0.xml --- a/swh/deposit/tests/data/atom/entry-data0.xml +++ b/swh/deposit/tests/data/atom/entry-data0.xml @@ -3,7 +3,6 @@ Awesome Compiler hal urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a - %s 2017-10-07T15:17:08Z some awesome author something diff --git a/swh/deposit/tests/data/atom/entry-data2.xml b/swh/deposit/tests/data/atom/entry-data2.xml --- a/swh/deposit/tests/data/atom/entry-data2.xml +++ b/swh/deposit/tests/data/atom/entry-data2.xml @@ -1,6 +1,5 @@ - some-external-id https://hal-test.archives-ouvertes.fr/some-external-id some awesome author diff --git a/swh/deposit/tests/data/atom/error-with-decimal.xml b/swh/deposit/tests/data/atom/error-with-decimal.xml --- a/swh/deposit/tests/data/atom/error-with-decimal.xml +++ b/swh/deposit/tests/data/atom/error-with-decimal.xml @@ -3,7 +3,6 @@ Composing a Web of Audio Applications hal hal-01243065 - hal-01243065 https://hal-test.archives-ouvertes.fr/hal-01243065 test diff --git a/swh/deposit/tests/data/atom/error-with-external-identifier.xml b/swh/deposit/tests/data/atom/error-with-external-identifier.xml new file mode 100644 --- /dev/null +++ b/swh/deposit/tests/data/atom/error-with-external-identifier.xml @@ -0,0 +1,7 @@ + + + Composing a Web of Audio Applications + hal + hal-01243065 + hal-01243065 + diff --git a/swh/deposit/tests/data/atom/metadata.xml b/swh/deposit/tests/data/atom/metadata.xml --- a/swh/deposit/tests/data/atom/metadata.xml +++ b/swh/deposit/tests/data/atom/metadata.xml @@ -4,7 +4,6 @@ Composing a Web of Audio Applications hal hal-01243065 - hal-01243065 https://hal-test.archives-ouvertes.fr/hal-01243065 test DSP programming