on master help sign in
Dailymotion's unit test
92368a4Cqoicebordel
searx/tests/engines/test_dailymotion.pynew file+74
@@ -0,0 +1,74 @@
1+from collections import defaultdict
2+import mock
3+from searx.engines import dailymotion
4+from searx.testing import SearxTestCase
5+
6+
7+class TestDailymotionEngine(SearxTestCase):
8+
9+ def test_request(self):
10+ query = 'test_query'
11+ dicto = defaultdict(dict)
12+ dicto['pageno'] = 0
13+ dicto['language'] = 'fr_FR'
14+ params = dailymotion.request(query, dicto)
15+ self.assertTrue('url' in params)
16+ self.assertTrue(query in params['url'])
17+ self.assertTrue('dailymotion.com' in params['url'])
18+ self.assertTrue('fr' in params['url'])
19+
20+ dicto['language'] = 'all'
21+ params = dailymotion.request(query, dicto)
22+ self.assertTrue('en' in params['url'])
23+
24+ def test_response(self):
25+ self.assertRaises(AttributeError, dailymotion.response, None)
26+ self.assertRaises(AttributeError, dailymotion.response, [])
27+ self.assertRaises(AttributeError, dailymotion.response, '')
28+ self.assertRaises(AttributeError, dailymotion.response, '[]')
29+
30+ response = mock.Mock(text='{}')
31+ self.assertEqual(dailymotion.response(response), [])
32+
33+ response = mock.Mock(text='{"data": []}')
34+ self.assertEqual(dailymotion.response(response), [])
35+
36+ json = """
37+ {
38+ "page": 1,
39+ "limit": 5,
40+ "explicit": false,
41+ "total": 289487,
42+ "has_more": true,
43+ "list": [
44+ {
45+ "created_time": 1422173451,
46+ "title": "Title",
47+ "description": "Description",
48+ "duration": 81,
49+ "url": "http://www.url",
50+ "thumbnail_360_url": "http://thumbnail",
51+ "id": "x2fit7q"
52+ }
53+ ]
54+ }
55+ """
56+ response = mock.Mock(text=json)
57+ results = dailymotion.response(response)
58+ self.assertEqual(type(results), list)
59+ self.assertEqual(len(results), 1)
60+ self.assertEqual(results[0]['title'], 'Title')
61+ self.assertEqual(results[0]['url'], 'http://www.url')
62+ self.assertEqual(results[0]['content'], 'Description')
63+ self.assertIn('x2fit7q', results[0]['embedded'])
64+
65+ json = """
66+ {"toto":[
67+ {"id":200,"name":"Artist Name",
68+ "link":"http:\/\/www.dailymotion.com\/artist\/1217","type":"artist"}
69+ ]}
70+ """
71+ response = mock.Mock(text=json)
72+ results = dailymotion.response(response)
73+ self.assertEqual(type(results), list)
74+ self.assertEqual(len(results), 0)
searx/tests/test_engines.py+1
@@ -1,4 +1,5 @@
1from searx.tests.engines.test_bing import * # noqa
1from searx.tests.engines.test_bing import * # noqa
2+from searx.tests.engines.test_dailymotion import * # noqa
2from searx.tests.engines.test_deezer import * # noqa
3from searx.tests.engines.test_deezer import * # noqa
3from searx.tests.engines.test_dummy import * # noqa
4from searx.tests.engines.test_dummy import * # noqa
4from searx.tests.engines.test_flickr import * # noqa
5from searx.tests.engines.test_flickr import * # noqa