Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/package/archive/tests/test_archive.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 datetime | |||||
import hashlib | import hashlib | ||||
from io import BytesIO | from io import BytesIO | ||||
from pathlib import Path | from pathlib import Path | ||||
import string | import string | ||||
import attr | import attr | ||||
import pytest | import pytest | ||||
from requests.exceptions import ContentDecodingError | from requests.exceptions import ContentDecodingError | ||||
from swh.loader.package.archive.loader import ArchiveLoader, ArchivePackageInfo | from swh.loader.package.archive.loader import ArchiveLoader, ArchivePackageInfo | ||||
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, hash_to_hex | from swh.model.hashutil import hash_to_bytes, hash_to_hex | ||||
from swh.model.model import ( | from swh.model.model import ( | ||||
ObjectType, | ObjectType, | ||||
Person, | Person, | ||||
Release, | Release, | ||||
Snapshot, | Snapshot, | ||||
SnapshotBranch, | SnapshotBranch, | ||||
TargetType, | TargetType, | ||||
Timestamp, | |||||
TimestampWithTimezone, | TimestampWithTimezone, | ||||
) | ) | ||||
URL = "https://ftp.gnu.org/gnu/8sync/" | URL = "https://ftp.gnu.org/gnu/8sync/" | ||||
GNU_ARTIFACTS = [ | GNU_ARTIFACTS = [ | ||||
{ | { | ||||
"time": 944729610, | "time": 944729610, | ||||
"url": "https://ftp.gnu.org/gnu/8sync/8sync-0.1.0.tar.gz", | "url": "https://ftp.gnu.org/gnu/8sync/8sync-0.1.0.tar.gz", | ||||
▲ Show 20 Lines • Show All 147 Lines • ▼ Show 20 Lines | assert swh_storage.release_get([release_id])[0] == Release( | ||||
message=( | message=( | ||||
b"Synthetic release for archive at " | b"Synthetic release for archive at " | ||||
b"https://ftp.gnu.org/gnu/8sync/8sync-0.1.0.tar.gz\n" | b"https://ftp.gnu.org/gnu/8sync/8sync-0.1.0.tar.gz\n" | ||||
), | ), | ||||
target=hash_to_bytes("3aebc29ed1fccc4a6f2f2010fb8e57882406b528"), | target=hash_to_bytes("3aebc29ed1fccc4a6f2f2010fb8e57882406b528"), | ||||
target_type=ObjectType.DIRECTORY, | target_type=ObjectType.DIRECTORY, | ||||
synthetic=True, | synthetic=True, | ||||
author=Person.from_fullname(b""), | author=Person.from_fullname(b""), | ||||
date=TimestampWithTimezone( | date=TimestampWithTimezone.from_datetime( | ||||
timestamp=Timestamp(seconds=944729610, microseconds=0), | datetime.datetime(1999, 12, 9, 8, 53, 30, tzinfo=datetime.timezone.utc) | ||||
offset=0, | |||||
negative_utc=False, | |||||
), | ), | ||||
) | ) | ||||
expected_contents = map(hash_to_bytes, _expected_new_contents_first_visit) | expected_contents = map(hash_to_bytes, _expected_new_contents_first_visit) | ||||
assert list(swh_storage.content_missing_per_sha1(expected_contents)) == [] | assert list(swh_storage.content_missing_per_sha1(expected_contents)) == [] | ||||
expected_dirs = map(hash_to_bytes, _expected_new_directories_first_visit) | expected_dirs = map(hash_to_bytes, _expected_new_directories_first_visit) | ||||
assert list(swh_storage.directory_missing(expected_dirs)) == [] | assert list(swh_storage.directory_missing(expected_dirs)) == [] | ||||
▲ Show 20 Lines • Show All 291 Lines • Show Last 20 Lines |