Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/package/rpm/tests/test_rpm.py
- This file was added.
from swh.loader.package.rpm.loader import RpmLoader | |||||
anlambert: (C) 2022 | |||||
from swh.loader.tests import assert_last_visit_matches, check_snapshot, get_stats | |||||
from swh.model.hashutil import hash_to_bytes | |||||
from swh.model.model import ObjectType, Release, Snapshot, SnapshotBranch, TargetType | |||||
URL = "rpm://Fedora/packages/nginx" | |||||
PACKAGE_FILES = { | |||||
"nginx-1.18.0-5.fc34.src.rpm": { # TODO: Use a smaller package | |||||
"name": "nginx", | |||||
"version": "1.18.0", | |||||
"release": "2.el8_2.ngx", # FIXME?s | |||||
"url": "https://archives.fedoraproject.org/nginx-1.18.0-5.fc34.src.rpm", | |||||
} | |||||
} | |||||
PACKAGE_PER_VERSION = {"36/Everything/0.7.2": PACKAGE_FILES} | |||||
def test_rpm_first_visit(swh_storage, requests_mock_datadir): # | |||||
loader = RpmLoader(swh_storage, URL, packages=PACKAGE_PER_VERSION) | |||||
actual_load_status = loader.load() | |||||
expected_snapshot_id = "afe532f23049819c001dc31dedc04bd081b7a344" | |||||
assert actual_load_status == { | |||||
"status": "eventful", | |||||
"snapshot_id": expected_snapshot_id, | |||||
} | |||||
Not Done Inline Actionsfedora34/everything/1.18.0-5 instead to match the lister output anlambert: `fedora34/everything/1.18.0-5` instead to match the lister output | |||||
assert_last_visit_matches( | |||||
swh_storage, | |||||
Not Done Inline Actions1.18.0-5 to match the lister output anlambert: `1.18.0-5` to match the lister output | |||||
URL, | |||||
status="full", | |||||
type="rpm", | |||||
snapshot=hash_to_bytes(expected_snapshot_id), | |||||
) | |||||
release_id = hash_to_bytes("c5a2415156c9bf4f97176e931a392edf428418e3") | |||||
expected_snapshot = Snapshot( | |||||
id=hash_to_bytes(expected_snapshot_id), | |||||
branches={ | |||||
b"36/Everything/0.7.2": SnapshotBranch( | |||||
target=release_id, | |||||
target_type=TargetType.RELEASE, | |||||
) | |||||
}, | |||||
) | |||||
check_snapshot(expected_snapshot, swh_storage) | |||||
assert swh_storage.release_get([release_id])[0] == Release( | |||||
id=release_id, | |||||
name=b"nginx", | |||||
message=b"Synthetic release for Rpm source package nginx version 36/Everything/0.7.2\n", | |||||
target=hash_to_bytes("044965ae8affff6fd0bcb908bb345e626ca99ef6"), | |||||
Not Done Inline Actionssame here anlambert: same here | |||||
target_type=ObjectType.DIRECTORY, | |||||
synthetic=True, | |||||
) | |||||
stats = get_stats(swh_storage) | |||||
assert { | |||||
"content": 20, | |||||
"directory": 1, | |||||
"origin": 1, | |||||
"origin_visit": 1, | |||||
"release": 1, | |||||
"revision": 0, | |||||
"skipped_content": 0, | |||||
"snapshot": 1, | |||||
} == stats | |||||
def test_debian_multiple_visits(swh_storage, requests_mock_datadir): | |||||
loader = RpmLoader(swh_storage, URL, packages=PACKAGE_PER_VERSION) | |||||
actual_load_status = loader.load() | |||||
expected_snapshot_id = "afe532f23049819c001dc31dedc04bd081b7a344" | |||||
assert actual_load_status == { | |||||
"status": "eventful", | |||||
"snapshot_id": expected_snapshot_id, | |||||
} | |||||
loader.load() | |||||
# actual_load_status2 = | |||||
# assert actual_load_status2 == { | |||||
# "status": "uneventful" | |||||
# } # TODO: Verify | |||||
assert_last_visit_matches( | |||||
swh_storage, | |||||
URL, | |||||
status="full", | |||||
type="rpm", | |||||
snapshot=hash_to_bytes(expected_snapshot_id), | |||||
) | |||||
stats2 = get_stats(swh_storage) | |||||
assert { | |||||
"content": 20 + 0, | |||||
"directory": 1 + 0, | |||||
"origin": 1, | |||||
"origin_visit": 1 + 1, # a new visit occurred | |||||
"release": 1, | |||||
"revision": 0, | |||||
"skipped_content": 0, | |||||
"snapshot": 1, # same snapshot across 2 visits | |||||
} == stats2 | |||||
urls = [ | |||||
m.url | |||||
for m in requests_mock_datadir.request_history | |||||
if m.url.startswith("https://archives.fedoraproject.org") | |||||
] | |||||
# visited each package artifact twice across 2 visits # FIXME | |||||
assert ( | |||||
urls == ["https://archives.fedoraproject.org/nginx-1.18.0-5.fc34.src.rpm"] * 2 | |||||
) # FIXME should be 1 | |||||
Done Inline ActionsThe content hasn't changed so it should be uneventful, right? KShivendu: The content hasn't changed so it should be uneventful, right? |
(C) 2022