Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/testcase.py
# Copyright (C) 2015-2018 The Software Heritage developers | # Copyright (C) 2015-2019 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU Affero General Public License version 3, or any later version | # License: GNU Affero General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import shutil | import shutil | ||||
from subprocess import run, PIPE | from subprocess import run, PIPE | ||||
from django.core.cache import cache | from django.core.cache import cache | ||||
from hypothesis.extra.django import TestCase | from hypothesis.extra.django import TestCase | ||||
from swh.model.hashutil import hash_to_bytes | from swh.model.hashutil import hash_to_bytes | ||||
from swh.web import config | from swh.web.common import converters | ||||
from swh.web.common import converters, service | from swh.web.tests.data import get_tests_data, override_storages | ||||
from swh.web.tests.data import get_tests_data | |||||
ctags_json_missing = \ | ctags_json_missing = \ | ||||
shutil.which('ctags') is None or \ | shutil.which('ctags') is None or \ | ||||
b'+json' not in run(['ctags', '--version'], stdout=PIPE).stdout | b'+json' not in run(['ctags', '--version'], stdout=PIPE).stdout | ||||
fossology_missing = shutil.which('nomossa') is None | fossology_missing = shutil.which('nomossa') is None | ||||
Show All 13 Lines | def _pre_setup(self): | ||||
tests_data = get_tests_data(reset=True) | tests_data = get_tests_data(reset=True) | ||||
self.storage = tests_data['storage'] | self.storage = tests_data['storage'] | ||||
self.idx_storage = tests_data['idx_storage'] | self.idx_storage = tests_data['idx_storage'] | ||||
self.mimetype_indexer = tests_data['mimetype_indexer'] | self.mimetype_indexer = tests_data['mimetype_indexer'] | ||||
self.license_indexer = tests_data['license_indexer'] | self.license_indexer = tests_data['license_indexer'] | ||||
self.ctags_indexer = tests_data['ctags_indexer'] | self.ctags_indexer = tests_data['ctags_indexer'] | ||||
# Update swh-web configuration to use the in-memory storage | # Update swh-web configuration to use the in-memory storages | ||||
# instantiated in the tests.data module | # instantiated in the tests.data module | ||||
swh_config = config.get_config() | override_storages(tests_data['storage'], tests_data['idx_storage']) | ||||
swh_config.update({'storage': self.storage}) | |||||
service.storage = self.storage | |||||
# Update swh-web configuration to use the in-memory indexer storage | |||||
# instantiated in the tests.data modules | |||||
swh_config.update({'indexer_storage': self.idx_storage}) | |||||
service.idx_storage = self.idx_storage | |||||
super()._pre_setup() | super()._pre_setup() | ||||
def content_add_mimetype(self, cnt_id): | def content_add_mimetype(self, cnt_id): | ||||
self.mimetype_indexer.run([hash_to_bytes(cnt_id)], | self.mimetype_indexer.run([hash_to_bytes(cnt_id)], | ||||
'update-dups') | 'update-dups') | ||||
def content_get_mimetype(self, cnt_id): | def content_get_mimetype(self, cnt_id): | ||||
▲ Show 20 Lines • Show All 99 Lines • Show Last 20 Lines |