Changeset View
Changeset View
Standalone View
Standalone View
swh/icinga_plugins/tests/test_deposit.py
Show First 20 Lines • Show All 83 Lines • ▼ Show 20 Lines | |||||
def test_status_template(): | def test_status_template(): | ||||
actual_status = status_template(status="deposited") | actual_status = status_template(status="deposited") | ||||
assert ( | assert ( | ||||
actual_status | actual_status | ||||
== """ | == """ | ||||
<entry xmlns="http://www.w3.org/2005/Atom" | <entry xmlns="http://www.w3.org/2005/Atom" | ||||
xmlns:sword="http://purl.org/net/sword/" | xmlns:sword="http://purl.org/net/sword/" | ||||
xmlns:dcterms="http://purl.org/dc/terms/"> | xmlns:dcterms="http://purl.org/dc/terms/"> | ||||
<deposit_id>42</deposit_id> | <deposit_id>42</deposit_id> | ||||
<deposit_status>deposited</deposit_status> | <deposit_status>deposited</deposit_status> | ||||
vlorentz: ugh, we really have to do something about these tag names that don't belong in the Atom… | |||||
Done Inline Actionsyes, and yes. does that mean, we need to start defining our own namespace and use it? ardumont: yes, and yes.
does that mean, we need to start defining our own namespace and use it?
(if so… | |||||
<deposit_status_detail></deposit_status_detail> | <deposit_status_detail></deposit_status_detail> | ||||
</entry> | </entry> | ||||
""" | """ | ||||
) | ) | ||||
actual_status = status_template(status="verified", status_detail="detail") | actual_status = status_template(status="verified", status_detail="detail") | ||||
assert ( | assert ( | ||||
actual_status | actual_status | ||||
▲ Show 20 Lines • Show All 62 Lines • ▼ Show 20 Lines | if not catch_exceptions and result.exception: | ||||
print(result.output) | print(result.output) | ||||
raise result.exception | raise result.exception | ||||
return result | return result | ||||
def test_deposit_immediate_success( | def test_deposit_immediate_success( | ||||
requests_mock, mocker, sample_archive, sample_metadata, mocked_time | requests_mock, mocker, sample_archive, sample_metadata, mocked_time | ||||
): | ): | ||||
"""Both deposit creation and deposit metadata update passed without delays | |||||
""" | |||||
scenario = WebScenario() | scenario = WebScenario() | ||||
status_xml = status_template( | |||||
status="done", | |||||
status_detail="", | |||||
swhid="swh:1:dir:02ed6084fb0e8384ac58980e07548a547431cf74", | |||||
) | |||||
# Initial deposit | |||||
scenario.add_step( | scenario.add_step( | ||||
"post", f"{BASE_URL}/testcol/", ENTRY_TEMPLATE.format(status="done") | "post", f"{BASE_URL}/testcol/", ENTRY_TEMPLATE.format(status="done") | ||||
) | ) | ||||
# Then metadata update | |||||
status_xml = status_template( | |||||
status="done", | |||||
status_detail="", | |||||
swhid="swh:1:dir:02ed6084fb0e8384ac58980e07548a547431cf74", | |||||
) | |||||
scenario.add_step("get", f"{BASE_URL}/testcol/42/status/", status_xml) | |||||
# internal deposit client does call status, then update metadata then status api | |||||
scenario.add_step( | |||||
"get", f"{BASE_URL}/testcol/42/status/", status_xml, | |||||
) | |||||
scenario.add_step( | |||||
"put", f"{BASE_URL}/testcol/42/metadata/", status_xml, | |||||
) | |||||
scenario.add_step( | |||||
"get", f"{BASE_URL}/testcol/42/status/", status_xml, | |||||
) | |||||
scenario.install_mock(requests_mock) | scenario.install_mock(requests_mock) | ||||
result = invoke( | result = invoke( | ||||
[ | [ | ||||
"check-deposit", | "check-deposit", | ||||
*COMMON_OPTIONS, | *COMMON_OPTIONS, | ||||
"single", | "single", | ||||
"--archive", | "--archive", | ||||
sample_archive, | sample_archive, | ||||
"--metadata", | "--metadata", | ||||
sample_metadata, | sample_metadata, | ||||
] | ] | ||||
) | ) | ||||
assert result.output == ( | assert result.output == ( | ||||
"DEPOSIT OK - Deposit took 0.00s and succeeded.\n" | "DEPOSIT OK - Deposit took 0.00s and succeeded.\n" | ||||
"| 'load_time' = 0.00s\n" | "| 'load_time' = 0.00s\n" | ||||
"| 'total_time' = 0.00s\n" | "| 'total_time' = 0.00s\n" | ||||
"| 'upload_time' = 0.00s\n" | "| 'upload_time' = 0.00s\n" | ||||
"| 'validation_time' = 0.00s\n" | "| 'validation_time' = 0.00s\n" | ||||
"DEPOSIT OK - Deposit Metadata update took 0.00s and succeeded.\n" | |||||
"| 'total_time' = 0.00s\n" | |||||
"| 'update_time' = 0.00s\n" | |||||
) | ) | ||||
assert result.exit_code == 0, f"Unexpected output: {result.output}" | assert result.exit_code == 0, f"Unexpected output: {result.output}" | ||||
def test_deposit_delays( | def test_deposit_delays( | ||||
requests_mock, mocker, sample_archive, sample_metadata, mocked_time | requests_mock, mocker, sample_archive, sample_metadata, mocked_time | ||||
): | ): | ||||
"""Deposit creation passed with some delays, deposit metadata update passed without | |||||
delay | |||||
""" | |||||
scenario = WebScenario() | scenario = WebScenario() | ||||
scenario.add_step( | scenario.add_step( | ||||
"post", f"{BASE_URL}/testcol/", ENTRY_TEMPLATE.format(status="deposited") | "post", f"{BASE_URL}/testcol/", ENTRY_TEMPLATE.format(status="deposited") | ||||
) | ) | ||||
scenario.add_step( | scenario.add_step( | ||||
"get", f"{BASE_URL}/testcol/42/status/", status_template(status="verified"), | "get", f"{BASE_URL}/testcol/42/status/", status_template(status="verified"), | ||||
) | ) | ||||
scenario.add_step( | scenario.add_step( | ||||
"get", f"{BASE_URL}/testcol/42/status/", status_template(status="loading"), | "get", f"{BASE_URL}/testcol/42/status/", status_template(status="loading"), | ||||
) | ) | ||||
scenario.add_step( | scenario.add_step( | ||||
"get", f"{BASE_URL}/testcol/42/status/", status_template(status="done"), | "get", f"{BASE_URL}/testcol/42/status/", status_template(status="done"), | ||||
) | ) | ||||
# Then metadata update | |||||
status_xml = status_template( | |||||
status="done", | |||||
status_detail="", | |||||
swhid="swh:1:dir:02ed6084fb0e8384ac58980e07548a547431cf74", | |||||
) | |||||
scenario.add_step("get", f"{BASE_URL}/testcol/42/status/", status_xml) | |||||
# internal deposit client does call status, then update metadata then status api | |||||
scenario.add_step( | |||||
"get", f"{BASE_URL}/testcol/42/status/", status_xml, | |||||
) | |||||
scenario.add_step( | |||||
"put", f"{BASE_URL}/testcol/42/metadata/", status_xml, | |||||
) | |||||
scenario.add_step( | |||||
"get", f"{BASE_URL}/testcol/42/status/", status_xml, | |||||
) | |||||
scenario.install_mock(requests_mock) | scenario.install_mock(requests_mock) | ||||
result = invoke( | result = invoke( | ||||
[ | [ | ||||
"check-deposit", | "check-deposit", | ||||
*COMMON_OPTIONS, | *COMMON_OPTIONS, | ||||
"single", | "single", | ||||
"--archive", | "--archive", | ||||
sample_archive, | sample_archive, | ||||
"--metadata", | "--metadata", | ||||
sample_metadata, | sample_metadata, | ||||
] | ] | ||||
) | ) | ||||
assert result.output == ( | assert result.output == ( | ||||
"DEPOSIT OK - Deposit took 30.00s and succeeded.\n" | "DEPOSIT OK - Deposit took 30.00s and succeeded.\n" | ||||
"| 'load_time' = 20.00s\n" | "| 'load_time' = 20.00s\n" | ||||
"| 'total_time' = 30.00s\n" | "| 'total_time' = 30.00s\n" | ||||
"| 'upload_time' = 0.00s\n" | "| 'upload_time' = 0.00s\n" | ||||
"| 'validation_time' = 10.00s\n" | "| 'validation_time' = 10.00s\n" | ||||
"DEPOSIT OK - Deposit Metadata update took 0.00s and succeeded.\n" | |||||
"| 'total_time' = 30.00s\n" | |||||
"| 'update_time' = 0.00s\n" | |||||
) | ) | ||||
assert result.exit_code == 0, f"Unexpected output: {result.output}" | assert result.exit_code == 0, f"Unexpected output: {result.output}" | ||||
def test_deposit_then_metadata_update_failed( | |||||
requests_mock, mocker, sample_archive, sample_metadata, mocked_time | |||||
): | |||||
"""Deposit creation passed, deposit metadata update failed | |||||
""" | |||||
scenario = WebScenario() | |||||
scenario.add_step( | |||||
"post", f"{BASE_URL}/testcol/", ENTRY_TEMPLATE.format(status="deposited") | |||||
) | |||||
scenario.add_step( | |||||
"get", f"{BASE_URL}/testcol/42/status/", status_template(status="verified"), | |||||
) | |||||
scenario.add_step( | |||||
"get", f"{BASE_URL}/testcol/42/status/", status_template(status="loading"), | |||||
) | |||||
scenario.add_step( | |||||
"get", f"{BASE_URL}/testcol/42/status/", status_template(status="done"), | |||||
) | |||||
# Then metadata update calls | |||||
failed_status_xml = status_template( | |||||
status="failed", # lying here | |||||
status_detail="Failure to ingest", | |||||
swhid="swh:1:dir:02ed6084fb0e8384ac58980e07548a547431cf74", | |||||
) | |||||
scenario.add_step("get", f"{BASE_URL}/testcol/42/status/", failed_status_xml) | |||||
scenario.add_step("get", f"{BASE_URL}/testcol/42/status/", failed_status_xml) | |||||
scenario.install_mock(requests_mock) | |||||
result = invoke( | |||||
[ | |||||
"check-deposit", | |||||
*COMMON_OPTIONS, | |||||
"single", | |||||
"--archive", | |||||
sample_archive, | |||||
"--metadata", | |||||
sample_metadata, | |||||
], | |||||
catch_exceptions=True, | |||||
) | |||||
assert result.output == ( | |||||
"DEPOSIT OK - Deposit took 30.00s and succeeded.\n" | |||||
"| 'load_time' = 20.00s\n" | |||||
"| 'total_time' = 30.00s\n" | |||||
"| 'upload_time' = 0.00s\n" | |||||
"| 'validation_time' = 10.00s\n" | |||||
"DEPOSIT CRITICAL - Deposit Metadata update failed: You can only update " | |||||
"metadata on deposit with status 'done' \n" | |||||
"| 'total_time' = 30.00s\n" | |||||
"| 'update_time' = 0.00s\n" | |||||
) | |||||
assert result.exit_code == 2, f"Unexpected output: {result.output}" | |||||
def test_deposit_delay_warning( | def test_deposit_delay_warning( | ||||
requests_mock, mocker, sample_archive, sample_metadata, mocked_time | requests_mock, mocker, sample_archive, sample_metadata, mocked_time | ||||
): | ): | ||||
"""Deposit creation exceeded delays, no deposit update occurred. | |||||
""" | |||||
scenario = WebScenario() | scenario = WebScenario() | ||||
scenario.add_step( | scenario.add_step( | ||||
"post", f"{BASE_URL}/testcol/", ENTRY_TEMPLATE.format(status="deposited") | "post", f"{BASE_URL}/testcol/", ENTRY_TEMPLATE.format(status="deposited") | ||||
) | ) | ||||
scenario.add_step( | scenario.add_step( | ||||
"get", f"{BASE_URL}/testcol/42/status/", status_template(status="verified"), | "get", f"{BASE_URL}/testcol/42/status/", status_template(status="verified"), | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 251 Lines • Show Last 20 Lines |
ugh, we really have to do something about these tag names that don't belong in the Atom namespace.
But out of scope for this diff