|
@@ -0,0 +1,131 @@
|
|
1
|
+# -*- coding: utf-8 -*-
|
|
2
|
+from collections import defaultdict
|
|
3
|
+import mock
|
|
4
|
+from searx.engines import bing_videos
|
|
5
|
+from searx.testing import SearxTestCase
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+class TestBingVideosEngine(SearxTestCase):
|
|
9
|
+
|
|
10
|
+ def test_request(self):
|
|
11
|
+ query = 'test_query'
|
|
12
|
+ dicto = defaultdict(dict)
|
|
13
|
+ dicto['pageno'] = 1
|
|
14
|
+ dicto['language'] = 'fr-FR'
|
|
15
|
+ dicto['safesearch'] = 0
|
|
16
|
+ dicto['time_range'] = ''
|
|
17
|
+ params = bing_videos.request(query, dicto)
|
|
18
|
+ self.assertTrue('url' in params)
|
|
19
|
+ self.assertTrue(query in params['url'])
|
|
20
|
+ self.assertTrue('bing.com' in params['url'])
|
|
21
|
+ self.assertTrue('SRCHHPGUSR' in params['cookies'])
|
|
22
|
+ self.assertTrue('OFF' in params['cookies']['SRCHHPGUSR'])
|
|
23
|
+ self.assertTrue('_EDGE_S' in params['cookies'])
|
|
24
|
+ self.assertTrue('fr-fr' in params['cookies']['_EDGE_S'])
|
|
25
|
+
|
|
26
|
+ dicto['pageno'] = 2
|
|
27
|
+ dicto['time_range'] = 'day'
|
|
28
|
+ dicto['safesearch'] = 2
|
|
29
|
+ params = bing_videos.request(query, dicto)
|
|
30
|
+ self.assertTrue('first=11' in params['url'])
|
|
31
|
+ self.assertTrue('1440' in params['url'])
|
|
32
|
+ self.assertIn('SRCHHPGUSR', params['cookies'])
|
|
33
|
+ self.assertTrue('STRICT' in params['cookies']['SRCHHPGUSR'])
|
|
34
|
+
|
|
35
|
+ def test_response(self):
|
|
36
|
+ self.assertRaises(AttributeError, bing_videos.response, None)
|
|
37
|
+ self.assertRaises(AttributeError, bing_videos.response, [])
|
|
38
|
+ self.assertRaises(AttributeError, bing_videos.response, '')
|
|
39
|
+ self.assertRaises(AttributeError, bing_videos.response, '[]')
|
|
40
|
+
|
|
41
|
+ response = mock.Mock(text='<html></html>')
|
|
42
|
+ self.assertEqual(bing_videos.response(response), [])
|
|
43
|
+
|
|
44
|
+ response = mock.Mock(text='<html></html>')
|
|
45
|
+ self.assertEqual(bing_videos.response(response), [])
|
|
46
|
+
|
|
47
|
+ html = """
|
|
48
|
+ <div>
|
|
49
|
+ <div class="dg_u">
|
|
50
|
+ <a class="dv_i" href="/videos/search?abcde">
|
|
51
|
+ <div class="vthblock">
|
|
52
|
+ <div class="vthumb">
|
|
53
|
+ <img src="thumb_1.jpg" />
|
|
54
|
+ </div>
|
|
55
|
+ <div>
|
|
56
|
+ <div class="tl">
|
|
57
|
+ Title 1
|
|
58
|
+ </div>
|
|
59
|
+ </div>
|
|
60
|
+ </div>
|
|
61
|
+ <div class="videoInfoPanel">
|
|
62
|
+ <div class="pubInfo">
|
|
63
|
+ <div>Content 1</div>
|
|
64
|
+ </div>
|
|
65
|
+ </div>
|
|
66
|
+ </a>
|
|
67
|
+ <div class="sa_wrapper"
|
|
68
|
+ data-eventpayload="{"purl": "https://url.com/1"}">
|
|
69
|
+ </div>
|
|
70
|
+ </div>
|
|
71
|
+ </div>
|
|
72
|
+ """
|
|
73
|
+ response = mock.Mock(text=html)
|
|
74
|
+ results = bing_videos.response(response)
|
|
75
|
+ self.assertEqual(type(results), list)
|
|
76
|
+ self.assertEqual(len(results), 1)
|
|
77
|
+ self.assertEqual(results[0]['title'], 'Title 1')
|
|
78
|
+ self.assertEqual(results[0]['url'], 'https://url.com/1')
|
|
79
|
+ self.assertEqual(results[0]['content'], 'Content 1')
|
|
80
|
+ self.assertEqual(results[0]['thumbnail'], 'thumb_1.jpg')
|
|
81
|
+
|
|
82
|
+ html = """
|
|
83
|
+ <div>
|
|
84
|
+ <div class="dg_u">
|
|
85
|
+ <a class="dv_i" href="https://url.com/1">
|
|
86
|
+ <div class="vthblock">
|
|
87
|
+ <div class="vthumb">
|
|
88
|
+ <img src="thumb_1.jpg" />
|
|
89
|
+ </div>
|
|
90
|
+ <div>
|
|
91
|
+ <div class="tl">
|
|
92
|
+ Title 1
|
|
93
|
+ </div>
|
|
94
|
+ </div>
|
|
95
|
+ </div>
|
|
96
|
+ <div class="videoInfoPanel">
|
|
97
|
+ <div class="pubInfo">
|
|
98
|
+ <div>Content 1</div>
|
|
99
|
+ </div>
|
|
100
|
+ </div>
|
|
101
|
+ </a>
|
|
102
|
+ </div>
|
|
103
|
+ <div class="dg_u">
|
|
104
|
+ <a class="dv_i" href="/videos/search?abcde">
|
|
105
|
+ <div class="vthblock">
|
|
106
|
+ <div class="vthumb">
|
|
107
|
+ <img src="thumb_2.jpg" />
|
|
108
|
+ </div>
|
|
109
|
+ <div>
|
|
110
|
+ <div class="tl">
|
|
111
|
+ Title 2
|
|
112
|
+ </div>
|
|
113
|
+ </div>
|
|
114
|
+ </div>
|
|
115
|
+ <div class="videoInfoPanel">
|
|
116
|
+ <div class="pubInfo">
|
|
117
|
+ <div>Content 2</div>
|
|
118
|
+ </div>
|
|
119
|
+ </div>
|
|
120
|
+ </a>
|
|
121
|
+ </div>
|
|
122
|
+ </div>
|
|
123
|
+ """
|
|
124
|
+ response = mock.Mock(text=html)
|
|
125
|
+ results = bing_videos.response(response)
|
|
126
|
+ self.assertEqual(type(results), list)
|
|
127
|
+ self.assertEqual(len(results), 1)
|
|
128
|
+ self.assertEqual(results[0]['title'], 'Title 1')
|
|
129
|
+ self.assertEqual(results[0]['url'], 'https://url.com/1')
|
|
130
|
+ self.assertEqual(results[0]['content'], 'Content 1')
|
|
131
|
+ self.assertEqual(results[0]['thumbnail'], 'thumb_1.jpg')
|