Changeset View
Changeset View
Standalone View
Standalone View
swh/indexer/tests/test_metadata.py
Show All 17 Lines | class MockStorage(): | ||||
def content_metadata_add(self, metadata, conflict_update=None): | def content_metadata_add(self, metadata, conflict_update=None): | ||||
self.state = metadata | self.state = metadata | ||||
self.conflict_update = conflict_update | self.conflict_update = conflict_update | ||||
def indexer_configuration_get(self, tool): | def indexer_configuration_get(self, tool): | ||||
return { | return { | ||||
'id': 30, | 'id': 30, | ||||
'name': 'hard_mapping_npm', | 'name': 'hard_mapping_npm', | ||||
'version': '0.1' | 'version': '0.1', | ||||
'configuration': { | |||||
'type': 'local', | |||||
'context': 'npm' | |||||
}, | |||||
} | } | ||||
class TestMetadataIndexer(ContentMetadataIndexer): | class TestMetadataIndexer(ContentMetadataIndexer): | ||||
"""Specific Metadata whose configuration is enough to satisfy the | """Specific Metadata whose configuration is enough to satisfy the | ||||
indexing tests. | indexing tests. | ||||
""" | """ | ||||
def prepare(self): | def prepare(self): | ||||
self.config = { | self.config = { | ||||
'rescheduling_task': None, | 'rescheduling_task': None, | ||||
'tools': { | 'tools': { | ||||
'name': 'hard_mapping_npm', | 'name': 'swh-metadata-translator', | ||||
'version': '0.1', | 'version': '0.0.1', | ||||
'configuration': { | 'configuration': { | ||||
'type': 'local', | 'type': 'local', | ||||
'debian-package': '' | 'context': 'npm' | ||||
} | } | ||||
} | } | ||||
} | } | ||||
self.storage = MockStorage() | self.storage = MockStorage() | ||||
self.log = logging.getLogger('swh.indexer') | self.log = logging.getLogger('swh.indexer') | ||||
self.objstorage = MockObjStorage() | self.objstorage = MockObjStorage() | ||||
self.task_destination = None | self.task_destination = None | ||||
self.rescheduling_task = self.config['rescheduling_task'] | self.rescheduling_task = self.config['rescheduling_task'] | ||||
Show All 13 Lines | class Metadata(unittest.TestCase): | ||||
@istest | @istest | ||||
def test_compute_metadata_none(self): | def test_compute_metadata_none(self): | ||||
""" | """ | ||||
testing content empty content is empty | testing content empty content is empty | ||||
should return None | should return None | ||||
""" | """ | ||||
# given | # given | ||||
content = b"" | content = b"" | ||||
tool = "hard_mapping_npm" | context = "npm" | ||||
# None if no metadata was found or an error occurred | # None if no metadata was found or an error occurred | ||||
declared_metadata = None | declared_metadata = None | ||||
# when | # when | ||||
result = compute_metadata(tool, content) | result = compute_metadata(context, content) | ||||
# then | # then | ||||
self.assertEqual(declared_metadata, result) | self.assertEqual(declared_metadata, result) | ||||
@istest | @istest | ||||
def test_compute_metadata_npm(self): | def test_compute_metadata_npm(self): | ||||
""" | """ | ||||
testing only computation of metadata with hard_mapping_npm | testing only computation of metadata with hard_mapping_npm | ||||
""" | """ | ||||
Show All 16 Lines | def test_compute_metadata_npm(self): | ||||
'codeRepository': { | 'codeRepository': { | ||||
'type': 'git', | 'type': 'git', | ||||
'url': 'https://github.com/moranegg/metadata_test' | 'url': 'https://github.com/moranegg/metadata_test' | ||||
}, | }, | ||||
'other': {} | 'other': {} | ||||
} | } | ||||
# when | # when | ||||
result = compute_metadata("hard_mapping_npm", content) | result = compute_metadata("npm", content) | ||||
# then | # then | ||||
self.assertEqual(declared_metadata, result) | self.assertEqual(declared_metadata, result) | ||||
@istest | @istest | ||||
def test_index_content_metadata_npm(self): | def test_index_content_metadata_npm(self): | ||||
""" | """ | ||||
testing NPM with package.json | testing NPM with package.json | ||||
- one sha1 uses a file that can't be translated to metadata and | - one sha1 uses a file that can't be translated to metadata and | ||||
▲ Show 20 Lines • Show All 77 Lines • Show Last 20 Lines |