Page MenuHomeSoftware Heritage

D7227.diff
No OneTemporary

D7227.diff

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
@@ -604,16 +604,24 @@
from xml.etree import ElementTree
from swh.deposit.client import PublicApiDepositClient
- from swh.deposit.utils import parse_swh_reference
+ from swh.deposit.utils import parse_swh_metadata_provenance, parse_swh_reference
# Parse to check for a swhid presence within the metadata file
with open(metadata_path, "r") as f:
metadata_raw = f.read()
- actual_swhid = parse_swh_reference(ElementTree.fromstring(metadata_raw))
+ metadata_tree = ElementTree.fromstring(metadata_raw)
+ actual_swhid = parse_swh_reference(metadata_tree)
if not actual_swhid:
raise InputError("A SWHID must be provided for a metadata-only deposit")
+ meta_prov_url = parse_swh_metadata_provenance(metadata_tree)
+ if not meta_prov_url:
+ logger.warning(
+ "A '<swh:metadata-provenance>' should be provided for a metadata-only "
+ "deposit"
+ )
+
with trap_and_report_exceptions():
client = PublicApiDepositClient(url=_url(url), auth=(username, password))
collection = _collection(client)
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
@@ -8,6 +8,7 @@
import json
import logging
import os
+from typing import Optional
from unittest.mock import MagicMock
from xml.etree import ElementTree
@@ -860,8 +861,17 @@
}
+@pytest.mark.parametrize(
+ "metadata_entry_key", ["entry-data-with-swhid", "entry-data-with-swhid-no-prov"]
+)
def test_cli_metadata_only_deposit_full_metadata_file(
- datadir, requests_mock_datadir, cli_runner, atom_dataset, tmp_path,
+ datadir,
+ requests_mock_datadir,
+ cli_runner,
+ atom_dataset,
+ tmp_path,
+ metadata_entry_key,
+ caplog,
):
"""Post metadata-only deposit through cli
@@ -870,7 +880,7 @@
"""
api_url_basename = "deposit.test.metadataonly"
swhid = "swh:1:dir:ef04a768181417fbc5eef4243e2507915f24deea"
- metadata = atom_dataset["entry-data-with-swhid"].format(swhid=swhid)
+ metadata = atom_dataset[metadata_entry_key].format(swhid=swhid)
metadata_path = os.path.join(tmp_path, "entry-data-with-swhid.xml")
with open(metadata_path, "w") as m:
m.write(metadata)
@@ -901,6 +911,19 @@
assert "error" not in actual_deposit_status
assert actual_deposit_status == expected_deposit_status
+ count_warnings = 0
+ warning_record: Optional[str] = None
+ for (_, log_level, msg) in caplog.record_tuples:
+ if log_level == logging.WARNING:
+ count_warnings += 1
+ warning_record = msg
+
+ if "no-prov" in metadata_entry_key:
+ assert count_warnings == 1
+ assert "metadata-provenance>' should be provided" in warning_record
+ else:
+ assert count_warnings == 0
+
def test_cli_metadata_only_deposit_invalid_swhid(
datadir, requests_mock_datadir, cli_runner, atom_dataset, tmp_path,
diff --git a/swh/deposit/tests/data/atom/entry-data-with-swhid.xml b/swh/deposit/tests/data/atom/entry-data-with-swhid-no-prov.xml
copy from swh/deposit/tests/data/atom/entry-data-with-swhid.xml
copy to swh/deposit/tests/data/atom/entry-data-with-swhid-no-prov.xml
diff --git a/swh/deposit/tests/data/atom/entry-data-with-swhid.xml b/swh/deposit/tests/data/atom/entry-data-with-swhid.xml
--- a/swh/deposit/tests/data/atom/entry-data-with-swhid.xml
+++ b/swh/deposit/tests/data/atom/entry-data-with-swhid.xml
@@ -1,6 +1,7 @@
<?xml version="1.0"?>
<entry xmlns="http://www.w3.org/2005/Atom"
xmlns:codemeta="https://doi.org/10.5063/SCHEMA/CODEMETA-2.0"
+ xmlns:schema="http://schema.org/"
xmlns:swh="https://www.softwareheritage.org/schema/2018/deposit">
<title>Awesome Compiler</title>
<id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>
@@ -9,5 +10,8 @@
<swh:reference>
<swh:object swhid="{swhid}" />
</swh:reference>
+ <swh:metadata-provenance>
+ <schema:url>https://inria.halpreprod.archives-ouvertes.fr/hal-abcdefgh</schema:url>
+ </swh:metadata-provenance>
</swh:deposit>
</entry>

File Metadata

Mime Type
text/plain
Expires
Dec 21 2024, 9:56 PM (11 w, 4 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3215613

Event Timeline