2017-07-22 05:17:28 +02:00
|
|
|
from collections import defaultdict
|
|
|
|
import mock
|
|
|
|
from searx.engines import google_videos
|
|
|
|
from searx.testing import SearxTestCase
|
|
|
|
|
|
|
|
|
|
|
|
class TestGoogleVideosEngine(SearxTestCase):
|
|
|
|
|
|
|
|
def test_request(self):
|
|
|
|
query = 'test_query'
|
|
|
|
dicto = defaultdict(dict)
|
|
|
|
dicto['pageno'] = 1
|
|
|
|
dicto['safesearch'] = 1
|
|
|
|
dicto['time_range'] = ''
|
|
|
|
params = google_videos.request(query, dicto)
|
|
|
|
self.assertIn('url', params)
|
|
|
|
self.assertIn(query, params['url'])
|
|
|
|
|
|
|
|
dicto['safesearch'] = 0
|
|
|
|
params = google_videos.request(query, dicto)
|
|
|
|
self.assertNotIn('safe', params['url'])
|
|
|
|
|
|
|
|
def test_response(self):
|
|
|
|
self.assertRaises(AttributeError, google_videos.response, None)
|
|
|
|
self.assertRaises(AttributeError, google_videos.response, [])
|
|
|
|
self.assertRaises(AttributeError, google_videos.response, '')
|
|
|
|
self.assertRaises(AttributeError, google_videos.response, '[]')
|
|
|
|
|
|
|
|
html = r"""
|
|
|
|
<div>
|
|
|
|
<div>
|
|
|
|
<div class="g">
|
2018-11-22 13:18:18 +01:00
|
|
|
<div class="r">
|
|
|
|
<a href="url_1"><h3>Title 1</h3></a>
|
2017-07-22 05:17:28 +02:00
|
|
|
</div>
|
2019-01-04 16:04:05 +01:00
|
|
|
<div class="s">
|
|
|
|
<div>
|
|
|
|
<a>
|
|
|
|
<g-img>
|
|
|
|
<img id="vidthumb1">
|
|
|
|
</g-img>
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
</div>
|
2017-07-22 05:17:28 +02:00
|
|
|
<div>
|
|
|
|
<span class="st">Content 1</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="g">
|
2018-11-22 13:18:18 +01:00
|
|
|
<div class="r">
|
|
|
|
<a href="url_2"><h3>Title 2</h3></a>
|
2017-07-22 05:17:28 +02:00
|
|
|
</div>
|
2019-01-04 16:04:05 +01:00
|
|
|
<div class="s">
|
|
|
|
<div>
|
|
|
|
<a>
|
|
|
|
<g-img>
|
|
|
|
<img id="vidthumb2">
|
|
|
|
</g-img>
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
</div>
|
2017-07-22 05:17:28 +02:00
|
|
|
<div>
|
|
|
|
<span class="st">Content 2</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2019-01-04 16:04:05 +01:00
|
|
|
<script>function _setImagesSrc(c,d,e){}</script>
|
2017-07-22 05:17:28 +02:00
|
|
|
"""
|
|
|
|
response = mock.Mock(text=html)
|
|
|
|
results = google_videos.response(response)
|
|
|
|
self.assertEqual(type(results), list)
|
|
|
|
self.assertEqual(len(results), 2)
|
|
|
|
self.assertEqual(results[0]['url'], u'url_1')
|
|
|
|
self.assertEqual(results[0]['title'], u'Title 1')
|
|
|
|
self.assertEqual(results[0]['content'], u'Content 1')
|
|
|
|
self.assertEqual(results[1]['url'], u'url_2')
|
|
|
|
self.assertEqual(results[1]['title'], u'Title 2')
|
|
|
|
self.assertEqual(results[1]['content'], u'Content 2')
|