@@ -0,0 +1,90 @@
1+from collections import defaultdict
3+from searx.engines import duckduckgo
4+from searx.testing import SearxTestCase
7+class TestBingEngine(SearxTestCase):
9+ def test_request(self):
11+ dicto = defaultdict(dict)
13+ dicto['language'] = 'fr_FR'
14+ params = duckduckgo.request(query, dicto)
15+ self.assertIn('url', params)
16+ self.assertIn(query, params['url'])
17+ self.assertIn('duckduckgo.com', params['url'])
18+ self.assertIn('fr-fr', params['url'])
20+ dicto['language'] = 'all'
21+ params = duckduckgo.request(query, dicto)
22+ self.assertIn('en-us', params['url'])
24+ def test_response(self):
25+ self.assertRaises(AttributeError, duckduckgo.response, None)
26+ self.assertRaises(AttributeError, duckduckgo.response, [])
27+ self.assertRaises(AttributeError, duckduckgo.response, '')
28+ self.assertRaises(AttributeError, duckduckgo.response, '[]')
30+ response = mock.Mock(text='<html></html>')
31+ self.assertEqual(duckduckgo.response(response), [])
34+ <div class="results_links results_links_deep web-result">
35+ <div class="icon_fav" style="display: block;">
36+ <a rel="nofollow" href="https://www.test.com/">
37+ <img width="16" height="16" alt=""
38+ src="/i/www.test.com.ico" style="visibility: visible;" name="i15" />
41+ <div class="links_main links_deep"> <!-- This is the visible part -->
42+ <a rel="nofollow" class="large" href="http://this.should.be.the.link/">
43+ This <b>is</b> <b>the</b> title
45+ <div class="snippet"><b>This</b> should be the content.</div>
47+ http://this.should.be.the.link/
52+ response = mock.Mock(text=html)
53+ results = duckduckgo.response(response)
54+ self.assertEqual(type(results), list)
55+ self.assertEqual(len(results), 1)
56+ self.assertEqual(results[0]['title'], 'This is the title')
57+ self.assertEqual(results[0]['url'], 'http://this.should.be.the.link/')
58+ self.assertEqual(results[0]['content'], 'This should be the content.')
61+ <div class="results_links results_links_deep web-result">
62+ <div class="icon_fav" style="display: block;">
64+ <div class="links_main links_deep"> <!-- This is the visible part -->
65+ <div class="snippet"><b>This</b> should be the content.</div>
67+ http://this.should.be.the.link/
71+ <div class="results_links results_links_deep web-result">
72+ <div class="icon_fav" style="display: block;">
73+ <img width="16" height="16" alt=""
74+ src="/i/www.test.com.ico" style="visibility: visible;" name="i15" />
76+ <div class="links_main links_deep"> <!-- This is the visible part -->
77+ <a rel="nofollow" class="large" href="">
78+ This <b>is</b> <b>the</b> title
80+ <div class="snippet"><b>This</b> should be the content.</div>
82+ http://this.should.be.the.link/
87+ response = mock.Mock(text=html)
88+ results = duckduckgo.response(response)
89+ self.assertEqual(type(results), list)
90+ self.assertEqual(len(results), 0)