Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/utils/test_archive.py
Show First 20 Lines • Show All 990 Lines • ▼ Show 20 Lines | def test_search_origin_use_ql(mocker, origin): | ||||
) | ) | ||||
def test_lookup_snapshot_sizes(archive_data, snapshot): | def test_lookup_snapshot_sizes(archive_data, snapshot): | ||||
branches = archive_data.snapshot_get(snapshot)["branches"] | branches = archive_data.snapshot_get(snapshot)["branches"] | ||||
expected_sizes = { | expected_sizes = { | ||||
"alias": 0, | "alias": 0, | ||||
"branch": 0, | |||||
"release": 0, | "release": 0, | ||||
"revision": 0, | "revision": 0, | ||||
} | } | ||||
for branch_name, branch_info in branches.items(): | for _, branch_info in branches.items(): | ||||
if branch_info is not None: | if branch_info is not None: | ||||
expected_sizes[branch_info["target_type"]] += 1 | expected_sizes[branch_info["target_type"]] += 1 | ||||
if branch_info["target_type"] in ("content", "directory", "revision"): | |||||
expected_sizes["branch"] += 1 | |||||
assert archive.lookup_snapshot_sizes(snapshot) == expected_sizes | assert archive.lookup_snapshot_sizes(snapshot) == expected_sizes | ||||
def test_lookup_snapshot_sizes_with_filtering(archive_data, revision): | def test_lookup_snapshot_sizes_with_filtering(archive_data, revision): | ||||
rev_id = hash_to_bytes(revision) | rev_id = hash_to_bytes(revision) | ||||
snapshot = Snapshot( | snapshot = Snapshot( | ||||
branches={ | branches={ | ||||
Show All 12 Lines | snapshot = Snapshot( | ||||
b"refs/pull/2": SnapshotBranch( | b"refs/pull/2": SnapshotBranch( | ||||
target=rev_id, | target=rev_id, | ||||
target_type=TargetType.REVISION, | target_type=TargetType.REVISION, | ||||
), | ), | ||||
}, | }, | ||||
) | ) | ||||
archive_data.snapshot_add([snapshot]) | archive_data.snapshot_add([snapshot]) | ||||
expected_sizes = {"alias": 0, "release": 0, "revision": 2} | expected_sizes = {"alias": 0, "branch": 2, "release": 0, "revision": 2} | ||||
assert ( | assert ( | ||||
archive.lookup_snapshot_sizes( | archive.lookup_snapshot_sizes( | ||||
snapshot.id.hex(), branch_name_exclude_prefix="refs/pull/" | snapshot.id.hex(), branch_name_exclude_prefix="refs/pull/" | ||||
) | ) | ||||
== expected_sizes | == expected_sizes | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 152 Lines • Show Last 20 Lines |