test_results.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # SPDX-License-Identifier: AGPL-3.0-or-later
  2. # pylint: disable=missing-module-docstring
  3. from searx.results import ResultContainer
  4. from tests import SearxTestCase
  5. def fake_result(url='https://aa.bb/cc?dd=ee#ff', title='aaa', content='bbb', engine='wikipedia', **kwargs):
  6. result = {
  7. # fmt: off
  8. 'url': url,
  9. 'title': title,
  10. 'content': content,
  11. 'engine': engine,
  12. # fmt: on
  13. }
  14. result.update(kwargs)
  15. return result
  16. class ResultContainerTestCase(SearxTestCase): # pylint: disable=missing-class-docstring
  17. def test_empty(self):
  18. c = ResultContainer()
  19. self.assertEqual(c.get_ordered_results(), [])
  20. def test_one_result(self):
  21. c = ResultContainer()
  22. c.extend('wikipedia', [fake_result()])
  23. self.assertEqual(c.results_length(), 1)
  24. def test_one_suggestion(self):
  25. c = ResultContainer()
  26. c.extend('wikipedia', [fake_result(suggestion=True)])
  27. self.assertEqual(len(c.suggestions), 1)
  28. self.assertEqual(c.results_length(), 0)
  29. def test_result_merge(self):
  30. c = ResultContainer()
  31. c.extend('wikipedia', [fake_result()])
  32. c.extend('wikidata', [fake_result(), fake_result(url='https://example.com/')])
  33. self.assertEqual(c.results_length(), 2)