Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/package/pypi/tests/test_pypi.py
# Copyright (C) 2019 The Software Heritage developers | # Copyright (C) 2019 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 os | import os | ||||
from os import path | from os import path | ||||
import pytest | import pytest | ||||
from unittest.mock import patch | from unittest.mock import patch | ||||
from swh.core.tarball import uncompress | from swh.core.tarball import uncompress | ||||
from swh.core.pytest_plugin import requests_mock_datadir_factory | from swh.core.pytest_plugin import requests_mock_datadir_factory | ||||
from swh.model.hashutil import hash_to_bytes | from swh.model.hashutil import hash_to_bytes | ||||
from swh.model.model import Person | |||||
from swh.loader.package.pypi.loader import ( | from swh.loader.package.pypi.loader import ( | ||||
PyPILoader, pypi_api_url, author, extract_intrinsic_metadata, | PyPILoader, pypi_api_url, author, extract_intrinsic_metadata, | ||||
artifact_to_revision_id | artifact_to_revision_id | ||||
) | ) | ||||
from swh.loader.package.tests.common import ( | from swh.loader.package.tests.common import ( | ||||
check_snapshot, check_metadata_paths, get_stats | check_snapshot, check_metadata_paths, get_stats | ||||
) | ) | ||||
def test_author_basic(): | def test_author_basic(): | ||||
data = { | data = { | ||||
'author': "i-am-groot", | 'author': "i-am-groot", | ||||
'author_email': 'iam@groot.org', | 'author_email': 'iam@groot.org', | ||||
} | } | ||||
actual_author = author(data) | actual_author = author(data) | ||||
expected_author = { | expected_author = Person( | ||||
'fullname': b'i-am-groot <iam@groot.org>', | fullname=b'i-am-groot <iam@groot.org>', | ||||
'name': b'i-am-groot', | name=b'i-am-groot', | ||||
'email': b'iam@groot.org', | email=b'iam@groot.org', | ||||
} | ) | ||||
assert actual_author == expected_author | assert actual_author == expected_author | ||||
def test_author_empty_email(): | def test_author_empty_email(): | ||||
data = { | data = { | ||||
'author': 'i-am-groot', | 'author': 'i-am-groot', | ||||
'author_email': '', | 'author_email': '', | ||||
} | } | ||||
actual_author = author(data) | actual_author = author(data) | ||||
expected_author = { | expected_author = Person( | ||||
'fullname': b'i-am-groot', | fullname=b'i-am-groot', | ||||
'name': b'i-am-groot', | name=b'i-am-groot', | ||||
'email': b'', | email=b'', | ||||
} | ) | ||||
assert actual_author == expected_author | assert actual_author == expected_author | ||||
def test_author_empty_name(): | def test_author_empty_name(): | ||||
data = { | data = { | ||||
'author': "", | 'author': "", | ||||
'author_email': 'iam@groot.org', | 'author_email': 'iam@groot.org', | ||||
} | } | ||||
actual_author = author(data) | actual_author = author(data) | ||||
expected_author = { | expected_author = Person( | ||||
'fullname': b' <iam@groot.org>', | fullname=b' <iam@groot.org>', | ||||
'name': b'', | name=b'', | ||||
'email': b'iam@groot.org', | email=b'iam@groot.org', | ||||
} | ) | ||||
assert actual_author == expected_author | assert actual_author == expected_author | ||||
def test_author_malformed(): | def test_author_malformed(): | ||||
data = { | data = { | ||||
'author': "['pierre', 'paul', 'jacques']", | 'author': "['pierre', 'paul', 'jacques']", | ||||
'author_email': None, | 'author_email': None, | ||||
} | } | ||||
actual_author = author(data) | actual_author = author(data) | ||||
expected_author = { | expected_author = Person( | ||||
'fullname': b"['pierre', 'paul', 'jacques']", | fullname=b"['pierre', 'paul', 'jacques']", | ||||
'name': b"['pierre', 'paul', 'jacques']", | name=b"['pierre', 'paul', 'jacques']", | ||||
'email': None, | email=None, | ||||
} | ) | ||||
assert actual_author == expected_author | assert actual_author == expected_author | ||||
def test_author_malformed_2(): | def test_author_malformed_2(): | ||||
data = { | data = { | ||||
'author': '[marie, jeanne]', | 'author': '[marie, jeanne]', | ||||
'author_email': '[marie@some, jeanne@thing]', | 'author_email': '[marie@some, jeanne@thing]', | ||||
} | } | ||||
actual_author = author(data) | actual_author = author(data) | ||||
expected_author = { | expected_author = Person( | ||||
'fullname': b'[marie, jeanne] <[marie@some, jeanne@thing]>', | fullname=b'[marie, jeanne] <[marie@some, jeanne@thing]>', | ||||
'name': b'[marie, jeanne]', | name=b'[marie, jeanne]', | ||||
'email': b'[marie@some, jeanne@thing]', | email=b'[marie@some, jeanne@thing]', | ||||
} | ) | ||||
assert actual_author == expected_author | assert actual_author == expected_author | ||||
def test_author_malformed_3(): | def test_author_malformed_3(): | ||||
data = { | data = { | ||||
'author': '[marie, jeanne, pierre]', | 'author': '[marie, jeanne, pierre]', | ||||
'author_email': '[marie@somewhere.org, jeanne@somewhere.org]', | 'author_email': '[marie@somewhere.org, jeanne@somewhere.org]', | ||||
} | } | ||||
actual_author = author(data) | actual_author = author(data) | ||||
expected_author = { | expected_author = Person( | ||||
'fullname': b'[marie, jeanne, pierre] <[marie@somewhere.org, jeanne@somewhere.org]>', # noqa | fullname=( | ||||
'name': b'[marie, jeanne, pierre]', | b'[marie, jeanne, pierre] ' | ||||
'email': b'[marie@somewhere.org, jeanne@somewhere.org]', | b'<[marie@somewhere.org, jeanne@somewhere.org]>' | ||||
} | ), | ||||
name=b'[marie, jeanne, pierre]', | |||||
email=b'[marie@somewhere.org, jeanne@somewhere.org]', | |||||
) | |||||
actual_author == expected_author | actual_author == expected_author | ||||
# configuration error # | # configuration error # | ||||
def test_badly_configured_loader_raise(monkeypatch): | def test_badly_configured_loader_raise(monkeypatch): | ||||
"""Badly configured loader should raise""" | """Badly configured loader should raise""" | ||||
▲ Show 20 Lines • Show All 701 Lines • Show Last 20 Lines |