Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F7123001
D4213.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
9 KB
Subscribers
None
D4213.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
@@ -4,6 +4,7 @@
# See top-level LICENSE file for more information
import contextlib
+import json
import logging
import os
from unittest.mock import MagicMock
@@ -42,19 +43,6 @@
return generate_slug()
-@pytest.fixture
-def client_mock(mocker, slug):
- """A successful deposit client with hard-coded default values
-
- """
- mocker.patch("swh.deposit.cli.client.generate_slug", return_value=slug)
- mock_client = MagicMock()
- mocker.patch("swh.deposit.cli.client._client", return_value=mock_client)
- mock_client.service_document.return_value = EXAMPLE_SERVICE_DOCUMENT
- mock_client.deposit_create.return_value = '{"foo": "bar"}'
- return mock_client
-
-
@pytest.fixture
def client_mock_api_down(mocker, slug):
"""A mock client whose connection with api fails due to maintenance issue
@@ -383,17 +371,11 @@
assert actual_metadata["codemeta:identifier"] is not None
-def test_multisteps_deposit(
- sample_archive, atom_dataset, mocker, caplog, datadir, client_mock, slug
-):
- """ from:
+def test_multisteps_deposit(sample_archive, datadir, slug, requests_mock_datadir):
+ """ First deposit a partial deposit (no metadata, only archive), then update the metadata part.
https://docs.softwareheritage.org/devel/swh-deposit/getting-started.html#multisteps-deposit
""" # noqa
- slug = generate_slug()
- mocker.patch("swh.deposit.cli.client.generate_slug", return_value=slug)
-
- # https://docs.softwareheritage.org/devel/swh-deposit/getting-started.html#create-an-incomplete-deposit
- client_mock.deposit_create.return_value = '{"deposit_id": "42"}'
+ api_url = "https://deposit.test.metadata/1"
runner = CliRunner()
result = runner.invoke(
@@ -401,7 +383,7 @@
[
"upload",
"--url",
- "mock://deposit.swh/1",
+ api_url,
"--username",
TEST_USER["username"],
"--password",
@@ -409,60 +391,52 @@
"--archive",
sample_archive["path"],
"--partial",
+ "--slug",
+ slug,
+ "--format",
+ "json",
],
)
- assert result.exit_code == 0, result.output
- assert result.output == ""
- assert caplog.record_tuples == [
- ("swh.deposit.cli.client", logging.INFO, '{"deposit_id": "42"}'),
- ]
-
- client_mock.deposit_create.assert_called_once_with(
- archive=sample_archive["path"],
- collection="softcol",
- in_progress=True,
- metadata=None,
- slug=slug,
- )
-
- # Clear mocking state
- caplog.clear()
- client_mock.reset_mock()
+ assert result.exit_code == 0, f"unexpected output: {result.output}"
+ actual_deposit = json.loads(result.output)
+ assert actual_deposit == {
+ "deposit_id": "666",
+ "deposit_status": "partial",
+ "deposit_status_detail": None,
+ "deposit_date": "Oct. 8, 2020, 4:57 p.m.",
+ }
# https://docs.softwareheritage.org/devel/swh-deposit/getting-started.html#add-content-or-metadata-to-the-deposit
-
metadata_path = os.path.join(datadir, "atom", "entry-data-deposit-binary.xml")
+ # Update deposit with metadata
result = runner.invoke(
cli,
[
"upload",
"--url",
- "mock://deposit.swh/1",
+ api_url,
"--username",
TEST_USER["username"],
"--password",
TEST_USER["password"],
"--metadata",
metadata_path,
+ "--deposit-id",
+ 666,
+ "--slug",
+ slug,
+ "--format",
+ "json",
],
)
- assert result.exit_code == 0, result.output
- assert result.output == ""
- assert caplog.record_tuples == [
- ("swh.deposit.cli.client", logging.INFO, '{"deposit_id": "42"}'),
- ]
-
- client_mock.deposit_create.assert_called_once_with(
- archive=None,
- collection="softcol",
- in_progress=False,
- metadata=metadata_path,
- slug=slug,
- )
-
- # Clear mocking state
- caplog.clear()
- client_mock.reset_mock()
+ assert result.exit_code == 0, f"unexpected output: {result.output}"
+ assert result.output is not None
+ actual_deposit = json.loads(result.output)
+ # deposit update scenario actually returns a deposit status dict
+ assert actual_deposit["deposit_id"] == "666"
+ # 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"
diff --git a/swh/deposit/tests/data/https_deposit.test.metadata/1_servicedocument b/swh/deposit/tests/data/https_deposit.test.metadata/1_servicedocument
new file mode 100644
--- /dev/null
+++ b/swh/deposit/tests/data/https_deposit.test.metadata/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.metadata/1/test/</sword:service>
+ <sword:name>test</sword:name>
+ </collection>
+ </workspace>
+</service>
diff --git a/swh/deposit/tests/data/https_deposit.test.metadata/1_test b/swh/deposit/tests/data/https_deposit.test.metadata/1_test
new file mode 100644
--- /dev/null
+++ b/swh/deposit/tests/data/https_deposit.test.metadata/1_test
@@ -0,0 +1,19 @@
+<entry xmlns="http://www.w3.org/2005/Atom"
+ xmlns:sword="http://purl.org/net/sword/"
+ xmlns:dcterms="http://purl.org/dc/terms/">
+ <deposit_id>666</deposit_id>
+ <deposit_date>Oct. 8, 2020, 4:57 p.m.</deposit_date>
+ <deposit_archive>hardcoded_sample_archive_path</deposit_archive>
+ <deposit_status>partial</deposit_status>
+
+ <!-- Edit-IRI -->
+ <link rel="edit" href="https://deposit.test.metadata/1/test/666/metadata/" />
+ <!-- EM-IRI -->
+ <link rel="edit-media" href="https://deposit.test.metadata/1/test/666/media/"/>
+ <!-- SE-IRI -->
+ <link rel="http://purl.org/net/sword/terms/add" href="https://deposit.test.metadata/1/test/666/metadata/" />
+ <!-- State-IRI -->
+ <link rel="alternate" href="https://deposit.test.metadata/1/test/666/status/" />
+
+ <sword:packaging>http://purl.org/net/sword/package/SimpleZip</sword:packaging>
+</entry>
diff --git a/swh/deposit/tests/data/https_deposit.test.metadata/1_test_666_metadata b/swh/deposit/tests/data/https_deposit.test.metadata/1_test_666_metadata
new file mode 100644
--- /dev/null
+++ b/swh/deposit/tests/data/https_deposit.test.metadata/1_test_666_metadata
@@ -0,0 +1,19 @@
+<entry xmlns="http://www.w3.org/2005/Atom"
+ xmlns:sword="http://purl.org/net/sword/"
+ xmlns:dcterms="http://purl.org/dc/terms/">
+ <deposit_id>666</deposit_id>
+ <deposit_date>Oct. 9, 2020, 8:44 p.m.</deposit_date>
+ <deposit_archive>something</deposit_archive>
+ <deposit_status>deposited</deposit_status>
+
+ <!-- Edit-IRI -->
+ <link rel="edit" href="https://deposit.test.metadata/1/test/666/metadata/" />
+ <!-- EM-IRI -->
+ <link rel="edit-media" href="https://deposit.test.metadata/1/test/666/media/"/>
+ <!-- SE-IRI -->
+ <link rel="http://purl.org/net/sword/terms/add" href="https://deposit.test.metadata/1/test/666/metadata/" />
+ <!-- State-IRI -->
+ <link rel="alternate" href="https://deposit.test.metadata/1/test/666/status/" />
+
+ <sword:packaging>http://purl.org/net/sword/package/SimpleZip</sword:packaging>
+</entry>
diff --git a/swh/deposit/tests/data/https_deposit.test.metadata/1_test_666_status b/swh/deposit/tests/data/https_deposit.test.metadata/1_test_666_status
new file mode 100644
--- /dev/null
+++ b/swh/deposit/tests/data/https_deposit.test.metadata/1_test_666_status
@@ -0,0 +1,8 @@
+<entry xmlns="http://www.w3.org/2005/Atom"
+ xmlns:sword="http://purl.org/net/sword/"
+ xmlns:dcterms="http://purl.org/dc/terms/">
+ <deposit_id>666</deposit_id>
+ <deposit_status>partial</deposit_status>
+ <deposit_status_detail>Deposit is partially received. To finalize it, In-Progress header should be false</deposit_status_detail>
+ <deposit_external_id>external-id</deposit_external_id>
+</entry>
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Dec 17, 3:24 PM (2 d, 20 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3220081
Attached To
D4213: test_client: Migrate multisteps_deposit scenario to use requests_mock_datadir
Event Timeline
Log In to Comment