test_vimeo.py 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. # -*- coding: utf-8 -*-
  2. from collections import defaultdict
  3. import mock
  4. from searx.engines import vimeo
  5. from searx.testing import SearxTestCase
  6. class TestVimeoEngine(SearxTestCase):
  7. def test_request(self):
  8. query = 'test_query'
  9. dicto = defaultdict(dict)
  10. dicto['pageno'] = 0
  11. params = vimeo.request(query, dicto)
  12. self.assertTrue('url' in params)
  13. self.assertTrue(query in params['url'])
  14. self.assertTrue('vimeo.com' in params['url'])
  15. def test_response(self):
  16. self.assertRaises(AttributeError, vimeo.response, None)
  17. self.assertRaises(AttributeError, vimeo.response, [])
  18. self.assertRaises(AttributeError, vimeo.response, '')
  19. self.assertRaises(AttributeError, vimeo.response, '[]')
  20. response = mock.Mock(text='<html></html>')
  21. self.assertEqual(vimeo.response(response), [])
  22. html = """
  23. <div id="browse_content" class="results_grid" data-search-id="696d5f8366914ec4ffec33cf7652de384976d4f4">
  24. <ul class="js-browse_list clearfix browse browse_videos browse_videos_thumbnails kane"
  25. data-stream="c2VhcmNoOjo6ZGVzYzp7InF1ZXJ5IjoidGVzdCJ9">
  26. <li data-position="7" data-result-id="clip_79600943">
  27. <div class="clip_thumbnail">
  28. <a href="/videoid" class="js-result_url">
  29. <div class="thumbnail_wrapper">
  30. <img src="http://image.url.webp" class="js-clip_thumbnail_image">
  31. <div class="overlay overlay_clip_meta">
  32. <div class="meta_data_footer">
  33. <span class="clip_upload_date">
  34. <time datetime="2013-11-17T08:49:09-05:00"
  35. title="dimanche 17 novembre 2013 08:49">Il y a 1 an</time>
  36. </span>
  37. <span class="clip_likes">
  38. <img src="https://f.vimeocdn.com/images_v6/svg/heart-icon.svg">2 215
  39. </span>
  40. <span class="clip_comments">
  41. <img src="https://f.vimeocdn.com/images_v6/svg/comment-icon.svg">75
  42. </span>
  43. <span class="overlay meta_data_footer clip_duration">01:12</span>
  44. </div>
  45. </div>
  46. </div>
  47. <span class="title">This is the title</span>
  48. </a>
  49. </div>
  50. <div class="clip_thumbnail_attribution">
  51. <a href="/fedorshmidt">
  52. <img src="https://i.vimeocdn.com/portrait/6628061_100x100.jpg" class="avatar">
  53. <span class="display_name">Fedor Shmidt</span>
  54. </a>
  55. <span class="plays">2,1M lectures</span>
  56. </div>
  57. </li>
  58. </ul>
  59. </div>
  60. """
  61. response = mock.Mock(text=html)
  62. results = vimeo.response(response)
  63. self.assertEqual(type(results), list)
  64. self.assertEqual(len(results), 1)
  65. self.assertEqual(results[0]['title'], 'This is the title')
  66. self.assertEqual(results[0]['url'], 'https://vimeo.com/videoid')
  67. self.assertEqual(results[0]['content'], '')
  68. self.assertEqual(results[0]['thumbnail'], 'http://image.url.webp')
  69. self.assertIn('/videoid', results[0]['embedded'])
  70. html = """
  71. <ol class="js-browse_list clearfix browse browse_videos browse_videos_thumbnails kane"
  72. data-stream="c2VhcmNoOjo6ZGVzYzp7InF1ZXJ5IjoidGVzdCJ9">
  73. <li id="clip_100785455" data-start-page="/search/page:1/sort:relevant/" data-position="1">
  74. <a href="/videoid" title="Futurama 3d (test shot)">
  75. <img src="http://image.url.webp"
  76. srcset="http://i.vimeocdn.com/video/482375085_590x332.webp 2x" alt=""
  77. class="thumbnail thumbnail_lg_wide">
  78. <div class="data">
  79. <p class="title">
  80. This is the title
  81. </p>
  82. <p class="meta">
  83. <time datetime="2014-07-15T04:16:27-04:00"
  84. title="mardi 15 juillet 2014 04:16">Il y a 6 mois</time>
  85. </p>
  86. </div>
  87. </a>
  88. </li>
  89. </ol>
  90. """
  91. response = mock.Mock(text=html)
  92. results = vimeo.response(response)
  93. self.assertEqual(type(results), list)
  94. self.assertEqual(len(results), 0)