summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCqoicebordel <Cqoicebordel@users.noreply.github.com>2015-01-27 22:37:11 +0100
committerCqoicebordel <Cqoicebordel@users.noreply.github.com>2015-01-27 22:37:11 +0100
commiteca5de73a7f38958d3ba14930b42aaa5a5fbf989 (patch)
treea3556b6d4bd2bd928dc21b57dafc076fb967a1a4
parentcfe81d741cdd2517c4587071e4afbdd0adb923bd (diff)
Searchcode code's test unit
-rw-r--r--searx/tests/engines/test_searchcode_code.py75
-rw-r--r--searx/tests/test_engines.py1
2 files changed, 76 insertions, 0 deletions
diff --git a/searx/tests/engines/test_searchcode_code.py b/searx/tests/engines/test_searchcode_code.py
new file mode 100644
index 000000000..c0ac2025c
--- /dev/null
+++ b/searx/tests/engines/test_searchcode_code.py
@@ -0,0 +1,75 @@
+from collections import defaultdict
+import mock
+from searx.engines import searchcode_code
+from searx.testing import SearxTestCase
+
+
+class TestSearchcodeCodeEngine(SearxTestCase):
+
+ def test_request(self):
+ query = 'test_query'
+ dicto = defaultdict(dict)
+ dicto['pageno'] = 0
+ params = searchcode_code.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_code.response, None)
+ self.assertRaises(AttributeError, searchcode_code.response, [])
+ self.assertRaises(AttributeError, searchcode_code.response, '')
+ self.assertRaises(AttributeError, searchcode_code.response, '[]')
+
+ response = mock.Mock(text='{}')
+ self.assertEqual(searchcode_code.response(response), [])
+
+ response = mock.Mock(text='{"data": []}')
+ self.assertEqual(searchcode_code.response(response), [])
+
+ json = """
+ {
+ "matchterm": "test",
+ "previouspage": null,
+ "searchterm": "test",
+ "query": "test",
+ "total": 1000,
+ "page": 0,
+ "nextpage": 1,
+ "results": [
+ {
+ "repo": "https://repo",
+ "linescount": 1044,
+ "location": "/tests",
+ "name": "Name",
+ "url": "https://url",
+ "md5hash": "ecac6e479edd2b9406c9e08603cec655",
+ "lines": {
+ "1": "// Test 011",
+ "2": "// Source: "
+ },
+ "id": 51223527,
+ "filename": "File.CPP"
+ }
+ ]
+ }
+ """
+ response = mock.Mock(text=json)
+ results = searchcode_code.response(response)
+ self.assertEqual(type(results), list)
+ self.assertEqual(len(results), 1)
+ self.assertEqual(results[0]['title'], 'Name - File.CPP')
+ self.assertEqual(results[0]['url'], 'https://url')
+ self.assertEqual(results[0]['repository'], 'https://repo')
+ self.assertEqual(results[0]['code_language'], 'cpp')
+
+ json = """
+ {"toto":[
+ {"id":200,"name":"Artist Name",
+ "link":"http:\/\/www.searchcode_code.com\/artist\/1217","type":"artist"}
+ ]}
+ """
+ response = mock.Mock(text=json)
+ results = searchcode_code.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 b99c30070..e7648bc08 100644
--- a/searx/tests/test_engines.py
+++ b/searx/tests/test_engines.py
@@ -4,4 +4,5 @@ from searx.tests.engines.test_dummy import * # noqa
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_youtube import * # noqa