test_google_videos.py 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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>
  28. <h3><a href="url_1">Title 1</h3>
  29. </div>
  30. <div>
  31. <span class="st">Content 1</span>
  32. </div>
  33. </div>
  34. <div class="g">
  35. <div>
  36. <h3><a href="url_2">Title 2</h3>
  37. </div>
  38. <div>
  39. <span class="st">Content 2</span>
  40. </div>
  41. </div>
  42. </div>
  43. </div>
  44. """
  45. response = mock.Mock(text=html)
  46. results = google_videos.response(response)
  47. self.assertEqual(type(results), list)
  48. self.assertEqual(len(results), 2)
  49. self.assertEqual(results[0]['url'], u'url_1')
  50. self.assertEqual(results[0]['title'], u'Title 1')
  51. self.assertEqual(results[0]['content'], u'Content 1')
  52. self.assertEqual(results[1]['url'], u'url_2')
  53. self.assertEqual(results[1]['title'], u'Title 2')
  54. self.assertEqual(results[1]['content'], u'Content 2')