diff --git a/swh/deposit/api/checks.py b/swh/deposit/api/checks.py --- a/swh/deposit/api/checks.py +++ b/swh/deposit/api/checks.py @@ -30,11 +30,11 @@ """ # following fields are mandatory required_fields = { - "author": False, + "atom:author": False, } # at least one value per couple below is mandatory alternate_fields = { - ("name", "title"): False, + ("atom:name", "atom:title"): False, } for field, value in metadata.items(): diff --git a/swh/deposit/cli/client.py b/swh/deposit/cli/client.py --- a/swh/deposit/cli/client.py +++ b/swh/deposit/cli/client.py @@ -95,7 +95,7 @@ # generate a metadata file with the minimum required metadata codemetadata = { - "entry": { + "atom:entry": { "@xmlns:atom": "http://www.w3.org/2005/Atom", "@xmlns:codemeta": "https://doi.org/10.5063/SCHEMA/CODEMETA-2.0", "codemeta:identifier": external_id, diff --git a/swh/deposit/tests/api/test_checks.py b/swh/deposit/tests/api/test_checks.py --- a/swh/deposit/tests/api/test_checks.py +++ b/swh/deposit/tests/api/test_checks.py @@ -12,16 +12,16 @@ "metadata_ok", [ { - "url": "something", - "external_identifier": "something-else", - "name": "foo", - "author": "someone", + "atom:url": "something", + "atom:external_identifier": "something-else", + "atom:name": "foo", + "atom:author": "someone", }, { - "url": "some url", - "external_identifier": "some id", - "title": "bar", - "author": "no one", + "atom:url": "some url", + "atom:external_identifier": "some id", + "atom:title": "bar", + "atom:author": "no one", }, ], ) @@ -36,22 +36,22 @@ [ ( { - "url": "something", - "external_identifier": "something-else", - "author": "someone", + "atom:url": "something", + "atom:external_identifier": "something-else", + "atom:author": "someone", }, { "summary": "Mandatory alternate fields are missing", - "fields": ["name or title"], + "fields": ["atom:name or atom:title"], }, ), ( { - "url": "something", - "external_identifier": "something-else", - "title": "foobar", + "atom:url": "something", + "atom:external_identifier": "something-else", + "atom:title": "foobar", }, - {"summary": "Mandatory fields are missing", "fields": ["author"],}, + {"summary": "Mandatory fields are missing", "fields": ["atom:author"],}, ), ], ) 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 @@ -52,16 +52,15 @@ """Posting empty body request should return a 400 response """ - for atom_key in ["entry-data-empty-body", "entry-data-empty-body-no-namespace"]: - atom_content = atom_dataset[atom_key] - response = authenticated_client.post( - reverse(COL_IRI, args=[deposit_collection.name]), - content_type="application/atom+xml;type=entry", - data=atom_content, - HTTP_SLUG="external-id", - ) - assert response.status_code == status.HTTP_400_BAD_REQUEST - assert b"Empty body request is not supported" in response.content + atom_content = atom_dataset["entry-data-empty-body"] + response = authenticated_client.post( + reverse(COL_IRI, args=[deposit_collection.name]), + content_type="application/atom+xml;type=entry", + data=atom_content, + HTTP_SLUG="external-id", + ) + assert response.status_code == status.HTTP_400_BAD_REQUEST + assert b"Empty body request is not supported" in response.content def test_post_deposit_atom_400_badly_formatted_atom( @@ -297,7 +296,7 @@ "utf-8" ) # noqa - for link in response_content["link"]: + for link in response_content["atom:link"]: if link["@rel"] == "http://purl.org/net/sword/terms/add": se_iri = link["@href"] break diff --git a/swh/deposit/tests/api/test_collection_post_binary.py b/swh/deposit/tests/api/test_collection_post_binary.py --- a/swh/deposit/tests/api/test_collection_post_binary.py +++ b/swh/deposit/tests/api/test_collection_post_binary.py @@ -125,9 +125,9 @@ assert response_content["swh:deposit_status"] == deposit.status # deprecated tags - assert response_content["deposit_archive"] == sample_archive["name"] - assert int(response_content["swh:deposit_id"]) == deposit.id - assert response_content["deposit_status"] == deposit.status + assert response_content["atom:deposit_archive"] == sample_archive["name"] + assert int(response_content["atom:deposit_id"]) == deposit.id + assert response_content["atom:deposit_status"] == deposit.status edit_iri = reverse("edit_iri", args=[deposit_collection.name, deposit.id]) diff --git a/swh/deposit/tests/api/test_collection_post_multipart.py b/swh/deposit/tests/api/test_collection_post_multipart.py --- a/swh/deposit/tests/api/test_collection_post_multipart.py +++ b/swh/deposit/tests/api/test_collection_post_multipart.py @@ -119,7 +119,7 @@ assert deposit_request.raw_metadata is None else: assert ( - deposit_request.metadata["id"] + deposit_request.metadata["atom:id"] == "urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a" ) assert deposit_request.raw_metadata == data_atom_entry @@ -189,7 +189,7 @@ assert deposit_request.raw_metadata is None else: assert ( - deposit_request.metadata["id"] + deposit_request.metadata["atom:id"] == "urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a" ) assert deposit_request.raw_metadata == data_atom_entry @@ -258,7 +258,7 @@ check_archive(sample_archive["name"], deposit_request.archive.name) else: assert ( - deposit_request.metadata["id"] + deposit_request.metadata["atom:id"] == "urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a" ) assert deposit_request.raw_metadata == data_atom_entry @@ -288,7 +288,7 @@ check_archive(sample_archive["name"], deposit_request.archive.name) else: assert ( - deposit_request.metadata["id"] + deposit_request.metadata["atom:id"] == "urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a" ) assert ( diff --git a/swh/deposit/tests/api/test_deposit_private_check.py b/swh/deposit/tests/api/test_deposit_private_check.py --- a/swh/deposit/tests/api/test_deposit_private_check.py +++ b/swh/deposit/tests/api/test_deposit_private_check.py @@ -133,10 +133,10 @@ assert len(details["metadata"]) == 2 mandatory = details["metadata"][0] assert mandatory["summary"] == MANDATORY_FIELDS_MISSING - assert set(mandatory["fields"]) == set(["author"]) + assert set(mandatory["fields"]) == set(["atom:author"]) alternate = details["metadata"][1] assert alternate["summary"] == ALTERNATE_FIELDS_MISSING - assert alternate["fields"] == ["name or title"] + assert alternate["fields"] == ["atom:name or atom:title"] deposit = Deposit.objects.get(pk=deposit.id) assert deposit.status == DEPOSIT_STATUS_REJECTED 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 @@ -362,7 +362,7 @@ ) assert response.status_code == status.HTTP_404_NOT_FOUND response_content = parse_xml(response.content) - assert "Unknown collection name" in response_content["sword:error"]["summary"] + assert "Unknown collection name" in response_content["sword:error"]["atom:summary"] def test_add_metadata_to_unknown_collection( @@ -386,7 +386,7 @@ ) assert response.status_code == status.HTTP_404_NOT_FOUND response_content = parse_xml(response.content) - assert "Unknown collection name" in response_content["sword:error"]["summary"] + assert "Unknown collection name" in response_content["sword:error"]["atom:summary"] def test_replace_metadata_to_unknown_deposit( @@ -410,7 +410,7 @@ response_content = parse_xml(response.content) assert ( "Deposit %s does not exist" % unknown_deposit_id - == response_content["sword:error"]["summary"] + == response_content["sword:error"]["atom:summary"] ) @@ -434,7 +434,7 @@ response_content = parse_xml(response.content) assert ( "Deposit %s does not exist" % unknown_deposit_id - == response_content["sword:error"]["summary"] + == response_content["sword:error"]["atom:summary"] ) @@ -458,7 +458,7 @@ response_content = parse_xml(response.content) assert ( "Deposit %s does not exist" % unknown_deposit_id - == response_content["sword:error"]["summary"] + == response_content["sword:error"]["atom:summary"] ) @@ -751,17 +751,16 @@ """ update_uri = reverse(EDIT_IRI, args=[deposit_collection.name, complete_deposit.id]) - for atom_key in ["entry-data-empty-body", "entry-data-empty-body-no-namespace"]: - atom_content = atom_dataset[atom_key] - response = authenticated_client.put( - update_uri, - content_type="application/atom+xml;type=entry", - data=atom_content, - HTTP_X_CHECK_SWHID=complete_deposit.swhid, - ) + atom_content = atom_dataset["entry-data-empty-body"] + response = authenticated_client.put( + update_uri, + content_type="application/atom+xml;type=entry", + data=atom_content, + HTTP_X_CHECK_SWHID=complete_deposit.swhid, + ) - assert response.status_code == status.HTTP_400_BAD_REQUEST - assert b"Empty body request is not supported" in response.content + assert response.status_code == status.HTTP_400_BAD_REQUEST + assert b"Empty body request is not supported" in response.content def test_put_update_metadata_done_deposit_failure_functional_checks( @@ -790,7 +789,8 @@ assert response.status_code == status.HTTP_400_BAD_REQUEST assert b"Functional metadata checks failure" in response.content # detail on the errors - assert b"- Mandatory fields are missing (author)" in response.content + assert b"- Mandatory fields are missing (atom:author)" in response.content assert ( - b"- Mandatory alternate fields are missing (name or title)" in response.content + b"- Mandatory alternate fields are missing (atom:name or atom:title)" + in response.content ) diff --git a/swh/deposit/tests/api/test_parsers.py b/swh/deposit/tests/api/test_parsers.py --- a/swh/deposit/tests/api/test_parsers.py +++ b/swh/deposit/tests/api/test_parsers.py @@ -36,7 +36,7 @@ actual_result = SWHXMLParser().parse(xml_no_duplicate) expected_dict = OrderedDict( [ - ("title", "Awesome Compiler"), + ("atom:title", "Awesome Compiler"), ( "codemeta:license", OrderedDict( @@ -94,7 +94,7 @@ expected_dict = OrderedDict( [ - ("title", "Another Compiler"), + ("atom:title", "Another Compiler"), ("codemeta:runtimePlatform", ["GNU/Linux", "Un*x"]), ( "codemeta:license", diff --git a/swh/deposit/tests/cli/test_client.py b/swh/deposit/tests/cli/test_client.py --- a/swh/deposit/tests/cli/test_client.py +++ b/swh/deposit/tests/cli/test_client.py @@ -134,9 +134,9 @@ ) actual_metadata = dict(parse_xml(actual_metadata_xml)) - assert actual_metadata["author"] == "deposit-client" - assert actual_metadata["title"] == "project-name" - assert actual_metadata["updated"] is not None + assert actual_metadata["atom:author"] == "deposit-client" + assert actual_metadata["atom:title"] == "project-name" + assert actual_metadata["atom:updated"] is not None assert actual_metadata["codemeta:name"] == "project-name" assert actual_metadata["codemeta:identifier"] == "external-id" assert actual_metadata["codemeta:author"] == [ @@ -185,10 +185,10 @@ with open(metadata_path) as fd: actual_metadata = dict(parse_xml(fd.read())) - assert actual_metadata["author"] == TEST_USER["username"] + assert actual_metadata["atom:author"] == TEST_USER["username"] assert actual_metadata["codemeta:name"] == "test-project" - assert actual_metadata["title"] == "test-project" - assert actual_metadata["updated"] is not None + assert actual_metadata["atom:title"] == "test-project" + assert actual_metadata["atom:updated"] is not None assert actual_metadata["codemeta:identifier"] == slug assert actual_metadata["codemeta:author"] == OrderedDict( [("codemeta:name", "Jane Doe")] diff --git a/swh/deposit/tests/data/atom/entry-data-empty-body-no-namespace.xml b/swh/deposit/tests/data/atom/entry-data-empty-body-no-namespace.xml deleted file mode 100644 --- a/swh/deposit/tests/data/atom/entry-data-empty-body-no-namespace.xml +++ /dev/null @@ -1,2 +0,0 @@ - - diff --git a/swh/deposit/utils.py b/swh/deposit/utils.py --- a/swh/deposit/utils.py +++ b/swh/deposit/utils.py @@ -15,7 +15,7 @@ def parse_xml(stream, encoding="utf-8"): namespaces = { - "http://www.w3.org/2005/Atom": None, + "http://www.w3.org/2005/Atom": "atom", "http://www.w3.org/2007/app": "app", "http://purl.org/dc/terms/": "dc", "https://doi.org/10.5063/SCHEMA/CODEMETA-2.0": "codemeta", @@ -26,8 +26,8 @@ data = xmltodict.parse( stream, encoding=encoding, namespaces=namespaces, process_namespaces=True ) - if "entry" in data: - data = data["entry"] + if "atom:entry" in data: + data = data["atom:entry"] return data