Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/package/deposit/tests/test_deposit.py
Show First 20 Lines • Show All 163 Lines • ▼ Show 20 Lines | |||||
def test_deposit_loading_ok(swh_storage, deposit_client, requests_mock_datadir): | def test_deposit_loading_ok(swh_storage, deposit_client, requests_mock_datadir): | ||||
url = "https://hal-test.archives-ouvertes.fr/some-external-id" | url = "https://hal-test.archives-ouvertes.fr/some-external-id" | ||||
deposit_id = 666 | deposit_id = 666 | ||||
loader = DepositLoader( | loader = DepositLoader( | ||||
swh_storage, url, deposit_id, deposit_client, default_filename="archive.zip" | swh_storage, url, deposit_id, deposit_client, default_filename="archive.zip" | ||||
) | ) | ||||
actual_load_status = loader.load() | actual_load_status = loader.load() | ||||
expected_snapshot_id = "1090aaadc9fd1a77798bf6187d309145cbd23c53" | expected_snapshot_id = "338b45d87e02fb5cbf324694bc4a898623d6a30f" | ||||
assert actual_load_status == { | assert actual_load_status == { | ||||
"status": "eventful", | "status": "eventful", | ||||
"snapshot_id": expected_snapshot_id, | "snapshot_id": expected_snapshot_id, | ||||
} | } | ||||
assert_last_visit_matches( | assert_last_visit_matches( | ||||
loader.storage, | loader.storage, | ||||
url, | url, | ||||
status="full", | status="full", | ||||
type="deposit", | type="deposit", | ||||
snapshot=hash_to_bytes(expected_snapshot_id), | snapshot=hash_to_bytes(expected_snapshot_id), | ||||
) | ) | ||||
release_id_hex = "77c127bff4f9137baf26774fe19e29d82a41f69d" | release_id_hex = "2566a64a27bc00362e265be9666d7606750530a1" | ||||
release_id = hash_to_bytes(release_id_hex) | release_id = hash_to_bytes(release_id_hex) | ||||
expected_snapshot = Snapshot( | expected_snapshot = Snapshot( | ||||
id=hash_to_bytes(expected_snapshot_id), | id=hash_to_bytes(expected_snapshot_id), | ||||
branches={ | branches={ | ||||
b"HEAD": SnapshotBranch(target=release_id, target_type=TargetType.RELEASE,), | b"HEAD": SnapshotBranch(target=release_id, target_type=TargetType.RELEASE,), | ||||
}, | }, | ||||
) | ) | ||||
check_snapshot(expected_snapshot, storage=loader.storage) | check_snapshot(expected_snapshot, storage=loader.storage) | ||||
release = loader.storage.release_get([release_id])[0] | release = loader.storage.release_get([release_id])[0] | ||||
date = TimestampWithTimezone( | date = TimestampWithTimezone( | ||||
timestamp=Timestamp(seconds=1507389428, microseconds=0), | timestamp=Timestamp(seconds=1507389428, microseconds=0), | ||||
offset=0, | offset=0, | ||||
negative_utc=False, | negative_utc=False, | ||||
) | ) | ||||
person = Person( | person = Person( | ||||
fullname=b"Software Heritage", | fullname=b"Software Heritage", | ||||
name=b"Software Heritage", | name=b"Software Heritage", | ||||
email=b"robot@softwareheritage.org", | email=b"robot@softwareheritage.org", | ||||
) | ) | ||||
assert release == Release( | assert release == Release( | ||||
id=release_id, | id=release_id, | ||||
name=b"HEAD", | name=b"HEAD", | ||||
message=b"hal: Deposit 666 in collection hal", | message=b"hal: Deposit 666 in collection hal\n", | ||||
author=person, | author=person, | ||||
date=date, | date=date, | ||||
target_type=ModelObjectType.DIRECTORY, | target_type=ModelObjectType.DIRECTORY, | ||||
target=b"\xfd-\xf1-\xc5SL\x1d\xa1\xe9\x18\x0b\x91Q\x02\xfbo`\x1d\x19", | target=b"\xfd-\xf1-\xc5SL\x1d\xa1\xe9\x18\x0b\x91Q\x02\xfbo`\x1d\x19", | ||||
synthetic=True, | synthetic=True, | ||||
metadata=None, | metadata=None, | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 75 Lines • ▼ Show 20 Lines | def test_deposit_loading_ok_2(swh_storage, deposit_client, requests_mock_datadir): | ||||
external_id = "some-external-id" | external_id = "some-external-id" | ||||
url = f"https://hal-test.archives-ouvertes.fr/{external_id}" | url = f"https://hal-test.archives-ouvertes.fr/{external_id}" | ||||
deposit_id = 777 | deposit_id = 777 | ||||
loader = DepositLoader( | loader = DepositLoader( | ||||
swh_storage, url, deposit_id, deposit_client, default_filename="archive.zip" | swh_storage, url, deposit_id, deposit_client, default_filename="archive.zip" | ||||
) | ) | ||||
actual_load_status = loader.load() | actual_load_status = loader.load() | ||||
expected_snapshot_id = "f87b25c121d9ab3ff0219b04b92d83f8c6f368f4" | expected_snapshot_id = "3449b8ff31abeacefd33cca60e3074c1649dc3a1" | ||||
assert actual_load_status == { | assert actual_load_status == { | ||||
"status": "eventful", | "status": "eventful", | ||||
"snapshot_id": expected_snapshot_id, | "snapshot_id": expected_snapshot_id, | ||||
} | } | ||||
assert_last_visit_matches( | assert_last_visit_matches( | ||||
loader.storage, | loader.storage, | ||||
url, | url, | ||||
status="full", | status="full", | ||||
type="deposit", | type="deposit", | ||||
snapshot=hash_to_bytes(expected_snapshot_id), | snapshot=hash_to_bytes(expected_snapshot_id), | ||||
) | ) | ||||
release_id = "c6891941d4033f4fb1dbf39b501c819ac618f957" | release_id = "ba6c9a59ae3256e765d32b211cc183dc2380aed7" | ||||
expected_snapshot = Snapshot( | expected_snapshot = Snapshot( | ||||
id=hash_to_bytes(expected_snapshot_id), | id=hash_to_bytes(expected_snapshot_id), | ||||
branches={ | branches={ | ||||
b"HEAD": SnapshotBranch( | b"HEAD": SnapshotBranch( | ||||
target=hash_to_bytes(release_id), target_type=TargetType.RELEASE | target=hash_to_bytes(release_id), target_type=TargetType.RELEASE | ||||
) | ) | ||||
}, | }, | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 148 Lines • ▼ Show 20 Lines | def test_deposit_loading_ok_3(swh_storage, deposit_client, requests_mock_datadir): | ||||
""" | """ | ||||
external_id = "hal-123456" | external_id = "hal-123456" | ||||
url = f"https://hal-test.archives-ouvertes.fr/{external_id}" | url = f"https://hal-test.archives-ouvertes.fr/{external_id}" | ||||
deposit_id = 888 | deposit_id = 888 | ||||
loader = DepositLoader(swh_storage, url, deposit_id, deposit_client) | loader = DepositLoader(swh_storage, url, deposit_id, deposit_client) | ||||
actual_load_status = loader.load() | actual_load_status = loader.load() | ||||
expected_snapshot_id = "212228fe041c763471c14545cf11dbec8003d6b4" | expected_snapshot_id = "4677843de89e398f1d6bfedc9ca9b89c451c55c8" | ||||
assert actual_load_status == { | assert actual_load_status == { | ||||
"status": "eventful", | "status": "eventful", | ||||
"snapshot_id": expected_snapshot_id, | "snapshot_id": expected_snapshot_id, | ||||
} | } | ||||
assert_last_visit_matches( | assert_last_visit_matches( | ||||
loader.storage, | loader.storage, | ||||
url, | url, | ||||
status="full", | status="full", | ||||
type="deposit", | type="deposit", | ||||
snapshot=hash_to_bytes(expected_snapshot_id), | snapshot=hash_to_bytes(expected_snapshot_id), | ||||
) | ) |