Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/package/npm/tests/test_npm.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 json | import json | ||||
import os | import os | ||||
import pytest | import pytest | ||||
from swh.loader.package import __version__ | from swh.loader.package import __version__ | ||||
from swh.loader.package.npm.loader import ( | from swh.loader.package.npm.loader import ( | ||||
NpmLoader, | NpmLoader, | ||||
_author_str, | _author_str, | ||||
extract_npm_package_author, | extract_npm_package_author, | ||||
) | ) | ||||
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 | from swh.model.hashutil import hash_to_bytes | ||||
from swh.model.model import ( | from swh.model.model import ( | ||||
Person, | Person, | ||||
RawExtrinsicMetadata, | RawExtrinsicMetadata, | ||||
Release, | Release, | ||||
Snapshot, | Snapshot, | ||||
SnapshotBranch, | SnapshotBranch, | ||||
TargetType, | TargetType, | ||||
Timestamp, | |||||
TimestampWithTimezone, | TimestampWithTimezone, | ||||
) | ) | ||||
from swh.model.model import MetadataAuthority, MetadataAuthorityType, MetadataFetcher | from swh.model.model import MetadataAuthority, MetadataAuthorityType, MetadataFetcher | ||||
from swh.model.model import ObjectType as ModelObjectType | from swh.model.model import ObjectType as ModelObjectType | ||||
from swh.model.swhids import CoreSWHID, ExtendedObjectType, ExtendedSWHID, ObjectType | from swh.model.swhids import CoreSWHID, ExtendedObjectType, ExtendedSWHID, ObjectType | ||||
from swh.storage.interface import PagedResult | from swh.storage.interface import PagedResult | ||||
▲ Show 20 Lines • Show All 315 Lines • ▼ Show 20 Lines | assert swh_storage.release_get([hash_to_bytes(release_id)])[0] == Release( | ||||
target=hash_to_bytes("42753c0c2ab00c4501b552ac4671c68f3cf5aece"), | target=hash_to_bytes("42753c0c2ab00c4501b552ac4671c68f3cf5aece"), | ||||
target_type=ModelObjectType.DIRECTORY, | target_type=ModelObjectType.DIRECTORY, | ||||
synthetic=True, | synthetic=True, | ||||
author=Person( | author=Person( | ||||
fullname=b"mooz <stillpedant@gmail.com>", | fullname=b"mooz <stillpedant@gmail.com>", | ||||
name=b"mooz", | name=b"mooz", | ||||
email=b"stillpedant@gmail.com", | email=b"stillpedant@gmail.com", | ||||
), | ), | ||||
date=TimestampWithTimezone( | date=TimestampWithTimezone.from_datetime( | ||||
timestamp=Timestamp(seconds=1388590833, microseconds=0), | datetime.datetime(2014, 1, 1, 15, 40, 33, tzinfo=datetime.timezone.utc) | ||||
offset=0, | |||||
negative_utc=False, | |||||
), | ), | ||||
id=hash_to_bytes(release_id), | id=hash_to_bytes(release_id), | ||||
) | ) | ||||
contents = swh_storage.content_get(_expected_new_contents_first_visit) | contents = swh_storage.content_get(_expected_new_contents_first_visit) | ||||
count = sum(0 if content is None else 1 for content in contents) | count = sum(0 if content is None else 1 for content in contents) | ||||
assert count == len(_expected_new_contents_first_visit) | assert count == len(_expected_new_contents_first_visit) | ||||
▲ Show 20 Lines • Show All 274 Lines • Show Last 20 Lines |