Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/package/pubdev/tests/test_pubdev.py
# Copyright (C) 2022 The Software Heritage developers | # Copyright (C) 2022 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 pytest | |||||
from swh.loader.package.pubdev.loader import PubDevLoader | from swh.loader.package.pubdev.loader import PubDevLoader | ||||
from swh.loader.package.utils import EMPTY_AUTHOR | from swh.loader.package.utils import EMPTY_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 ( | ||||
ObjectType, | ObjectType, | ||||
Person, | Person, | ||||
Release, | Release, | ||||
Snapshot, | Snapshot, | ||||
SnapshotBranch, | SnapshotBranch, | ||||
TargetType, | TargetType, | ||||
TimestampWithTimezone, | TimestampWithTimezone, | ||||
) | ) | ||||
EXPECTED_PACKAGES = [ | EXPECTED_PACKAGES = [ | ||||
{ | { | ||||
"url": "https://pub.dev/api/packages/Autolinker", # one version | "url": "https://pub.dev/packages/Autolinker", # one version | ||||
}, | }, | ||||
{ | { | ||||
"url": "https://pub.dev/api/packages/pdf", # multiple versions | "url": "https://pub.dev/packages/pdf", # multiple versions | ||||
}, | }, | ||||
{ | { | ||||
"url": "https://pub.dev/api/packages/bezier", # multiple authors | "url": "https://pub.dev/packages/bezier", # multiple authors | ||||
}, | }, | ||||
{ | { | ||||
"url": "https://pub.dev/api/packages/authentication", # empty author | "url": "https://pub.dev/packages/authentication", # empty author | ||||
}, | }, | ||||
{ | { | ||||
"url": "https://pub.dev/api/packages/abstract_io", # loose versions names | "url": "https://pub.dev/packages/abstract_io", # loose versions names | ||||
}, | }, | ||||
] | ] | ||||
def test_get_versions(requests_mock_datadir, swh_storage): | def test_get_versions(requests_mock_datadir, swh_storage): | ||||
loader = PubDevLoader( | loader = PubDevLoader( | ||||
swh_storage, | swh_storage, | ||||
url=EXPECTED_PACKAGES[1]["url"], | url=EXPECTED_PACKAGES[1]["url"], | ||||
▲ Show 20 Lines • Show All 213 Lines • ▼ Show 20 Lines | def test_pubdev_loader_empty_author(datadir, requests_mock_datadir, swh_storage): | ||||
) | ) | ||||
check_snapshot(expected_snapshot, swh_storage) | check_snapshot(expected_snapshot, swh_storage) | ||||
release = swh_storage.release_get([hash_to_bytes(expected_release_id)])[0] | release = swh_storage.release_get([hash_to_bytes(expected_release_id)])[0] | ||||
assert release.author == EMPTY_AUTHOR | assert release.author == EMPTY_AUTHOR | ||||
def test_pubdev_invalid_origin(swh_storage, requests_mock_datadir): | def test_pubdev_invalid_origin(swh_storage): | ||||
loader = PubDevLoader( | |||||
with pytest.raises(AssertionError): | |||||
PubDevLoader( | |||||
swh_storage, | swh_storage, | ||||
"http://nowhere/api/packages/42", | "http://nowhere/api/packages/42", | ||||
) | ) | ||||
load_status = loader.load() | |||||
assert load_status["status"] == "failed" |