Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/package/archive/tests/test_archive.py
# Copyright (C) 2019 The Software Heritage developers | # Copyright (C) 2019 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 | ||||
from swh.model.hashutil import hash_to_bytes | from swh.model.hashutil import hash_to_bytes | ||||
from swh.loader.package.archive.loader import ArchiveLoader, artifact_identity | from swh.loader.package.archive.loader import ArchiveLoader | ||||
from swh.loader.package.tests.common import ( | from swh.loader.package.tests.common import ( | ||||
check_snapshot, check_metadata_paths, get_stats | check_snapshot, check_metadata_paths, get_stats | ||||
) | ) | ||||
URL = 'https://ftp.gnu.org/gnu/8sync/' | URL = 'https://ftp.gnu.org/gnu/8sync/' | ||||
GNU_ARTIFACTS = [ | GNU_ARTIFACTS = [ | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 278 Lines • ▼ Show 20 Lines | def test_2_visits_with_new_artifact(swh_config, requests_mock_datadir): | ||||
urls = [ | urls = [ | ||||
m.url for m in requests_mock_datadir.request_history | m.url for m in requests_mock_datadir.request_history | ||||
if m.url.startswith('https://ftp.gnu.org') | if m.url.startswith('https://ftp.gnu.org') | ||||
] | ] | ||||
# 1 artifact (2nd time no modification) + 1 new artifact | # 1 artifact (2nd time no modification) + 1 new artifact | ||||
assert len(urls) == 2 | assert len(urls) == 2 | ||||
def test_artifact_identity(): | |||||
"""Compute primary key should return the right identity | |||||
""" | |||||
data = { | |||||
'a': 1, | |||||
'b': 2, | |||||
'length': 221837, | |||||
'filename': '8sync-0.1.0.tar.gz', | |||||
'version': '0.1.0', | |||||
} | |||||
for id_keys, expected_id in [ | |||||
(['a', 'b'], [1, 2]), | |||||
([], []), | |||||
(['a', 'key-that-does-not-exist'], [1, None]) | |||||
]: | |||||
actual_id = artifact_identity(data, id_keys=id_keys) | |||||
assert actual_id == expected_id | |||||
def test_2_visits_without_change_not_gnu(swh_config, requests_mock_datadir): | def test_2_visits_without_change_not_gnu(swh_config, requests_mock_datadir): | ||||
"""Load a project archive (not gnu) ends up with 1 snapshot | """Load a project archive (not gnu) ends up with 1 snapshot | ||||
""" | """ | ||||
url = 'https://something.else.org/8sync/' | url = 'https://something.else.org/8sync/' | ||||
artifacts = [ # this is not a gnu artifact | artifacts = [ # this is not a gnu artifact | ||||
{ | { | ||||
'time': '1999-12-09T09:53:30+00:00', # it's also not a timestamp | 'time': '1999-12-09T09:53:30+00:00', # it's also not a timestamp | ||||
Show All 35 Lines |