Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/data.py
Show First 20 Lines • Show All 223 Lines • ▼ Show 20 Lines | for origin in _TEST_ORIGINS: | ||||
content_path[entry['sha1']] = '/'.join( | content_path[entry['sha1']] = '/'.join( | ||||
[hash_to_hex(dir_id), entry['path'].decode('utf-8')]) | [hash_to_hex(dir_id), entry['path'].decode('utf-8')]) | ||||
if entry['type'] == 'file': | if entry['type'] == 'file': | ||||
contents.add(entry['sha1']) | contents.add(entry['sha1']) | ||||
elif entry['type'] == 'dir': | elif entry['type'] == 'dir': | ||||
directories.add(hash_to_hex(entry['target'])) | directories.add(hash_to_hex(entry['target'])) | ||||
# Get all checksums for each content | # Get all checksums for each content | ||||
contents_metadata = storage.content_get_metadata(contents) | result = storage.content_get_metadata(contents) | ||||
contents = [] | contents = [] | ||||
for sha1, contents_metadata in result.items(): | |||||
for content_metadata in contents_metadata: | for content_metadata in contents_metadata: | ||||
contents.append({ | contents.append({ | ||||
algo: hash_to_hex(content_metadata[algo]) | algo: hash_to_hex(content_metadata[algo]) | ||||
for algo in DEFAULT_ALGORITHMS | for algo in DEFAULT_ALGORITHMS | ||||
}) | }) | ||||
path = content_path[content_metadata['sha1']] | path = content_path[sha1] | ||||
cnt = next(storage.content_get([content_metadata['sha1']])) | cnt = next(storage.content_get([sha1])) | ||||
mimetype, encoding = get_mimetype_and_encoding_for_content(cnt['data']) | mimetype, encoding = get_mimetype_and_encoding_for_content( | ||||
cnt['data']) | |||||
content_display_data = prepare_content_for_display( | content_display_data = prepare_content_for_display( | ||||
cnt['data'], mimetype, path) | cnt['data'], mimetype, path) | ||||
contents[-1]['path'] = path | contents[-1]['path'] = path | ||||
contents[-1]['mimetype'] = mimetype | contents[-1]['mimetype'] = mimetype | ||||
contents[-1]['encoding'] = encoding | contents[-1]['encoding'] = encoding | ||||
contents[-1]['hljs_language'] = content_display_data['language'] | contents[-1]['hljs_language'] = content_display_data['language'] | ||||
contents[-1]['data'] = content_display_data['content_data'] | contents[-1]['data'] = content_display_data['content_data'] | ||||
_contents[contents[-1]['sha1']] = contents[-1] | _contents[contents[-1]['sha1']] = contents[-1] | ||||
# Create indexer storage instance that will be shared by indexers | # Create indexer storage instance that will be shared by indexers | ||||
idx_storage = get_indexer_storage('memory', {}) | idx_storage = get_indexer_storage('memory', {}) | ||||
# Add the empty directory to the test archive | # Add the empty directory to the test archive | ||||
empty_dir_id = directory_identifier({'entries': []}) | empty_dir_id = directory_identifier({'entries': []}) | ||||
empty_dir_id_bin = hash_to_bytes(empty_dir_id) | empty_dir_id_bin = hash_to_bytes(empty_dir_id) | ||||
storage.directory_add([{'id': empty_dir_id_bin, 'entries': []}]) | storage.directory_add([{'id': empty_dir_id_bin, 'entries': []}]) | ||||
▲ Show 20 Lines • Show All 222 Lines • Show Last 20 Lines |