diff --git a/swh/deposit/api/checks.py b/swh/deposit/api/checks.py index 2243aee8d12c894d37fb4c46e46c8806bb4e5ed4..0c5888e9a0a77b8f04112e810fd458bdad8b7452 100644 --- a/swh/deposit/api/checks.py +++ b/swh/deposit/api/checks.py @@ -120,6 +120,19 @@ def check_metadata(metadata: ElementTree.Element) -> Tuple[bool, Optional[Dict]] - (False, <detailed-error>) otherwise. """ + if metadata.tag != "{http://www.w3.org/2005/Atom}entry": + return False, { + "metadata": [ + { + "fields": ["atom:entry"], + "summary": ( + "Root element should be {http://www.w3.org/2005/Atom}entry, " + f"but it is {metadata.tag}" + ), + } + ] + } + suggested_fields = [] # at least one value per couple below is mandatory alternate_fields = { diff --git a/swh/deposit/tests/api/test_checks.py b/swh/deposit/tests/api/test_checks.py index b287d3580db4e71163530df59c3decde422cd547..1c471b8d5e2c67d84457b01499a0c765b9813942 100644 --- a/swh/deposit/tests/api/test_checks.py +++ b/swh/deposit/tests/api/test_checks.py @@ -458,6 +458,89 @@ _parameters2 = [ "fields": ["atom:author or codemeta:author"], }, ), + ( + "wrong-root-element", + f"""\ + <not-entry {XMLNS}> + <url>some url</url> + <title>bar</title> + <codemeta:author> + <codemeta:name>someone</codemeta:name> + <codemeta:name>an alias</codemeta:name> + </codemeta:author> + {PROVENANCE_XML} + </not-entry> + """, + { + "fields": ["atom:entry"], + "summary": "Root element should be " + "{http://www.w3.org/2005/Atom}entry, but it is " + "{http://www.w3.org/2005/Atom}not-entry", + }, + ), + ( + "wrong-root-element-namespace", + f"""\ + <codemeta:entry {XMLNS}> + <url>some url</url> + <title>bar</title> + <codemeta:author> + <codemeta:name>someone</codemeta:name> + <codemeta:name>an alias</codemeta:name> + </codemeta:author> + </codemeta:entry> + """, + { + "fields": ["atom:entry"], + "summary": "Root element should be " + "{http://www.w3.org/2005/Atom}entry, but it is " + "{https://doi.org/10.5063/SCHEMA/CODEMETA-2.0}entry", + }, + ), + ( + "wrong-root-element-no-namespace", + f"""\ + <entry xmlns:atom="http://www.w3.org/2005/Atom" + xmlns:swh="https://www.softwareheritage.org/schema/2018/deposit" + xmlns:codemeta="https://doi.org/10.5063/SCHEMA/CODEMETA-2.0" + xmlns:schema="http://schema.org/"> + <atom:url>some url</atom:url> + <codemeta:name>bar</codemeta:name> + <title>bar</title> + <codemeta:author> + <codemeta:name>someone</codemeta:name> + <codemeta:name>an alias</codemeta:name> + </codemeta:author> + </entry> + """, + { + "fields": ["atom:entry"], + "summary": "Root element should be " + "{http://www.w3.org/2005/Atom}entry, but it is entry", + }, + ), + ( + "wrong-root-element-default-namespace", + f"""\ + <entry xmlns:atom="http://www.w3.org/2005/Atom" + xmlns:swh="https://www.softwareheritage.org/schema/2018/deposit" + xmlns="https://doi.org/10.5063/SCHEMA/CODEMETA-2.0" + xmlns:schema="http://schema.org/"> + <atom:url>some url</atom:url> + <name>bar</name> + <author> + <name>someone</name> + <name>an alias</name> + </author> + </entry> + """, + { + "fields": ["atom:entry"], + "summary": "Root element should be " + "{http://www.w3.org/2005/Atom}entry, but it is " + "{https://doi.org/10.5063/SCHEMA/CODEMETA-2.0}entry", + }, + ), ( "wrong-title-namespace", f"""\ @@ -477,16 +560,16 @@ _parameters2 = [ ( "wrong-author-namespace", f"""\ - <entry xmlns:atom="http://www.w3.org/2005/Atom" - xmlns:swh="https://www.softwareheritage.org/schema/2018/deposit" - xmlns:codemeta="https://doi.org/10.5063/SCHEMA/CODEMETA-2.0" - xmlns:schema="http://schema.org/"> + <atom:entry xmlns:atom="http://www.w3.org/2005/Atom" + xmlns:swh="https://www.softwareheritage.org/schema/2018/deposit" + xmlns:codemeta="https://doi.org/10.5063/SCHEMA/CODEMETA-2.0" + xmlns:schema="http://schema.org/"> <atom:url>something</atom:url> <atom:external_identifier>something-else</atom:external_identifier> <atom:title>foobar</atom:title> <author>foo</author> {PROVENANCE_XML} - </entry> + </atom:entry> """, { "summary": "Mandatory fields are missing",