Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/package/tests/test_utils.py
# Copyright (C) 2019-2020 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 json | import json | ||||
import os | import os | ||||
import pytest | import pytest | ||||
from swh.loader.exception import NotFound | |||||
import swh.loader.package | import swh.loader.package | ||||
from swh.loader.package.utils import api_info, download, release_name | from swh.loader.package.utils import api_info, download, release_name | ||||
def test_version_generation(): | def test_version_generation(): | ||||
assert ( | assert ( | ||||
swh.loader.package.__version__ != "devel" | swh.loader.package.__version__ != "devel" | ||||
), "Make sure swh.loader.core is installed (e.g. pip install -e .)" | ), "Make sure swh.loader.core is installed (e.g. pip install -e .)" | ||||
▲ Show 20 Lines • Show All 110 Lines • ▼ Show 20 Lines | |||||
def test_api_info_failure(requests_mock): | def test_api_info_failure(requests_mock): | ||||
"""Failure to fetch info/release information should raise""" | """Failure to fetch info/release information should raise""" | ||||
url = "https://pypi.org/pypi/requests/json" | url = "https://pypi.org/pypi/requests/json" | ||||
status_code = 400 | status_code = 400 | ||||
requests_mock.get(url, status_code=status_code) | requests_mock.get(url, status_code=status_code) | ||||
with pytest.raises(ValueError) as e0: | with pytest.raises(NotFound) as e0: | ||||
api_info(url) | api_info(url) | ||||
assert e0.value.args[0] == "Fail to query '%s'. Reason: %s" % (url, status_code) | assert e0.value.args[0] == "Fail to query '%s'. Reason: %s" % (url, status_code) | ||||
def test_api_info(requests_mock): | def test_api_info(requests_mock): | ||||
"""Fetching json info from pypi project should be ok""" | """Fetching json info from pypi project should be ok""" | ||||
url = "https://pypi.org/pypi/requests/json" | url = "https://pypi.org/pypi/requests/json" | ||||
Show All 13 Lines |