diff --git a/swh/search/__init__.py b/swh/search/__init__.py index 4d766a4..7474665 100644 --- a/swh/search/__init__.py +++ b/swh/search/__init__.py @@ -1,32 +1,32 @@ # Copyright (C) 2019 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information def get_search(cls, args): """Get an search object of class `search_class` with arguments `search_args`. Args: cls (str): search's class, either 'local' or 'remote' args (dict): dictionary of arguments passed to the search class constructor Returns: an instance of swh.search's classes (either local or remote) Raises: ValueError if passed an unknown search class. """ if cls == 'remote': from .api.client import RemoteSearch as Search elif cls == 'elasticsearch': from .elasticsearch import ElasticSearch as Search elif cls == 'memory': - from .in_memory import InmemorySearchTest as Search + from .in_memory import InMemorySearch as Search else: raise ValueError('Unknown indexer search class `%s`' % cls) return Search(**args) diff --git a/swh/search/tests/test_api_client.py b/swh/search/tests/test_api_client.py index a4234ee..c38cb8d 100644 --- a/swh/search/tests/test_api_client.py +++ b/swh/search/tests/test_api_client.py @@ -1,45 +1,48 @@ # Copyright (C) 2019 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information import unittest import pytest from swh.core.api.tests.server_testing import ServerTestFixture -from swh.search.elasticsearch import ElasticSearch +from swh.search import get_search from swh.search.api.server import app -from swh.search.api.client import RemoteSearch from .test_search import CommonSearchTest class TestRemoteSearch(CommonSearchTest, ServerTestFixture, unittest.TestCase): @pytest.fixture(autouse=True) def _instantiate_search(self, elasticsearch_host): self._elasticsearch_host = elasticsearch_host def setUp(self): self.config = { 'search': { 'cls': 'elasticsearch', 'args': { 'hosts': [self._elasticsearch_host], } } } self.app = app super().setUp() self.reset() - self.search = RemoteSearch(self.url()) + self.search = get_search('remote', { + 'url': self.url(), + }) def reset(self): - search = ElasticSearch([self._elasticsearch_host]) + search = get_search('elasticsearch', { + 'hosts': [self._elasticsearch_host], + }) search.deinitialize() search.initialize() @pytest.mark.skip('Elasticsearch also returns close matches, ' 'so this test would fail') def test_origin_url_paging(self, count): pass diff --git a/swh/search/tests/test_elasticsearch.py b/swh/search/tests/test_elasticsearch.py index fb5dc8a..73b4486 100644 --- a/swh/search/tests/test_elasticsearch.py +++ b/swh/search/tests/test_elasticsearch.py @@ -1,29 +1,31 @@ # Copyright (C) 2019 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information import unittest import pytest -from swh.search.elasticsearch import ElasticSearch +from swh.search import get_search from .test_search import CommonSearchTest class BaseElasticsearchTest(unittest.TestCase): @pytest.fixture(autouse=True) def _instantiate_search(self, elasticsearch_host): self._elasticsearch_host = elasticsearch_host - self.search = ElasticSearch([elasticsearch_host]) + self.search = get_search('elasticsearch', { + 'hosts': [elasticsearch_host], + }) def setUp(self): self.reset() def reset(self): self.search.deinitialize() self.search.initialize() class TestElasticsearchSearch(CommonSearchTest, BaseElasticsearchTest): pass diff --git a/swh/search/tests/test_in_memory.py b/swh/search/tests/test_in_memory.py index 7c8fd8e..8ca9e6d 100644 --- a/swh/search/tests/test_in_memory.py +++ b/swh/search/tests/test_in_memory.py @@ -1,36 +1,36 @@ # Copyright (C) 2019 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information import unittest import pytest -from swh.search.in_memory import InMemorySearch +from swh.search import get_search from .test_search import CommonSearchTest class InmemorySearchTest(unittest.TestCase, CommonSearchTest): @pytest.fixture(autouse=True) def _instantiate_search(self): - self.search = InMemorySearch() + self.search = get_search('memory', {}) def setUp(self): self.reset() def reset(self): self.search.deinitialize() self.search.initialize() @pytest.mark.skip('Not implemented in the in-memory search') def test_origin_intrinsic_metadata_description(self): pass @pytest.mark.skip('Not implemented in the in-memory search') def test_origin_intrinsic_metadata_nested(self): pass @pytest.mark.skip('Not implemented in the in-memory search') def test_origin_intrinsic_metadata_paging(self): pass