Changeset View
Changeset View
Standalone View
Standalone View
swh/search/tests/test_cli.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 tempfile | import tempfile | ||||
from unittest.mock import patch, MagicMock | from unittest.mock import patch, MagicMock | ||||
from click.testing import CliRunner | from click.testing import CliRunner | ||||
▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | def test__journal_client__origin(self): | ||||
message.value.return_value = value | message.value.return_value = value | ||||
mock_consumer = MockedKafkaConsumerWithTopics([message]) | mock_consumer = MockedKafkaConsumerWithTopics([message]) | ||||
with patch('swh.journal.client.Consumer', | with patch('swh.journal.client.Consumer', | ||||
return_value=mock_consumer): | return_value=mock_consumer): | ||||
result = invoke(False, [ | result = invoke(False, [ | ||||
'journal-client', 'objects', | 'journal-client', 'objects', | ||||
'--max-messages', '1', | '--stop-after-objects', '1', | ||||
], JOURNAL_OBJECTS_CONFIG, | ], JOURNAL_OBJECTS_CONFIG, | ||||
elasticsearch_host=self._elasticsearch_host) | elasticsearch_host=self._elasticsearch_host) | ||||
# Check the output | # Check the output | ||||
expected_output = ( | expected_output = ( | ||||
'Processed 1 messages.\n' | 'Processed 1 messages.\n' | ||||
'Done.\n' | 'Done.\n' | ||||
) | ) | ||||
Show All 23 Lines | def test__journal_client__origin_visit(self): | ||||
message.value.return_value = value | message.value.return_value = value | ||||
mock_consumer = MockedKafkaConsumerWithTopics([message]) | mock_consumer = MockedKafkaConsumerWithTopics([message]) | ||||
with patch('swh.journal.client.Consumer', | with patch('swh.journal.client.Consumer', | ||||
return_value=mock_consumer): | return_value=mock_consumer): | ||||
result = invoke(False, [ | result = invoke(False, [ | ||||
'journal-client', 'objects', | 'journal-client', 'objects', | ||||
'--max-messages', '1', | '--stop-after-objects', '1', | ||||
], JOURNAL_OBJECTS_CONFIG, | ], JOURNAL_OBJECTS_CONFIG, | ||||
elasticsearch_host=self._elasticsearch_host) | elasticsearch_host=self._elasticsearch_host) | ||||
# Check the output | # Check the output | ||||
expected_output = ( | expected_output = ( | ||||
'Processed 1 messages.\n' | 'Processed 1 messages.\n' | ||||
'Done.\n' | 'Done.\n' | ||||
) | ) | ||||
Show All 9 Lines |