@@ -0,0 +1,232 @@
1+# -*- coding: utf-8 -*-
2+from collections import defaultdict
4+from searx.engines import wolframalpha_noapi
5+from searx.testing import SearxTestCase
8+class TestWolframAlphaNoAPIEngine(SearxTestCase):
10+ def test_request(self):
12+ dicto = defaultdict(dict)
14+ params = wolframalpha_noapi.request(query, dicto)
15+ self.assertIn('url', params)
16+ self.assertIn(query, params['url'])
17+ self.assertIn('wolframalpha.com', params['url'])
19+ def test_response(self):
20+ self.assertRaises(AttributeError, wolframalpha_noapi.response, None)
21+ self.assertRaises(AttributeError, wolframalpha_noapi.response, [])
22+ self.assertRaises(AttributeError, wolframalpha_noapi.response, '')
23+ self.assertRaises(AttributeError, wolframalpha_noapi.response, '[]')
25+ response = mock.Mock(text='<html></html>')
26+ self.assertEqual(wolframalpha_noapi.response(response), [])
30+ <title> sqrt(-1) - Wolfram|Alpha</title>
31+ <meta charset="utf-8" />
33+ <script type="text/javascript">
35+ document.domain = "wolframalpha.com";
36+ context = parent ? parent : document;
39+ if (typeof(context.$) == "undefined") {
45+ catch(e){ context = window;}
49+ if (typeof context.jsonArray.popups.pod_0100 == "undefined" ) {
50+ context.jsonArray.popups.pod_0100 = [];
53+ context.jsonArray.popups.pod_0100.push( {"stringified": "sqrt(-1)","mInput": "","mOutput": "", "popLinks": {} });
59+ $("#results #pod_0100:not(iframe #pod_0100)")
60+ .add("#showsteps #pod_0100:not(iframe #pod_0100)")
61+ .add(".results-pod #pod_0100:not(iframe #pod_0100)")
62+ .data("tempFileID", 'MSP44501e0dda34g97a0c8900003i71207d6491ab22')
63+ .data("podIdentifier", '\x22Input\x22')
64+ .data("podShortIdentifier", '\x22Input\x22')
65+ .data("buttonStates", '\x22\x22')
66+ .data("scanner", '\x22\x22');
67+ $("#results #pod_0100-popup:not(iframe #pod_0100-popup)")
68+ .add("#showsteps #pod_0100-popup:not(iframe #pod_0100-popup)")
69+ .add(".results-pod #pod_0100-popup:not(iframe #pod_0100-popup)")
70+ .data("tempFileID", 'MSP44501e0dda34g97a0c8900003i71207d6491ab22')
71+ .data("podIdentifier", '\x22Input\x22')
72+ .data("podShortIdentifier", '\x22Input\x22')
73+ .data("buttonStates", '\x22\x22')
74+ .data("scanner", '\x22\x22');
76+ $("#results #subpod_0100_1")
77+ .add("#showsteps #subpod_0100_1:not(iframe #subpod_0100_1)")
78+ .add(".results-pod #subpod_0100_1")
79+ .data("tempFileID", "MSP44511e0dda34g97a0c89000059490h319161eea3")
80+ .data("cellDataTempFile", "MSP44521e0dda34g97a0c89000011378c50d38ede6h")
81+ .data("tempFileServer", "")
82+ .data("dataSources", "")
84+ .data("sharetype", "1")
85+ .data("shareable", "false");
93+ if (typeof context.jsonArray.popups.pod_0200 == "undefined" ) {
94+ context.jsonArray.popups.pod_0200 = [];
97+ context.jsonArray.popups.pod_0200.push( {"stringified": "i","mInput": "","mOutput": "", "popLinks": {} });
103+ $("#results #pod_0200:not(iframe #pod_0200)")
104+ .add("#showsteps #pod_0200:not(iframe #pod_0200)")
105+ .add(".results-pod #pod_0200:not(iframe #pod_0200)")
106+ .data("tempFileID", 'MSP44541e0dda34g97a0c8900004f449i50fa482fd8')
107+ .data("podIdentifier", '\x22Result\x22')
108+ .data("podShortIdentifier", '\x22Result\x22')
109+ .data("buttonStates", '\x22Result\x22\x20\x2D\x3E\x20\x7BAll,\x20None,\x20None,\x20None,\x20None\x7D')
110+ .data("scanner", '\x22\x22');
111+ $("#results #pod_0200-popup:not(iframe #pod_0200-popup)")
112+ .add("#showsteps #pod_0200-popup:not(iframe #pod_0200-popup)")
113+ .add(".results-pod #pod_0200-popup:not(iframe #pod_0200-popup)")
114+ .data("tempFileID", 'MSP44541e0dda34g97a0c8900004f449i50fa482fd8')
115+ .data("podIdentifier", '\x22Result\x22')
116+ .data("podShortIdentifier", '\x22Result\x22')
117+ .data("buttonStates", '\x22Result\x22\x20\x2D\x3E\x20\x7BAll,\x20None,\x20None\x7D')
118+ .data("scanner", '\x22\x22');
120+ $("#results #subpod_0200_1")
121+ .add("#showsteps #subpod_0200_1:not(iframe #subpod_0200_1)")
122+ .add(".results-pod #subpod_0200_1")
123+ .data("tempFileID", "MSP44551e0dda34g97a0c8900003gdgd37faa7272e0")
124+ .data("cellDataTempFile", "MSP44561e0dda34g97a0c89000018ea1iae00104g13")
125+ .data("tempFileServer", "")
126+ .data("dataSources", "")
127+ .data("sources", "")
128+ .data("sharetype", "1")
129+ .data("shareable", "false");
135+ response = mock.Mock(text=html)
136+ results = wolframalpha_noapi.response(response)
137+ self.assertEqual(type(results), list)
138+ self.assertEqual(len(results), 1)
139+ self.assertIn("i", results[0]['answer'])
143+ <title> integral 1/x - Wolfram|Alpha</title>
144+ <meta charset="utf-8" />
146+ <script type="text/javascript">
149+ document.domain = "wolframalpha.com";
150+ context = parent ? parent : document;
153+ if (typeof(context.$) == "undefined") {
159+ catch(e){ context = window;}
163+ if (typeof context.jsonArray.popups.pod_0100 == "undefined" ) {
164+ context.jsonArray.popups.pod_0100 = [];
167+ context.jsonArray.popups.pod_0100.push( {"stringified": "integral 1\/x dx = log(x)+constant"});
173+ $("#results #pod_0100:not(iframe #pod_0100)")
174+ .add("#showsteps #pod_0100:not(iframe #pod_0100)")
175+ .add(".results-pod #pod_0100:not(iframe #pod_0100)")
176+ .data("tempFileID", 'MSP2051if2202e8bg0757100000d119b05egf583d3')
177+ .data("podIdentifier", '\x22IndefiniteIntegral\x22')
178+ .data("podShortIdentifier", '\x22IndefiniteIntegral\x22')
179+ .data("buttonStates", '\x22Indefinite\x20integral\x22\x20\x2D\x3E\x20\x7B\x7D')
180+ .data("scanner", '\x22\x22');
181+ $("#results #pod_0100-popup:not(iframe #pod_0100-popup)")
182+ .add("#showsteps #pod_0100-popup:not(iframe #pod_0100-popup)")
183+ .add(".results-pod #pod_0100-popup:not(iframe #pod_0100-popup)")
184+ .data("tempFileID", 'MSP2051if2202e8bg0757100000d119b05egf583d3')
185+ .data("podIdentifier", '\x22IndefiniteIntegral\x22')
186+ .data("podShortIdentifier", '\x22IndefiniteIntegral\x22')
187+ .data("buttonStates", '\x22Indefinite\x20integral\x22\x20\x2D\x3E\x20\x7B\x7D')
188+ .data("scanner", '\x22\x22');
190+ $("#results #subpod_0100_1")
191+ .add("#showsteps #subpod_0100_1:not(iframe #subpod_0100_1)")
192+ .add(".results-pod #subpod_0100_1")
193+ .data("tempFileID", "MSP2071if2202e8bg0757100004dg60f2a4ca8cf73")
194+ .data("cellDataTempFile", "MSP2081if2202e8bg0757100001h18329f72fe90fg")
195+ .data("tempFileServer", "")
196+ .data("dataSources", "")
197+ .data("sources", "")
198+ .data("sharetype", "1")
199+ .data("shareable", "false");
206+ $("#results #pod_0200:not(iframe #pod_0200)")
207+ .add("#showsteps #pod_0200:not(iframe #pod_0200)")
208+ .add(".results-pod #pod_0200:not(iframe #pod_0200)")
209+ .data("tempFileID", '')
210+ .data("podIdentifier", '\x22Plot\x22')
211+ .data("podShortIdentifier", '')
212+ .data("buttonStates", '')
213+ .data("scanner", '\x22\x22');
214+ $("#results #pod_0200-popup:not(iframe #pod_0200-popup)")
215+ .add("#showsteps #pod_0200-popup:not(iframe #pod_0200-popup)")
216+ .add(".results-pod #pod_0200-popup:not(iframe #pod_0200-popup)")
217+ .data("tempFileID", '')
218+ .data("podIdentifier", '\x22Plot\x22')
219+ .data("podShortIdentifier", '')
220+ .data("buttonStates", '')
221+ .data("scanner", '\x22\x22');
228+ response = mock.Mock(text=html)
229+ results = wolframalpha_noapi.response(response)
230+ self.assertEqual(type(results), list)
231+ self.assertEqual(len(results), 1)
232+ self.assertIn("log(x)+c", results[0]['answer'])