Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/package/crates/tests/test_crates.py
# Copyright (C) 2022 The Software Heritage developers | # Copyright (C) 2022 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import pytest | import pytest | ||||
from swh.loader.package.crates.loader import CratesLoader | from swh.loader.package.crates.loader import CratesLoader | ||||
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 ( | from swh.model.model import ( | ||||
ObjectType, | ObjectType, | ||||
Person, | Person, | ||||
Release, | Release, | ||||
Snapshot, | Snapshot, | ||||
SnapshotBranch, | SnapshotBranch, | ||||
TargetType, | TargetType, | ||||
TimestampWithTimezone, | |||||
) | ) | ||||
CRATES_EXTRA = [ | CRATES_EXTRA = [ | ||||
{ | { | ||||
"url": "https://crates.io/api/v1/crates/hg-core", | "url": "https://crates.io/api/v1/crates/hg-core", | ||||
"artifacts": [ | "artifacts": [ | ||||
{ | { | ||||
"checksums": { | "checksums": { | ||||
"sha256": "48a45b46c2a8c38348adb1205b13c3c5eb0174e0c0fec52cc88e9fb1de14c54d", # noqa: B950 | "sha256": "48a45b46c2a8c38348adb1205b13c3c5eb0174e0c0fec52cc88e9fb1de14c54d", # noqa: B950 | ||||
}, | }, | ||||
"filename": "hg-core-0.0.1.crate", | "filename": "hg-core-0.0.1.crate", | ||||
"url": "https://static.crates.io/crates/hg-core/hg-core-0.0.1.crate", | "url": "https://static.crates.io/crates/hg-core/hg-core-0.0.1.crate", | ||||
"version": "0.0.1", | "version": "0.0.1", | ||||
}, | }, | ||||
], | ], | ||||
"crates_metadata": [ | |||||
{ | |||||
"version": "0.0.1", | |||||
"yanked": False, | |||||
}, | |||||
], | |||||
}, | }, | ||||
{ | { | ||||
"url": "https://crates.io/api/v1/crates/micro-timer", | "url": "https://crates.io/api/v1/crates/micro-timer", | ||||
"artifacts": [ | "artifacts": [ | ||||
{ | { | ||||
"checksums": { | "checksums": { | ||||
"sha256": "69ad8fd116f8af0298ae4e83e587b1600af12709022471e25581c3aeb1da77ce", # noqa: B950 | "sha256": "69ad8fd116f8af0298ae4e83e587b1600af12709022471e25581c3aeb1da77ce", # noqa: B950 | ||||
}, | }, | ||||
▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | CRATES_EXTRA = [ | ||||
"checksums": { | "checksums": { | ||||
"sha256": "5de32cb59a062672560d6f0842c4aa7714727457b9fe2daf8987d995a176a405", # noqa: B950 | "sha256": "5de32cb59a062672560d6f0842c4aa7714727457b9fe2daf8987d995a176a405", # noqa: B950 | ||||
}, | }, | ||||
"filename": "micro-timer-0.4.0.crate", | "filename": "micro-timer-0.4.0.crate", | ||||
"url": "https://static.crates.io/crates/micro-timer/micro-timer-0.4.0.crate", | "url": "https://static.crates.io/crates/micro-timer/micro-timer-0.4.0.crate", | ||||
"version": "0.4.0", | "version": "0.4.0", | ||||
}, | }, | ||||
], | ], | ||||
"crates_metadata": [ | |||||
{ | |||||
"version": "0.1.0", | |||||
"yanked": False, | |||||
}, | |||||
{ | |||||
"version": "0.1.1", | |||||
"yanked": False, | |||||
}, | |||||
{ | |||||
"version": "0.1.2", | |||||
"yanked": False, | |||||
}, | |||||
{ | |||||
"version": "0.2.0", | |||||
"yanked": False, | |||||
}, | |||||
{ | |||||
"version": "0.2.1", | |||||
"yanked": False, | |||||
}, | |||||
{ | |||||
"version": "0.3.0", | |||||
"yanked": False, | |||||
}, | |||||
{ | |||||
"version": "0.3.1", | |||||
"yanked": False, | |||||
}, | |||||
{ | |||||
"version": "0.4.0", | |||||
"yanked": False, | |||||
}, | |||||
], | |||||
}, | }, | ||||
] | ] | ||||
def test_get_versions(requests_mock_datadir, swh_storage): | def test_get_versions(requests_mock_datadir, swh_storage): | ||||
loader = CratesLoader( | loader = CratesLoader( | ||||
swh_storage, | swh_storage, | ||||
url=CRATES_EXTRA[1]["url"], | url=CRATES_EXTRA[1]["url"], | ||||
artifacts=CRATES_EXTRA[1]["artifacts"], | artifacts=CRATES_EXTRA[1]["artifacts"], | ||||
crates_metadata=CRATES_EXTRA[1]["crates_metadata"], | |||||
) | ) | ||||
assert loader.get_versions() == [ | assert loader.get_versions() == [ | ||||
"0.1.0", | "0.1.0", | ||||
"0.1.1", | "0.1.1", | ||||
"0.1.2", | "0.1.2", | ||||
"0.2.0", | "0.2.0", | ||||
"0.2.1", | "0.2.1", | ||||
"0.3.0", | "0.3.0", | ||||
"0.3.1", | "0.3.1", | ||||
"0.4.0", | "0.4.0", | ||||
] | ] | ||||
def test_get_default_version(requests_mock_datadir, swh_storage): | def test_get_default_version(requests_mock_datadir, swh_storage): | ||||
loader = CratesLoader( | loader = CratesLoader( | ||||
swh_storage, | swh_storage, | ||||
url=CRATES_EXTRA[1]["url"], | url=CRATES_EXTRA[1]["url"], | ||||
artifacts=CRATES_EXTRA[1]["artifacts"], | artifacts=CRATES_EXTRA[1]["artifacts"], | ||||
crates_metadata=CRATES_EXTRA[1]["crates_metadata"], | |||||
) | ) | ||||
assert loader.get_default_version() == "0.4.0" | assert loader.get_default_version() == "0.4.0" | ||||
def test_crate_invalid_origin_archive_not_found(swh_storage, requests_mock_datadir): | def test_crate_invalid_origin_archive_not_found(swh_storage, requests_mock_datadir): | ||||
url = "https://nowhere-to-run/nowhere-to-hide" | url = "https://nowhere-to-run/nowhere-to-hide" | ||||
loader = CratesLoader( | loader = CratesLoader( | ||||
swh_storage, | swh_storage, | ||||
url, | url, | ||||
artifacts=[ | artifacts=[ | ||||
{ | { | ||||
"filename": "nowhere-to-hide-0.0.1.crate", | "filename": "nowhere-to-hide-0.0.1.crate", | ||||
"url": "https://nowhere-to-run/nowhere-to-hide-0.0.1.crate", | "url": "https://nowhere-to-run/nowhere-to-hide-0.0.1.crate", | ||||
"version": "0.0.1", | "version": "0.0.1", | ||||
}, | }, | ||||
], | ], | ||||
crates_metadata=[ | |||||
{ | |||||
"yanked": True, | |||||
"version": "0.0.1", | |||||
}, | |||||
], | |||||
) | ) | ||||
with pytest.raises(Exception): | with pytest.raises(Exception): | ||||
assert loader.load() == {"status": "failed"} | assert loader.load() == {"status": "failed"} | ||||
assert_last_visit_matches( | assert_last_visit_matches( | ||||
swh_storage, url, status="not_found", type="crates", snapshot=None | swh_storage, url, status="not_found", type="crates", snapshot=None | ||||
) | ) | ||||
def test_crates_loader_load_one_version(datadir, requests_mock_datadir, swh_storage): | def test_crates_loader_load_one_version(datadir, requests_mock_datadir, swh_storage): | ||||
loader = CratesLoader( | loader = CratesLoader( | ||||
swh_storage, | swh_storage, | ||||
url=CRATES_EXTRA[0]["url"], | url=CRATES_EXTRA[0]["url"], | ||||
artifacts=CRATES_EXTRA[0]["artifacts"], | artifacts=CRATES_EXTRA[0]["artifacts"], | ||||
crates_metadata=CRATES_EXTRA[0]["crates_metadata"], | |||||
) | ) | ||||
actual_load_status = loader.load() | actual_load_status = loader.load() | ||||
assert actual_load_status["status"] == "eventful" | assert actual_load_status["status"] == "eventful" | ||||
assert actual_load_status["snapshot_id"] is not None | assert actual_load_status["snapshot_id"] is not None | ||||
expected_snapshot_id = "b3affb4949eb89b244f0e1d1fe235fc1d26bde76" | expected_snapshot_id = "928cb3df7184a1b695395dec10ebef744f2b7660" | ||||
expected_release_id = "237c4cdd44a90e620795e5a07ebcc72bc82487f7" | expected_release_id = "725e370ecd11edbd598fb669f99e48c269fedb16" | ||||
assert expected_snapshot_id == actual_load_status["snapshot_id"] | assert expected_snapshot_id == actual_load_status["snapshot_id"] | ||||
expected_snapshot = Snapshot( | expected_snapshot = Snapshot( | ||||
id=hash_to_bytes(actual_load_status["snapshot_id"]), | id=hash_to_bytes(actual_load_status["snapshot_id"]), | ||||
branches={ | branches={ | ||||
b"releases/0.0.1/hg-core-0.0.1.crate": SnapshotBranch( | b"releases/0.0.1/hg-core-0.0.1.crate": SnapshotBranch( | ||||
target=hash_to_bytes(expected_release_id), | target=hash_to_bytes(expected_release_id), | ||||
Show All 23 Lines | assert swh_storage.release_get([hash_to_bytes(expected_release_id)])[0] == Release( | ||||
name=b"0.0.1", | name=b"0.0.1", | ||||
message=b"Synthetic release for Crate source package hg-core version 0.0.1\n\n" | message=b"Synthetic release for Crate source package hg-core version 0.0.1\n\n" | ||||
b"Mercurial pure Rust core library, with no assumption " | b"Mercurial pure Rust core library, with no assumption " | ||||
b"on Python bindings (FFI)\n", | b"on Python bindings (FFI)\n", | ||||
target=hash_to_bytes("674c3b0b54628d55b93a79dc7adf304efc01b371"), | target=hash_to_bytes("674c3b0b54628d55b93a79dc7adf304efc01b371"), | ||||
target_type=ObjectType.DIRECTORY, | target_type=ObjectType.DIRECTORY, | ||||
synthetic=True, | synthetic=True, | ||||
author=Person.from_fullname(b"Georges Racinet <georges.racinet@octobus.net>"), | author=Person.from_fullname(b"Georges Racinet <georges.racinet@octobus.net>"), | ||||
date=TimestampWithTimezone.from_iso8601("2019-04-16T18:48:11.404457+00:00"), | date=None, | ||||
id=hash_to_bytes(expected_release_id), | id=hash_to_bytes(expected_release_id), | ||||
) | ) | ||||
def test_crates_loader_load_n_versions(datadir, requests_mock_datadir, swh_storage): | def test_crates_loader_load_n_versions( | ||||
datadir, requests_mock_datadir_visits, swh_storage | |||||
): | |||||
url = CRATES_EXTRA[1]["url"] | url = CRATES_EXTRA[1]["url"] | ||||
loader = CratesLoader( | loader = CratesLoader( | ||||
swh_storage, | swh_storage, | ||||
url=CRATES_EXTRA[1]["url"], | url=url, | ||||
artifacts=CRATES_EXTRA[1]["artifacts"], | artifacts=CRATES_EXTRA[1]["artifacts"], | ||||
crates_metadata=CRATES_EXTRA[1]["crates_metadata"], | |||||
) | ) | ||||
actual_load_status = loader.load() | actual_load_status = loader.load() | ||||
assert actual_load_status["status"] == "eventful" | assert actual_load_status["status"] == "eventful" | ||||
assert actual_load_status["snapshot_id"] is not None | assert actual_load_status["snapshot_id"] is not None | ||||
expected_snapshot_id = "3f8ca5908a570fa32270b07a0946bcffa88babd5" | expected_snapshot_id = "fbf6b3dc59d1896c06684d36936f60f0c4725246" | ||||
assert expected_snapshot_id == actual_load_status["snapshot_id"] | assert expected_snapshot_id == actual_load_status["snapshot_id"] | ||||
expected_snapshot = Snapshot( | expected_snapshot = Snapshot( | ||||
id=hash_to_bytes(expected_snapshot_id), | id=hash_to_bytes(expected_snapshot_id), | ||||
branches={ | branches={ | ||||
b"releases/0.4.0/micro-timer-0.4.0.crate": SnapshotBranch( | b"releases/0.4.0/micro-timer-0.4.0.crate": SnapshotBranch( | ||||
target=hash_to_bytes("b038a927244c852fb3794aecbebdc70f68ddf067"), | target=hash_to_bytes("572ba4e68e2aee61668846cb167f17053c31ce6a"), | ||||
target_type=TargetType.RELEASE, | target_type=TargetType.RELEASE, | ||||
), | ), | ||||
b"releases/0.3.1/micro-timer-0.3.1.crate": SnapshotBranch( | b"releases/0.3.1/micro-timer-0.3.1.crate": SnapshotBranch( | ||||
target=hash_to_bytes("ea331a2ce755e6f0cd9d05c9be52accde68536c4"), | target=hash_to_bytes("6afa35992f22322e756ccc3809e80c3a6bbc661f"), | ||||
target_type=TargetType.RELEASE, | target_type=TargetType.RELEASE, | ||||
), | ), | ||||
b"releases/0.3.0/micro-timer-0.3.0.crate": SnapshotBranch( | b"releases/0.3.0/micro-timer-0.3.0.crate": SnapshotBranch( | ||||
target=hash_to_bytes("7ea45f915ace083ed361bb12593625bf4cf1f5f2"), | target=hash_to_bytes("5e8e4876e6ae12a67c4fbed1dfc8e620bfe23335"), | ||||
target_type=TargetType.RELEASE, | target_type=TargetType.RELEASE, | ||||
), | ), | ||||
b"releases/0.2.1/micro-timer-0.2.1.crate": SnapshotBranch( | b"releases/0.2.1/micro-timer-0.2.1.crate": SnapshotBranch( | ||||
target=hash_to_bytes("074f27605be8b759e5d7c638f026aac3709f58e5"), | target=hash_to_bytes("34e78f65474c17b39981c51c2df829fdf2629f49"), | ||||
target_type=TargetType.RELEASE, | target_type=TargetType.RELEASE, | ||||
), | ), | ||||
b"releases/0.2.0/micro-timer-0.2.0.crate": SnapshotBranch( | b"releases/0.2.0/micro-timer-0.2.0.crate": SnapshotBranch( | ||||
target=hash_to_bytes("a1d642aaa54c5361f67e57adbd86e01f3a3276f8"), | target=hash_to_bytes("89b69ea42d296c3f3f407ad03016f67f75d1eb4f"), | ||||
target_type=TargetType.RELEASE, | target_type=TargetType.RELEASE, | ||||
), | ), | ||||
b"releases/0.1.2/micro-timer-0.1.2.crate": SnapshotBranch( | b"releases/0.1.2/micro-timer-0.1.2.crate": SnapshotBranch( | ||||
target=hash_to_bytes("60f18ae067ce235bc60243bf5cdaaae474b11978"), | target=hash_to_bytes("018cebf60e22b7f61080ba63566f8f181139dfb5"), | ||||
target_type=TargetType.RELEASE, | target_type=TargetType.RELEASE, | ||||
), | ), | ||||
b"releases/0.1.1/micro-timer-0.1.1.crate": SnapshotBranch( | b"releases/0.1.1/micro-timer-0.1.1.crate": SnapshotBranch( | ||||
target=hash_to_bytes("fd6c55dfd016d58647a2d44b29a3fd4e3afa7671"), | target=hash_to_bytes("c5883a1b72029f820592e850638d8521260e6eb3"), | ||||
target_type=TargetType.RELEASE, | target_type=TargetType.RELEASE, | ||||
), | ), | ||||
b"releases/0.1.0/micro-timer-0.1.0.crate": SnapshotBranch( | b"releases/0.1.0/micro-timer-0.1.0.crate": SnapshotBranch( | ||||
target=hash_to_bytes("3e07559a4b366a397b1ca154e72753ce27223ca1"), | target=hash_to_bytes("a9c8423c5db2a4313c1f0252705c020f9aba51f5"), | ||||
target_type=TargetType.RELEASE, | target_type=TargetType.RELEASE, | ||||
), | ), | ||||
b"HEAD": SnapshotBranch( | b"HEAD": SnapshotBranch( | ||||
target=b"releases/0.4.0/micro-timer-0.4.0.crate", | target=b"releases/0.4.0/micro-timer-0.4.0.crate", | ||||
target_type=TargetType.ALIAS, | target_type=TargetType.ALIAS, | ||||
), | ), | ||||
}, | }, | ||||
) | ) | ||||
Show All 14 Lines | ): | ||||
assert_last_visit_matches( | assert_last_visit_matches( | ||||
swh_storage, | swh_storage, | ||||
url, | url, | ||||
status="full", | status="full", | ||||
type="crates", | type="crates", | ||||
snapshot=expected_snapshot.id, | snapshot=expected_snapshot.id, | ||||
) | ) | ||||
def test_crates_loader_load_multiple_visits_no_changes( | |||||
datadir, requests_mock_datadir_visits, requests_mock_datadir, swh_storage | |||||
): | |||||
url = CRATES_EXTRA[0]["url"] | |||||
loader = CratesLoader( | |||||
swh_storage, | |||||
url=url, | |||||
artifacts=CRATES_EXTRA[0]["artifacts"], | |||||
crates_metadata=CRATES_EXTRA[0]["crates_metadata"], | |||||
) | |||||
visit_1_actual_load_status = loader.load() | |||||
assert visit_1_actual_load_status["status"] == "eventful" | |||||
assert visit_1_actual_load_status["snapshot_id"] is not None | |||||
expected_snapshot_id = "928cb3df7184a1b695395dec10ebef744f2b7660" | |||||
expected_release_id = "725e370ecd11edbd598fb669f99e48c269fedb16" | |||||
assert expected_snapshot_id == visit_1_actual_load_status["snapshot_id"] | |||||
expected_snapshot = Snapshot( | |||||
id=hash_to_bytes(visit_1_actual_load_status["snapshot_id"]), | |||||
branches={ | |||||
b"releases/0.0.1/hg-core-0.0.1.crate": SnapshotBranch( | |||||
target=hash_to_bytes(expected_release_id), | |||||
target_type=TargetType.RELEASE, | |||||
), | |||||
b"HEAD": SnapshotBranch( | |||||
target=b"releases/0.0.1/hg-core-0.0.1.crate", | |||||
target_type=TargetType.ALIAS, | |||||
), | |||||
}, | |||||
) | |||||
check_snapshot(expected_snapshot, swh_storage) | |||||
assert_last_visit_matches( | |||||
swh_storage, url, status="full", type="crates", snapshot=expected_snapshot.id | |||||
) | |||||
stats = get_stats(swh_storage) | |||||
assert { | |||||
"content": 1, | |||||
"directory": 2, | |||||
"origin": 1, | |||||
"origin_visit": 1, | |||||
"release": 1, | |||||
"revision": 0, | |||||
"skipped_content": 0, | |||||
"snapshot": 1, | |||||
} == stats | |||||
assert swh_storage.release_get([hash_to_bytes(expected_release_id)])[0] == Release( | |||||
name=b"0.0.1", | |||||
message=b"Synthetic release for Crate source package hg-core version 0.0.1\n\n" | |||||
b"Mercurial pure Rust core library, with no assumption " | |||||
b"on Python bindings (FFI)\n", | |||||
target=hash_to_bytes("674c3b0b54628d55b93a79dc7adf304efc01b371"), | |||||
target_type=ObjectType.DIRECTORY, | |||||
synthetic=True, | |||||
author=Person.from_fullname(b"Georges Racinet <georges.racinet@octobus.net>"), | |||||
date=None, | |||||
id=hash_to_bytes(expected_release_id), | |||||
) | |||||
actual_load_status2 = loader.load() | |||||
assert actual_load_status2 == { | |||||
"status": "uneventful", | |||||
"snapshot_id": actual_load_status2["snapshot_id"], | |||||
} | |||||
visit_status2 = assert_last_visit_matches( | |||||
swh_storage, url, status="full", type="crates" | |||||
) | |||||
stats2 = get_stats(swh_storage) | |||||
expected_stats2 = stats.copy() | |||||
expected_stats2["origin_visit"] = 1 + 1 | |||||
assert expected_stats2 == stats2 | |||||
# same snapshot | |||||
assert visit_status2.snapshot == expected_snapshot.id | |||||
def test_crates_loader_load_multiple_version_incremental( | |||||
datadir, requests_mock_datadir_visits, swh_storage | |||||
): | |||||
url = CRATES_EXTRA[1]["url"] | |||||
# one version in artifacts | |||||
artifacts_0 = CRATES_EXTRA[1]["artifacts"].copy() | |||||
artifacts_0 = [ | |||||
version for version in artifacts_0 if version["version"] in ["0.1.0"] | |||||
] | |||||
crates_metadata_0 = CRATES_EXTRA[1]["crates_metadata"].copy() | |||||
crates_metadata_0 = [ | |||||
version for version in crates_metadata_0 if version["version"] in ["0.1.0"] | |||||
] | |||||
# two versions in artifacts | |||||
artifacts_1 = CRATES_EXTRA[1]["artifacts"].copy() | |||||
artifacts_1 = [ | |||||
version for version in artifacts_1 if version["version"] in ["0.1.0", "0.1.1"] | |||||
] | |||||
crates_metadata_1 = CRATES_EXTRA[1]["crates_metadata"].copy() | |||||
crates_metadata_1 = [ | |||||
version | |||||
for version in crates_metadata_1 | |||||
if version["version"] in ["0.1.0", "0.1.1"] | |||||
] | |||||
# Visit 1 | |||||
loader = CratesLoader( | |||||
swh_storage, | |||||
url=url, | |||||
artifacts=artifacts_0, | |||||
crates_metadata=crates_metadata_0, | |||||
) | |||||
visit1_actual_load_status = loader.load() | |||||
visit1_stats = get_stats(swh_storage) | |||||
expected_snapshot_id = hash_to_bytes("1831491e030dc33a7626f660a2da9343b47c1863") | |||||
assert visit1_actual_load_status == { | |||||
"status": "eventful", | |||||
"snapshot_id": expected_snapshot_id.hex(), | |||||
} | |||||
assert_last_visit_matches( | |||||
swh_storage, url, status="full", type="crates", snapshot=expected_snapshot_id | |||||
) | |||||
vlorentz: Create a new loader instance, so tests behave more like production | |||||
assert { | |||||
"content": 1, | |||||
"directory": 2, | |||||
"origin": 1, | |||||
"origin_visit": 1, | |||||
"release": 1, | |||||
"revision": 0, | |||||
"skipped_content": 0, | |||||
"snapshot": 1, | |||||
} == visit1_stats | |||||
# Visit 2 | |||||
loader = CratesLoader( | |||||
swh_storage, | |||||
url=url, | |||||
artifacts=artifacts_0, | |||||
crates_metadata=crates_metadata_0, | |||||
) | |||||
# set loader artifacts to list two versions | |||||
loader.artifacts = {artifact["version"]: artifact for artifact in artifacts_1} | |||||
loader.crates_metadata = { | |||||
crate_metadata["version"]: crate_metadata | |||||
for crate_metadata in crates_metadata_1 | |||||
} | |||||
visit2_actual_load_status = loader.load() | |||||
visit2_stats = get_stats(swh_storage) | |||||
assert visit2_actual_load_status["status"] == "eventful", visit2_actual_load_status | |||||
expected_snapshot_id2 = hash_to_bytes("d220b3eb09828fdb6b6250af667220f04ce20479") | |||||
assert visit2_actual_load_status == { | |||||
"status": "eventful", | |||||
"snapshot_id": expected_snapshot_id2.hex(), | |||||
} | |||||
assert_last_visit_matches( | |||||
swh_storage, url, status="full", type="crates", snapshot=expected_snapshot_id2 | |||||
) | |||||
expected_snapshot = Snapshot( | |||||
id=expected_snapshot_id2, | |||||
branches={ | |||||
b"releases/0.1.1/micro-timer-0.1.1.crate": SnapshotBranch( | |||||
target=hash_to_bytes("c5883a1b72029f820592e850638d8521260e6eb3"), | |||||
target_type=TargetType.RELEASE, | |||||
), | |||||
b"releases/0.1.0/micro-timer-0.1.0.crate": SnapshotBranch( | |||||
target=hash_to_bytes("a9c8423c5db2a4313c1f0252705c020f9aba51f5"), | |||||
target_type=TargetType.RELEASE, | |||||
), | |||||
b"HEAD": SnapshotBranch( | |||||
target=b"releases/0.1.1/micro-timer-0.1.1.crate", | |||||
target_type=TargetType.ALIAS, | |||||
), | |||||
}, | |||||
) | |||||
assert_last_visit_matches( | |||||
swh_storage, url, status="full", type="crates", snapshot=expected_snapshot.id | |||||
) | |||||
check_snapshot(expected_snapshot, swh_storage) | |||||
assert { | |||||
"content": 1 + 1, | |||||
"directory": 2 + 2, | |||||
"origin": 1, | |||||
"origin_visit": 1 + 1, | |||||
"release": 1 + 1, | |||||
"revision": 0, | |||||
"skipped_content": 0, | |||||
"snapshot": 1 + 1, | |||||
} == visit2_stats |
Create a new loader instance, so tests behave more like production