on master help sign in
Add test case in wolframalpha_noapi

[fix] Display multiple answers in wolframalpha_api

commitd05c676ed5b1dc5372b1cb380740161b3613f7cc authora01200356 <a01200356@itesm.mx> dateSat 2 Jan 2016, 22:29 (11 years ago) parent19d025f
3 files changed+28−8
searx/engines/wolframalpha_api.py+6−5 searx/settings.yml+1−1 searx/tests/engines/test_wolframalpha_noapi.py+21−2
searx/engines/wolframalpha_api.py+6−5
@@ -52,12 +52,13 @@ def response(resp):
5252 if search_results.xpath(failure_xpath):
5353 return []
5454
55− # parse answer
56− answer = search_results.xpath(answer_xpath)
57− if answer:
58− answer = replace_pua_chars(answer[0].text)
55+ # parse answers
56+ answers = search_results.xpath(answer_xpath)
57+ if answers:
58+ for answer in answers:
59+ answer = replace_pua_chars(answer.text)
5960
60− results.append({'answer': answer})
61+ results.append({'answer': answer})
6162
6263 # TODO: append a result with title and link, like in the no api version
6364
searx/settings.yml+1−1
@@ -305,7 +305,7 @@ engines:
305305 # You can use the engine using the official stable API, but you need an API key
306306 # See : http://products.wolframalpha.com/api/
307307 # engine : wolframalpha_api
308− # api_key: 'apikey' # required!
308+ # api_key: '5952JX-X52L3VKWT8' # required!
309309 engine : wolframalpha_noapi
310310 timeout: 6.0
311311
searx/tests/engines/test_wolframalpha_noapi.py+21−2
@@ -22,8 +22,27 @@ class TestWolframAlphaNoAPIEngine(SearxTestCase):
2222 self.assertRaises(AttributeError, wolframalpha_noapi.response, '')
2323 self.assertRaises(AttributeError, wolframalpha_noapi.response, '[]')
2424
25− # response = mock.Mock(text='<html></html>')
26− # self.assertEqual(wolframalpha_noapi.response(response), [])
25+ html = """
26+ <!DOCTYPE html>
27+ <title> Parangaricutirimícuaro - Wolfram|Alpha</title>
28+ <meta charset="utf-8" />
29+ <body>
30+ <div id="closest">
31+ <p class="pfail">Wolfram|Alpha doesn't know how to interpret your input.</p>
32+ <div id="dtips">
33+ <div class="tip">
34+ <span class="tip-title">Tip:&nbsp;</span>
35+ Check your spelling, and use English
36+ <span class="tip-extra"></span>
37+ </div>
38+ </div>
39+ </div>
40+ </body>
41+ </html>
42+ """
43+
44+ response = mock.Mock(text=html)
45+ self.assertEqual(wolframalpha_noapi.response(response), [])
2746
2847 html = """
2948 <!DOCTYPE html>