Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/tests/cli/test_client.py
Show First 20 Lines • Show All 108 Lines • ▼ Show 20 Lines | ): | ||||
""" | """ | ||||
runner = CliRunner() | runner = CliRunner() | ||||
result = runner.invoke( | result = runner.invoke( | ||||
cli, | cli, | ||||
[ | [ | ||||
"upload", | "upload", | ||||
"--url", | "--url", | ||||
"mock://deposit.swh/1", | "https://deposit.swh.test/1", | ||||
vlorentz: good | |||||
"--username", | "--username", | ||||
TEST_USER["username"], | TEST_USER["username"], | ||||
"--password", | "--password", | ||||
TEST_USER["password"], | TEST_USER["password"], | ||||
"--name", | "--name", | ||||
"test-project", | "test-project", | ||||
"--archive", | "--archive", | ||||
sample_archive["path"], | sample_archive["path"], | ||||
Show All 11 Lines | assert caplog.record_tuples == [ | ||||
"Database backend maintenance: Temporarily unavailable, try again later.", | "Database backend maintenance: Temporarily unavailable, try again later.", | ||||
) | ) | ||||
] | ] | ||||
client_mock_api_down.service_document.assert_called_once_with() | client_mock_api_down.service_document.assert_called_once_with() | ||||
def test_single_minimal_deposit( | def test_single_minimal_deposit( | ||||
sample_archive, mocker, caplog, client_mock, slug, tmp_path | sample_archive, mocker, caplog, slug, tmp_path, requests_mock_datadir | ||||
): | ): | ||||
""" from: | """ from: | ||||
https://docs.softwareheritage.org/devel/swh-deposit/getting-started.html#single-deposit | https://docs.softwareheritage.org/devel/swh-deposit/getting-started.html#single-deposit | ||||
""" # noqa | """ # noqa | ||||
metadata_path = os.path.join(tmp_path, "metadata.xml") | metadata_path = os.path.join(tmp_path, "metadata.xml") | ||||
mocker.patch( | mocker.patch( | ||||
"tempfile.TemporaryDirectory", | "tempfile.TemporaryDirectory", | ||||
return_value=contextlib.nullcontext(str(tmp_path)), | return_value=contextlib.nullcontext(str(tmp_path)), | ||||
) | ) | ||||
runner = CliRunner() | runner = CliRunner() | ||||
result = runner.invoke( | result = runner.invoke( | ||||
cli, | cli, | ||||
[ | [ | ||||
"upload", | "upload", | ||||
"--url", | "--url", | ||||
"mock://deposit.swh/1", | "https://deposit.swh.test/1", | ||||
"--username", | "--username", | ||||
TEST_USER["username"], | TEST_USER["username"], | ||||
"--password", | "--password", | ||||
TEST_USER["password"], | TEST_USER["password"], | ||||
"--name", | "--name", | ||||
"test-project", | "test-project", | ||||
"--archive", | "--archive", | ||||
sample_archive["path"], | sample_archive["path"], | ||||
"--author", | "--author", | ||||
"Jane Doe", | "Jane Doe", | ||||
"--slug", | |||||
slug, | |||||
], | ], | ||||
) | ) | ||||
assert result.exit_code == 0, result.output | assert result.exit_code == 0, result.output | ||||
assert result.output == "" | assert result.output == "" | ||||
assert caplog.record_tuples == [ | |||||
("swh.deposit.cli.client", logging.INFO, '{"foo": "bar"}'), | |||||
] | |||||
client_mock.deposit_create.assert_called_once_with( | interesting_records = [] | ||||
archive=sample_archive["path"], | for record in caplog.record_tuples: | ||||
collection="softcol", | if record[0] == "swh.deposit.cli.client": | ||||
in_progress=False, | interesting_records.append(record) | ||||
metadata=metadata_path, | |||||
slug=slug, | assert len(interesting_records) == 1 | ||||
) | assert interesting_records == [ | ||||
( | |||||
"swh.deposit.cli.client", | |||||
logging.INFO, | |||||
"{'deposit_id': '615', 'deposit_status': 'partial', 'deposit_status_detail': None, 'deposit_date': 'Oct. 8, 2020, 4:57 p.m.'}", # noqa | |||||
), | |||||
Done Inline ActionsI'm gonna simplify this in a future refactoring diff. ardumont: I'm gonna simplify this in a future refactoring diff.
(we can ask for the `--format json` as… | |||||
] | |||||
with open(metadata_path) as fd: | with open(metadata_path) as fd: | ||||
assert ( | assert ( | ||||
fd.read() | fd.read() | ||||
== f"""\ | == f"""\ | ||||
<?xml version="1.0" encoding="utf-8"?> | <?xml version="1.0" encoding="utf-8"?> | ||||
<entry xmlns="http://www.w3.org/2005/Atom" \ | <entry xmlns="http://www.w3.org/2005/Atom" \ | ||||
xmlns:codemeta="https://doi.org/10.5063/SCHEMA/CODEMETA-2.0"> | xmlns:codemeta="https://doi.org/10.5063/SCHEMA/CODEMETA-2.0"> | ||||
Show All 28 Lines | def test_metadata_validation(sample_archive, mocker, caplog, tmp_path): | ||||
runner = CliRunner() | runner = CliRunner() | ||||
# Test missing author | # Test missing author | ||||
result = runner.invoke( | result = runner.invoke( | ||||
cli, | cli, | ||||
[ | [ | ||||
"upload", | "upload", | ||||
"--url", | "--url", | ||||
"mock://deposit.swh/1", | "https://deposit.swh.test/1", | ||||
"--username", | "--username", | ||||
TEST_USER["username"], | TEST_USER["username"], | ||||
"--password", | "--password", | ||||
TEST_USER["password"], | TEST_USER["password"], | ||||
"--name", | "--name", | ||||
"test-project", | "test-project", | ||||
"--archive", | "--archive", | ||||
sample_archive["path"], | sample_archive["path"], | ||||
▲ Show 20 Lines • Show All 227 Lines • Show Last 20 Lines |
good