Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F7163534
D1409.id4533.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
7 KB
Subscribers
None
D1409.id4533.diff
View Options
diff --git a/swh/loader/npm/client.py b/swh/loader/npm/client.py
--- a/swh/loader/npm/client.py
+++ b/swh/loader/npm/client.py
@@ -56,7 +56,10 @@
Returns:
str: the last releases package version
"""
- return self.package_metadata['dist-tags']['latest']
+ latest = ''
+ if 'latest' in self.package_metadata['dist-tags']:
+ latest = self.package_metadata['dist-tags']['latest']
+ return latest
def package_versions(self, known_versions=None):
"""
diff --git a/swh/loader/npm/tests/common.py b/swh/loader/npm/tests/common.py
--- a/swh/loader/npm/tests/common.py
+++ b/swh/loader/npm/tests/common.py
@@ -9,10 +9,15 @@
RESOURCES_PATH = os.path.join(os.path.dirname(__file__), 'resources')
+empty_package = '22u-validators'
+empty_package_url = 'https://www.npmjs.com/package/%s' % empty_package
+empty_package_metadata_url = 'https://replicate.npmjs.com/%s/' % empty_package
+
package = 'org'
package_url = 'https://www.npmjs.com/package/%s' % package
package_metadata_url = 'https://replicate.npmjs.com/%s/' % package
+EMPTY_PACKAGE_METADATA_JSON_FILENAME = '22u-validators.json'
FIRST_VISIT_PACKAGE_METADATA_JSON_FILENAME = 'org_metadata_visit1.json'
SECOND_VISIT_PACKAGE_METADATA_JSON_FILENAME = 'org_metadata_visit2.json'
@@ -27,12 +32,12 @@
return self.file_data
-def init_test_data(m, package_metadata_json_file):
+def init_test_data(m, package_metadata_json_file, package_metadata_url):
- org_metadata_filepath = os.path.join(RESOURCES_PATH,
- package_metadata_json_file)
+ package_metadata_filepath = os.path.join(RESOURCES_PATH,
+ package_metadata_json_file)
- with open(org_metadata_filepath) as json_file:
+ with open(package_metadata_filepath) as json_file:
package_metadata = json.load(json_file)
m.register_uri('GET', package_metadata_url, json=package_metadata)
diff --git a/swh/loader/npm/tests/resources/22u-validators.json b/swh/loader/npm/tests/resources/22u-validators.json
new file mode 100644
--- /dev/null
+++ b/swh/loader/npm/tests/resources/22u-validators.json
@@ -0,0 +1,20 @@
+{
+ "_id": "22u-validators",
+ "_rev": "1-4853f78ded9c4fbcfe4c097ee96a4589",
+ "name": "22u-validators",
+ "time": {
+ "modified": "2017-06-07T01:30:36.011Z",
+ "created": "2015-07-19T13:07:40.046Z",
+ "0.1.0": "2015-07-19T13:07:40.046Z"
+ },
+ "maintainers": [
+ {
+ "email": "nich.curtis@22u.io",
+ "name": "22u.io"
+ }
+ ],
+ "dist-tags": {},
+ "versions": {},
+ "readme": "",
+ "readmeFilename": ""
+}
\ No newline at end of file
diff --git a/swh/loader/npm/tests/test_client.py b/swh/loader/npm/tests/test_client.py
--- a/swh/loader/npm/tests/test_client.py
+++ b/swh/loader/npm/tests/test_client.py
@@ -28,7 +28,8 @@
class TestNpmClient(unittest.TestCase):
def test_fetch_package_metadata(self, m):
- package_metadata = init_test_data(m, PACKAGE_METADATA_JSON_FILENAME)
+ package_metadata = init_test_data(m, PACKAGE_METADATA_JSON_FILENAME,
+ package_metadata_url)
with tempfile.TemporaryDirectory() as tempdir:
npm_client = NpmClient(tempdir)
npm_client.fetch_package_metadata(package_metadata_url)
@@ -36,7 +37,8 @@
self.assertEqual(npm_client.package, package)
def test_package_versions(self, m):
- package_metadata = init_test_data(m, PACKAGE_METADATA_JSON_FILENAME)
+ package_metadata = init_test_data(m, PACKAGE_METADATA_JSON_FILENAME,
+ package_metadata_url)
with tempfile.TemporaryDirectory() as tempdir:
npm_client = NpmClient(tempdir)
npm_client.fetch_package_metadata(package_metadata_url)
@@ -47,7 +49,8 @@
get_package_versions_data(package_metadata))
def test_prepare_package_versions(self, m):
- package_metadata = init_test_data(m, PACKAGE_METADATA_JSON_FILENAME)
+ package_metadata = init_test_data(m, PACKAGE_METADATA_JSON_FILENAME,
+ package_metadata_url)
package_versions_data = get_package_versions_data(package_metadata)
with tempfile.TemporaryDirectory() as tempdir:
npm_client = NpmClient(tempdir)
diff --git a/swh/loader/npm/tests/test_loader.py b/swh/loader/npm/tests/test_loader.py
--- a/swh/loader/npm/tests/test_loader.py
+++ b/swh/loader/npm/tests/test_loader.py
@@ -10,9 +10,12 @@
from swh.loader.core.tests import BaseLoaderStorageTest
from swh.loader.npm.loader import NpmLoader
+from swh.model.identifiers import snapshot_identifier
from .common import (
+ empty_package, empty_package_url, empty_package_metadata_url,
package, package_url, package_metadata_url, init_test_data,
+ EMPTY_PACKAGE_METADATA_JSON_FILENAME,
FIRST_VISIT_PACKAGE_METADATA_JSON_FILENAME,
SECOND_VISIT_PACKAGE_METADATA_JSON_FILENAME,
)
@@ -199,6 +202,10 @@
@classmethod
def setUpClass(cls):
+ cls.reset_loader()
+
+ @classmethod
+ def reset_loader(cls):
cls.loader = NpmLoaderTest()
cls.storage = cls.loader.storage
@@ -206,9 +213,35 @@
counters_reset = dict.fromkeys(self.loader.counters.keys(), 0)
self.loader.counters.update(counters_reset)
+ def test_npm_loader_empty_package(self, m):
+
+ init_test_data(m, EMPTY_PACKAGE_METADATA_JSON_FILENAME,
+ empty_package_metadata_url)
+ self.loader.load(empty_package, empty_package_url,
+ empty_package_metadata_url)
+
+ self.assertCountContents(0)
+ self.assertCountDirectories(0)
+ self.assertCountRevisions(0)
+ self.assertCountReleases(0)
+ self.assertCountSnapshots(1)
+
+ expected_branches = {}
+
+ self.assertSnapshotEqual(
+ snapshot_identifier({'branches': expected_branches}),
+ expected_branches
+ )
+
+ self.assertEqual(self.loader.load_status(), {'status': 'uneventful'})
+ self.assertEqual(self.loader.visit_status(), 'full')
+ self.assertFalse(os.path.exists(self.loader.temp_directory))
+
def test_npm_loader_first_visit(self, m):
- init_test_data(m, FIRST_VISIT_PACKAGE_METADATA_JSON_FILENAME)
+ self.reset_loader()
+ init_test_data(m, FIRST_VISIT_PACKAGE_METADATA_JSON_FILENAME,
+ package_metadata_url)
self.loader.load(package, package_url, package_metadata_url)
self.assertCountContents(len(_expected_new_contents_first_visit))
@@ -239,7 +272,8 @@
self.reset_loader_counters()
- init_test_data(m, FIRST_VISIT_PACKAGE_METADATA_JSON_FILENAME)
+ init_test_data(m, FIRST_VISIT_PACKAGE_METADATA_JSON_FILENAME,
+ package_metadata_url)
self.loader.load(package, package_url, package_metadata_url)
# previously loaded objects should still be here
@@ -263,7 +297,8 @@
self.reset_loader_counters()
- init_test_data(m, SECOND_VISIT_PACKAGE_METADATA_JSON_FILENAME)
+ init_test_data(m, SECOND_VISIT_PACKAGE_METADATA_JSON_FILENAME,
+ package_metadata_url)
self.loader.load(package, package_url, package_metadata_url)
expected_nb_contents = sum([len(_expected_new_contents_first_visit),
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Jan 30, 10:00 AM (19 h, 5 m ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3217091
Attached To
D1409: npm.client: Handle packages with no versions
Event Timeline
Log In to Comment