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 tempfile | import tempfile | ||||
from unittest.mock import patch, MagicMock | import yaml | ||||
import pytest | |||||
from unittest.mock import patch, MagicMock | |||||
from click.testing import CliRunner | from click.testing import CliRunner | ||||
from swh.journal.serializers import value_to_kafka | from swh.journal.serializers import value_to_kafka | ||||
from swh.journal.tests.utils import MockedKafkaConsumer | from swh.journal.tests.utils import MockedKafkaConsumer | ||||
from swh.search.cli import cli | from swh.search.cli import cli | ||||
from .test_elasticsearch import BaseElasticsearchTest | from .test_elasticsearch import BaseElasticsearchTest | ||||
▲ Show 20 Lines • Show All 101 Lines • ▼ Show 20 Lines | def test__journal_client__origin_visit(self): | ||||
self.search.flush() | self.search.flush() | ||||
results = self.search.origin_search(url_pattern="foobar", with_visit=True) | results = self.search.origin_search(url_pattern="foobar", with_visit=True) | ||||
assert results == { | assert results == { | ||||
"next_page_token": None, | "next_page_token": None, | ||||
"results": [{"url": "http://foobar.baz"}], | "results": [{"url": "http://foobar.baz"}], | ||||
} | } | ||||
def test__journal_client__missing_main_journal_config_key(self): | |||||
"""Missing configuration on journal should raise""" | |||||
with pytest.raises(KeyError, match="journal"): | |||||
invoke( | |||||
catch_exceptions=False, | |||||
args=["journal-client", "objects", "--stop-after-objects", "1",], | |||||
config="", # missing config will make it raise | |||||
elasticsearch_host=self._elasticsearch_host, | |||||
) | |||||
def test__journal_client__missing_journal_config_keys(self): | |||||
"""Missing configuration on mandatory journal keys should raise""" | |||||
journal_config = yaml.safe_load( | |||||
JOURNAL_OBJECTS_CONFIG | |||||
) # default configuration which is fine | |||||
for key in journal_config["journal"].keys(): | |||||
if key == "prefix": # optional | |||||
continue | |||||
cfg = copy.deepcopy(journal_config) | |||||
del cfg["journal"][key] # make config incomplete | |||||
yaml_cfg = yaml.dump(cfg) | |||||
with pytest.raises(TypeError, match=f"{key}"): | |||||
invoke( | |||||
catch_exceptions=False, | |||||
args=["journal-client", "objects", "--stop-after-objects", "1",], | |||||
config=yaml_cfg, # incomplete config will make the cli raise | |||||
elasticsearch_host=self._elasticsearch_host, | |||||
) |