test_results.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # -*- coding: utf-8 -*-
  2. from searx.results import ResultContainer
  3. from searx.testing import SearxTestCase
  4. def fake_result(url='https://aa.bb/cc?dd=ee#ff',
  5. title='aaa',
  6. content='bbb',
  7. engine='wikipedia', **kwargs):
  8. result = {'url': url,
  9. 'title': title,
  10. 'content': content,
  11. 'engine': engine}
  12. result.update(kwargs)
  13. return result
  14. # TODO
  15. class ResultContainerTestCase(SearxTestCase):
  16. def test_empty(self):
  17. c = ResultContainer("en-US")
  18. self.assertEqual(c.get_ordered_results(), [])
  19. def test_one_result(self):
  20. c = ResultContainer("en-US")
  21. c.extend('wikipedia', [fake_result()])
  22. self.assertEqual(c.results_length(), 1)
  23. def test_one_suggestion(self):
  24. c = ResultContainer("en-US")
  25. c.extend('wikipedia', [fake_result(suggestion=True)])
  26. self.assertEqual(len(c.suggestions), 1)
  27. self.assertEqual(c.results_length(), 0)
  28. def test_result_merge(self):
  29. c = ResultContainer("en-US")
  30. c.extend('wikipedia', [fake_result()])
  31. c.extend('wikidata', [fake_result(), fake_result(url='https://example.com/')])
  32. self.assertEqual(c.results_length(), 2)