diff --git a/swh/loader/pypi/tests/test_model.py b/swh/loader/pypi/tests/test_model.py index 84fbd4d..ea835d1 100644 --- a/swh/loader/pypi/tests/test_model.py +++ b/swh/loader/pypi/tests/test_model.py @@ -1,148 +1,148 @@ # Copyright (C) 2018 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 import os import json import tempfile import shutil from unittest import TestCase from nose.tools import istest from swh.loader.pypi.model import PyPiProject, author from swh.loader.pypi.client import PyPiClient, _project_pkginfo class PyPiClientWithCache(PyPiClient): """Force the use of the cache to bypass pypi calls """ def __init__(self, temp_directory, cache_dir): super().__init__(temp_directory=temp_directory, cache=True, cache_dir=cache_dir) RESOURCES_PATH = './swh/loader/pypi/tests/resources' class ModelTest(TestCase): def setUp(self): project = '0805nexter' project_metadata_file = '%s/%s.json' % (RESOURCES_PATH, project) with open(project_metadata_file) as f: data = json.load(f) release_files = [] for f in os.listdir(RESOURCES_PATH): if f.endswith('.json'): continue file = os.path.join(RESOURCES_PATH, f) release_files.append(file) temp_dir = tempfile.mkdtemp( dir='/tmp/', prefix='swh.loader.pypi.tests-') project_metadata_url = 'https://pypi.org/pypi/%s/json' % project # Will use the pypi with cache client = PyPiClientWithCache( temp_directory=temp_dir, cache_dir=RESOURCES_PATH) self.project = PyPiProject( client=client, project=project, project_metadata_url=project_metadata_url, data=data) self.data = data self.temp_dir = temp_dir self.project_name = project def tearDown(self): if os.path.exists(self.temp_dir): shutil.rmtree(self.temp_dir) @istest def info(self): actual_info = self.project.info() expected_info = { 'home_page': self.data['info']['home_page'], 'description': self.data['info']['description'], 'summary': self.data['info']['summary'], 'license': self.data['info']['license'], 'package_url': self.data['info']['package_url'], 'project_url': self.data['info']['project_url'], 'upstream': self.data['info']['project_urls']['Homepage'], } self.assertEqual(expected_info, actual_info) @istest def author(self): info = self.data['info'] actual_author = author(info) name = info['author'].encode('utf-8') email = info['author_email'].encode('utf-8') expected_author = { 'fullname': b'%s <%s>' % (name, email), 'name': name, 'email': email, } self.assertEqual(expected_author, actual_author) @istest def releases(self): - actual_releases = self.project.releases() + actual_releases = self.project.releases([]) expected_releases = { '1.1.0': { 'archive_type': 'zip', 'blake2s256': 'df9413bde66e6133b10cadefad6fcf9cbbc369b47831089112c846d79f14985a', # noqa 'date': '2016-01-31T05:28:42', 'filename': '0805nexter-1.1.0.zip', 'message': '', 'name': '1.1.0', 'sha1': '127d8697db916ba1c67084052196a83319a25000', 'sha1_git': '4b8f1350e6d9fa00256e974ae24c09543d85b196', 'sha256': '52cd128ad3afe539478abc7440d4b043384295fbe6b0958a237cb6d926465035', # noqa 'size': 862, 'url': 'https://files.pythonhosted.org/packages/ec/65/c0116953c9a3f47de89e71964d6c7b0c783b01f29fa3390584dbf3046b4d/0805nexter-1.1.0.zip', # noqa }, '1.2.0': { 'archive_type': 'zip', 'blake2s256': '67010586b5b9a4aaa3b1c386f9dc8b4c99e6e40f37732a717a5f9b9b1185e588', # noqa 'date': '2016-01-31T05:51:25', 'filename': '0805nexter-1.2.0.zip', 'message': '', 'name': '1.2.0', 'sha1': 'd55238554b94da7c5bf4a349ece0fe3b2b19f79c', 'sha1_git': '8638d33a96cb25d8319af21417f00045ec6ee810', 'sha256': '49785c6ae39ea511b3c253d7621c0b1b6228be2f965aca8a491e6b84126d0709', # noqa 'size': 898, 'url': 'https://files.pythonhosted.org/packages/c4/a0/4562cda161dc4ecbbe9e2a11eb365400c0461845c5be70d73869786809c4/0805nexter-1.2.0.zip', # noqa } } dir_paths = [] for _release_info, _author, _release, _dir_path in actual_releases: version = _release_info['version'] expected_pkginfo = _project_pkginfo(_dir_path) self.assertEquals(_release_info, expected_pkginfo) expected_author = author(expected_pkginfo) self.assertEqual(_author, expected_author) expected_release = expected_releases[version] self.assertEqual(_release, expected_release) self.assertTrue(version in _dir_path) self.assertTrue(self.project_name in _dir_path) # path still exists self.assertTrue(os.path.exists(_dir_path)) dir_paths.append(_dir_path) # Ensure uncompressed paths have been destroyed for _dir_path in dir_paths: # path no longer exists self.assertFalse(os.path.exists(_dir_path))