Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/package/archive/tests/test_archive.py
# Copyright (C) 2019-2020 The Software Heritage developers | # Copyright (C) 2019-2020 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 attr | |||||
from swh.model.hashutil import hash_to_bytes | from swh.model.hashutil import hash_to_bytes | ||||
from swh.model.model import Snapshot, SnapshotBranch, TargetType | from swh.model.model import Snapshot, SnapshotBranch, TargetType | ||||
from swh.loader.package.archive.loader import ArchiveLoader | from swh.loader.package.archive.loader import ArchiveLoader, ArchivePackageInfo | ||||
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 ( | from swh.loader.tests import ( | ||||
assert_last_visit_matches, | assert_last_visit_matches, | ||||
check_snapshot, | check_snapshot, | ||||
get_stats, | get_stats, | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 320 Lines • ▼ Show 20 Lines | def test_2_visits_without_change_not_gnu(swh_config, requests_mock_datadir): | ||||
assert_last_visit_matches(loader.storage, url, status="full", type="tar") | assert_last_visit_matches(loader.storage, url, status="full", type="tar") | ||||
urls = [ | urls = [ | ||||
m.url | m.url | ||||
for m in requests_mock_datadir.request_history | for m in requests_mock_datadir.request_history | ||||
if m.url.startswith("https://ftp.gnu.org") | if m.url.startswith("https://ftp.gnu.org") | ||||
] | ] | ||||
assert len(urls) == 1 | assert len(urls) == 1 | ||||
def test_artifact_identity(): | |||||
"""Compute primary key should return the right identity | |||||
""" | |||||
@attr.s | |||||
class TestPackageInfo(ArchivePackageInfo): | |||||
a = attr.ib() | |||||
b = attr.ib() | |||||
metadata = GNU_ARTIFACTS[0] | |||||
p_info = TestPackageInfo(raw={**metadata, "a": 1, "b": 2}, a=1, b=2, **metadata,) | |||||
for id_keys, expected_id in [ | |||||
(["a", "b"], [1, 2]), | |||||
([], []), | |||||
(["a", "key-that-does-not-exist"], [1, None]), | |||||
( | |||||
None, | |||||
[ | |||||
metadata["time"], | |||||
metadata["url"], | |||||
metadata["length"], | |||||
metadata["version"], | |||||
], | |||||
), | |||||
]: | |||||
actual_id = p_info.artifact_identity(id_keys=id_keys) | |||||
assert actual_id == expected_id |