|
@@ -1,204 +0,0 @@
|
1
|
|
-from collections import defaultdict
|
2
|
|
-import mock
|
3
|
|
-from searx.engines import youtube
|
4
|
|
-from searx.testing import SearxTestCase
|
5
|
|
-
|
6
|
|
-
|
7
|
|
-class TestYoutubeEngine(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 = youtube.request(query, dicto)
|
15
|
|
- self.assertTrue('url' in params)
|
16
|
|
- self.assertTrue(query in params['url'])
|
17
|
|
- self.assertTrue('youtube.com' in params['url'])
|
18
|
|
- self.assertTrue('fr' in params['url'])
|
19
|
|
-
|
20
|
|
- dicto['language'] = 'all'
|
21
|
|
- params = youtube.request(query, dicto)
|
22
|
|
- self.assertFalse('fr' in params['url'])
|
23
|
|
-
|
24
|
|
- def test_response(self):
|
25
|
|
- self.assertRaises(AttributeError, youtube.response, None)
|
26
|
|
- self.assertRaises(AttributeError, youtube.response, [])
|
27
|
|
- self.assertRaises(AttributeError, youtube.response, '')
|
28
|
|
- self.assertRaises(AttributeError, youtube.response, '[]')
|
29
|
|
-
|
30
|
|
- response = mock.Mock(text='{}')
|
31
|
|
- self.assertEqual(youtube.response(response), [])
|
32
|
|
-
|
33
|
|
- response = mock.Mock(text='{"data": []}')
|
34
|
|
- self.assertEqual(youtube.response(response), [])
|
35
|
|
-
|
36
|
|
- json = """
|
37
|
|
- {"feed":{"entry":[{
|
38
|
|
- "id":{"$t":"http://gdata.youtube.com/feeds/api/videos/DIVZCPfAOeM"},
|
39
|
|
- "published":{"$t":"2015-01-23T21:25:00.000Z"},
|
40
|
|
- "updated":{"$t":"2015-01-26T14:38:15.000Z"},
|
41
|
|
- "title":{"$t":"Title",
|
42
|
|
- "type":"text"},"content":{"$t":"Description","type":"text"},
|
43
|
|
- "link":[{"rel":"alternate","type":"text/html",
|
44
|
|
- "href":"https://www.youtube.com/watch?v=DIVZCPfAOeM&feature=youtube_gdata"},
|
45
|
|
- {"rel":"http://gdata.youtube.com/schemas/2007#video.related",
|
46
|
|
- "type":"application/atom+xml",
|
47
|
|
- "href":"https://gdata.youtube.com/feeds/api/videos/DIVZCPfAOeM/related"},
|
48
|
|
- {"rel":"http://gdata.youtube.com/schemas/2007#mobile","type":"text/html",
|
49
|
|
- "href":"https://m.youtube.com/details?v=DIVZCPfAOeM"},
|
50
|
|
- {"rel":"self","type":"application/atom+xml",
|
51
|
|
- "href":"https://gdata.youtube.com/feeds/api/videos/DIVZCPfAOeM"}],
|
52
|
|
- "author":[{"name":{"$t":"Cauet"},
|
53
|
|
- "uri":{"$t":"https://gdata.youtube.com/feeds/api/users/cauetofficiel"} }],
|
54
|
|
- "gd$comments":{"gd$feedLink":{"rel":"http://gdata.youtube.com/schemas/2007#comments",
|
55
|
|
- "href":"https://gdata.youtube.com/feeds/api/videos/DIVZCPfAOeM/comments",
|
56
|
|
- "countHint":8} },
|
57
|
|
- "media$group":{"media$category":[{"$t":"Comedy","label":"Comedy",
|
58
|
|
- "scheme":"http://gdata.youtube.com/schemas/2007/categories.cat"}],
|
59
|
|
- "media$content":[{"url":"https://www.youtube.com/v/DIVZCPfAOeM?version=3&f=videos&app=youtube_gdata",
|
60
|
|
- "type":"application/x-shockwave-flash","medium":"video",
|
61
|
|
- "isDefault":"true","expression":"full","duration":354,"yt$format":5},
|
62
|
|
- {"url":"rtsp://r1---sn-cg07luel.c.youtube.com/CiILENy73wIaGQnjOcD3CFmFDBMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp",
|
63
|
|
- "type":"video/3gpp","medium":"video","expression":"full","duration":354,
|
64
|
|
- "yt$format":1},
|
65
|
|
- {"url":"rtsp://r1---sn-cg07luel.c.youtube.com/CiILENy73wIaGQnjOcD3CFmFDBMYESARFEgGUgZ2aWRlb3MM/0/0/0/video.3gp",
|
66
|
|
- "type":"video/3gpp","medium":"video","expression":"full","duration":354,"yt$format":6}],
|
67
|
|
- "media$description":{"$t":"Desc","type":"plain"},
|
68
|
|
- "media$keywords":{},
|
69
|
|
- "media$player":[{"url":"https://www.youtube.com/watch?v=DIVZCPfAOeM&feature=youtube_gdata_player"}],
|
70
|
|
- "media$thumbnail":[{"url":"https://i.ytimg.com/vi/DIVZCPfAOeM/0.jpg",
|
71
|
|
- "height":360,"width":480,"time":"00:02:57"},
|
72
|
|
- {"url":"https://i.ytimg.com/vi/DIVZCPfAOeM/1.jpg","height":90,"width":120,"time":"00:01:28.500"},
|
73
|
|
- {"url":"https://i.ytimg.com/vi/DIVZCPfAOeM/2.jpg","height":90,"width":120,"time":"00:02:57"},
|
74
|
|
- {"url":"https://i.ytimg.com/vi/DIVZCPfAOeM/3.jpg","height":90,"width":120,"time":"00:04:25.500"}],
|
75
|
|
- "media$title":{"$t":"Title","type":"plain"},
|
76
|
|
- "yt$duration":{"seconds":"354"} },
|
77
|
|
- "gd$rating":{"average":4.932159,"max":5,"min":1,"numRaters":1533,
|
78
|
|
- "rel":"http://schemas.google.com/g/2005#overall"},
|
79
|
|
- "yt$statistics":{"favoriteCount":"0","viewCount":"92464"} }
|
80
|
|
- ]
|
81
|
|
- }
|
82
|
|
- }
|
83
|
|
- """
|
84
|
|
- response = mock.Mock(text=json)
|
85
|
|
- results = youtube.response(response)
|
86
|
|
- self.assertEqual(type(results), list)
|
87
|
|
- self.assertEqual(len(results), 1)
|
88
|
|
- self.assertEqual(results[0]['title'], 'Title')
|
89
|
|
- self.assertEqual(results[0]['url'], 'https://www.youtube.com/watch?v=DIVZCPfAOeM')
|
90
|
|
- self.assertEqual(results[0]['content'], 'Description')
|
91
|
|
- self.assertEqual(results[0]['thumbnail'], 'https://i.ytimg.com/vi/DIVZCPfAOeM/0.jpg')
|
92
|
|
- self.assertTrue('DIVZCPfAOeM' in results[0]['embedded'])
|
93
|
|
-
|
94
|
|
- json = """
|
95
|
|
- {"feed":{"entry":[{
|
96
|
|
- "id":{"$t":"http://gdata.youtube.com/feeds/api/videos/DIVZCPfAOeM"},
|
97
|
|
- "published":{"$t":"2015-01-23T21:25:00.000Z"},
|
98
|
|
- "updated":{"$t":"2015-01-26T14:38:15.000Z"},
|
99
|
|
- "title":{"$t":"Title",
|
100
|
|
- "type":"text"},"content":{"$t":"Description","type":"text"},
|
101
|
|
- "link":[{"rel":"http://gdata.youtube.com/schemas/2007#video.related",
|
102
|
|
- "type":"application/atom+xml",
|
103
|
|
- "href":"https://gdata.youtube.com/feeds/api/videos/DIVZCPfAOeM/related"},
|
104
|
|
- {"rel":"self","type":"application/atom+xml",
|
105
|
|
- "href":"https://gdata.youtube.com/feeds/api/videos/DIVZCPfAOeM"}],
|
106
|
|
- "author":[{"name":{"$t":"Cauet"},
|
107
|
|
- "uri":{"$t":"https://gdata.youtube.com/feeds/api/users/cauetofficiel"} }],
|
108
|
|
- "gd$comments":{"gd$feedLink":{"rel":"http://gdata.youtube.com/schemas/2007#comments",
|
109
|
|
- "href":"https://gdata.youtube.com/feeds/api/videos/DIVZCPfAOeM/comments",
|
110
|
|
- "countHint":8} },
|
111
|
|
- "media$group":{"media$category":[{"$t":"Comedy","label":"Comedy",
|
112
|
|
- "scheme":"http://gdata.youtube.com/schemas/2007/categories.cat"}],
|
113
|
|
- "media$content":[{"url":"https://www.youtube.com/v/DIVZCPfAOeM?version=3&f=videos&app=youtube_gdata",
|
114
|
|
- "type":"application/x-shockwave-flash","medium":"video",
|
115
|
|
- "isDefault":"true","expression":"full","duration":354,"yt$format":5},
|
116
|
|
- {"url":"rtsp://r1---sn-cg07luel.c.youtube.com/CiILENy73wIaGQnjOcD3CFmFDBMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp",
|
117
|
|
- "type":"video/3gpp","medium":"video","expression":"full","duration":354,
|
118
|
|
- "yt$format":1},
|
119
|
|
- {"url":"rtsp://r1---sn-cg07luel.c.youtube.com/CiILENy73wIaGQnjOcD3CFmFDBMYESARFEgGUgZ2aWRlb3MM/0/0/0/video.3gp",
|
120
|
|
- "type":"video/3gpp","medium":"video","expression":"full","duration":354,"yt$format":6}],
|
121
|
|
- "media$description":{"$t":"Desc","type":"plain"},
|
122
|
|
- "media$keywords":{},
|
123
|
|
- "media$player":[{"url":"https://www.youtube.com/watch?v=DIVZCPfAOeM&feature=youtube_gdata_player"}],
|
124
|
|
- "media$thumbnail":[{"url":"https://i.ytimg.com/vi/DIVZCPfAOeM/0.jpg",
|
125
|
|
- "height":360,"width":480,"time":"00:02:57"},
|
126
|
|
- {"url":"https://i.ytimg.com/vi/DIVZCPfAOeM/1.jpg","height":90,"width":120,"time":"00:01:28.500"},
|
127
|
|
- {"url":"https://i.ytimg.com/vi/DIVZCPfAOeM/2.jpg","height":90,"width":120,"time":"00:02:57"},
|
128
|
|
- {"url":"https://i.ytimg.com/vi/DIVZCPfAOeM/3.jpg","height":90,"width":120,"time":"00:04:25.500"}],
|
129
|
|
- "media$title":{"$t":"Title","type":"plain"},
|
130
|
|
- "yt$duration":{"seconds":"354"} },
|
131
|
|
- "gd$rating":{"average":4.932159,"max":5,"min":1,"numRaters":1533,
|
132
|
|
- "rel":"http://schemas.google.com/g/2005#overall"},
|
133
|
|
- "yt$statistics":{"favoriteCount":"0","viewCount":"92464"} }
|
134
|
|
- ]
|
135
|
|
- }
|
136
|
|
- }
|
137
|
|
- """
|
138
|
|
- response = mock.Mock(text=json)
|
139
|
|
- results = youtube.response(response)
|
140
|
|
- self.assertEqual(type(results), list)
|
141
|
|
- self.assertEqual(len(results), 0)
|
142
|
|
-
|
143
|
|
- json = """
|
144
|
|
- {"feed":{"entry":[{
|
145
|
|
- "id":{"$t":"http://gdata.youtube.com/feeds/api/videos/DIVZCPfAOeM"},
|
146
|
|
- "published":{"$t":"2015-01-23T21:25:00.000Z"},
|
147
|
|
- "updated":{"$t":"2015-01-26T14:38:15.000Z"},
|
148
|
|
- "title":{"$t":"Title",
|
149
|
|
- "type":"text"},"content":{"$t":"Description","type":"text"},
|
150
|
|
- "link":[{"rel":"alternate","type":"text/html",
|
151
|
|
- "href":"https://www.youtube.com/watch?v=DIVZCPfAOeM"},
|
152
|
|
- {"rel":"http://gdata.youtube.com/schemas/2007#video.related",
|
153
|
|
- "type":"application/atom+xml",
|
154
|
|
- "href":"https://gdata.youtube.com/feeds/api/videos/DIVZCPfAOeM/related"},
|
155
|
|
- {"rel":"http://gdata.youtube.com/schemas/2007#mobile","type":"text/html",
|
156
|
|
- "href":"https://m.youtube.com/details?v=DIVZCPfAOeM"},
|
157
|
|
- {"rel":"self","type":"application/atom+xml",
|
158
|
|
- "href":"https://gdata.youtube.com/feeds/api/videos/DIVZCPfAOeM"}],
|
159
|
|
- "author":[{"name":{"$t":"Cauet"},
|
160
|
|
- "uri":{"$t":"https://gdata.youtube.com/feeds/api/users/cauetofficiel"} }],
|
161
|
|
- "gd$comments":{"gd$feedLink":{"rel":"http://gdata.youtube.com/schemas/2007#comments",
|
162
|
|
- "href":"https://gdata.youtube.com/feeds/api/videos/DIVZCPfAOeM/comments",
|
163
|
|
- "countHint":8} },
|
164
|
|
- "media$group":{"media$category":[{"$t":"Comedy","label":"Comedy",
|
165
|
|
- "scheme":"http://gdata.youtube.com/schemas/2007/categories.cat"}],
|
166
|
|
- "media$content":[{"url":"https://www.youtube.com/v/DIVZCPfAOeM?version=3&f=videos&app=youtube_gdata",
|
167
|
|
- "type":"application/x-shockwave-flash","medium":"video",
|
168
|
|
- "isDefault":"true","expression":"full","duration":354,"yt$format":5},
|
169
|
|
- {"url":"rtsp://r1---sn-cg07luel.c.youtube.com/CiILENy73wIaGQnjOcD3CFmFDBMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp",
|
170
|
|
- "type":"video/3gpp","medium":"video","expression":"full","duration":354,
|
171
|
|
- "yt$format":1},
|
172
|
|
- {"url":"rtsp://r1---sn-cg07luel.c.youtube.com/CiILENy73wIaGQnjOcD3CFmFDBMYESARFEgGUgZ2aWRlb3MM/0/0/0/video.3gp",
|
173
|
|
- "type":"video/3gpp","medium":"video","expression":"full","duration":354,"yt$format":6}],
|
174
|
|
- "media$description":{"$t":"Desc","type":"plain"},
|
175
|
|
- "media$keywords":{},
|
176
|
|
- "media$player":[{"url":"https://www.youtube.com/watch?v=DIVZCPfAOeM&feature=youtube_gdata_player"}],
|
177
|
|
- "media$title":{"$t":"Title","type":"plain"},
|
178
|
|
- "yt$duration":{"seconds":"354"} },
|
179
|
|
- "gd$rating":{"average":4.932159,"max":5,"min":1,"numRaters":1533,
|
180
|
|
- "rel":"http://schemas.google.com/g/2005#overall"},
|
181
|
|
- "yt$statistics":{"favoriteCount":"0","viewCount":"92464"} }
|
182
|
|
- ]
|
183
|
|
- }
|
184
|
|
- }
|
185
|
|
- """
|
186
|
|
- response = mock.Mock(text=json)
|
187
|
|
- results = youtube.response(response)
|
188
|
|
- self.assertEqual(type(results), list)
|
189
|
|
- self.assertEqual(len(results), 1)
|
190
|
|
- self.assertEqual(results[0]['title'], 'Title')
|
191
|
|
- self.assertEqual(results[0]['url'], 'https://www.youtube.com/watch?v=DIVZCPfAOeM')
|
192
|
|
- self.assertEqual(results[0]['content'], 'Description')
|
193
|
|
- self.assertEqual(results[0]['thumbnail'], '')
|
194
|
|
- self.assertTrue('DIVZCPfAOeM' in results[0]['embedded'])
|
195
|
|
-
|
196
|
|
- json = """
|
197
|
|
- {"toto":{"entry":[]
|
198
|
|
- }
|
199
|
|
- }
|
200
|
|
- """
|
201
|
|
- response = mock.Mock(text=json)
|
202
|
|
- results = youtube.response(response)
|
203
|
|
- self.assertEqual(type(results), list)
|
204
|
|
- self.assertEqual(len(results), 0)
|