Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/package/pubdev/tests/test_pubdev.py
- This file was added.
# Copyright (C) 2022 The Software Heritage developers | |||||
# See the AUTHORS file at the top-level directory of this distribution | |||||
# License: GNU General Public License version 3, or any later version | |||||
# See top-level LICENSE file for more information | |||||
from swh.loader.package.pubdev.loader import PubDevLoader | |||||
EXPECTED_PACKAGES = [ | |||||
{ | |||||
"url": "https://pub.dev/api/packages/Autolinker", | |||||
}, | |||||
{ | |||||
"url": "https://pub.dev/api/packages/pdf", | |||||
}, | |||||
] | |||||
def test_get_versions(requests_mock_datadir, swh_storage): | |||||
loader = PubDevLoader( | |||||
swh_storage, | |||||
url=EXPECTED_PACKAGES[1]["url"], | |||||
) | |||||
assert loader.get_versions() == [ | |||||
"1.0.0", | |||||
"3.8.2", | |||||
] | |||||
def test_get_default_version(requests_mock_datadir, swh_storage): | |||||
loader = PubDevLoader( | |||||
swh_storage, | |||||
url=EXPECTED_PACKAGES[1]["url"], | |||||
) | |||||
assert loader.get_default_version() == "3.8.2" | |||||
def test_pubdev_loader_load_one_version(datadir, requests_mock_datadir, swh_storage): | |||||
loader = PubDevLoader( | |||||
swh_storage, | |||||
url=EXPECTED_PACKAGES[0]["url"], | |||||
) | |||||
actual_load_status = loader.load() | |||||
assert actual_load_status["status"] == "eventful" | |||||
assert actual_load_status["snapshot_id"] is not None | |||||
def test_pubdev_loader_load_multiple_versions( | |||||
datadir, requests_mock_datadir, swh_storage | |||||
): | |||||
loader = PubDevLoader( | |||||
swh_storage, | |||||
url=EXPECTED_PACKAGES[1]["url"], | |||||
) | |||||
actual_load_status = loader.load() | |||||
assert actual_load_status["status"] == "eventful" | |||||
assert actual_load_status["snapshot_id"] is not None |