Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/data.py
Show All 14 Lines | |||||
from swh.indexer.fossology_license import FossologyLicenseIndexer | from swh.indexer.fossology_license import FossologyLicenseIndexer | ||||
from swh.indexer.mimetype import MimetypeIndexer | from swh.indexer.mimetype import MimetypeIndexer | ||||
from swh.indexer.ctags import CtagsIndexer | from swh.indexer.ctags import CtagsIndexer | ||||
from swh.indexer.storage import get_indexer_storage | from swh.indexer.storage import get_indexer_storage | ||||
from swh.model.from_disk import Directory | from swh.model.from_disk import Directory | ||||
from swh.model.hashutil import hash_to_hex, hash_to_bytes, DEFAULT_ALGORITHMS | from swh.model.hashutil import hash_to_hex, hash_to_bytes, DEFAULT_ALGORITHMS | ||||
from swh.model.identifiers import directory_identifier | from swh.model.identifiers import directory_identifier | ||||
from swh.loader.git.from_disk import GitLoaderFromArchive | from swh.loader.git.from_disk import GitLoaderFromArchive | ||||
from swh.search import get_search | |||||
from swh.storage.algos.dir_iterators import dir_iterator | from swh.storage.algos.dir_iterators import dir_iterator | ||||
from swh.web import config | from swh.web import config | ||||
from swh.web.browse.utils import ( | from swh.web.browse.utils import ( | ||||
get_mimetype_and_encoding_for_content, prepare_content_for_display | get_mimetype_and_encoding_for_content, prepare_content_for_display | ||||
) | ) | ||||
from swh.web.common import service | from swh.web.common import service | ||||
from swh.web.common.highlightjs import get_hljs_language_from_filename | from swh.web.common.highlightjs import get_hljs_language_from_filename | ||||
▲ Show 20 Lines • Show All 214 Lines • ▼ Show 20 Lines | for content_metadata in contents_metadata: | ||||
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', {}) | ||||
# Create search instance | |||||
search = get_search('memory', {}) | |||||
search.initialize() | |||||
ardumont: } for | |||||
search.origin_update({'url': origin['url']}for origin in _TEST_ORIGINS) | |||||
# 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': []}]) | ||||
# Return tests data | # Return tests data | ||||
return { | return { | ||||
'storage': storage, | 'storage': storage, | ||||
'idx_storage': idx_storage, | 'idx_storage': idx_storage, | ||||
'search': search, | |||||
'origins': _TEST_ORIGINS, | 'origins': _TEST_ORIGINS, | ||||
'contents': contents, | 'contents': contents, | ||||
'directories': list(directories), | 'directories': list(directories), | ||||
'releases': list(releases), | 'releases': list(releases), | ||||
'revisions': list(map(hash_to_hex, revisions)), | 'revisions': list(map(hash_to_hex, revisions)), | ||||
'snapshots': list(snapshots), | 'snapshots': list(snapshots), | ||||
'generated_checksums': set(), | 'generated_checksums': set(), | ||||
} | } | ||||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | if _tests_data is None: | ||||
_tests_data.update(indexers) | _tests_data.update(indexers) | ||||
if reset or _current_tests_data is None: | if reset or _current_tests_data is None: | ||||
_current_tests_data = deepcopy(_tests_data) | _current_tests_data = deepcopy(_tests_data) | ||||
for (name, logger) in _indexer_loggers.items(): | for (name, logger) in _indexer_loggers.items(): | ||||
_current_tests_data[name].log = logger | _current_tests_data[name].log = logger | ||||
return _current_tests_data | return _current_tests_data | ||||
def override_storages(storage, idx_storage): | def override_storages(storage, idx_storage, search): | ||||
Not Done Inline Actionsshould be renamed to something more storage independent. Also, i'd be surprised this is used for production code. ardumont: should be renamed to something more storage independent.
It overrides internal api services the… | |||||
Not Done Inline Actions
No, it really overrides storage and search components by their in-memory implementation.
Pytest fixtures using these in-memory storages under the hood have landed in master. anlambert: > It overrides internal api services the webapp relies on.
No, it really overrides storage and… | |||||
""" | """ | ||||
Helper function to replace the storages from which archive data | Helper function to replace the storages from which archive data | ||||
are fetched. | are fetched. | ||||
""" | """ | ||||
swh_config = config.get_config() | swh_config = config.get_config() | ||||
swh_config.update({'storage': storage}) | swh_config.update({ | ||||
service.storage = storage | 'storage': storage, | ||||
'indexer_storage': idx_storage, | |||||
'search': search, | |||||
}) | |||||
swh_config.update({'indexer_storage': idx_storage}) | service.storage = storage | ||||
service.idx_storage = idx_storage | service.idx_storage = idx_storage | ||||
service.search = search | |||||
# Implement some special endpoints used to provide input tests data | # Implement some special endpoints used to provide input tests data | ||||
# when executing end to end tests with cypress | # when executing end to end tests with cypress | ||||
_content_code_data_exts = {} # type: Dict[str, Dict[str, str]] | _content_code_data_exts = {} # type: Dict[str, Dict[str, str]] | ||||
_content_code_data_filenames = {} # type: Dict[str, Dict[str, str]] | _content_code_data_filenames = {} # type: Dict[str, Dict[str, str]] | ||||
_content_other_data_exts = {} # type: Dict[str, Dict[str, str]] | _content_other_data_exts = {} # type: Dict[str, Dict[str, str]] | ||||
▲ Show 20 Lines • Show All 135 Lines • Show Last 20 Lines |
} for