Page MenuHomeSoftware Heritage

D4222.id14904.diff
No OneTemporary

D4222.id14904.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
@@ -203,21 +203,21 @@
metadata = generate_metadata_file(name, slug, authors, temp_dir)
elif not archive_deposit and not partial and not deposit_id:
# If we meet all the following conditions:
- # * there is not an archive-only deposit
+ # * this is not an archive-only deposit request
# * it is not part of a multipart deposit (either create/update
# or finish)
# * it misses either name or authors
raise InputError(
- "Either a metadata file (--metadata) or both --author and "
- "--name must be provided, unless this is an archive-only "
- "deposit."
+ "For metadata deposit request, either a metadata file with "
+ "--metadata or both --author and --name must be provided. "
+ "If this is an archive deposit request, none is required."
)
elif name or authors:
# If we are generating metadata, then all mandatory metadata
# must be present
raise InputError(
- "Either a metadata file (--metadata) or both --author and "
- "--name must be provided."
+ "For metadata deposit request, either a metadata file with "
+ "--metadata or both --author and --name must be provided."
)
else:
# TODO: this is a multipart deposit, we might want to check that
@@ -225,8 +225,8 @@
pass
elif name or authors:
raise InputError(
- "Using a metadata file (--metadata) is incompatible with "
- "--author and --name, which are used to generate one."
+ "Using --metadata flag is incompatible with both "
+ "--author and --name (Those are used to generate one metadata file)."
)
if metadata_deposit:
@@ -238,7 +238,7 @@
if metadata_deposit and not metadata:
raise InputError(
"Metadata deposit must be provided for metadata "
- "deposit (either a filepath or --name and --author)"
+ "deposit, either a filepath with --metadata or --name and --author"
)
if not archive and not metadata and partial:
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
@@ -205,70 +205,123 @@
runner = CliRunner()
- # Test missing author
- result = runner.invoke(
- cli,
- [
- "upload",
- "--url",
- "https://deposit.swh.test/1",
- "--username",
- TEST_USER["username"],
- "--password",
- TEST_USER["password"],
- "--name",
- "test-project",
- "--archive",
- sample_archive["path"],
- "--slug",
- slug,
- ],
- )
-
- assert result.exit_code == 1, f"unexpected result: {result.output}"
- assert result.output == ""
- expected_error_log_record = (
- "swh.deposit.cli.client",
- logging.ERROR,
- (
- "Problem during parsing options: Either a metadata file"
- " (--metadata) or both --author and --name must be provided, "
- "unless this is an archive-only deposit."
- ),
- )
- assert expected_error_log_record in caplog.record_tuples
-
- # Clear mocking state
- caplog.clear()
-
- # Test missing name
- result = runner.invoke(
- cli,
- [
- "upload",
- "--url",
- "https://deposit.swh.test/1",
- "--username",
- TEST_USER["username"],
- "--password",
- TEST_USER["password"],
- "--archive",
- sample_archive["path"],
- "--author",
- "Jane Doe",
- "--slug",
- slug,
- ],
- )
+ for flag_title_or_name, author_or_name in [
+ ("--author", "no one"),
+ ("--name", "test-project"),
+ ]:
+ # Test missing author then missing name
+ result = runner.invoke(
+ cli,
+ [
+ "upload",
+ "--url",
+ "https://deposit.swh.test/1",
+ "--username",
+ TEST_USER["username"],
+ "--password",
+ TEST_USER["password"],
+ "--archive",
+ sample_archive["path"],
+ "--slug",
+ slug,
+ flag_title_or_name,
+ author_or_name,
+ ],
+ )
- assert result.exit_code == 1, result.output
- assert result.output == ""
- assert expected_error_log_record in caplog.record_tuples
+ assert result.exit_code == 1, f"unexpected result: {result.output}"
+ assert result.output == ""
+ expected_error_log_record = (
+ "swh.deposit.cli.client",
+ logging.ERROR,
+ (
+ "Problem during parsing options: "
+ "For metadata deposit request, either a metadata file with "
+ "--metadata or both --author and --name must be provided. "
+ "If this is an archive deposit request, none is required."
+ ),
+ )
+ assert expected_error_log_record in caplog.record_tuples
+
+ # Clear mocking state
+ caplog.clear()
+
+ # incompatible flags: Test both --metadata and --author, then --metadata and
+ # --name
+ result = runner.invoke(
+ cli,
+ [
+ "upload",
+ "--url",
+ "https://deposit.swh.test/1",
+ "--username",
+ TEST_USER["username"],
+ "--password",
+ TEST_USER["password"],
+ "--name",
+ "test-project",
+ "--deposit-id",
+ 666,
+ "--archive",
+ sample_archive["path"],
+ "--slug",
+ slug,
+ ],
+ )
+ assert result.exit_code == 1, f"unexpected result: {result.output}"
+ assert result.output == ""
+ expected_error_log_record = (
+ "swh.deposit.cli.client",
+ logging.ERROR,
+ (
+ "Problem during parsing options: "
+ "For metadata deposit request, either a metadata file with "
+ "--metadata or both --author and --name must be provided."
+ ),
+ )
+ assert expected_error_log_record in caplog.record_tuples
+
+ # Clear mocking state
+ caplog.clear()
+
+ # incompatible flags check (Test both --metadata and --author,
+ # then --metadata and --name)
+ result = runner.invoke(
+ cli,
+ [
+ "upload",
+ "--url",
+ "https://deposit.swh.test/1",
+ "--username",
+ TEST_USER["username"],
+ "--password",
+ TEST_USER["password"],
+ "--archive",
+ sample_archive["path"],
+ "--metadata",
+ metadata_path,
+ "--author",
+ "Jane Doe",
+ "--slug",
+ slug,
+ ],
+ )
- # Clear mocking state
- caplog.clear()
+ assert result.exit_code == 1, result.output
+ assert result.output == ""
+ expected_error_log_record_2 = (
+ "swh.deposit.cli.client",
+ logging.ERROR,
+ (
+ "Problem during parsing options: "
+ "Using --metadata flag is incompatible with both "
+ "--author and --name (Those are used to generate one metadata file)."
+ ),
+ )
+ assert expected_error_log_record_2 in caplog.record_tuples
+ caplog.clear()
- # Test both --metadata and --author
+ # no actionable command
result = runner.invoke(
cli,
[
@@ -279,14 +332,7 @@
TEST_USER["username"],
"--password",
TEST_USER["password"],
- "--archive",
- sample_archive["path"],
- "--metadata",
- metadata_path,
- "--author",
- "Jane Doe",
- "--slug",
- slug,
+ "--partial",
],
)
@@ -296,9 +342,8 @@
"swh.deposit.cli.client",
logging.ERROR,
(
- "Problem during parsing options: Using a metadata file "
- "(--metadata) is incompatible with --author and --name, "
- "which are used to generate one."
+ "Problem during parsing options: "
+ "Please provide an actionable command. See --help for more information"
),
)
assert expected_error_log_record_2 in caplog.record_tuples

File Metadata

Mime Type
text/plain
Expires
Wed, Sep 17, 4:55 PM (1 m, 9 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3230633

Event Timeline