Changeset View
Changeset View
Standalone View
Standalone View
swh/search/tests/conftest.py
# Copyright (C) 2019 The Software Heritage developers | # Copyright (C) 2019-2020 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 General Public License version 3, or any later version | # License: GNU 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 logging | |||||
import socket | import socket | ||||
import subprocess | import subprocess | ||||
import time | import time | ||||
import elasticsearch | import elasticsearch | ||||
import pytest | import pytest | ||||
from swh.search import get_search | |||||
logger = logging.getLogger(__name__) | |||||
def free_port(): | def free_port(): | ||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | ||||
sock.bind(("127.0.0.1", 0)) | sock.bind(("127.0.0.1", 0)) | ||||
port = sock.getsockname()[1] | port = sock.getsockname()[1] | ||||
sock.close() | sock.close() | ||||
return port | return port | ||||
▲ Show 20 Lines • Show All 83 Lines • ▼ Show 20 Lines | def elasticsearch_session(tmpdir_factory): | ||||
p.kill() | p.kill() | ||||
p.wait() | p.wait() | ||||
@pytest.fixture(scope="class") | @pytest.fixture(scope="class") | ||||
def elasticsearch_host(elasticsearch_session): | def elasticsearch_host(elasticsearch_session): | ||||
yield elasticsearch_session | yield elasticsearch_session | ||||
@pytest.fixture | |||||
def swh_search(elasticsearch_host): | |||||
"""Instantiate a search client, initialize the elasticsearch instance, | |||||
and returns it | |||||
""" | |||||
logger.debug("swh_search: elasticsearch_host: %s", elasticsearch_host) | |||||
search = get_search("elasticsearch", {"hosts": [elasticsearch_host],}) | |||||
search.deinitialize() | |||||
search.initialize() | |||||
yield search |