from collections import defaultdict import mock from searx.engines import vimeo from searx.testing import SearxTestCase class TestVimeoEngine(SearxTestCase): def test_request(self): query = 'test_query' dicto = defaultdict(dict) dicto['pageno'] = 0 params = vimeo.request(query, dicto) self.assertTrue('url' in params) self.assertTrue(query in params['url']) self.assertTrue('vimeo.com' in params['url']) def test_response(self): self.assertRaises(AttributeError, vimeo.response, None) self.assertRaises(AttributeError, vimeo.response, []) self.assertRaises(AttributeError, vimeo.response, '') self.assertRaises(AttributeError, vimeo.response, '[]') response = mock.Mock(text='') self.assertEqual(vimeo.response(response), []) html = """
""" response = mock.Mock(text=html) results = vimeo.response(response) self.assertEqual(type(results), list) self.assertEqual(len(results), 1) self.assertEqual(results[0]['title'], 'This is the title') self.assertEqual(results[0]['url'], 'http://vimeo.com/videoid') self.assertEqual(results[0]['content'], '') self.assertEqual(results[0]['thumbnail'], 'http://image.url.webp') self.assertIn('/videoid', results[0]['embedded']) html = """ """ response = mock.Mock(text=html) results = vimeo.response(response) self.assertEqual(type(results), list) self.assertEqual(len(results), 0)