Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/package/pypi/tests/test_pypi.py
Show First 20 Lines • Show All 733 Lines • ▼ Show 20 Lines | assert_last_visit_matches( | ||||
loader.storage, url, status="full", type="pypi", snapshot=expected_snapshot.id | loader.storage, url, status="full", type="pypi", snapshot=expected_snapshot.id | ||||
) | ) | ||||
def test_pypi_artifact_to_revision_id_none(): | def test_pypi_artifact_to_revision_id_none(): | ||||
"""Current loader version should stop soon if nothing can be found | """Current loader version should stop soon if nothing can be found | ||||
""" | """ | ||||
artifact_metadata = { | |||||
"digests": { | class artifact_metadata: | ||||
"sha256": "6975816f2c5ad4046acc676ba112f2fff945b01522d63948531f11f11e0892ec", # noqa | sha256 = "6975816f2c5ad4046acc676ba112f2fff945b01522d63948531f11f11e0892ec" | ||||
}, | |||||
} | |||||
ardumont: i don't think the noqa is needed anymore ;) | |||||
assert artifact_to_revision_id({}, artifact_metadata) is None | assert artifact_to_revision_id({}, artifact_metadata) is None | ||||
known_artifacts = { | known_artifacts = { | ||||
"b11ebac8c9d0c9e5063a2df693a18e3aba4b2f92": { | "b11ebac8c9d0c9e5063a2df693a18e3aba4b2f92": { | ||||
"original_artifact": {"sha256": "something-irrelevant",}, | "original_artifact": {"sha256": "something-irrelevant",}, | ||||
}, | }, | ||||
} | } | ||||
assert artifact_to_revision_id(known_artifacts, artifact_metadata) is None | assert artifact_to_revision_id(known_artifacts, artifact_metadata) is None | ||||
def test_pypi_artifact_to_revision_id_old_loader_version(): | 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 | ||||
""" | """ | ||||
artifact_metadata = { | |||||
"digests": { | class artifact_metadata: | ||||
"sha256": "6975816f2c5ad4046acc676ba112f2fff945b01522d63948531f11f11e0892ec", # noqa | sha256 = "6975816f2c5ad4046acc676ba112f2fff945b01522d63948531f11f11e0892ec" | ||||
} | |||||
} | |||||
known_artifacts = { | known_artifacts = { | ||||
hash_to_bytes("b11ebac8c9d0c9e5063a2df693a18e3aba4b2f92"): { | hash_to_bytes("b11ebac8c9d0c9e5063a2df693a18e3aba4b2f92"): { | ||||
"original_artifact": {"sha256": "something-wrong",}, | "original_artifact": {"sha256": "something-wrong",}, | ||||
}, | }, | ||||
hash_to_bytes("845673bfe8cbd31b1eaf757745a964137e6f9116"): { | hash_to_bytes("845673bfe8cbd31b1eaf757745a964137e6f9116"): { | ||||
"original_artifact": { | "original_artifact": { | ||||
"sha256": "6975816f2c5ad4046acc676ba112f2fff945b01522d63948531f11f11e0892ec", # noqa | "sha256": "6975816f2c5ad4046acc676ba112f2fff945b01522d63948531f11f11e0892ec", # noqa | ||||
}, | }, | ||||
}, | }, | ||||
} | } | ||||
assert artifact_to_revision_id(known_artifacts, artifact_metadata) == hash_to_bytes( | assert artifact_to_revision_id(known_artifacts, artifact_metadata) == hash_to_bytes( | ||||
"845673bfe8cbd31b1eaf757745a964137e6f9116" | "845673bfe8cbd31b1eaf757745a964137e6f9116" | ||||
) | ) | ||||
def test_pypi_artifact_to_revision_id_current_loader_version(): | def test_pypi_artifact_to_revision_id_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 | ||||
""" | """ | ||||
artifact_metadata = { | |||||
"digests": { | class artifact_metadata: | ||||
"sha256": "6975816f2c5ad4046acc676ba112f2fff945b01522d63948531f11f11e0892ec", # noqa | sha256 = "6975816f2c5ad4046acc676ba112f2fff945b01522d63948531f11f11e0892ec" | ||||
} | |||||
} | |||||
known_artifacts = { | known_artifacts = { | ||||
hash_to_bytes("b11ebac8c9d0c9e5063a2df693a18e3aba4b2f92"): { | hash_to_bytes("b11ebac8c9d0c9e5063a2df693a18e3aba4b2f92"): { | ||||
"original_artifact": [ | "original_artifact": [ | ||||
{ | { | ||||
"checksums": { | "checksums": { | ||||
"sha256": "6975816f2c5ad4046acc676ba112f2fff945b01522d63948531f11f11e0892ec", # noqa | "sha256": "6975816f2c5ad4046acc676ba112f2fff945b01522d63948531f11f11e0892ec", # noqa | ||||
}, | }, | ||||
} | } | ||||
], | ], | ||||
}, | }, | ||||
hash_to_bytes("845673bfe8cbd31b1eaf757745a964137e6f9116"): { | hash_to_bytes("845673bfe8cbd31b1eaf757745a964137e6f9116"): { | ||||
"original_artifact": [{"checksums": {"sha256": "something-wrong"},}], | "original_artifact": [{"checksums": {"sha256": "something-wrong"},}], | ||||
}, | }, | ||||
} | } | ||||
assert artifact_to_revision_id(known_artifacts, artifact_metadata) == hash_to_bytes( | assert artifact_to_revision_id(known_artifacts, artifact_metadata) == hash_to_bytes( | ||||
"b11ebac8c9d0c9e5063a2df693a18e3aba4b2f92" | "b11ebac8c9d0c9e5063a2df693a18e3aba4b2f92" | ||||
) | ) | ||||
def test_pypi_artifact_to_revision_id_failures(): | |||||
with pytest.raises(KeyError, match="sha256"): | |||||
artifact_metadata = { | |||||
"digests": {}, | |||||
} | |||||
assert artifact_to_revision_id({}, artifact_metadata) | |||||
with pytest.raises(KeyError, match="digests"): | |||||
artifact_metadata = { | |||||
"something": "wrong", | |||||
} | |||||
assert artifact_to_revision_id({}, artifact_metadata) | |||||
Not Done Inline Actionswhy does that go away? ardumont: why does that go away? | |||||
Done Inline Actionswhen the metadata is empty, PackageInfo.from_metadata crashes so artifact_to_revision_id can't even be called with empty metadata vlorentz: when the metadata is empty, `PackageInfo.from_metadata` crashes so `artifact_to_revision_id`… | |||||
def test_pypi_artifact_with_no_intrinsic_metadata(swh_config, requests_mock_datadir): | def test_pypi_artifact_with_no_intrinsic_metadata(swh_config, requests_mock_datadir): | ||||
"""Skip artifact with no intrinsic metadata during ingestion | """Skip artifact with no intrinsic metadata during ingestion | ||||
""" | """ | ||||
url = "https://pypi.org/project/upymenu" | url = "https://pypi.org/project/upymenu" | ||||
loader = PyPILoader(url) | loader = PyPILoader(url) | ||||
actual_load_status = loader.load() | actual_load_status = loader.load() | ||||
Show All 13 Lines |
i don't think the noqa is needed anymore ;)