Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/tests/algos/test_snapshot.py
Show First 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | def test_snapshot_get_latest_none(swh_storage, sample_data): | ||||
origin_visit, origin_visit2 = sample_data.origin_visits[:2] | origin_visit, origin_visit2 = sample_data.origin_visits[:2] | ||||
assert origin_visit.origin == origin.url | assert origin_visit.origin == origin.url | ||||
swh_storage.origin_visit_add([origin_visit]) | swh_storage.origin_visit_add([origin_visit]) | ||||
assert snapshot_get_latest(swh_storage, origin.url) is None | assert snapshot_get_latest(swh_storage, origin.url) is None | ||||
ov1 = swh_storage.origin_visit_get_latest(origin.url) | ov1 = swh_storage.origin_visit_get_latest(origin.url) | ||||
assert ov1 is not None | assert ov1 is not None | ||||
visit_id = ov1["visit"] | |||||
# visit references a snapshot but the snapshot does not exist in backend for some | # visit references a snapshot but the snapshot does not exist in backend for some | ||||
# reason | # reason | ||||
complete_snapshot = sample_data.snapshots[2] | complete_snapshot = sample_data.snapshots[2] | ||||
swh_storage.origin_visit_status_add( | swh_storage.origin_visit_status_add( | ||||
[ | [ | ||||
OriginVisitStatus( | OriginVisitStatus( | ||||
origin=origin.url, | origin=origin.url, | ||||
visit=visit_id, | visit=ov1.visit, | ||||
date=origin_visit2.date, | date=origin_visit2.date, | ||||
status="partial", | status="partial", | ||||
snapshot=complete_snapshot.id, | snapshot=complete_snapshot.id, | ||||
) | ) | ||||
] | ] | ||||
) | ) | ||||
# so we do not find it | # so we do not find it | ||||
assert snapshot_get_latest(swh_storage, origin.url) is None | assert snapshot_get_latest(swh_storage, origin.url) is None | ||||
assert snapshot_get_latest(swh_storage, origin.url, branches_count=1) is None | assert snapshot_get_latest(swh_storage, origin.url, branches_count=1) is None | ||||
def test_snapshot_get_latest(swh_storage, sample_data): | def test_snapshot_get_latest(swh_storage, sample_data): | ||||
origin = sample_data.origin | origin = sample_data.origin | ||||
swh_storage.origin_add([origin]) | swh_storage.origin_add([origin]) | ||||
visit1, visit2 = sample_data.origin_visits[:2] | visit1, visit2 = sample_data.origin_visits[:2] | ||||
assert visit1.origin == origin.url | assert visit1.origin == origin.url | ||||
swh_storage.origin_visit_add([visit1]) | swh_storage.origin_visit_add([visit1]) | ||||
ov1 = swh_storage.origin_visit_get_latest(origin.url) | ov1 = swh_storage.origin_visit_get_latest(origin.url) | ||||
visit_id = ov1["visit"] | |||||
# Add snapshot to visit1, latest snapshot = visit 1 snapshot | # Add snapshot to visit1, latest snapshot = visit 1 snapshot | ||||
complete_snapshot = sample_data.snapshots[2] | complete_snapshot = sample_data.snapshots[2] | ||||
swh_storage.snapshot_add([complete_snapshot]) | swh_storage.snapshot_add([complete_snapshot]) | ||||
swh_storage.origin_visit_status_add( | swh_storage.origin_visit_status_add( | ||||
[ | [ | ||||
OriginVisitStatus( | OriginVisitStatus( | ||||
origin=origin.url, | origin=origin.url, | ||||
visit=visit_id, | visit=ov1.visit, | ||||
date=visit2.date, | date=visit2.date, | ||||
status="partial", | status="partial", | ||||
snapshot=None, | snapshot=None, | ||||
) | ) | ||||
] | ] | ||||
) | ) | ||||
assert visit1.date < visit2.date | assert visit1.date < visit2.date | ||||
# no snapshot associated to the visit, so None | # no snapshot associated to the visit, so None | ||||
actual_snapshot = snapshot_get_latest( | actual_snapshot = snapshot_get_latest( | ||||
swh_storage, origin.url, allowed_statuses=["partial"] | swh_storage, origin.url, allowed_statuses=["partial"] | ||||
) | ) | ||||
assert actual_snapshot is None | assert actual_snapshot is None | ||||
date_now = now() | date_now = now() | ||||
assert visit2.date < date_now | assert visit2.date < date_now | ||||
swh_storage.origin_visit_status_add( | swh_storage.origin_visit_status_add( | ||||
[ | [ | ||||
OriginVisitStatus( | OriginVisitStatus( | ||||
origin=origin.url, | origin=origin.url, | ||||
visit=visit_id, | visit=ov1.visit, | ||||
date=date_now, | date=date_now, | ||||
status="full", | status="full", | ||||
snapshot=complete_snapshot.id, | snapshot=complete_snapshot.id, | ||||
) | ) | ||||
] | ] | ||||
) | ) | ||||
swh_storage.origin_visit_add( | swh_storage.origin_visit_add( | ||||
Show All 14 Lines |