logo

searx

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

test_google_videos.py (2859B)


  1. from collections import defaultdict
  2. import mock
  3. from searx.engines import google_videos
  4. from searx.testing import SearxTestCase
  5. class TestGoogleVideosEngine(SearxTestCase):
  6. def test_request(self):
  7. query = 'test_query'
  8. dicto = defaultdict(dict)
  9. dicto['pageno'] = 1
  10. dicto['safesearch'] = 1
  11. dicto['time_range'] = ''
  12. params = google_videos.request(query, dicto)
  13. self.assertIn('url', params)
  14. self.assertIn(query, params['url'])
  15. dicto['safesearch'] = 0
  16. params = google_videos.request(query, dicto)
  17. self.assertNotIn('safe', params['url'])
  18. def test_response(self):
  19. self.assertRaises(AttributeError, google_videos.response, None)
  20. self.assertRaises(AttributeError, google_videos.response, [])
  21. self.assertRaises(AttributeError, google_videos.response, '')
  22. self.assertRaises(AttributeError, google_videos.response, '[]')
  23. html = r"""
  24. <div>
  25. <div>
  26. <div class="g">
  27. <div class="r">
  28. <a href="url_1"><h3>Title 1</h3></a>
  29. </div>
  30. <div class="s">
  31. <div>
  32. <a>
  33. <g-img>
  34. <img id="vidthumb1">
  35. </g-img>
  36. </a>
  37. </div>
  38. </div>
  39. <div>
  40. <span class="st">Content 1</span>
  41. </div>
  42. </div>
  43. <div class="g">
  44. <div class="r">
  45. <a href="url_2"><h3>Title 2</h3></a>
  46. </div>
  47. <div class="s">
  48. <div>
  49. <a>
  50. <g-img>
  51. <img id="vidthumb2">
  52. </g-img>
  53. </a>
  54. </div>
  55. </div>
  56. <div>
  57. <span class="st">Content 2</span>
  58. </div>
  59. </div>
  60. </div>
  61. </div>
  62. <script>function _setImagesSrc(c,d,e){}</script>
  63. """
  64. response = mock.Mock(text=html)
  65. results = google_videos.response(response)
  66. self.assertEqual(type(results), list)
  67. self.assertEqual(len(results), 2)
  68. self.assertEqual(results[0]['url'], u'url_1')
  69. self.assertEqual(results[0]['title'], u'Title 1')
  70. self.assertEqual(results[0]['content'], u'Content 1')
  71. self.assertEqual(results[1]['url'], u'url_2')
  72. self.assertEqual(results[1]['title'], u'Title 2')
  73. self.assertEqual(results[1]['content'], u'Content 2')