Changeset View
Changeset View
Standalone View
Standalone View
swh/search/tests/test_cli.py
# Copyright (C) 2019-2020 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 copy | import copy | ||||
import tempfile | import tempfile | ||||
from click.testing import CliRunner | from click.testing import CliRunner | ||||
from confluent_kafka import Producer | from confluent_kafka import Producer | ||||
import pytest | import pytest | ||||
import yaml | import yaml | ||||
from swh.journal.serializers import value_to_kafka | from swh.journal.serializers import value_to_kafka | ||||
from swh.model.hashutil import hash_to_bytes | from swh.model.hashutil import hash_to_bytes | ||||
from swh.search import get_search | |||||
from swh.search.cli import search_cli_group | from swh.search.cli import search_cli_group | ||||
CLI_CONFIG = """ | CLI_CONFIG = """ | ||||
search: | search: | ||||
cls: elasticsearch | cls: elasticsearch | ||||
args: | args: | ||||
hosts: | hosts: | ||||
- '%(elasticsearch_host)s' | - '%(elasticsearch_host)s' | ||||
index_prefix: test | |||||
""" | """ | ||||
JOURNAL_OBJECTS_CONFIG_TEMPLATE = """ | JOURNAL_OBJECTS_CONFIG_TEMPLATE = """ | ||||
journal: | journal: | ||||
brokers: | brokers: | ||||
- {broker} | - {broker} | ||||
prefix: {prefix} | prefix: {prefix} | ||||
group_id: {group_id} | group_id: {group_id} | ||||
▲ Show 20 Lines • Show All 352 Lines • ▼ Show 20 Lines | journal: | ||||
with pytest.raises(ValueError, match="object_types"): | with pytest.raises(ValueError, match="object_types"): | ||||
invoke( | invoke( | ||||
False, | False, | ||||
# Missing --object-types (and no config key) will make the cli raise | # Missing --object-types (and no config key) will make the cli raise | ||||
["journal-client", "objects", "--stop-after-objects", "1"], | ["journal-client", "objects", "--stop-after-objects", "1"], | ||||
journal_cfg, | journal_cfg, | ||||
elasticsearch_host=elasticsearch_host, | elasticsearch_host=elasticsearch_host, | ||||
) | ) | ||||
def test__initialize__with_prefix(elasticsearch_host): | |||||
"""Initializing the index with a prefix should create an <prefix>_origin index""" | |||||
search = get_search( | |||||
"elasticsearch", hosts=[elasticsearch_host], index_prefix="test" | |||||
) | |||||
assert search.origin_index == "test_origin" | |||||
def test__initialize__without_prefix(elasticsearch_host): | |||||
"""Initializing the index without a prefix should create an origin index""" | |||||
search = get_search("elasticsearch", hosts=[elasticsearch_host]) | |||||
assert search.origin_index == "origin" |