Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F7123074
D4219.id14892.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
5 KB
Subscribers
None
D4219.id14892.diff
View Options
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
@@ -3,6 +3,7 @@
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information
+import ast
import contextlib
import json
import logging
@@ -11,6 +12,7 @@
from click.testing import CliRunner
import pytest
+import yaml
from swh.deposit.cli import deposit as cli
from swh.deposit.cli.client import InputError, _client, _collection, _url, generate_slug
@@ -418,3 +420,59 @@
# FIXME: should be "deposited" but current limitation in the
# requests_mock_datadir_visits use, cannot find a way to make it work right now
assert actual_deposit["deposit_status"] == "partial"
+
+
+@pytest.mark.parametrize(
+ "output_format,callable_fn",
+ [
+ ("json", json.loads),
+ ("yaml", yaml.safe_load),
+ (
+ "logging",
+ ast.literal_eval,
+ ), # not enough though, the caplog fixture is needed
+ ],
+)
+def test_cli_deposit_status_json(
+ output_format, callable_fn, datadir, slug, requests_mock_datadir, caplog
+):
+ """Check deposit status cli with all possible output formats
+
+ """
+ api_url_basename = "deposit.test.status"
+ deposit_id = 1033
+ deposit_status_xml_path = os.path.join(
+ datadir, f"https_{api_url_basename}", f"1_test_{deposit_id}_status"
+ )
+ with open(deposit_status_xml_path, "r") as f:
+ deposit_status_xml = f.read()
+ expected_deposit_dict = dict(parse_xml(deposit_status_xml))
+
+ runner = CliRunner()
+ result = runner.invoke(
+ cli,
+ [
+ "status",
+ "--url",
+ f"https://{api_url_basename}/1",
+ "--username",
+ TEST_USER["username"],
+ "--password",
+ TEST_USER["password"],
+ "--deposit-id",
+ deposit_id,
+ "--format",
+ output_format,
+ ],
+ )
+ 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 = callable_fn(result_output)
+ assert actual_deposit == expected_deposit_dict
diff --git a/swh/deposit/tests/data/https_deposit.test.status/1_servicedocument b/swh/deposit/tests/data/https_deposit.test.status/1_servicedocument
new file mode 100644
--- /dev/null
+++ b/swh/deposit/tests/data/https_deposit.test.status/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.status/1_test_1033_status b/swh/deposit/tests/data/https_deposit.test.status/1_test_1033_status
new file mode 100644
--- /dev/null
+++ b/swh/deposit/tests/data/https_deposit.test.status/1_test_1033_status
@@ -0,0 +1,10 @@
+<entry xmlns="http://www.w3.org/2005/Atom"
+ xmlns:sword="http://purl.org/net/sword/"
+ xmlns:dcterms="http://purl.org/dc/terms/">
+ <deposit_id>1033</deposit_id>
+ <deposit_status>done</deposit_status>
+ <deposit_status_detail>The deposit has been successfully loaded into the Software Heritage archive</deposit_status_detail>
+ <deposit_swh_id>swh:1:dir:ef04a768181417fbc5eef4243e2507915f24deea</deposit_swh_id>
+ <deposit_swh_id_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=/</deposit_swh_id_context>
+ <deposit_external_id>check-deposit-2020-10-08T13:52:34.509655</deposit_external_id>
+</entry>
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Dec 17, 7:47 PM (2 d, 16 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3220485
Attached To
D4219: test_client: Add scenario on deposit status cli
Event Timeline
Log In to Comment