|
@@ -0,0 +1,60 @@
|
|
1
|
+from collections import defaultdict
|
|
2
|
+import mock
|
|
3
|
+from searx.engines import google_videos
|
|
4
|
+from searx.testing import SearxTestCase
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+class TestGoogleVideosEngine(SearxTestCase):
|
|
8
|
+
|
|
9
|
+ def test_request(self):
|
|
10
|
+ query = 'test_query'
|
|
11
|
+ dicto = defaultdict(dict)
|
|
12
|
+ dicto['pageno'] = 1
|
|
13
|
+ dicto['safesearch'] = 1
|
|
14
|
+ dicto['time_range'] = ''
|
|
15
|
+ params = google_videos.request(query, dicto)
|
|
16
|
+ self.assertIn('url', params)
|
|
17
|
+ self.assertIn(query, params['url'])
|
|
18
|
+
|
|
19
|
+ dicto['safesearch'] = 0
|
|
20
|
+ params = google_videos.request(query, dicto)
|
|
21
|
+ self.assertNotIn('safe', params['url'])
|
|
22
|
+
|
|
23
|
+ def test_response(self):
|
|
24
|
+ self.assertRaises(AttributeError, google_videos.response, None)
|
|
25
|
+ self.assertRaises(AttributeError, google_videos.response, [])
|
|
26
|
+ self.assertRaises(AttributeError, google_videos.response, '')
|
|
27
|
+ self.assertRaises(AttributeError, google_videos.response, '[]')
|
|
28
|
+
|
|
29
|
+ html = r"""
|
|
30
|
+ <div>
|
|
31
|
+ <div>
|
|
32
|
+ <div class="g">
|
|
33
|
+ <div>
|
|
34
|
+ <h3><a href="url_1">Title 1</h3>
|
|
35
|
+ </div>
|
|
36
|
+ <div>
|
|
37
|
+ <span class="st">Content 1</span>
|
|
38
|
+ </div>
|
|
39
|
+ </div>
|
|
40
|
+ <div class="g">
|
|
41
|
+ <div>
|
|
42
|
+ <h3><a href="url_2">Title 2</h3>
|
|
43
|
+ </div>
|
|
44
|
+ <div>
|
|
45
|
+ <span class="st">Content 2</span>
|
|
46
|
+ </div>
|
|
47
|
+ </div>
|
|
48
|
+ </div>
|
|
49
|
+ </div>
|
|
50
|
+ """
|
|
51
|
+ response = mock.Mock(text=html)
|
|
52
|
+ results = google_videos.response(response)
|
|
53
|
+ self.assertEqual(type(results), list)
|
|
54
|
+ self.assertEqual(len(results), 2)
|
|
55
|
+ self.assertEqual(results[0]['url'], u'url_1')
|
|
56
|
+ self.assertEqual(results[0]['title'], u'Title 1')
|
|
57
|
+ self.assertEqual(results[0]['content'], u'Content 1')
|
|
58
|
+ self.assertEqual(results[1]['url'], u'url_2')
|
|
59
|
+ self.assertEqual(results[1]['title'], u'Title 2')
|
|
60
|
+ self.assertEqual(results[1]['content'], u'Content 2')
|