@@ -0,0 +1,96 @@
1+from collections import defaultdict
3+from searx.engines import yacy
4+from searx.testing import SearxTestCase
7+class TestYacyEngine(SearxTestCase):
9+ def test_request(self):
11+ dicto = defaultdict(dict)
13+ dicto['language'] = 'fr_FR'
14+ params = yacy.request(query, dicto)
15+ self.assertIn('url', params)
16+ self.assertIn(query, params['url'])
17+ self.assertIn('localhost', params['url'])
18+ self.assertIn('fr', params['url'])
20+ dicto['language'] = 'all'
21+ params = yacy.request(query, dicto)
22+ self.assertIn('url', params)
23+ self.assertNotIn('lr=lang_', params['url'])
25+ def test_response(self):
26+ self.assertRaises(AttributeError, yacy.response, None)
27+ self.assertRaises(AttributeError, yacy.response, [])
28+ self.assertRaises(AttributeError, yacy.response, '')
29+ self.assertRaises(AttributeError, yacy.response, '[]')
31+ response = mock.Mock(text='{}')
32+ self.assertEqual(yacy.response(response), [])
34+ response = mock.Mock(text='{"data": []}')
35+ self.assertEqual(yacy.response(response), [])
41+ "title": "YaCy P2P-Search for test",
42+ "description": "Search for test",
43+ "link": "http://search.yacy.de:7001/yacysearch.html?query=test&resource=global&contentdom=0",
45+ "url": "http://search.yacy.de:7001/env/grafics/yacy.png",
46+ "title": "Search for test",
47+ "link": "http://search.yacy.de:7001/yacysearch.html?query=test&resource=global&contentdom=0"
49+ "totalResults": "249",
52+ "searchTerms": "test",
55+ "title": "This is the title",
56+ "link": "http://this.is.the.url",
58+ "description": "This should be the content",
59+ "pubDate": "Sat, 08 Jun 2013 02:00:00 +0200",
61+ "sizename": "43 kbyte",
62+ "guid": "lzh_1T_5FP-A",
63+ "faviconCode": "XTS4uQ_5FP-A",
64+ "host": "www.gamestar.de",
65+ "path": "/spiele/city-of-heroes-freedom/47019.html",
66+ "file": "47019.html",
67+ "urlhash": "lzh_1T_5FP-A",
68+ "ranking": "0.20106804"
71+ "title": "This is the title2",
72+ "icon": "/ViewImage.png?maxwidth=96&maxheight=96&code=7EbAbW6BpPOA",
73+ "image": "http://image.url/image.png",
74+ "cache": "/ViewImage.png?quadratic=&url=http://golem.ivwbox.de/cgi-bin/ivw/CP/G_INET?d=14071378",
75+ "url": "http://this.is.the.url",
76+ "urlhash": "7EbAbW6BpPOA",
77+ "host": "www.golem.de",
86+ response = mock.Mock(text=json)
87+ results = yacy.response(response)
88+ self.assertEqual(type(results), list)
89+ self.assertEqual(len(results), 2)
90+ self.assertEqual(results[0]['title'], 'This is the title')
91+ self.assertEqual(results[0]['url'], 'http://this.is.the.url')
92+ self.assertEqual(results[0]['content'], 'This should be the content')
93+ self.assertEqual(results[1]['img_src'], 'http://image.url/image.png')
94+ self.assertEqual(results[1]['content'], '')
95+ self.assertEqual(results[1]['url'], 'http://this.is.the.url')
96+ self.assertEqual(results[1]['title'], 'This is the title2')