summaryrefslogtreecommitdiff
path: root/tests/unit
diff options
context:
space:
mode:
authormarc <a01200356@itesm.mx>2017-07-21 22:17:28 -0500
committerAdam Tauber <asciimoo@gmail.com>2017-07-26 15:49:16 +0200
commit856dfc3018083d62308f18f36b50e5b0d767edf6 (patch)
tree88aaeef52b108835db607aafe68337133a4632e7 /tests/unit
parent081f51db4ef057e34fc1b9934d0c0cc19427f512 (diff)
downloadsearxng-856dfc3018083d62308f18f36b50e5b0d767edf6.tar.gz
searxng-856dfc3018083d62308f18f36b50e5b0d767edf6.zip
add google videos
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/engines/test_google_videos.py60
1 files changed, 60 insertions, 0 deletions
diff --git a/tests/unit/engines/test_google_videos.py b/tests/unit/engines/test_google_videos.py
new file mode 100644
index 000000000..a48e9a755
--- /dev/null
+++ b/tests/unit/engines/test_google_videos.py
@@ -0,0 +1,60 @@
+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">
+ <div>
+ <h3><a href="url_1">Title 1</h3>
+ </div>
+ <div>
+ <span class="st">Content 1</span>
+ </div>
+ </div>
+ <div class="g">
+ <div>
+ <h3><a href="url_2">Title 2</h3>
+ </div>
+ <div>
+ <span class="st">Content 2</span>
+ </div>
+ </div>
+ </div>
+ </div>
+ """
+ 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')