Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/package/debian/tests/test_debian.py
Show All 17 Lines | from swh.loader.package.debian.loader import ( | ||||
dsc_information, | dsc_information, | ||||
extract_package, | extract_package, | ||||
get_intrinsic_package_metadata, | get_intrinsic_package_metadata, | ||||
prepare_person, | prepare_person, | ||||
uid_to_person, | uid_to_person, | ||||
) | ) | ||||
from swh.loader.tests import assert_last_visit_matches, check_snapshot, get_stats | from swh.loader.tests import assert_last_visit_matches, check_snapshot, get_stats | ||||
from swh.model.hashutil import hash_to_bytes | from swh.model.hashutil import hash_to_bytes | ||||
from swh.model.model import Person, Snapshot, SnapshotBranch, TargetType | from swh.model.model import ( | ||||
ObjectType, | |||||
Person, | |||||
Release, | |||||
Snapshot, | |||||
SnapshotBranch, | |||||
TargetType, | |||||
Timestamp, | |||||
TimestampWithTimezone, | |||||
) | |||||
logger = logging.getLogger(__name__) | logger = logging.getLogger(__name__) | ||||
URL = "deb://Debian/packages/cicero" | URL = "deb://Debian/packages/cicero" | ||||
PACKAGE_FILES = { | PACKAGE_FILES = { | ||||
"name": "cicero", | "name": "cicero", | ||||
▲ Show 20 Lines • Show All 70 Lines • ▼ Show 20 Lines | def test_debian_first_visit(swh_storage, requests_mock_datadir): | ||||
loader = DebianLoader( | loader = DebianLoader( | ||||
swh_storage, | swh_storage, | ||||
URL, | URL, | ||||
date="2019-10-12T05:58:09.165557+00:00", | date="2019-10-12T05:58:09.165557+00:00", | ||||
packages=PACKAGE_PER_VERSION, | packages=PACKAGE_PER_VERSION, | ||||
) | ) | ||||
actual_load_status = loader.load() | actual_load_status = loader.load() | ||||
expected_snapshot_id = "8bc5d12e2443ab216fdd2f969b25b39e96c20fef" | expected_snapshot_id = "20073c91e85b8bcbd2639990e76765d25bd2c0a6" | ||||
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( | ||||
swh_storage, | swh_storage, | ||||
URL, | URL, | ||||
status="full", | status="full", | ||||
type="deb", | type="deb", | ||||
snapshot=hash_to_bytes(expected_snapshot_id), | snapshot=hash_to_bytes(expected_snapshot_id), | ||||
) | ) | ||||
release_id = hash_to_bytes("ed191d99e070a33458a4a402becd0b4bba09cd1e") | |||||
expected_snapshot = Snapshot( | expected_snapshot = Snapshot( | ||||
id=hash_to_bytes(expected_snapshot_id), | id=hash_to_bytes(expected_snapshot_id), | ||||
branches={ | branches={ | ||||
b"releases/stretch/contrib/0.7.2-3": SnapshotBranch( | b"releases/stretch/contrib/0.7.2-3": SnapshotBranch( | ||||
target_type=TargetType.RELEASE, | target_type=TargetType.RELEASE, target=release_id, | ||||
target=hash_to_bytes("5a99736512d381700c5f54d7fdd6b46e136535a2"), | |||||
) | ) | ||||
}, | }, | ||||
) # different than the previous loader as no release is done | ) # different than the previous loader as no release is done | ||||
check_snapshot(expected_snapshot, swh_storage) | check_snapshot(expected_snapshot, swh_storage) | ||||
assert swh_storage.release_get([release_id])[0] == Release( | |||||
id=release_id, | |||||
name=b"stretch/contrib/0.7.2-3", | |||||
message=b"Synthetic release for Debian source package cicero version 0.7.2-3", | |||||
target=hash_to_bytes("798df511408c53bf842a8e54d4d335537836bdc3"), | |||||
target_type=ObjectType.DIRECTORY, | |||||
synthetic=True, | |||||
author=Person( | |||||
fullname=b"Samuel Thibault <sthibault@debian.org>", | |||||
name=b"Samuel Thibault", | |||||
email=b"sthibault@debian.org", | |||||
), | |||||
date=TimestampWithTimezone( | |||||
timestamp=Timestamp(seconds=1413730355, microseconds=0), | |||||
offset=120, | |||||
negative_utc=False, | |||||
), | |||||
) | |||||
stats = get_stats(swh_storage) | stats = get_stats(swh_storage) | ||||
assert { | assert { | ||||
"content": 42, | "content": 42, | ||||
"directory": 2, | "directory": 2, | ||||
"origin": 1, | "origin": 1, | ||||
"origin_visit": 1, | "origin_visit": 1, | ||||
"release": 1, # all artifacts under 1 release | "release": 1, # all artifacts under 1 release | ||||
"revision": 0, | "revision": 0, | ||||
Show All 10 Lines | loader = DebianLoader( | ||||
swh_storage, | swh_storage, | ||||
URL, | URL, | ||||
date="2019-10-12T05:58:09.165557+00:00", | date="2019-10-12T05:58:09.165557+00:00", | ||||
packages=PACKAGE_PER_VERSION, | packages=PACKAGE_PER_VERSION, | ||||
) | ) | ||||
actual_load_status = loader.load() | actual_load_status = loader.load() | ||||
expected_snapshot_id = "8bc5d12e2443ab216fdd2f969b25b39e96c20fef" | expected_snapshot_id = "20073c91e85b8bcbd2639990e76765d25bd2c0a6" | ||||
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( | ||||
swh_storage, | swh_storage, | ||||
URL, | URL, | ||||
status="full", | status="full", | ||||
type="deb", | type="deb", | ||||
snapshot=hash_to_bytes(expected_snapshot_id), | snapshot=hash_to_bytes(expected_snapshot_id), | ||||
) | ) | ||||
expected_snapshot = Snapshot( | expected_snapshot = Snapshot( | ||||
id=hash_to_bytes(expected_snapshot_id), | id=hash_to_bytes(expected_snapshot_id), | ||||
branches={ | branches={ | ||||
b"releases/stretch/contrib/0.7.2-3": SnapshotBranch( | b"releases/stretch/contrib/0.7.2-3": SnapshotBranch( | ||||
target_type=TargetType.RELEASE, | target_type=TargetType.RELEASE, | ||||
target=hash_to_bytes("5a99736512d381700c5f54d7fdd6b46e136535a2"), | target=hash_to_bytes("ed191d99e070a33458a4a402becd0b4bba09cd1e"), | ||||
) | ) | ||||
}, | }, | ||||
) # different than the previous loader as no release is done | ) # different than the previous loader as no release is done | ||||
check_snapshot(expected_snapshot, swh_storage) | check_snapshot(expected_snapshot, swh_storage) | ||||
stats = get_stats(swh_storage) | stats = get_stats(swh_storage) | ||||
assert { | assert { | ||||
▲ Show 20 Lines • Show All 220 Lines • ▼ Show 20 Lines | def test_debian_multiple_packages(swh_storage, requests_mock_datadir): | ||||
loader = DebianLoader( | loader = DebianLoader( | ||||
swh_storage, | swh_storage, | ||||
URL, | URL, | ||||
date="2019-10-12T05:58:09.165557+00:00", | date="2019-10-12T05:58:09.165557+00:00", | ||||
packages=PACKAGES_PER_VERSION, | packages=PACKAGES_PER_VERSION, | ||||
) | ) | ||||
actual_load_status = loader.load() | actual_load_status = loader.load() | ||||
expected_snapshot_id = "3d26243c91eb084c350627a5a102cfe039c5b92a" | expected_snapshot_id = "3e423d7889ebd8df0ed0373016f035dfed8541cb" | ||||
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( | ||||
swh_storage, | swh_storage, | ||||
URL, | URL, | ||||
status="full", | status="full", | ||||
type="deb", | type="deb", | ||||
snapshot=hash_to_bytes(expected_snapshot_id), | snapshot=hash_to_bytes(expected_snapshot_id), | ||||
) | ) | ||||
expected_snapshot = Snapshot( | expected_snapshot = Snapshot( | ||||
id=hash_to_bytes(expected_snapshot_id), | id=hash_to_bytes(expected_snapshot_id), | ||||
branches={ | branches={ | ||||
b"releases/stretch/contrib/0.7.2-3": SnapshotBranch( | b"releases/stretch/contrib/0.7.2-3": SnapshotBranch( | ||||
target_type=TargetType.RELEASE, | target_type=TargetType.RELEASE, | ||||
target=hash_to_bytes("5a99736512d381700c5f54d7fdd6b46e136535a2"), | target=hash_to_bytes("ed191d99e070a33458a4a402becd0b4bba09cd1e"), | ||||
), | ), | ||||
b"releases/buster/contrib/0.7.2-4": SnapshotBranch( | b"releases/buster/contrib/0.7.2-4": SnapshotBranch( | ||||
target_type=TargetType.RELEASE, | target_type=TargetType.RELEASE, | ||||
target=hash_to_bytes("192fc7ccce80f64a0d3cf33d379133af067ec721"), | target=hash_to_bytes("d3dff4a416816c36dc284e49c1c9eed52c2d2ef4"), | ||||
), | ), | ||||
}, | }, | ||||
) | ) | ||||
check_snapshot(expected_snapshot, swh_storage) | check_snapshot(expected_snapshot, swh_storage) |