Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/package/tests/test_loader.py
Show All 39 Lines | def test_loader_origin_visit_failure(swh_storage): | ||||
assert actual_load_status == {"status": "failed"} | assert actual_load_status == {"status": "failed"} | ||||
loader.storage = FakeStorage2() | loader.storage = FakeStorage2() | ||||
actual_load_status2 = loader.load() | actual_load_status2 = loader.load() | ||||
assert actual_load_status2 == {"status": "failed"} | assert actual_load_status2 == {"status": "failed"} | ||||
def test_resolve_revision_from(): | def test_resolve_revision_from_artifacts(): | ||||
loader = PackageLoader(None, None) | loader = PackageLoader(None, None) | ||||
loader.known_artifact_to_extid = MagicMock( | loader.known_artifact_to_extid = MagicMock( | ||||
wraps=lambda known_artifact: known_artifact["key"].encode() | wraps=lambda known_artifact: known_artifact["key"].encode() | ||||
) | ) | ||||
known_artifacts = { | known_artifacts = { | ||||
b"a" * 40: {"key": "extid-of-aaaa"}, | b"a" * 40: {"key": "extid-of-aaaa"}, | ||||
b"b" * 40: {"key": "extid-of-bbbb"}, | b"b" * 40: {"key": "extid-of-bbbb"}, | ||||
} | } | ||||
p_info = MagicMock() | p_info = MagicMock() | ||||
# No known artifact -> it would be useless to compute the extid | # No known artifact -> it would be useless to compute the extid | ||||
assert loader.resolve_revision_from({}, p_info) is None | assert loader.resolve_revision_from_artifacts({}, p_info) is None | ||||
p_info.extid.assert_not_called() | p_info.extid.assert_not_called() | ||||
loader.known_artifact_to_extid.assert_not_called() | loader.known_artifact_to_extid.assert_not_called() | ||||
p_info.extid.reset_mock() | p_info.extid.reset_mock() | ||||
# Some artifacts, but the PackageInfo does not support extids | # Some artifacts, but the PackageInfo does not support extids | ||||
p_info.extid.return_value = None | p_info.extid.return_value = None | ||||
assert loader.resolve_revision_from(known_artifacts, p_info) is None | assert loader.resolve_revision_from_artifacts(known_artifacts, p_info) is None | ||||
p_info.extid.assert_called_once() | p_info.extid.assert_called_once() | ||||
loader.known_artifact_to_extid.assert_not_called() | loader.known_artifact_to_extid.assert_not_called() | ||||
p_info.extid.reset_mock() | p_info.extid.reset_mock() | ||||
# Some artifacts, and the PackageInfo is not one of them (ie. cache miss) | # Some artifacts, and the PackageInfo is not one of them (ie. cache miss) | ||||
p_info.extid.return_value = b"extid-of-cccc" | p_info.extid.return_value = b"extid-of-cccc" | ||||
assert loader.resolve_revision_from(known_artifacts, p_info) is None | assert loader.resolve_revision_from_artifacts(known_artifacts, p_info) is None | ||||
p_info.extid.assert_called_once() | p_info.extid.assert_called_once() | ||||
loader.known_artifact_to_extid.assert_any_call({"key": "extid-of-aaaa"}) | loader.known_artifact_to_extid.assert_any_call({"key": "extid-of-aaaa"}) | ||||
loader.known_artifact_to_extid.assert_any_call({"key": "extid-of-bbbb"}) | loader.known_artifact_to_extid.assert_any_call({"key": "extid-of-bbbb"}) | ||||
p_info.extid.reset_mock() | p_info.extid.reset_mock() | ||||
loader.known_artifact_to_extid.reset_mock() | loader.known_artifact_to_extid.reset_mock() | ||||
# Some artifacts, and the PackageInfo is one of them (ie. cache hit) | # Some artifacts, and the PackageInfo is one of them (ie. cache hit) | ||||
p_info.extid.return_value = b"extid-of-aaaa" | p_info.extid.return_value = b"extid-of-aaaa" | ||||
assert loader.resolve_revision_from(known_artifacts, p_info) == b"a" * 40 | assert loader.resolve_revision_from_artifacts(known_artifacts, p_info) == b"a" * 40 | ||||
p_info.extid.assert_called_once() | p_info.extid.assert_called_once() | ||||
loader.known_artifact_to_extid.assert_called_once_with({"key": "extid-of-aaaa"}) | loader.known_artifact_to_extid.assert_called_once_with({"key": "extid-of-aaaa"}) | ||||
def test_manifest_extid(): | def test_manifest_extid(): | ||||
"""Compute primary key should return the right identity | """Compute primary key should return the right identity | ||||
""" | """ | ||||
Show All 40 Lines |