Browse Source

Add test case in wolframalpha_noapi

[fix] Display multiple answers in wolframalpha_api
a01200356 9 years ago
parent
commit
d05c676ed5

+ 6
- 5
searx/engines/wolframalpha_api.py View File

@@ -52,12 +52,13 @@ def response(resp):
52 52
     if search_results.xpath(failure_xpath):
53 53
         return []
54 54
 
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)
59 60
 
60
-        results.append({'answer': answer})
61
+            results.append({'answer': answer})
61 62
 
62 63
     # TODO: append a result with title and link, like in the no api version
63 64
 

+ 1
- 1
searx/settings.yml View File

@@ -305,7 +305,7 @@ engines:
305 305
     # You can use the engine using the official stable API, but you need an API key
306 306
     # See : http://products.wolframalpha.com/api/
307 307
     #    engine : wolframalpha_api
308
-    #    api_key: 'apikey' # required!
308
+    #    api_key: '5952JX-X52L3VKWT8' # required!
309 309
     engine : wolframalpha_noapi
310 310
     timeout: 6.0
311 311
 

+ 21
- 2
searx/tests/engines/test_wolframalpha_noapi.py View File

@@ -22,8 +22,27 @@ class TestWolframAlphaNoAPIEngine(SearxTestCase):
22 22
         self.assertRaises(AttributeError, wolframalpha_noapi.response, '')
23 23
         self.assertRaises(AttributeError, wolframalpha_noapi.response, '[]')
24 24
 
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), [])
27 46
 
28 47
         html = """
29 48
         <!DOCTYPE html>