Check exception context for actual error message.

This commit is contained in:
Richard Lyons 2024-06-22 14:02:28 +02:00
parent 7897ad1d5a
commit 4c80c2458a
1 changed files with 13 additions and 9 deletions

View File

@ -46,14 +46,16 @@ class TestElasticsearchEngine(SearxTestCase): # pylint: disable=missing-class-d
def test_basic_failures(self): def test_basic_failures(self):
queries = [ queries = [
['match', 'stuff'], ['match', 'stuff', 'query format must be "key:value'],
['term', 'stuff'], ['term', 'stuff', 'query format must be key:value'],
['terms', 'stuff'], ['terms', 'stuff', 'query format must be key:value1,value2'],
] ]
for query in queries: for query in queries:
elasticsearch_engine.query_type = query[0] elasticsearch_engine.query_type = query[0]
self.assertRaises(ValueError, elasticsearch_engine.request, query[1], self.default_params) with self.assertRaises(ValueError) as context:
elasticsearch_engine.request(query[1], self.default_params)
self.assertIn(query[2], str(context.exception))
def test_custom_queries(self): def test_custom_queries(self):
queries = [ queries = [
@ -117,16 +119,18 @@ class TestElasticsearchEngine(SearxTestCase): # pylint: disable=missing-class-d
def test_custom_failures(self): def test_custom_failures(self):
queries = [ queries = [
['stuff', '{"query": {"match": {"{{KEY}}": {"query": "{{VALUE}}"}}}}'], ['stuff', '{"query": {"match": {"{{KEY}}": {"query": "{{VALUE}}"}}}}', 'query format must be "key:value"'],
['stuff', '{"query": {"terms": {"{{KEY}}": "{{VALUES}}"}}}'], ['stuff', '{"query": {"terms": {"{{KEY}}": "{{VALUES}}"}}}', 'query format must be "key:value"'],
['stuff', '{"query": {"simple_query_string": {"query": {{QUERY}}}}}'], ['stuff', '{"query": {"simple_query_string": {"query": {{QUERY}}}}}', 'invalid custom_query string'],
['stuff', '"query": {"simple_query_string": {"query": "{{QUERY}}"}}}'], ['stuff', '"query": {"simple_query_string": {"query": "{{QUERY}}"}}}', 'invalid custom_query string'],
] ]
elasticsearch_engine.query_type = 'custom' elasticsearch_engine.query_type = 'custom'
for query in queries: for query in queries:
elasticsearch_engine.custom_query_json = query[1] elasticsearch_engine.custom_query_json = query[1]
self.assertRaises(ValueError, elasticsearch_engine.request, query[0], self.default_params) with self.assertRaises(ValueError) as context:
elasticsearch_engine.request(query[0], self.default_params)
self.assertIn(query[2], str(context.exception))
# vi:sw=4 # vi:sw=4