Changeset View
Changeset View
Standalone View
Standalone View
swh/indexer/tests/test_utils.py
Show First 20 Lines • Show All 266 Lines • ▼ Show 20 Lines | |||||
class MockIndexerStorage(): | class MockIndexerStorage(): | ||||
"""Mock an swh-indexer storage. | """Mock an swh-indexer storage. | ||||
""" | """ | ||||
added_data = [] | added_data = [] | ||||
revision_metadata = {} | revision_metadata = {} | ||||
tools = {} | |||||
def indexer_configuration_add(self, tools): | def indexer_configuration_add(self, tools): | ||||
results = [] | results = [] | ||||
for tool in tools: | for tool in tools: | ||||
results.append(self._indexer_configuration_add_one(tool)) | results.append(self._indexer_configuration_add_one(tool)) | ||||
return results | return results | ||||
def _indexer_configuration_add_one(self, tool): | def _indexer_configuration_add_one(self, tool): | ||||
if tool['tool_name'] == 'swh-metadata-translator': | if tool['tool_name'] == 'swh-metadata-translator': | ||||
return { | tool2 = { | ||||
'id': 30, | 'id': 30, | ||||
'tool_name': 'swh-metadata-translator', | 'tool_name': 'swh-metadata-translator', | ||||
'tool_version': '0.0.1', | 'tool_version': '0.0.1', | ||||
'tool_configuration': { | 'tool_configuration': { | ||||
'type': 'local', | 'type': 'local', | ||||
'context': 'NpmMapping' | 'context': 'NpmMapping' | ||||
}, | }, | ||||
} | } | ||||
elif tool['tool_name'] == 'swh-metadata-detector': | elif tool['tool_name'] == 'swh-metadata-detector': | ||||
return { | tool2 = { | ||||
'id': 7, | 'id': 7, | ||||
'tool_name': 'swh-metadata-detector', | 'tool_name': 'swh-metadata-detector', | ||||
'tool_version': '0.0.1', | 'tool_version': '0.0.1', | ||||
'tool_configuration': { | 'tool_configuration': { | ||||
'type': 'local', | 'type': 'local', | ||||
'context': 'NpmMapping' | 'context': 'NpmMapping' | ||||
}, | }, | ||||
} | } | ||||
elif tool['tool_name'] == 'origin-metadata': | elif tool['tool_name'] == 'origin-metadata': | ||||
return { | tool2 = { | ||||
'id': 8, | 'id': 8, | ||||
'tool_name': 'origin-metadata', | 'tool_name': 'origin-metadata', | ||||
'tool_version': '0.0.1', | 'tool_version': '0.0.1', | ||||
'tool_configuration': {}, | 'tool_configuration': {}, | ||||
} | } | ||||
else: | else: | ||||
assert False, 'Unknown tool {tool_name}'.format(**tool) | assert False, 'Unknown tool {tool_name}'.format(**tool) | ||||
self.tools[tool2['id']] = tool2 | |||||
return tool2 | |||||
def content_metadata_missing(self, sha1s): | def content_metadata_missing(self, sha1s): | ||||
yield from [] | yield from [] | ||||
def content_metadata_add(self, metadata, conflict_update=None): | def content_metadata_add(self, metadata, conflict_update=None): | ||||
self.added_data.append( | self.added_data.append( | ||||
('content_metadata', conflict_update, metadata)) | ('content_metadata', conflict_update, metadata)) | ||||
def revision_metadata_add(self, metadata, conflict_update=None): | def revision_metadata_add(self, metadata, conflict_update=None): | ||||
assert conflict_update | assert conflict_update | ||||
self.added_data.append( | self.added_data.append( | ||||
('revision_metadata', conflict_update, metadata)) | ('revision_metadata', conflict_update, metadata)) | ||||
for item in metadata: | for item in metadata: | ||||
assert isinstance(item['id'], bytes) | assert isinstance(item['id'], bytes) | ||||
self.revision_metadata.setdefault(item['id'], []).append(item) | self.revision_metadata.setdefault(item['id'], []).append(item) | ||||
def revision_metadata_get(self, ids): | def revision_metadata_get(self, ids): | ||||
for id_ in ids: | for id_ in ids: | ||||
assert isinstance(id_, bytes) | assert isinstance(id_, bytes) | ||||
yield from self.revision_metadata.get(id_) | for item in self.revision_metadata.get(id_): | ||||
item = item.copy() | |||||
tool_id = item.pop('indexer_configuration_id') | |||||
item['tool'] = self.tools[tool_id].copy() | |||||
yield item | |||||
def origin_intrinsic_metadata_add(self, metadata, conflict_update=None): | def origin_intrinsic_metadata_add(self, metadata, conflict_update=None): | ||||
self.added_data.append( | self.added_data.append( | ||||
('origin_intrinsic_metadata', conflict_update, metadata)) | ('origin_intrinsic_metadata', conflict_update, metadata)) | ||||
def content_metadata_get(self, sha1s): | def content_metadata_get(self, sha1s): | ||||
return [{ | return [{ | ||||
'tool': { | 'tool': { | ||||
▲ Show 20 Lines • Show All 395 Lines • Show Last 20 Lines |