Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F9697750
D5770.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
8 KB
Subscribers
None
D5770.diff
View Options
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
@@ -516,7 +516,7 @@
url = _url(url)
logger.debug("Status deposit")
with trap_and_report_exceptions():
- client = PublicApiDepositClient(url=url, auth=(username, password))
+ client = PublicApiDepositClient(url=_url(url), auth=(username, password))
collection = _collection(client)
print_result(
@@ -573,3 +573,29 @@
result = client.deposit_metadata_only(collection, metadata_path)
print_result(result, output_format)
+
+
+@deposit.command("list")
+@credentials_decorator
+@output_format_decorator
+@click.option(
+ "--page", default=1, help="Page number when requesting more information",
+)
+@click.option(
+ "--page-size", default=100, help="Page number when requesting more information",
+)
+@click.pass_context
+def deposit_list(ctx, url, username, password, output_format, page, page_size):
+ """Deposit metadata only upload
+
+ """
+ from swh.deposit.client import PublicApiDepositClient
+
+ url = _url(url)
+ logger.debug("List deposits for user %s", username)
+ with trap_and_report_exceptions():
+ client = PublicApiDepositClient(url=_url(url), auth=(username, password))
+ collection = _collection(client)
+ result = client.deposit_list(collection, page=page, page_size=page_size)
+
+ print_result(result, output_format)
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
@@ -645,7 +645,7 @@
@pytest.mark.parametrize(
- "output_format,callable_fn",
+ "output_format,parser_fn",
[
("json", json.loads),
("yaml", yaml.safe_load),
@@ -656,7 +656,7 @@
],
)
def test_cli_deposit_status_with_output_format(
- output_format, callable_fn, datadir, slug, requests_mock_datadir, caplog, cli_runner
+ output_format, parser_fn, datadir, slug, requests_mock_datadir, caplog, cli_runner
):
"""Check deposit status cli with all possible output formats (json, yaml, logging).
@@ -697,7 +697,7 @@
else:
result_output = result.output
- actual_deposit = callable_fn(result_output)
+ actual_deposit = parser_fn(result_output)
assert actual_deposit == expected_deposit_status
@@ -956,3 +956,78 @@
actual_error = api_call.parse_result_error(error_xml)
assert actual_error == {"error": summary}
+
+
+@pytest.mark.parametrize(
+ "output_format,parser_fn",
+ [
+ ("json", json.loads),
+ ("yaml", yaml.safe_load),
+ (
+ "logging",
+ ast.literal_eval,
+ ), # not enough though, the caplog fixture is needed
+ ],
+)
+def test_cli_deposit_collection_list(
+ output_format, parser_fn, datadir, slug, requests_mock_datadir, caplog, cli_runner
+):
+ """Check deposit status cli with all possible output formats (json, yaml, logging).
+
+ """
+ api_url_basename = "deposit.test.list"
+
+ expected_deposits = {
+ "count": "3",
+ "deposits": [
+ {
+ "external_id": "check-deposit-2020-10-09T13:10:00.000000",
+ "id": "1031",
+ "status": "rejected",
+ "status_detail": "Deposit without archive",
+ },
+ {
+ "external_id": "check-deposit-2020-10-10T13:20:00.000000",
+ "id": "1032",
+ "status": "rejected",
+ "status_detail": "Deposit without archive",
+ },
+ {
+ "complete_date": "2020-10-08T13:52:34.509655",
+ "external_id": "check-deposit-2020-10-08T13:52:34.509655",
+ "id": "1033",
+ "reception_date": "2020-10-08T13:50:30",
+ "status": "done",
+ "status_detail": "The deposit has been successfully loaded into "
+ "the Software Heritage archive",
+ "swhid": "swh:1:dir:ef04a768181417fbc5eef4243e2507915f24deea",
+ "swhid_context": "swh:1:dir:ef04a768181417fbc5eef4243e2507915f24deea;origin=https://www.softwareheritage.org/check-deposit-2020-10-08T13:52:34.509655;visit=swh:1:snp:c477c6ef51833127b13a86ece7d75e5b3cc4e93d;anchor=swh:1:rev:f26f3960c175f15f6e24200171d446b86f6f7230;path=/", # noqa
+ },
+ ],
+ }
+
+ # fmt: off
+ result = cli_runner.invoke(
+ cli,
+ [
+ "list",
+ "--url", f"https://{api_url_basename}/1",
+ "--username", TEST_USER["username"],
+ "--password", TEST_USER["password"],
+ "--page", 1,
+ "--page-size", 10,
+ "--format", output_format,
+ ],
+ )
+ # fmt: on
+ assert result.exit_code == 0, f"unexpected output: {result.output}"
+
+ if output_format == "logging":
+ assert len(caplog.record_tuples) == 1
+ # format: (<module>, <log-level>, <log-msg>)
+ _, _, result_output = caplog.record_tuples[0]
+ else:
+ result_output = result.output
+
+ actual_deposit = parser_fn(result_output)
+ assert actual_deposit == expected_deposits
diff --git a/swh/deposit/tests/data/https_deposit.test.list/1_servicedocument b/swh/deposit/tests/data/https_deposit.test.list/1_servicedocument
new file mode 100644
--- /dev/null
+++ b/swh/deposit/tests/data/https_deposit.test.list/1_servicedocument
@@ -0,0 +1,26 @@
+<?xml version="1.0" ?>
+<service xmlns:dcterms="http://purl.org/dc/terms/"
+ xmlns:sword="http://purl.org/net/sword/terms/"
+ xmlns:atom="http://www.w3.org/2005/Atom"
+ xmlns="http://www.w3.org/2007/app">
+
+ <sword:version>2.0</sword:version>
+ <sword:maxUploadSize>209715200</sword:maxUploadSize>
+
+ <workspace>
+ <atom:title>The Software Heritage (SWH) Archive</atom:title>
+ <collection href="test">
+ <atom:title>test Software Collection</atom:title>
+ <accept>application/zip</accept>
+ <accept>application/x-tar</accept>
+ <sword:collectionPolicy>Collection Policy</sword:collectionPolicy>
+ <dcterms:abstract>Software Heritage Archive</dcterms:abstract>
+ <sword:treatment>Collect, Preserve, Share</sword:treatment>
+ <sword:mediation>false</sword:mediation>
+ <sword:metadataRelevantHeader>false</sword:metadataRelevantHeader>
+ <sword:acceptPackaging>http://purl.org/net/sword/package/SimpleZip</sword:acceptPackaging>
+ <sword:service>https://deposit.test.status/1/test/</sword:service>
+ <sword:name>test</sword:name>
+ </collection>
+ </workspace>
+</service>
diff --git a/swh/deposit/tests/data/https_deposit.test.list/1_test,page=1,page_size=10 b/swh/deposit/tests/data/https_deposit.test.list/1_test,page=1,page_size=10
new file mode 100644
--- /dev/null
+++ b/swh/deposit/tests/data/https_deposit.test.list/1_test,page=1,page_size=10
@@ -0,0 +1,28 @@
+<feed xmlns="http://www.w3.org/2005/Atom"
+ xmlns:sword="http://purl.org/net/sword/terms/"
+ xmlns:dcterms="http://purl.org/dc/terms/"
+ xmlns:sd="https://www.softwareheritage.org/schema/2018/deposit">
+ <sd:count>3</sd:count>
+ <entry>
+ <sd:id>1031</sd:id>
+ <sd:status>rejected</sd:status>
+ <sd:status_detail>Deposit without archive</sd:status_detail>
+ <sd:external_id>check-deposit-2020-10-09T13:10:00.000000</sd:external_id>
+ </entry>
+ <entry>
+ <sd:id>1032</sd:id>
+ <sd:status>rejected</sd:status>
+ <sd:status_detail>Deposit without archive</sd:status_detail>
+ <sd:external_id>check-deposit-2020-10-10T13:20:00.000000</sd:external_id>
+ </entry>
+ <entry>
+ <sd:id>1033</sd:id>
+ <sd:reception_date>2020-10-08T13:50:30</sd:reception_date>
+ <sd:complete_date>2020-10-08T13:52:34.509655</sd:complete_date>
+ <sd:status>done</sd:status>
+ <sd:status_detail>The deposit has been successfully loaded into the Software Heritage archive</sd:status_detail>
+ <sd:swhid>swh:1:dir:ef04a768181417fbc5eef4243e2507915f24deea</sd:swhid>
+ <sd:swhid_context>swh:1:dir:ef04a768181417fbc5eef4243e2507915f24deea;origin=https://www.softwareheritage.org/check-deposit-2020-10-08T13:52:34.509655;visit=swh:1:snp:c477c6ef51833127b13a86ece7d75e5b3cc4e93d;anchor=swh:1:rev:f26f3960c175f15f6e24200171d446b86f6f7230;path=/</sd:swhid_context>
+ <sd:external_id>check-deposit-2020-10-08T13:52:34.509655</sd:external_id>
+ </entry>
+</feed>
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Aug 18, 12:47 AM (3 w, 1 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3217831
Attached To
D5770: Open `swh deposit list` cli to allow user to list their deposits
Event Timeline
Log In to Comment