2024-03-11 13:06:26 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
# pylint: disable=missing-module-docstring
|
2015-10-03 15:26:07 +00:00
|
|
|
|
|
|
|
from searx.results import ResultContainer
|
2021-09-02 14:01:34 +00:00
|
|
|
from tests import SearxTestCase
|
2015-10-03 15:26:07 +00:00
|
|
|
|
|
|
|
|
2021-12-27 08:26:22 +00:00
|
|
|
def fake_result(url='https://aa.bb/cc?dd=ee#ff', title='aaa', content='bbb', engine='wikipedia', **kwargs):
|
2021-12-27 08:16:03 +00:00
|
|
|
result = {
|
|
|
|
# fmt: off
|
|
|
|
'url': url,
|
|
|
|
'title': title,
|
|
|
|
'content': content,
|
|
|
|
'engine': engine,
|
|
|
|
# fmt: on
|
|
|
|
}
|
2015-10-03 15:26:07 +00:00
|
|
|
result.update(kwargs)
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
2024-03-11 13:06:26 +00:00
|
|
|
class ResultContainerTestCase(SearxTestCase): # pylint: disable=missing-class-docstring
|
2015-10-03 15:26:07 +00:00
|
|
|
def test_empty(self):
|
|
|
|
c = ResultContainer()
|
|
|
|
self.assertEqual(c.get_ordered_results(), [])
|
|
|
|
|
|
|
|
def test_one_result(self):
|
|
|
|
c = ResultContainer()
|
|
|
|
c.extend('wikipedia', [fake_result()])
|
|
|
|
self.assertEqual(c.results_length(), 1)
|
|
|
|
|
|
|
|
def test_one_suggestion(self):
|
|
|
|
c = ResultContainer()
|
|
|
|
c.extend('wikipedia', [fake_result(suggestion=True)])
|
|
|
|
self.assertEqual(len(c.suggestions), 1)
|
|
|
|
self.assertEqual(c.results_length(), 0)
|
|
|
|
|
|
|
|
def test_result_merge(self):
|
|
|
|
c = ResultContainer()
|
|
|
|
c.extend('wikipedia', [fake_result()])
|
|
|
|
c.extend('wikidata', [fake_result(), fake_result(url='https://example.com/')])
|
|
|
|
self.assertEqual(c.results_length(), 2)
|