Changeset View
Changeset View
Standalone View
Standalone View
swh/indexer/tests/test_metadata.py
Show All 11 Lines | |||||
from swh.indexer.metadata_detector import ( | from swh.indexer.metadata_detector import ( | ||||
detect_metadata, extract_minimal_metadata_dict | detect_metadata, extract_minimal_metadata_dict | ||||
) | ) | ||||
from swh.indexer.metadata import ( | from swh.indexer.metadata import ( | ||||
ContentMetadataIndexer, RevisionMetadataIndexer | ContentMetadataIndexer, RevisionMetadataIndexer | ||||
) | ) | ||||
from .utils import ( | from .utils import ( | ||||
BASE_TEST_CONFIG, fill_obj_storage, fill_storage | BASE_TEST_CONFIG, fill_obj_storage, fill_storage, | ||||
YARN_PARSER_METADATA | |||||
) | ) | ||||
TRANSLATOR_TOOL = { | TRANSLATOR_TOOL = { | ||||
'name': 'swh-metadata-translator', | 'name': 'swh-metadata-translator', | ||||
'version': '0.0.2', | 'version': '0.0.2', | ||||
'configuration': { | 'configuration': { | ||||
'type': 'local', | 'type': 'local', | ||||
▲ Show 20 Lines • Show All 1,019 Lines • ▼ Show 20 Lines | def test_revision_metadata_indexer(self): | ||||
tool = metadata_indexer.idx_storage.indexer_configuration_get( | tool = metadata_indexer.idx_storage.indexer_configuration_get( | ||||
{'tool_'+k: v for (k, v) in TRANSLATOR_TOOL.items()}) | {'tool_'+k: v for (k, v) in TRANSLATOR_TOOL.items()}) | ||||
assert tool is not None | assert tool is not None | ||||
metadata_indexer.idx_storage.content_metadata_add([{ | metadata_indexer.idx_storage.content_metadata_add([{ | ||||
'indexer_configuration_id': tool['id'], | 'indexer_configuration_id': tool['id'], | ||||
'id': b'cde', | 'id': b'cde', | ||||
'translated_metadata': { | 'translated_metadata': YARN_PARSER_METADATA, | ||||
'@context': 'https://doi.org/10.5063/schema/codemeta-2.0', | |||||
'type': 'SoftwareSourceCode', | |||||
'issueTracker': | |||||
'https://github.com/librariesio/yarn-parser/issues', | |||||
'version': '1.0.0', | |||||
'name': 'yarn-parser', | |||||
'author': ['Andrew Nesbitt'], | |||||
'url': | |||||
'https://github.com/librariesio/yarn-parser#readme', | |||||
'processorRequirements': {'node': '7.5'}, | |||||
'license': 'AGPL-3.0', | |||||
'keywords': ['yarn', 'parse', 'lock', 'dependencies'], | |||||
'codeRepository': | |||||
'git+https://github.com/librariesio/yarn-parser.git', | |||||
'description': | |||||
'Tiny web service for parsing yarn.lock files', | |||||
} | |||||
}]) | }]) | ||||
sha1_gits = [ | sha1_gits = [ | ||||
hash_to_bytes('8dbb6aeb036e7fd80664eb8bfd1507881af1ba9f'), | hash_to_bytes('8dbb6aeb036e7fd80664eb8bfd1507881af1ba9f'), | ||||
] | ] | ||||
metadata_indexer.run(sha1_gits, 'update-dups') | metadata_indexer.run(sha1_gits, 'update-dups') | ||||
results = list(metadata_indexer.idx_storage.revision_metadata_get( | results = list(metadata_indexer.idx_storage.revision_metadata_get( | ||||
sha1_gits)) | sha1_gits)) | ||||
expected_results = [{ | expected_results = [{ | ||||
'id': hash_to_bytes('8dbb6aeb036e7fd80664eb8bfd1507881af1ba9f'), | 'id': hash_to_bytes('8dbb6aeb036e7fd80664eb8bfd1507881af1ba9f'), | ||||
'tool': TRANSLATOR_TOOL, | 'tool': TRANSLATOR_TOOL, | ||||
'translated_metadata': { | 'translated_metadata': YARN_PARSER_METADATA, | ||||
'@context': 'https://doi.org/10.5063/schema/codemeta-2.0', | |||||
'url': | |||||
'https://github.com/librariesio/yarn-parser#readme', | |||||
'codeRepository': | |||||
'git+https://github.com/librariesio/yarn-parser.git', | |||||
'author': ['Andrew Nesbitt'], | |||||
'license': 'AGPL-3.0', | |||||
'version': '1.0.0', | |||||
'description': | |||||
'Tiny web service for parsing yarn.lock files', | |||||
'issueTracker': | |||||
'https://github.com/librariesio/yarn-parser/issues', | |||||
'name': 'yarn-parser', | |||||
'keywords': ['yarn', 'parse', 'lock', 'dependencies'], | |||||
}, | |||||
'mappings': ['npm'], | 'mappings': ['npm'], | ||||
}] | }] | ||||
for result in results: | for result in results: | ||||
del result['tool']['id'] | del result['tool']['id'] | ||||
# then | # then | ||||
self.assertEqual(expected_results, results) | self.assertEqual(expected_results, results) |