logo

searx

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

test_bing_videos.py (4335B)


  1. # -*- coding: utf-8 -*-
  2. from collections import defaultdict
  3. import mock
  4. from searx.engines import bing_videos
  5. from searx.testing import SearxTestCase
  6. class TestBingVideosEngine(SearxTestCase):
  7. def test_request(self):
  8. bing_videos.supported_languages = ['fr-FR', 'en-US']
  9. query = 'test_query'
  10. dicto = defaultdict(dict)
  11. dicto['pageno'] = 1
  12. dicto['language'] = 'fr-FR'
  13. dicto['safesearch'] = 0
  14. dicto['time_range'] = ''
  15. params = bing_videos.request(query, dicto)
  16. self.assertTrue('url' in params)
  17. self.assertTrue(query in params['url'])
  18. self.assertTrue('bing.com' in params['url'])
  19. self.assertTrue('SRCHHPGUSR' in params['cookies'])
  20. self.assertTrue('OFF' in params['cookies']['SRCHHPGUSR'])
  21. self.assertTrue('_EDGE_S' in params['cookies'])
  22. self.assertTrue('fr-fr' in params['cookies']['_EDGE_S'])
  23. dicto['pageno'] = 2
  24. dicto['time_range'] = 'day'
  25. dicto['safesearch'] = 2
  26. params = bing_videos.request(query, dicto)
  27. self.assertTrue('first=11' in params['url'])
  28. self.assertTrue('1440' in params['url'])
  29. self.assertIn('SRCHHPGUSR', params['cookies'])
  30. self.assertTrue('STRICT' in params['cookies']['SRCHHPGUSR'])
  31. def test_response(self):
  32. self.assertRaises(AttributeError, bing_videos.response, None)
  33. self.assertRaises(AttributeError, bing_videos.response, [])
  34. self.assertRaises(AttributeError, bing_videos.response, '')
  35. self.assertRaises(AttributeError, bing_videos.response, '[]')
  36. response = mock.Mock(text='<html></html>')
  37. self.assertEqual(bing_videos.response(response), [])
  38. response = mock.Mock(text='<html></html>')
  39. self.assertEqual(bing_videos.response(response), [])
  40. html = """
  41. <div class="dg_u">
  42. <div id="mc_vtvc_1" class="mc_vtvc">
  43. <a class="mc_vtvc_link" href="/video">
  44. <div class="mc_vtvc_th">
  45. <div class="cico">
  46. <img src="thumb_1.jpg" />
  47. </div>
  48. <div class="mc_vtvc_ban_lo">
  49. <div class="vtbc">
  50. <div class="mc_bc_w b_smText">
  51. <div class="mc_bc pivot bpi_2">
  52. <span title="">
  53. <span class="mv_vtvc_play cipg "></span>
  54. </span>
  55. </div>
  56. <div class="mc_bc items">10:06</div>
  57. </div>
  58. </div>
  59. </div>
  60. </div>
  61. <div class="mc_vtvc_meta">
  62. <div class="mc_vtvc_title" title="Title 1"></div>
  63. <div class="mc_vtvc_meta_block_area">
  64. <div class="mc_vtvc_meta_block">
  65. <div class="mc_vtvc_meta_row">
  66. <span>65,696,000+ views</span>
  67. <span>1 year ago</span>
  68. </div>
  69. <div class="mc_vtvc_meta_row mc_vtvc_meta_row_channel">Content 1</div>
  70. <div class="mc_vtvc_meta_row"><span>
  71. <div class="cico mc_vtvc_src_ico">
  72. <div></div>
  73. </div>
  74. <span>YouTube</span>
  75. </span></div>
  76. </div>
  77. </div>
  78. </div>
  79. <div class="vrhdata"></div>
  80. </a>
  81. </div>
  82. </div>
  83. """
  84. response = mock.Mock(text=html)
  85. results = bing_videos.response(response)
  86. self.assertEqual(type(results), list)
  87. self.assertEqual(len(results), 1)
  88. self.assertEqual(results[0]['title'], 'Title 1')
  89. self.assertEqual(results[0]['url'], 'https://bing.com/video')
  90. self.assertEqual(results[0]['content'], 'Content 1')
  91. self.assertEqual(results[0]['thumbnail'], 'thumb_1.jpg')