logo

searx

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

test_fdroid.py (1621B)


  1. import mock
  2. from collections import defaultdict
  3. from searx.engines import fdroid
  4. from searx.testing import SearxTestCase
  5. class TestFdroidEngine(SearxTestCase):
  6. def test_request(self):
  7. query = 'test_query'
  8. dic = defaultdict(dict)
  9. dic['pageno'] = 1
  10. params = fdroid.request(query, dic)
  11. self.assertTrue('url' in params)
  12. self.assertTrue(query in params['url'])
  13. self.assertTrue('f-droid.org' in params['url'])
  14. def test_response(self):
  15. resp = mock.Mock(text='<html></html>')
  16. self.assertEqual(fdroid.response(resp), [])
  17. html = """
  18. <a href="https://google.com/qwerty">
  19. <div id="appheader">
  20. <div style="float:left;padding-right:10px;">
  21. <img src="http://example.com/image.png"
  22. style="width:48px;border:none;">
  23. </div>
  24. <div style="float:right;">
  25. <p>Details...</p>
  26. </div>
  27. <p style="color:#000000;">
  28. <span style="font-size:20px;">Sample title</span>
  29. <br>
  30. Sample content
  31. </p>
  32. </div>
  33. </a>
  34. """
  35. resp = mock.Mock(text=html)
  36. results = fdroid.response(resp)
  37. self.assertEqual(type(results), list)
  38. self.assertEqual(len(results), 1)
  39. self.assertEqual(results[0]['url'], 'https://google.com/qwerty')
  40. self.assertEqual(results[0]['title'], 'Sample title')
  41. self.assertEqual(results[0]['content'], 'Sample content')
  42. self.assertEqual(results[0]['img_src'], 'http://example.com/image.png')