swh_storage = <swh.storage.retry.RetryingProxyStorage object at 0x7fb6c8a6d710>
deposit_client = <swh.loader.package.deposit.loader.ApiClient object at 0x7fb6c816c438>
requests_mock_datadir = <requests_mock.mocker.Mocker object at 0x7fb6c814cd30>
def test_deposit_loading_ok(swh_storage, deposit_client, requests_mock_datadir):
url = "https://hal-test.archives-ouvertes.fr/some-external-id"
deposit_id = 666
loader = DepositLoader(swh_storage, url, deposit_id, deposit_client)
actual_load_status = loader.load()
expected_snapshot_id = "b2b327b33dc85818bd23c3ccda8b7e675a66ecbd"
assert actual_load_status == {
"status": "eventful",
"snapshot_id": expected_snapshot_id,
}
assert_last_visit_matches(loader.storage, url, status="full", type="deposit")
stats = get_stats(loader.storage)
assert {
"content": 303,
"directory": 12,
"origin": 1,
"origin_visit": 1,
"release": 0,
"revision": 1,
"skipped_content": 0,
"snapshot": 1,
} == stats
revision_id_hex = "637318680351f5d78856d13264faebbd91efe9bb"
revision_id = hash_to_bytes(revision_id_hex)
expected_snapshot = Snapshot(
id=hash_to_bytes(expected_snapshot_id),
branches={
b"HEAD": SnapshotBranch(
target=revision_id, target_type=TargetType.REVISION,
),
},
)
check_snapshot(expected_snapshot, storage=loader.storage)
revision = loader.storage.revision_get([revision_id])[0]
assert revision is not None
# check metadata
fetcher = MetadataFetcher(name="swh-deposit", version="0.0.1",)
authority = MetadataAuthority(
type=MetadataAuthorityType.DEPOSIT_CLIENT,
url="https://hal-test.archives-ouvertes.fr/",
)
# Check origin metadata
orig_meta = loader.storage.raw_extrinsic_metadata_get(
MetadataTargetType.ORIGIN, url, authority
)
assert orig_meta.next_page_token is None
raw_meta = loader.client.metadata_get(deposit_id)
all_metadata_raw: List[str] = raw_meta["metadata_raw"]
# 2 raw metadata xml + 1 json dict
assert len(orig_meta.results) == len(all_metadata_raw) + 1
orig_meta0 = orig_meta.results[0]
assert orig_meta0.authority == authority
assert orig_meta0.fetcher == fetcher
# Check directory metadata
directory_id = hash_to_hex(revision.directory)
directory_swhid = SWHID(object_type="directory", object_id=directory_id)
actual_dir_meta = loader.storage.raw_extrinsic_metadata_get(
MetadataTargetType.DIRECTORY, directory_swhid, authority
)
assert actual_dir_meta.next_page_token is None
assert len(actual_dir_meta.results) == len(all_metadata_raw)
for dir_meta in actual_dir_meta.results:
assert dir_meta.authority == authority
assert dir_meta.fetcher == fetcher
assert dir_meta.metadata.decode() in all_metadata_raw
# Retrieve the information for deposit status update query to the deposit
urls = [
m
for m in requests_mock_datadir.request_history
if m.url == f"{DEPOSIT_URL}/{deposit_id}/update/"
]
assert len(urls) == 1
update_query = urls[0]
body = update_query.json()
expected_body = {
"status": "done",
"revision_id": revision_id_hex,
"directory_id": hash_to_hex(revision.directory),
"snapshot_id": expected_snapshot_id,
"origin_url": url,
}
> assert body == expected_body
E AssertionError: assert {'status': 'failed'} == {'directory_i...a66ecbd', ...}
E Differing items:
E {'status': 'failed'} != {'status': 'done'}
E Right contains 4 more items:
E {'directory_id': 'fd2df12dc5534c1da1e9180b915102fb6f601d19',
E 'origin_url': 'https://hal-test.archives-ouvertes.fr/some-external-id',
E 'revision_id': '637318680351f5d78856d13264faebbd91efe9bb',
E 'snapshot_id': 'b2b327b33dc85818bd23c3ccda8b7e675a66ecbd'}...
E
E ...Full output truncated (12 lines hidden), use '-vv' to show
.tox/py3/lib/python3.7/site-packages/swh/loader/package/deposit/tests/test_deposit.py:279: AssertionError
TEST RESULT
TEST RESULT
- Run At
- Feb 25 2021, 11:50 AM