Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/package/pypi/tests/test_pypi.py
Show All 9 Lines | |||||
import pytest | import pytest | ||||
from swh.core.pytest_plugin import requests_mock_datadir_factory | from swh.core.pytest_plugin import requests_mock_datadir_factory | ||||
from swh.core.tarball import uncompress | from swh.core.tarball import uncompress | ||||
from swh.loader.package import __version__ | from swh.loader.package import __version__ | ||||
from swh.loader.package.pypi.loader import ( | from swh.loader.package.pypi.loader import ( | ||||
PyPILoader, | PyPILoader, | ||||
artifact_to_revision_id, | |||||
author, | author, | ||||
extract_intrinsic_metadata, | extract_intrinsic_metadata, | ||||
pypi_api_url, | pypi_api_url, | ||||
) | ) | ||||
from swh.loader.package.tests.common import check_metadata_paths | from swh.loader.package.tests.common import check_metadata_paths | ||||
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.identifiers import ( | from swh.model.identifiers import ( | ||||
▲ Show 20 Lines • Show All 765 Lines • ▼ Show 20 Lines | def test_pypi_visit_1_release_with_2_artifacts(swh_storage, requests_mock_datadir): | ||||
) | ) | ||||
check_snapshot(expected_snapshot, swh_storage) | check_snapshot(expected_snapshot, swh_storage) | ||||
assert_last_visit_matches( | assert_last_visit_matches( | ||||
swh_storage, url, status="full", type="pypi", snapshot=expected_snapshot.id | swh_storage, url, status="full", type="pypi", snapshot=expected_snapshot.id | ||||
) | ) | ||||
def test_pypi_artifact_to_revision_id_none(): | def test_pypi__known_artifact_to_extid__old_loader_version(): | ||||
"""Current loader version should stop soon if nothing can be found | |||||
""" | |||||
class artifact_metadata: | |||||
sha256 = "6975816f2c5ad4046acc676ba112f2fff945b01522d63948531f11f11e0892ec" | |||||
assert artifact_to_revision_id({}, artifact_metadata) is None | |||||
known_artifacts = { | |||||
"b11ebac8c9d0c9e5063a2df693a18e3aba4b2f92": { | |||||
"original_artifact": {"sha256": "something-irrelevant",}, | |||||
}, | |||||
} | |||||
assert artifact_to_revision_id(known_artifacts, artifact_metadata) is None | |||||
def test_pypi_artifact_to_revision_id_old_loader_version(): | |||||
"""Current loader version should solve old metadata scheme | """Current loader version should solve old metadata scheme | ||||
""" | """ | ||||
assert ( | |||||
PyPILoader.known_artifact_to_extid( | |||||
{"original_artifact": {"sha256": "something-wrong",},} | |||||
) | |||||
is None | |||||
) | |||||
class artifact_metadata: | |||||
sha256 = "6975816f2c5ad4046acc676ba112f2fff945b01522d63948531f11f11e0892ec" | sha256 = "6975816f2c5ad4046acc676ba112f2fff945b01522d63948531f11f11e0892ec" | ||||
assert PyPILoader.known_artifact_to_extid( | |||||
known_artifacts = { | {"original_artifact": {"sha256": sha256}} | ||||
hash_to_bytes("b11ebac8c9d0c9e5063a2df693a18e3aba4b2f92"): { | ) == hash_to_bytes(sha256) | ||||
"original_artifact": {"sha256": "something-wrong",}, | |||||
}, | |||||
hash_to_bytes("845673bfe8cbd31b1eaf757745a964137e6f9116"): { | |||||
"original_artifact": { | |||||
"sha256": "6975816f2c5ad4046acc676ba112f2fff945b01522d63948531f11f11e0892ec", # noqa | |||||
}, | |||||
}, | |||||
} | |||||
assert artifact_to_revision_id(known_artifacts, artifact_metadata) == hash_to_bytes( | |||||
"845673bfe8cbd31b1eaf757745a964137e6f9116" | |||||
) | |||||
def test_pypi_artifact_to_revision_id_current_loader_version(): | def test_pypi__known_artifact_to_extid__current_loader_version(): | ||||
"""Current loader version should be able to solve current metadata scheme | """Current loader version should be able to solve current metadata scheme | ||||
""" | """ | ||||
class artifact_metadata: | |||||
sha256 = "6975816f2c5ad4046acc676ba112f2fff945b01522d63948531f11f11e0892ec" | sha256 = "6975816f2c5ad4046acc676ba112f2fff945b01522d63948531f11f11e0892ec" | ||||
known_artifacts = { | assert PyPILoader.known_artifact_to_extid( | ||||
hash_to_bytes("b11ebac8c9d0c9e5063a2df693a18e3aba4b2f92"): { | {"original_artifact": [{"checksums": {"sha256": sha256,},}],} | ||||
"original_artifact": [ | ) == hash_to_bytes(sha256) | ||||
{ | |||||
"checksums": { | |||||
"sha256": "6975816f2c5ad4046acc676ba112f2fff945b01522d63948531f11f11e0892ec", # noqa | |||||
}, | |||||
} | |||||
], | |||||
}, | |||||
hash_to_bytes("845673bfe8cbd31b1eaf757745a964137e6f9116"): { | |||||
"original_artifact": [{"checksums": {"sha256": "something-wrong"},}], | |||||
}, | |||||
} | |||||
assert artifact_to_revision_id(known_artifacts, artifact_metadata) == hash_to_bytes( | assert ( | ||||
"b11ebac8c9d0c9e5063a2df693a18e3aba4b2f92" | PyPILoader.known_artifact_to_extid( | ||||
{"original_artifact": [{"checksums": {"sha256": "something-wrong"},}],}, | |||||
) | |||||
is None | |||||
) | ) | ||||
# there should not be more than one artifact | # there should not be more than one artifact | ||||
with pytest.raises(ValueError): | with pytest.raises(ValueError): | ||||
PyPILoader.known_artifact_to_extid( | PyPILoader.known_artifact_to_extid( | ||||
{ | { | ||||
"original_artifact": [ | "original_artifact": [ | ||||
{"checksums": {"sha256": sha256,},}, | {"checksums": {"sha256": sha256,},}, | ||||
Show All 38 Lines |