@@ -0,0 +1,75 @@
1+from collections import defaultdict
3+from searx.engines import searchcode_code
4+from searx.testing import SearxTestCase
7+class TestSearchcodeCodeEngine(SearxTestCase):
9+ def test_request(self):
11+ dicto = defaultdict(dict)
13+ params = searchcode_code.request(query, dicto)
14+ self.assertIn('url', params)
15+ self.assertIn(query, params['url'])
16+ self.assertIn('searchcode.com', params['url'])
18+ def test_response(self):
19+ self.assertRaises(AttributeError, searchcode_code.response, None)
20+ self.assertRaises(AttributeError, searchcode_code.response, [])
21+ self.assertRaises(AttributeError, searchcode_code.response, '')
22+ self.assertRaises(AttributeError, searchcode_code.response, '[]')
24+ response = mock.Mock(text='{}')
25+ self.assertEqual(searchcode_code.response(response), [])
27+ response = mock.Mock(text='{"data": []}')
28+ self.assertEqual(searchcode_code.response(response), [])
33+ "previouspage": null,
34+ "searchterm": "test",
41+ "repo": "https://repo",
43+ "location": "/tests",
45+ "url": "https://url",
46+ "md5hash": "ecac6e479edd2b9406c9e08603cec655",
52+ "filename": "File.CPP"
57+ response = mock.Mock(text=json)
58+ results = searchcode_code.response(response)
59+ self.assertEqual(type(results), list)
60+ self.assertEqual(len(results), 1)
61+ self.assertEqual(results[0]['title'], 'Name - File.CPP')
62+ self.assertEqual(results[0]['url'], 'https://url')
63+ self.assertEqual(results[0]['repository'], 'https://repo')
64+ self.assertEqual(results[0]['code_language'], 'cpp')
68+ {"id":200,"name":"Artist Name",
69+ "link":"http:\/\/www.searchcode_code.com\/artist\/1217","type":"artist"}
72+ response = mock.Mock(text=json)
73+ results = searchcode_code.response(response)
74+ self.assertEqual(type(results), list)
75+ self.assertEqual(len(results), 0)