From d05c676ed5b1dc5372b1cb380740161b3613f7cc Mon Sep 17 00:00:00 2001 From: a01200356 Date: Sat, 2 Jan 2016 22:29:20 -0600 Subject: [PATCH] Add test case in wolframalpha_noapi [fix] Display multiple answers in wolframalpha_api --- searx/engines/wolframalpha_api.py | 11 +++++---- searx/settings.yml | 2 +- .../tests/engines/test_wolframalpha_noapi.py | 23 +++++++++++++++++-- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/searx/engines/wolframalpha_api.py b/searx/engines/wolframalpha_api.py index d4127be4c..540d81351 100644 --- a/searx/engines/wolframalpha_api.py +++ b/searx/engines/wolframalpha_api.py @@ -52,12 +52,13 @@ def response(resp): if search_results.xpath(failure_xpath): return [] - # parse answer - answer = search_results.xpath(answer_xpath) - if answer: - answer = replace_pua_chars(answer[0].text) + # parse answers + answers = search_results.xpath(answer_xpath) + if answers: + for answer in answers: + answer = replace_pua_chars(answer.text) - results.append({'answer': answer}) + results.append({'answer': answer}) # TODO: append a result with title and link, like in the no api version diff --git a/searx/settings.yml b/searx/settings.yml index 2c327184e..600c20c0d 100644 --- a/searx/settings.yml +++ b/searx/settings.yml @@ -305,7 +305,7 @@ engines: # You can use the engine using the official stable API, but you need an API key # See : http://products.wolframalpha.com/api/ # engine : wolframalpha_api - # api_key: 'apikey' # required! + # api_key: '5952JX-X52L3VKWT8' # required! engine : wolframalpha_noapi timeout: 6.0 diff --git a/searx/tests/engines/test_wolframalpha_noapi.py b/searx/tests/engines/test_wolframalpha_noapi.py index 5815e52fe..b2ae5469e 100644 --- a/searx/tests/engines/test_wolframalpha_noapi.py +++ b/searx/tests/engines/test_wolframalpha_noapi.py @@ -22,8 +22,27 @@ class TestWolframAlphaNoAPIEngine(SearxTestCase): self.assertRaises(AttributeError, wolframalpha_noapi.response, '') self.assertRaises(AttributeError, wolframalpha_noapi.response, '[]') - # response = mock.Mock(text='') - # self.assertEqual(wolframalpha_noapi.response(response), []) + html = """ + + Parangaricutirimícuaro - Wolfram|Alpha + + +
+

Wolfram|Alpha doesn't know how to interpret your input.

+
+
+ Tip:  + Check your spelling, and use English + +
+
+
+ + + """ + + response = mock.Mock(text=html) + self.assertEqual(wolframalpha_noapi.response(response), []) html = """