logo

searx

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

test_vimeo.py (2660B)


  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. json = u"""
  21. {"filtered":{"total":274641,"page":1,"per_page":18,"paging":{"next":"?sizes=590x332&page=2","previous":null,"first":"?sizes=590x332&page=1","last":"?sizes=590x332&page=15258"},"data":[{"is_staffpick":false,"is_featured":true,"type":"clip","clip":{"uri":"\\/videos\\/106557563","name":"Hot Rod Revue: The South","link":"https:\\/\\/vimeo.com\\/106557563","duration":4069,"created_time":"2014-09-19T03:38:04+00:00","privacy":{"view":"ptv"},"pictures":{"sizes":[{"width":"590","height":"332","link":"https:\\/\\/i.vimeocdn.com\\/video\\/489717884_590x332.jpg?r=pad","link_with_play_button":"https:\\/\\/i.vimeocdn.com\\/filter\\/overlay?src0=https%3A%2F%2Fi.vimeocdn.com%2Fvideo%2F489717884_590x332.jpg&src1=http%3A%2F%2Ff.vimeocdn.com%2Fp%2Fimages%2Fcrawler_play.png"}]},"stats":{"plays":null},"metadata":{"connections":{"comments":{"total":0},"likes":{"total":5}},"interactions":[]},"user":{"name":"Cal Thorley","link":"https:\\/\\/vimeo.com\\/calthorley","pictures":{"sizes":[{"width":30,"height":30,"link":"https:\\/\\/i.vimeocdn.com\\/portrait\\/2545308_30x30?r=pad"},{"width":75,"height":75,"link":"https:\\/\\/i.vimeocdn.com\\/portrait\\/2545308_75x75?r=pad"},{"width":100,"height":100,"link":"https:\\/\\/i.vimeocdn.com\\/portrait\\/2545308_100x100?r=pad"},{"width":300,"height":300,"link":"https:\\/\\/i.vimeocdn.com\\/portrait\\/2545308_300x300?r=pad"}]}}}}]}};
  22. """ # noqa
  23. response = mock.Mock(text=json)
  24. results = vimeo.response(response)
  25. self.assertEqual(type(results), list)
  26. self.assertEqual(len(results), 1)
  27. self.assertEqual(results[0]['title'], u'Hot Rod Revue: The South')
  28. self.assertEqual(results[0]['url'], 'https://vimeo.com/106557563')
  29. self.assertEqual(results[0]['content'], '')
  30. self.assertEqual(results[0]['thumbnail'], 'https://i.vimeocdn.com/video/489717884_590x332.jpg?r=pad')