Page MenuHomeSoftware Heritage

D1733.id5822.diff
No OneTemporary

D1733.id5822.diff

diff --git a/swh/lister/pypi/tests/api_response.html b/swh/lister/pypi/tests/api_response.html
new file mode 100644
--- /dev/null
+++ b/swh/lister/pypi/tests/api_response.html
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>Simple index</title>
+ </head>
+ <body>
+ <a href="/simple/0lever-so/">0lever-so</a>
+ <a href="/simple/0lever-utils/">0lever-utils</a>
+ <a href="/simple/0-orchestrator/">0-orchestrator</a>
+ <a href="/simple/0wned/">0wned</a>
+ </body>
+</html>
\ No newline at end of file
diff --git a/swh/lister/pypi/tests/test_lister.py b/swh/lister/pypi/tests/test_lister.py
new file mode 100644
--- /dev/null
+++ b/swh/lister/pypi/tests/test_lister.py
@@ -0,0 +1,55 @@
+# Copyright (C) 2019 the Software Heritage developers
+# License: GNU General Public License version 3, or any later version
+# See top-level LICENSE file for more information
+
+from swh.lister.pypi.lister import PyPILister
+from unittest.mock import patch
+import requests_mock
+import requests
+
+lister = PyPILister()
+
+expected_packages = ['0lever-so', '0lever-utils', '0-orchestrator', '0wned']
+
+expected_model = {
+ 'uid': 'arrow',
+ 'name': 'arrow',
+ 'full_name': 'arrow',
+ 'html_url': 'https://pypi.org/pypi/arrow/json',
+ 'origin_url': 'https://pypi.org/project/arrow/',
+ 'origin_type': 'pypi',
+ }
+
+
+def test_list_packages():
+ f = open('swh/lister/pypi/tests/api_response.html')
+ api_response = f.read()
+
+ adapter = requests_mock.Adapter()
+ session = requests.Session()
+ session.mount('mock', adapter)
+
+ adapter.register_uri('GET', 'mock://test.com/path', text=api_response)
+ response = session.get('mock://test.com/path')
+
+ packages = lister.list_packages(response)
+ assert len(packages) == 4
+ for package in expected_packages:
+ assert package in packages
+
+
+def test_transport_response_simplified():
+ model = lister.transport_response_simplified(['arrow'])
+ assert len(model) == 1
+ for key, values in model[0].items():
+ assert values == expected_model[key]
+
+
+def test_task_dict():
+ with patch('swh.lister.pypi.lister.utils.create_task_dict') \
+ as mock_create_tasks:
+ lister.task_dict(origin_type='pypi', origin_url='https://abc',
+ name='test_pack', html_url='https://def')
+ mock_create_tasks.assert_called_once_with(
+ 'load-pypi', 'recurring', 'test_pack', 'https://abc',
+ project_metadata_url='https://def')

File Metadata

Mime Type
text/plain
Expires
Tue, Dec 17, 9:48 PM (2 d, 14 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3228718

Event Timeline