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 | |||||
ORIGIN = "rpm://Fedora/packages/nginx" | |||||
PACKAGES = { | |||||
"34/Everything/1.18.0": { | |||||
"name": "nginx", | |||||
"version": "1.18.0", | |||||
"release": 34, | |||||
"url": "https://archives.fedoraproject.org/nginx-1.18.0-5.fc34.src.rpm", | |||||
} | |||||
} | |||||
def test_rpm_first_visit(swh_storage, requests_mock_datadir): # | |||||
loader = RpmLoader(swh_storage, ORIGIN, packages=PACKAGES) | |||||
actual_load_status = loader.load() | |||||
expected_snapshot_id = "e3b7c9a045c508fd7a8305aa89fc1b817c80e6c9" | |||||
assert actual_load_status == { | |||||
"status": "eventful", | |||||
"snapshot_id": expected_snapshot_id, | |||||
} | |||||
assert_last_visit_matches( | |||||
swh_storage, | |||||
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 | |||||
ORIGIN, | |||||
status="full", | |||||
Not Done Inline Actions1.18.0-5 to match the lister output anlambert: `1.18.0-5` to match the lister output | |||||
type="rpm", | |||||
snapshot=hash_to_bytes(expected_snapshot_id), | |||||
) | |||||
release_id = hash_to_bytes("6d4cd2e3429d223e862753c7c8a94bb7e8c21db1") | |||||
expected_snapshot = Snapshot( | |||||
id=hash_to_bytes(expected_snapshot_id), | |||||
branches={ | |||||
b"34/Everything/1.18.0": 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 " | |||||
b"nginx version 34/Everything/1.18.0\n" | |||||
), | |||||
Not Done Inline Actionssame here anlambert: same here | |||||
target=hash_to_bytes("044965ae8affff6fd0bcb908bb345e626ca99ef6"), | |||||
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_rpm_multiple_visits(swh_storage, requests_mock_datadir): | |||||
loader = RpmLoader(swh_storage, ORIGIN, packages=PACKAGES) | |||||
actual_load_status = loader.load() | |||||
expected_snapshot_id = "e3b7c9a045c508fd7a8305aa89fc1b817c80e6c9" | |||||
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, | |||||
ORIGIN, | |||||
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