logo

searx

My custom branche(s) on searx, a meta-search engine git clone https://hacktivis.me/git/searx.git

test_results.py (1225B)


  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()
  18. self.assertEqual(c.get_ordered_results(), [])
  19. def test_one_result(self):
  20. c = ResultContainer()
  21. c.extend('wikipedia', [fake_result()])
  22. self.assertEqual(c.results_length(), 1)
  23. def test_one_suggestion(self):
  24. c = ResultContainer()
  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()
  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)