Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/npm/tests/test_utils.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 json | import json | ||||
import os | import os | ||||
import unittest | import unittest | ||||
from swh.loader.npm.utils import ( | from swh.loader.npm.utils import ( | ||||
parse_npm_package_author, extract_npm_package_author | parse_npm_package_author, extract_npm_package_author | ||||
) | ) | ||||
from swh.loader.npm.tests.common import ( | from swh.loader.npm.tests.common import ( | ||||
RESOURCES_PATH, SECOND_VISIT_PACKAGE_METADATA_JSON_FILENAME | RESOURCES_PATH, package, package_metadata_file | ||||
) | ) | ||||
class TestNpmClient(unittest.TestCase): | class TestNpmClient(unittest.TestCase): | ||||
def _parse_author_string_test(self, author_str, expected_result): | def _parse_author_string_test(self, author_str, expected_result): | ||||
self.assertEqual( | self.assertEqual( | ||||
parse_npm_package_author(author_str), | parse_npm_package_author(author_str), | ||||
▲ Show 20 Lines • Show All 141 Lines • ▼ Show 20 Lines | def test_parse_npm_package_author(self): | ||||
'John Doe ()', | 'John Doe ()', | ||||
{ | { | ||||
'name': 'John Doe' | 'name': 'John Doe' | ||||
} | } | ||||
) | ) | ||||
def test_extract_npm_package_author(self): | def test_extract_npm_package_author(self): | ||||
package_metadata_filepath = os.path.join( | package_metadata_filepath = os.path.join( | ||||
RESOURCES_PATH, SECOND_VISIT_PACKAGE_METADATA_JSON_FILENAME) | RESOURCES_PATH, package_metadata_file(package, visit=2)) | ||||
with open(package_metadata_filepath) as json_file: | with open(package_metadata_filepath) as json_file: | ||||
package_metadata = json.load(json_file) | package_metadata = json.load(json_file) | ||||
self.assertEqual( | self.assertEqual( | ||||
extract_npm_package_author(package_metadata['versions']['0.0.2']), | extract_npm_package_author(package_metadata['versions']['0.0.2']), | ||||
{ | { | ||||
'fullname': b'mooz <stillpedant@gmail.com>', | 'fullname': b'mooz <stillpedant@gmail.com>', | ||||
▲ Show 20 Lines • Show All 88 Lines • Show Last 20 Lines |