Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/package/tests/test_loader.py
# Copyright (C) 2019-2021 The Software Heritage developers | # Copyright (C) 2019-2021 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 hashlib | |||||
import string | |||||
import attr | import attr | ||||
import pytest | import pytest | ||||
from swh.loader.package.loader import BasePackageInfo, PackageLoader | from swh.loader.package.loader import BasePackageInfo, PackageLoader | ||||
class FakeStorage: | class FakeStorage: | ||||
def origin_add(self, origins): | def origin_add(self, origins): | ||||
Show All 22 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_artifact_identity(): | def test_extid(): | ||||
"""Compute primary key should return the right identity | """Compute primary key should return the right identity | ||||
""" | """ | ||||
@attr.s | @attr.s | ||||
class TestPackageInfo(BasePackageInfo): | class TestPackageInfo(BasePackageInfo): | ||||
a = attr.ib() | a = attr.ib() | ||||
b = attr.ib() | b = attr.ib() | ||||
length = attr.ib() | length = attr.ib() | ||||
filename = attr.ib() | filename = attr.ib() | ||||
version = attr.ib() | version = attr.ib() | ||||
ID_KEYS = ["a", "b"] | MANIFEST_FORMAT = string.Template("$a $b") | ||||
p_info = TestPackageInfo( | p_info = TestPackageInfo( | ||||
url="http://example.org/", | url="http://example.org/", | ||||
a=1, | a=1, | ||||
b=2, | b=2, | ||||
length=221837, | length=221837, | ||||
filename="8sync-0.1.0.tar.gz", | filename="8sync-0.1.0.tar.gz", | ||||
version="0.1.0", | version="0.1.0", | ||||
) | ) | ||||
actual_id = p_info.artifact_identity() | actual_id = p_info.extid() | ||||
assert actual_id == [1, 2] | assert actual_id == hashlib.sha256(b"1 2").digest() | ||||
def test_no_env_swh_config_filename_raise(monkeypatch): | def test_no_env_swh_config_filename_raise(monkeypatch): | ||||
"""No SWH_CONFIG_FILENAME environment variable makes package loader init raise | """No SWH_CONFIG_FILENAME environment variable makes package loader init raise | ||||
""" | """ | ||||
class DummyPackageLoader(PackageLoader): | class DummyPackageLoader(PackageLoader): | ||||
Show All 10 Lines |