Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/package/cran/tests/test_cran.py
Show All 17 Lines | from swh.loader.package.cran.loader import ( | ||||
parse_date, | parse_date, | ||||
parse_debian_control, | parse_debian_control, | ||||
) | ) | ||||
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 Snapshot, SnapshotBranch, TargetType, TimestampWithTimezone | from swh.model.model import Snapshot, SnapshotBranch, TargetType, TimestampWithTimezone | ||||
SNAPSHOT = Snapshot( | SNAPSHOT = Snapshot( | ||||
id=hash_to_bytes("920adcccc78aaeedd3cfa4459dd900d8c3431a21"), | id=hash_to_bytes("56ed00938d83892bd5b42f2f368ae38a1dbfa718"), | ||||
branches={ | branches={ | ||||
b"HEAD": SnapshotBranch( | b"HEAD": SnapshotBranch( | ||||
target=b"releases/2.22-6", target_type=TargetType.ALIAS | target=b"releases/2.22-6", target_type=TargetType.ALIAS | ||||
), | ), | ||||
b"releases/2.22-6": SnapshotBranch( | b"releases/2.22-6": SnapshotBranch( | ||||
target=hash_to_bytes("42bdb16facd5140424359c8ce89a28ecfa1ce603"), | target=hash_to_bytes("42993a72eac50a4a83523c9327a52be3593755a8"), | ||||
target_type=TargetType.REVISION, | target_type=TargetType.RELEASE, | ||||
), | ), | ||||
}, | }, | ||||
) | ) | ||||
def test_cran_parse_date(): | def test_cran_parse_date(): | ||||
data = [ | data = [ | ||||
# parsable, some have debatable results though | # parsable, some have debatable results though | ||||
▲ Show 20 Lines • Show All 147 Lines • ▼ Show 20 Lines | def test_cran_one_visit(swh_storage, requests_mock_datadir): | ||||
check_snapshot(SNAPSHOT, swh_storage) | check_snapshot(SNAPSHOT, swh_storage) | ||||
visit_stats = get_stats(swh_storage) | visit_stats = get_stats(swh_storage) | ||||
assert { | assert { | ||||
"content": 33, | "content": 33, | ||||
"directory": 7, | "directory": 7, | ||||
"origin": 1, | "origin": 1, | ||||
"origin_visit": 1, | "origin_visit": 1, | ||||
"release": 0, | "release": 1, | ||||
"revision": 1, | "revision": 0, | ||||
"skipped_content": 0, | "skipped_content": 0, | ||||
"snapshot": 1, | "snapshot": 1, | ||||
} == visit_stats | } == visit_stats | ||||
urls = [ | urls = [ | ||||
m.url | m.url | ||||
for m in requests_mock_datadir.request_history | for m in requests_mock_datadir.request_history | ||||
if m.url.startswith(base_url) | if m.url.startswith(base_url) | ||||
Show All 29 Lines | def test_cran_2_visits_same_origin(swh_storage, requests_mock_datadir): | ||||
) | ) | ||||
visit_stats = get_stats(swh_storage) | visit_stats = get_stats(swh_storage) | ||||
assert { | assert { | ||||
"content": 33, | "content": 33, | ||||
"directory": 7, | "directory": 7, | ||||
"origin": 1, | "origin": 1, | ||||
"origin_visit": 1, | "origin_visit": 1, | ||||
"release": 0, | "release": 1, | ||||
"revision": 1, | "revision": 0, | ||||
"skipped_content": 0, | "skipped_content": 0, | ||||
"snapshot": 1, | "snapshot": 1, | ||||
} == visit_stats | } == visit_stats | ||||
# second visit | # second visit | ||||
actual_load_status2 = loader.load() | actual_load_status2 = loader.load() | ||||
assert actual_load_status2 == { | assert actual_load_status2 == { | ||||
▲ Show 20 Lines • Show All 99 Lines • ▼ Show 20 Lines | ): | ||||
} | } | ||||
visit_stats = get_stats(swh_storage) | visit_stats = get_stats(swh_storage) | ||||
assert { | assert { | ||||
"content": 33, | "content": 33, | ||||
"directory": 7, | "directory": 7, | ||||
"origin": 1, | "origin": 1, | ||||
"origin_visit": 1, | "origin_visit": 1, | ||||
"release": 0, | "release": 1, | ||||
"revision": 1, | "revision": 0, | ||||
"skipped_content": 0, | "skipped_content": 0, | ||||
"snapshot": 1, | "snapshot": 1, | ||||
} == visit_stats | } == visit_stats | ||||
assert_last_visit_matches( | assert_last_visit_matches( | ||||
swh_storage, origin_url, status="partial", type="cran", snapshot=SNAPSHOT.id | swh_storage, origin_url, status="partial", type="cran", snapshot=SNAPSHOT.id | ||||
) | ) |