Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/package/pypi/tests/test_pypi.py
Show First 20 Lines • Show All 391 Lines • ▼ Show 20 Lines | expected_snapshot = Snapshot( | ||||
), | ), | ||||
b"HEAD": SnapshotBranch( | b"HEAD": SnapshotBranch( | ||||
target=b"releases/1.2.0", target_type=TargetType.ALIAS, | target=b"releases/1.2.0", target_type=TargetType.ALIAS, | ||||
), | ), | ||||
}, | }, | ||||
) | ) | ||||
check_snapshot(expected_snapshot, storage=swh_storage) | check_snapshot(expected_snapshot, storage=swh_storage) | ||||
expected_contents = map( | |||||
hash_to_bytes, | |||||
[ | |||||
"405859113963cb7a797642b45f171d6360425d16", | |||||
"e5686aa568fdb1d19d7f1329267082fe40482d31", | |||||
"83ecf6ec1114fd260ca7a833a2d165e71258c338", | |||||
], | |||||
) | |||||
assert list(swh_storage.content_missing_per_sha1(expected_contents)) == [] | |||||
expected_dirs = map( | |||||
hash_to_bytes, | |||||
[ | |||||
"b178b66bd22383d5f16f4f5c923d39ca798861b4", | |||||
"c3a58f8b57433a4b56caaa5033ae2e0931405338", | |||||
], | |||||
) | |||||
assert list(swh_storage.directory_missing(expected_dirs)) == [] | |||||
# {revision hash: directory hash} | |||||
expected_revs = { | |||||
hash_to_bytes("e445da4da22b31bfebb6ffc4383dbf839a074d21"): hash_to_bytes( | |||||
"b178b66bd22383d5f16f4f5c923d39ca798861b4" | |||||
), # noqa | |||||
} | |||||
assert list(swh_storage.revision_missing(expected_revs)) == [] | |||||
stats = get_stats(swh_storage) | stats = get_stats(swh_storage) | ||||
assert { | assert { | ||||
"content": 3, | "content": 3, | ||||
"directory": 2, | "directory": 2, | ||||
"origin": 1, | "origin": 1, | ||||
"origin_visit": 1, | "origin_visit": 1, | ||||
"release": 0, | "release": 0, | ||||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | assert { | ||||
"origin": 1, | "origin": 1, | ||||
"origin_visit": 1, | "origin_visit": 1, | ||||
"release": 0, | "release": 0, | ||||
"revision": 2, | "revision": 2, | ||||
"skipped_content": 0, | "skipped_content": 0, | ||||
"snapshot": 1, | "snapshot": 1, | ||||
} == stats | } == stats | ||||
expected_contents = map( | |||||
hash_to_bytes, | |||||
[ | |||||
"a61e24cdfdab3bb7817f6be85d37a3e666b34566", | |||||
"938c33483285fd8ad57f15497f538320df82aeb8", | |||||
"a27576d60e08c94a05006d2e6d540c0fdb5f38c8", | |||||
"405859113963cb7a797642b45f171d6360425d16", | |||||
"e5686aa568fdb1d19d7f1329267082fe40482d31", | |||||
"83ecf6ec1114fd260ca7a833a2d165e71258c338", | |||||
], | |||||
) | |||||
assert list(swh_storage.content_missing_per_sha1(expected_contents)) == [] | |||||
expected_dirs = map( | |||||
hash_to_bytes, | |||||
[ | |||||
"05219ba38bc542d4345d5638af1ed56c7d43ca7d", | |||||
"cf019eb456cf6f78d8c4674596f1c9a97ece8f44", | |||||
"b178b66bd22383d5f16f4f5c923d39ca798861b4", | |||||
"c3a58f8b57433a4b56caaa5033ae2e0931405338", | |||||
], | |||||
) | |||||
assert list(swh_storage.directory_missing(expected_dirs)) == [] | |||||
# {revision hash: directory hash} | |||||
expected_revs = { | |||||
hash_to_bytes("4c99891f93b81450385777235a37b5e966dd1571"): hash_to_bytes( | |||||
"05219ba38bc542d4345d5638af1ed56c7d43ca7d" | |||||
), # noqa | |||||
hash_to_bytes("e445da4da22b31bfebb6ffc4383dbf839a074d21"): hash_to_bytes( | |||||
"b178b66bd22383d5f16f4f5c923d39ca798861b4" | |||||
), # noqa | |||||
} | |||||
assert list(swh_storage.revision_missing(expected_revs)) == [] | |||||
def test_pypi_multiple_visits_with_no_change(swh_storage, requests_mock_datadir): | def test_pypi_multiple_visits_with_no_change(swh_storage, requests_mock_datadir): | ||||
"""Multiple visits with no changes results in 1 same snapshot | """Multiple visits with no changes results in 1 same snapshot | ||||
""" | """ | ||||
url = "https://pypi.org/project/0805nexter" | url = "https://pypi.org/project/0805nexter" | ||||
loader = PyPILoader(swh_storage, url) | loader = PyPILoader(swh_storage, url) | ||||
▲ Show 20 Lines • Show All 138 Lines • ▼ Show 20 Lines | assert { | ||||
"origin": 1, | "origin": 1, | ||||
"origin_visit": 1 + 1, | "origin_visit": 1 + 1, | ||||
"release": 0, | "release": 0, | ||||
"revision": 2 + 1, # 1 more revision | "revision": 2 + 1, # 1 more revision | ||||
"skipped_content": 0, | "skipped_content": 0, | ||||
"snapshot": 1 + 1, # 1 more snapshot | "snapshot": 1 + 1, # 1 more snapshot | ||||
} == visit2_stats | } == visit2_stats | ||||
expected_contents = map( | |||||
hash_to_bytes, | |||||
[ | |||||
"a61e24cdfdab3bb7817f6be85d37a3e666b34566", | |||||
"938c33483285fd8ad57f15497f538320df82aeb8", | |||||
"a27576d60e08c94a05006d2e6d540c0fdb5f38c8", | |||||
"405859113963cb7a797642b45f171d6360425d16", | |||||
"e5686aa568fdb1d19d7f1329267082fe40482d31", | |||||
"83ecf6ec1114fd260ca7a833a2d165e71258c338", | |||||
"92689fa2b7fb4d4fc6fb195bf73a50c87c030639", | |||||
], | |||||
) | |||||
assert list(swh_storage.content_missing_per_sha1(expected_contents)) == [] | |||||
expected_dirs = map( | |||||
hash_to_bytes, | |||||
[ | |||||
"05219ba38bc542d4345d5638af1ed56c7d43ca7d", | |||||
"cf019eb456cf6f78d8c4674596f1c9a97ece8f44", | |||||
"b178b66bd22383d5f16f4f5c923d39ca798861b4", | |||||
"c3a58f8b57433a4b56caaa5033ae2e0931405338", | |||||
"e226e7e4ad03b4fc1403d69a18ebdd6f2edd2b3a", | |||||
"52604d46843b898f5a43208045d09fcf8731631b", | |||||
], | |||||
) | |||||
assert list(swh_storage.directory_missing(expected_dirs)) == [] | |||||
# {revision hash: directory hash} | |||||
expected_revs = { | |||||
hash_to_bytes("4c99891f93b81450385777235a37b5e966dd1571"): hash_to_bytes( | |||||
"05219ba38bc542d4345d5638af1ed56c7d43ca7d" | |||||
), # noqa | |||||
hash_to_bytes("e445da4da22b31bfebb6ffc4383dbf839a074d21"): hash_to_bytes( | |||||
"b178b66bd22383d5f16f4f5c923d39ca798861b4" | |||||
), # noqa | |||||
hash_to_bytes("51247143b01445c9348afa9edfae31bf7c5d86b1"): hash_to_bytes( | |||||
"e226e7e4ad03b4fc1403d69a18ebdd6f2edd2b3a" | |||||
), # noqa | |||||
} | |||||
assert list(swh_storage.revision_missing(expected_revs)) == [] | |||||
urls = [ | urls = [ | ||||
m.url | m.url | ||||
for m in requests_mock_datadir_visits.request_history | for m in requests_mock_datadir_visits.request_history | ||||
if m.url.startswith("https://files.pythonhosted.org") | if m.url.startswith("https://files.pythonhosted.org") | ||||
] | ] | ||||
# visited each artifact once across 2 visits | # visited each artifact once across 2 visits | ||||
assert len(urls) == len(set(urls)) | assert len(urls) == len(set(urls)) | ||||
▲ Show 20 Lines • Show All 154 Lines • Show Last 20 Lines |