@@ -0,0 +1,116 @@
1+# -*- coding: utf-8 -*-
2+from collections import defaultdict
4+from searx.engines import faroo
5+from searx.testing import SearxTestCase
8+class TestFarooEngine(SearxTestCase):
10+ def test_request(self):
12+ dicto = defaultdict(dict)
14+ dicto['language'] = 'fr_FR'
15+ dicto['category'] = 'general'
16+ params = faroo.request(query, dicto)
17+ self.assertIn('url', params)
18+ self.assertIn(query, params['url'])
19+ self.assertIn('faroo.com', params['url'])
20+ self.assertIn('en', params['url'])
21+ self.assertIn('web', params['url'])
23+ dicto['language'] = 'all'
24+ params = faroo.request(query, dicto)
25+ self.assertIn('en', params['url'])
27+ dicto['language'] = 'de_DE'
28+ params = faroo.request(query, dicto)
29+ self.assertIn('de', params['url'])
31+ def test_response(self):
32+ self.assertRaises(AttributeError, faroo.response, None)
33+ self.assertRaises(AttributeError, faroo.response, [])
34+ self.assertRaises(AttributeError, faroo.response, '')
35+ self.assertRaises(AttributeError, faroo.response, '[]')
37+ response = mock.Mock(text='{}')
38+ self.assertEqual(faroo.response(response), [])
40+ response = mock.Mock(text='{"data": []}')
41+ self.assertEqual(faroo.response(response), [])
43+ response = mock.Mock(text='{"data": []}', status_code=401)
44+ self.assertRaises(Exception, faroo.response, response)
46+ response = mock.Mock(text='{"data": []}', status_code=429)
47+ self.assertRaises(Exception, faroo.response, response)
53+ "title": "This is the title",
54+ "kwic": "This is the content",
56+ "url": "http://this.is.the.url/",
58+ "domain": "css3test.com",
59+ "author": "Jim Dalrymple",
62+ "date": 1360622563000,
66+ "title": "This is the title2",
67+ "kwic": "This is the content2",
69+ "url": "http://this.is.the.url2/",
71+ "domain": "css3test.com",
72+ "author": "Jim Dalrymple",
78+ "title": "This is the title3",
79+ "kwic": "This is the content3",
81+ "url": "http://this.is.the.url3/",
82+ "iurl": "http://upload.wikimedia.org/optimized.jpg",
83+ "domain": "css3test.com",
84+ "author": "Jim Dalrymple",
98+ response = mock.Mock(text=json)
99+ results = faroo.response(response)
100+ self.assertEqual(type(results), list)
101+ self.assertEqual(len(results), 4)
102+ self.assertEqual(results[0]['title'], 'This is the title')
103+ self.assertEqual(results[0]['url'], 'http://this.is.the.url/')
104+ self.assertEqual(results[0]['content'], 'This is the content')
105+ self.assertEqual(results[1]['title'], 'This is the title2')
106+ self.assertEqual(results[1]['url'], 'http://this.is.the.url2/')
107+ self.assertEqual(results[1]['content'], 'This is the content2')
108+ self.assertEqual(results[3]['img_src'], 'http://upload.wikimedia.org/optimized.jpg')
113+ response = mock.Mock(text=json)
114+ results = faroo.response(response)
115+ self.assertEqual(type(results), list)
116+ self.assertEqual(len(results), 0)