Page MenuHomeSoftware Heritage

D2122.diff
No OneTemporary

D2122.diff

diff --git a/swh/lister/npm/tests/api_empty_response.json b/swh/lister/npm/tests/data/api_empty_response.json
rename from swh/lister/npm/tests/api_empty_response.json
rename to swh/lister/npm/tests/data/api_empty_response.json
diff --git a/swh/lister/npm/tests/api_inc_empty_response.json b/swh/lister/npm/tests/data/api_inc_empty_response.json
rename from swh/lister/npm/tests/api_inc_empty_response.json
rename to swh/lister/npm/tests/data/api_inc_empty_response.json
diff --git a/swh/lister/npm/tests/api_inc_response.json b/swh/lister/npm/tests/data/api_inc_response.json
rename from swh/lister/npm/tests/api_inc_response.json
rename to swh/lister/npm/tests/data/api_inc_response.json
diff --git a/swh/lister/npm/tests/api_response.json b/swh/lister/npm/tests/data/replicate.npmjs.com/_all_docs,startkey=%22%22,limit=1001
rename from swh/lister/npm/tests/api_response.json
rename to swh/lister/npm/tests/data/replicate.npmjs.com/_all_docs,startkey=%22%22,limit=1001
diff --git a/swh/lister/npm/tests/data/replicate.npmjs.com/api_response.json b/swh/lister/npm/tests/data/replicate.npmjs.com/api_response.json
new file mode 120000
--- /dev/null
+++ b/swh/lister/npm/tests/data/replicate.npmjs.com/api_response.json
@@ -0,0 +1 @@
+_all_docs,startkey=%22%22,limit=1001
\ No newline at end of file
diff --git a/swh/lister/npm/tests/test_npm_lister.py b/swh/lister/npm/tests/test_lister.py
rename from swh/lister/npm/tests/test_npm_lister.py
rename to swh/lister/npm/tests/test_lister.py
--- a/swh/lister/npm/tests/test_npm_lister.py
+++ b/swh/lister/npm/tests/test_lister.py
@@ -1,7 +1,10 @@
-# Copyright (C) 2018-2019 the Software Heritage developers
+# Copyright (C) 2018-2019 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 logging
+
import re
import requests_mock
import unittest
@@ -10,12 +13,15 @@
from swh.lister.npm.lister import NpmLister, NpmIncrementalLister
+logger = logging.getLogger(__name__)
+
+
class NpmListerTester(HttpListerTesterBase, unittest.TestCase):
Lister = NpmLister
test_re = re.compile(r'^.*/_all_docs\?startkey=%22(.+)%22.*')
lister_subdir = 'npm'
- good_api_response_file = 'api_response.json'
- bad_api_response_file = 'api_empty_response.json'
+ good_api_response_file = 'data/replicate.npmjs.com/api_response.json'
+ bad_api_response_file = 'data/api_empty_response.json'
first_index = 'jquery'
entries_per_page = 100
@@ -31,8 +37,8 @@
Lister = NpmIncrementalLister
test_re = re.compile(r'^.*/_changes\?since=([0-9]+).*')
lister_subdir = 'npm'
- good_api_response_file = 'api_inc_response.json'
- bad_api_response_file = 'api_inc_empty_response.json'
+ good_api_response_file = 'data/api_inc_response.json'
+ bad_api_response_file = 'data/api_inc_empty_response.json'
first_index = '6920642'
entries_per_page = 100
@@ -42,3 +48,31 @@
# it can not succeed for the npm lister due to the
# overriding of the string_pattern_check method
pass
+
+
+def test_lister_npm_basic_listing(swh_listers, requests_mock_datadir):
+ lister = swh_listers['npm']
+
+ lister.run()
+
+ r = lister.scheduler.search_tasks(task_type='load-npm')
+ assert len(r) == 100
+
+ for row in r:
+ logger.debug('row: %s', row)
+ assert row['type'] == 'load-npm'
+ # arguments check
+ args = row['arguments']['args']
+ assert len(args) == 2
+
+ package = args[0]
+ url = args[1]
+ assert url == 'https://www.npmjs.com/package/%s' % package
+
+ # kwargs
+ kwargs = row['arguments']['kwargs']
+ meta_url = kwargs['package_metadata_url']
+ assert meta_url == 'https://replicate.npmjs.com/%s' % package
+
+ assert row['policy'] == 'recurring'
+ assert row['priority'] is None

File Metadata

Mime Type
text/plain
Expires
Nov 5 2024, 8:03 AM (8 w, 2 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3219945

Event Timeline