Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/tests/test_init.py
Show First 20 Lines • Show All 378 Lines • ▼ Show 20 Lines | def test_check_snapshot_failures(swh_storage): | ||||
) | ) | ||||
s = swh_storage.snapshot_add([snapshot]) | s = swh_storage.snapshot_add([snapshot]) | ||||
assert s == { | assert s == { | ||||
"snapshot:add": 1, | "snapshot:add": 1, | ||||
} | } | ||||
unexpected_snapshot = { | unexpected_snapshot = { | ||||
"id": "2498dbf535f882bc7f9a18fb16c9ad27fda7bab7", # id is correct | # id is correct | ||||
"id": hash_to_bytes(snap_id_hex), | |||||
"branches": { | "branches": { | ||||
b"master": { | b"master": { | ||||
"target": hash_to_bytes(hash_hex), # wrong branch | "target": hash_to_bytes(hash_hex), # wrong branch | ||||
"target_type": "release", | "target_type": "release", | ||||
} | } | ||||
}, | }, | ||||
} | } | ||||
# 0. not a Snapshot object, raise! | # 0. not a Snapshot object, raise! | ||||
with pytest.raises(AssertionError, match="variable 'snapshot' must be a snapshot"): | with pytest.raises(AssertionError, match="variable 'snapshot' must be a snapshot"): | ||||
check_snapshot(ORIGIN_VISIT, swh_storage) | check_snapshot(ORIGIN_VISIT, swh_storage) | ||||
# 1. snapshot id is correct but branches mismatched | # 1. snapshot id is correct but branches mismatched | ||||
for snap_id in [snap_id_hex, snapshot.id]: | |||||
with pytest.raises(AssertionError, match="Differing attributes"): | with pytest.raises(AssertionError, match="Differing attributes"): | ||||
unexpected_snapshot["id"] = snap_id | unexpected_snapshot["id"] = snapshot.id | ||||
check_snapshot(unexpected_snapshot, swh_storage) | check_snapshot(unexpected_snapshot, swh_storage) | ||||
# 2. snapshot id is not correct, it's not found in the storage | # 2. snapshot id is not correct, it's not found in the storage | ||||
wrong_snap_id_hex = "999666f535f882bc7f9a18fb16c9ad27fda7bab7" | wrong_snap_id = hash_to_bytes("999666f535f882bc7f9a18fb16c9ad27fda7bab7") | ||||
for snap_id in [wrong_snap_id_hex, hash_to_bytes(wrong_snap_id_hex)]: | unexpected_snapshot["id"] = wrong_snap_id | ||||
unexpected_snapshot["id"] = wrong_snap_id_hex | |||||
with pytest.raises(AssertionError, match="is not found"): | with pytest.raises(AssertionError, match="is not found"): | ||||
check_snapshot(unexpected_snapshot, swh_storage) | check_snapshot(unexpected_snapshot, swh_storage) | ||||
# 3. snapshot references an inexistent alias | # 3. snapshot references an inexistent alias | ||||
snapshot0 = Snapshot( | snapshot0 = Snapshot( | ||||
id=hash_to_bytes("123666f535f882bc7f9a18fb16c9ad27fda7bab7"), | id=hash_to_bytes("123666f535f882bc7f9a18fb16c9ad27fda7bab7"), | ||||
branches={ | branches={ | ||||
b"alias": SnapshotBranch(target=b"HEAD", target_type=TargetType.ALIAS,), | b"alias": SnapshotBranch(target=b"HEAD", target_type=TargetType.ALIAS,), | ||||
}, | }, | ||||
) | ) | ||||
Show All 39 Lines |