summaryrefslogtreecommitdiff
path: root/tests/unit
diff options
context:
space:
mode:
authormarc <a01200356@itesm.mx>2017-05-20 22:33:08 -0500
committerAdam Tauber <asciimoo@gmail.com>2017-05-23 20:07:09 +0200
commitc65a409f0d2728ba5a0c3ffa1a0cb05659033a71 (patch)
tree7c56b415c5693544b08d32afcf1c1c073b273545 /tests/unit
parente60e98156f9aeeb40ca7272c883704c095d9f7d4 (diff)
downloadsearxng-c65a409f0d2728ba5a0c3ffa1a0cb05659033a71.tar.gz
searxng-c65a409f0d2728ba5a0c3ffa1a0cb05659033a71.zip
add duckduckgo images engine
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/engines/test_duckduckgo_images.py72
1 files changed, 72 insertions, 0 deletions
diff --git a/tests/unit/engines/test_duckduckgo_images.py b/tests/unit/engines/test_duckduckgo_images.py
new file mode 100644
index 000000000..5f94e3c2b
--- /dev/null
+++ b/tests/unit/engines/test_duckduckgo_images.py
@@ -0,0 +1,72 @@
+# -*- coding: utf-8 -*-
+from collections import defaultdict
+import mock
+from searx.engines import duckduckgo_images
+from searx.testing import SearxTestCase
+
+
+class TestDuckduckgoImagesEngine(SearxTestCase):
+
+ def test_request(self):
+ query = 'test_query'
+ dicto = defaultdict(dict)
+ dicto['is_test'] = True
+ dicto['pageno'] = 1
+ dicto['safesearch'] = 0
+ dicto['language'] = 'all'
+ params = duckduckgo_images.request(query, dicto)
+ self.assertIn('url', params)
+ self.assertIn(query, params['url'])
+ self.assertIn('duckduckgo.com', params['url'])
+ self.assertIn('s=0', params['url'])
+ self.assertIn('p=-1', params['url'])
+ self.assertIn('vqd=12345', params['url'])
+
+ # test paging and safe search
+ dicto['pageno'] = 2
+ dicto['safesearch'] = 2
+ params = duckduckgo_images.request(query, dicto)
+ self.assertIn('url', params)
+ self.assertIn(query, params['url'])
+ self.assertIn('s=50', params['url'])
+ self.assertIn('p=1', params['url'])
+
+ def test_response(self):
+ self.assertRaises(AttributeError, duckduckgo_images.response, None)
+ self.assertRaises(AttributeError, duckduckgo_images.response, [])
+ self.assertRaises(AttributeError, duckduckgo_images.response, '')
+ self.assertRaises(AttributeError, duckduckgo_images.response, '[]')
+
+ response = mock.Mock(text='If this error persists, please let us know: ops@duckduckgo.com')
+ self.assertEqual(duckduckgo_images.response(response), [])
+
+ json = u"""
+ {
+ "query": "test_query",
+ "results": [
+ {
+ "title": "Result 1",
+ "url": "https://site1.url",
+ "thumbnail": "https://thumb1.nail",
+ "image": "https://image1"
+ },
+ {
+ "title": "Result 2",
+ "url": "https://site2.url",
+ "thumbnail": "https://thumb2.nail",
+ "image": "https://image2"
+ }
+ ]
+ }
+ """
+ response = mock.Mock(text=json)
+ results = duckduckgo_images.response(response)
+ self.assertEqual(len(results), 2)
+ self.assertEqual(results[0]['title'], 'Result 1')
+ self.assertEqual(results[0]['url'], 'https://site1.url')
+ self.assertEqual(results[0]['thumbnail_src'], 'https://thumb1.nail')
+ self.assertEqual(results[0]['img_src'], 'https://image1')
+ self.assertEqual(results[1]['title'], 'Result 2')
+ self.assertEqual(results[1]['url'], 'https://site2.url')
+ self.assertEqual(results[1]['thumbnail_src'], 'https://thumb2.nail')
+ self.assertEqual(results[1]['img_src'], 'https://image2')