Changeset View
Changeset View
Standalone View
Standalone View
swh/indexer/tests/test_metadata.py
Show First 20 Lines • Show All 80 Lines • ▼ Show 20 Lines | def setUp(self): | ||||
self.content_tool = { | self.content_tool = { | ||||
'name': 'swh-metadata-translator', | 'name': 'swh-metadata-translator', | ||||
'version': '0.0.1', | 'version': '0.0.1', | ||||
'configuration': { | 'configuration': { | ||||
'type': 'local', | 'type': 'local', | ||||
'context': 'npm' | 'context': 'npm' | ||||
} | } | ||||
} | } | ||||
MockIndexerStorage.added_data = [] | |||||
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"" | ||||
▲ Show 20 Lines • Show All 107 Lines • ▼ Show 20 Lines | def test_index_content_metadata_npm(self): | ||||
'02fb2c89e14f7fab46701478c83779c7beb7b069'] | '02fb2c89e14f7fab46701478c83779c7beb7b069'] | ||||
# this metadata indexer computes only metadata for package.json | # this metadata indexer computes only metadata for package.json | ||||
# in npm context with a hard mapping | # in npm context with a hard mapping | ||||
metadata_indexer = TestContentMetadataIndexer( | metadata_indexer = TestContentMetadataIndexer( | ||||
tool=self.content_tool, config={}) | tool=self.content_tool, config={}) | ||||
# when | # when | ||||
metadata_indexer.run(sha1s, policy_update='ignore-dups') | metadata_indexer.run(sha1s, policy_update='ignore-dups') | ||||
results = metadata_indexer.idx_storage.state | results = metadata_indexer.idx_storage.added_data | ||||
expected_results = [{ | expected_results = [('content_metadata', False, [{ | ||||
'indexer_configuration_id': 30, | 'indexer_configuration_id': 30, | ||||
'translated_metadata': { | 'translated_metadata': { | ||||
'other': {}, | 'other': {}, | ||||
'codeRepository': { | 'codeRepository': { | ||||
'type': 'git', | 'type': 'git', | ||||
'url': 'https://github.com/moranegg/metadata_test' | 'url': 'https://github.com/moranegg/metadata_test' | ||||
}, | }, | ||||
'description': 'Simple package.json test for indexer', | 'description': 'Simple package.json test for indexer', | ||||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | def test_index_content_metadata_npm(self): | ||||
], | ], | ||||
'url': 'https://docs.npmjs.com/' | 'url': 'https://docs.npmjs.com/' | ||||
}, | }, | ||||
'id': 'd4c647f0fc257591cc9ba1722484229780d1c607' | 'id': 'd4c647f0fc257591cc9ba1722484229780d1c607' | ||||
}, { | }, { | ||||
'indexer_configuration_id': 30, | 'indexer_configuration_id': 30, | ||||
'translated_metadata': None, | 'translated_metadata': None, | ||||
'id': '02fb2c89e14f7fab46701478c83779c7beb7b069' | 'id': '02fb2c89e14f7fab46701478c83779c7beb7b069' | ||||
}] | }])] | ||||
# The assertion below returns False sometimes because of nested lists | # The assertion below returns False sometimes because of nested lists | ||||
self.assertEqual(expected_results, results) | self.assertEqual(expected_results, results) | ||||
def test_detect_metadata_package_json(self): | def test_detect_metadata_package_json(self): | ||||
# given | # given | ||||
df = [{ | df = [{ | ||||
'sha1_git': b'abc', | 'sha1_git': b'abc', | ||||
Show All 31 Lines | class Metadata(unittest.TestCase): | ||||
def test_revision_metadata_indexer(self): | def test_revision_metadata_indexer(self): | ||||
metadata_indexer = TestRevisionMetadataIndexer() | metadata_indexer = TestRevisionMetadataIndexer() | ||||
sha1_gits = [ | sha1_gits = [ | ||||
b'8dbb6aeb036e7fd80664eb8bfd1507881af1ba9f', | b'8dbb6aeb036e7fd80664eb8bfd1507881af1ba9f', | ||||
] | ] | ||||
metadata_indexer.run(sha1_gits, 'update-dups') | metadata_indexer.run(sha1_gits, 'update-dups') | ||||
results = metadata_indexer.idx_storage.state | results = metadata_indexer.idx_storage.added_data | ||||
expected_results = [{ | expected_results = [('revision_metadata', True, [{ | ||||
'id': b'8dbb6aeb036e7fd80664eb8bfd1507881af1ba9f', | 'id': b'8dbb6aeb036e7fd80664eb8bfd1507881af1ba9f', | ||||
'translated_metadata': { | 'translated_metadata': { | ||||
'identifier': None, | 'identifier': None, | ||||
'maintainer': None, | 'maintainer': None, | ||||
'url': [ | 'url': [ | ||||
'https://github.com/librariesio/yarn-parser#readme' | 'https://github.com/librariesio/yarn-parser#readme' | ||||
], | ], | ||||
'codeRepository': [{ | 'codeRepository': [{ | ||||
Show All 17 Lines | def test_revision_metadata_indexer(self): | ||||
'yarn': '^0.21.0', | 'yarn': '^0.21.0', | ||||
'body-parser': '^1.15.2' | 'body-parser': '^1.15.2' | ||||
}], | }], | ||||
'name': ['yarn-parser'], | 'name': ['yarn-parser'], | ||||
'keywords': [['yarn', 'parse', 'lock', 'dependencies']], | 'keywords': [['yarn', 'parse', 'lock', 'dependencies']], | ||||
'email': None | 'email': None | ||||
}, | }, | ||||
'indexer_configuration_id': 7 | 'indexer_configuration_id': 7 | ||||
}] | }])] | ||||
# then | # then | ||||
self.assertEqual(expected_results, results) | self.assertEqual(expected_results, results) |