summaryrefslogtreecommitdiff
path: root/searx
diff options
context:
space:
mode:
authorCqoicebordel <Cqoicebordel@users.noreply.github.com>2015-01-27 22:38:56 +0100
committerCqoicebordel <Cqoicebordel@users.noreply.github.com>2015-01-27 22:38:56 +0100
commit0f81aa8410623e790f4ad01b32e2b37f6258356a (patch)
tree472194c3e62235c378bfb206f6572af4657b8104 /searx
parenteca5de73a7f38958d3ba14930b42aaa5a5fbf989 (diff)
downloadsearxng-0f81aa8410623e790f4ad01b32e2b37f6258356a.tar.gz
searxng-0f81aa8410623e790f4ad01b32e2b37f6258356a.zip
Searchcode doc's test unit
Diffstat (limited to 'searx')
-rw-r--r--searx/tests/engines/test_searchcode_doc.py73
-rw-r--r--searx/tests/test_engines.py1
2 files changed, 74 insertions, 0 deletions
diff --git a/searx/tests/engines/test_searchcode_doc.py b/searx/tests/engines/test_searchcode_doc.py
new file mode 100644
index 000000000..b9dcf380b
--- /dev/null
+++ b/searx/tests/engines/test_searchcode_doc.py
@@ -0,0 +1,73 @@
+from collections import defaultdict
+import mock
+from searx.engines import searchcode_doc
+from searx.testing import SearxTestCase
+
+
+class TestSearchcodeDocEngine(SearxTestCase):
+
+ def test_request(self):
+ query = 'test_query'
+ dicto = defaultdict(dict)
+ dicto['pageno'] = 0
+ params = searchcode_doc.request(query, dicto)
+ self.assertIn('url', params)
+ self.assertIn(query, params['url'])
+ self.assertIn('searchcode.com', params['url'])
+
+ def test_response(self):
+ self.assertRaises(AttributeError, searchcode_doc.response, None)
+ self.assertRaises(AttributeError, searchcode_doc.response, [])
+ self.assertRaises(AttributeError, searchcode_doc.response, '')
+ self.assertRaises(AttributeError, searchcode_doc.response, '[]')
+
+ response = mock.Mock(text='{}')
+ self.assertEqual(searchcode_doc.response(response), [])
+
+ response = mock.Mock(text='{"data": []}')
+ self.assertEqual(searchcode_doc.response(response), [])
+
+ json = """
+ {
+ "matchterm": "test",
+ "previouspage": null,
+ "searchterm": "test",
+ "query": "test",
+ "total": 60,
+ "page": 0,
+ "nextpage": 1,
+ "results": [
+ {
+ "synopsis": "Synopsis",
+ "displayname": null,
+ "name": "test",
+ "url": "http://url",
+ "type": "Type",
+ "icon": null,
+ "namespace": "Namespace",
+ "description": "Description"
+ }
+ ]
+ }
+ """
+ response = mock.Mock(text=json)
+ results = searchcode_doc.response(response)
+ self.assertEqual(type(results), list)
+ self.assertEqual(len(results), 1)
+ self.assertEqual(results[0]['title'], '[Type] Namespace test')
+ self.assertEqual(results[0]['url'], 'http://url')
+ self.assertIn('Synopsis', results[0]['content'])
+ self.assertIn('Type', results[0]['content'])
+ self.assertIn('test', results[0]['content'])
+ self.assertIn('Description', results[0]['content'])
+
+ json = """
+ {"toto":[
+ {"id":200,"name":"Artist Name",
+ "link":"http:\/\/www.searchcode_doc.com\/artist\/1217","type":"artist"}
+ ]}
+ """
+ response = mock.Mock(text=json)
+ results = searchcode_doc.response(response)
+ self.assertEqual(type(results), list)
+ self.assertEqual(len(results), 0)
diff --git a/searx/tests/test_engines.py b/searx/tests/test_engines.py
index e7648bc08..f46e3dc2a 100644
--- a/searx/tests/test_engines.py
+++ b/searx/tests/test_engines.py
@@ -5,4 +5,5 @@ from searx.tests.engines.test_flickr import * # noqa
from searx.tests.engines.test_github import * # noqa
from searx.tests.engines.test_mixcloud import * # noqa
from searx.tests.engines.test_searchcode_code import * # noqa
+from searx.tests.engines.test_searchcode_doc import * # noqa
from searx.tests.engines.test_youtube import * # noqa