@@ -40,7 +40,7 @@ class TestWolframAlphaNoAPIEngine(SearxTestCase):
4040 </body>
4141 </html>
4242 """
43−
43+ # test failed query
4444 response = mock.Mock(text=html)
4545 self.assertEqual(wolframalpha_noapi.response(response), [])
4646
@@ -51,113 +51,30 @@ class TestWolframAlphaNoAPIEngine(SearxTestCase):
5151 <body>
5252 <script type="text/javascript">
5353 try {
54− document.domain = "wolframalpha.com";
55− context = parent ? parent : document;
56− } catch(e){}
57− try {
58− if (typeof(context.$) == "undefined") {
59− context = window;
60− } else {
61− $=context.$;
54+ if (typeof context.jsonArray.popups.pod_0100 == "undefined" ) {
55+ context.jsonArray.popups.pod_0100 = [];
6256 }
63− }
64− catch(e){ context = window;}
65−
66− try {
67−
68− if (typeof context.jsonArray.popups.pod_0100 == "undefined" ) {
69− context.jsonArray.popups.pod_0100 = [];
70− }
71−
72− context.jsonArray.popups.pod_0100.push( {"stringified": "sqrt(-1)","mInput": "","mOutput": "", "popLinks": {} });
73−
74− } catch(e) { }
75−
76− try {
77−
78− $("#results #pod_0100:not(iframe #pod_0100)")
79− .add("#showsteps #pod_0100:not(iframe #pod_0100)")
80− .add(".results-pod #pod_0100:not(iframe #pod_0100)")
81− .data("tempFileID", 'MSP44501e0dda34g97a0c8900003i71207d6491ab22')
82− .data("podIdentifier", '\x22Input\x22')
83− .data("podShortIdentifier", '\x22Input\x22')
84− .data("buttonStates", '\x22\x22')
85− .data("scanner", '\x22\x22');
86− $("#results #pod_0100-popup:not(iframe #pod_0100-popup)")
87− .add("#showsteps #pod_0100-popup:not(iframe #pod_0100-popup)")
88− .add(".results-pod #pod_0100-popup:not(iframe #pod_0100-popup)")
89− .data("tempFileID", 'MSP44501e0dda34g97a0c8900003i71207d6491ab22')
90− .data("podIdentifier", '\x22Input\x22')
91− .data("podShortIdentifier", '\x22Input\x22')
92− .data("buttonStates", '\x22\x22')
93− .data("scanner", '\x22\x22');
94−
95− $("#results #subpod_0100_1")
96− .add("#showsteps #subpod_0100_1:not(iframe #subpod_0100_1)")
97− .add(".results-pod #subpod_0100_1")
98− .data("tempFileID", "MSP44511e0dda34g97a0c89000059490h319161eea3")
99− .data("cellDataTempFile", "MSP44521e0dda34g97a0c89000011378c50d38ede6h")
100− .data("tempFileServer", "")
101− .data("dataSources", "")
102− .data("sources", "")
103− .data("sharetype", "1")
104− .data("shareable", "false");
105−
106− } catch(e){}
107−
108− //false
109−
110− try {
111−
112− if (typeof context.jsonArray.popups.pod_0200 == "undefined" ) {
113− context.jsonArray.popups.pod_0200 = [];
114− }
115−
116− context.jsonArray.popups.pod_0200.push( {"stringified": "i","mInput": "","mOutput": "", "popLinks": {} });
117−
118− } catch(e) { }
119−
120− try {
57+ context.jsonArray.popups.pod_0100.push( {"stringified": "sqrt(-1)","mInput": "","mOutput": ""});
58+ } catch(e) { }
12159
122− $("#results #pod_0200:not(iframe #pod_0200)")
123− .add("#showsteps #pod_0200:not(iframe #pod_0200)")
124− .add(".results-pod #pod_0200:not(iframe #pod_0200)")
125− .data("tempFileID", 'MSP44541e0dda34g97a0c8900004f449i50fa482fd8')
126− .data("podIdentifier", '\x22Result\x22')
127− .data("podShortIdentifier", '\x22Result\x22')
128− .data("buttonStates", '\x22Result\x22\x20\x2D\x3E\x20\x7BAll,\x20None,\x20None,\x20None,\x20None\x7D')
129− .data("scanner", '\x22\x22');
130− $("#results #pod_0200-popup:not(iframe #pod_0200-popup)")
131− .add("#showsteps #pod_0200-popup:not(iframe #pod_0200-popup)")
132− .add(".results-pod #pod_0200-popup:not(iframe #pod_0200-popup)")
133− .data("tempFileID", 'MSP44541e0dda34g97a0c8900004f449i50fa482fd8')
134− .data("podIdentifier", '\x22Result\x22')
135− .data("podShortIdentifier", '\x22Result\x22')
136− .data("buttonStates", '\x22Result\x22\x20\x2D\x3E\x20\x7BAll,\x20None,\x20None\x7D')
137− .data("scanner", '\x22\x22');
138−
139− $("#results #subpod_0200_1")
140− .add("#showsteps #subpod_0200_1:not(iframe #subpod_0200_1)")
141− .add(".results-pod #subpod_0200_1")
142− .data("tempFileID", "MSP44551e0dda34g97a0c8900003gdgd37faa7272e0")
143− .data("cellDataTempFile", "MSP44561e0dda34g97a0c89000018ea1iae00104g13")
144− .data("tempFileServer", "")
145− .data("dataSources", "")
146− .data("sources", "")
147− .data("sharetype", "1")
148− .data("shareable", "false");
149− } catch(e){}
60+ try {
61+ if (typeof context.jsonArray.popups.pod_0200 == "undefined" ) {
62+ context.jsonArray.popups.pod_0200 = [];
63+ }
64+ context.jsonArray.popups.pod_0200.push( {"stringified": "i","mInput": "","mOutput": ""});
65+ } catch(e) { }
15066 </script>
15167 </body>
15268 </html>
15369 """
70+ # test plaintext
15471 response = mock.Mock(text=html)
15572 results = wolframalpha_noapi.response(response)
15673 self.assertEqual(type(results), list)
15774 self.assertEqual(len(results), 2)
158− self.assertIn("i", results[0]['answer'])
159− self.assertIn("sqrt(-1) - Wolfram|Alpha", results[1]['title'])
160− self.assertIn("http://www.wolframalpha.com/input/?i=+sqrt%28-1%29", results[1]['url'])
75+ self.assertEquals('i', results[0]['answer'])
76+ self.assertIn('sqrt(-1) - Wolfram|Alpha', results[1]['title'])
77+ self.assertEquals('http://www.wolframalpha.com/input/?i=+sqrt%28-1%29', results[1]['url'])
16178
16279 html = """
16380 <!DOCTYPE html>
@@ -165,91 +82,78 @@ class TestWolframAlphaNoAPIEngine(SearxTestCase):
16582 <meta charset="utf-8" />
16683 <body>
16784 <script type="text/javascript">
168− //true
16985 try {
170− document.domain = "wolframalpha.com";
171− context = parent ? parent : document;
172− } catch(e){}
173− try {
174− if (typeof(context.$) == "undefined") {
175− context = window;
176− } else {
177− $=context.$;
178− }
86+ if (typeof context.jsonArray.popups.pod_0100 == "undefined" ) {
87+ context.jsonArray.popups.pod_0100 = [];
17988 }
180− catch(e){ context = window;}
181−
182− try {
183−
184− if (typeof context.jsonArray.popups.pod_0100 == "undefined" ) {
185− context.jsonArray.popups.pod_0100 = [];
186− }
187−
188− context.jsonArray.popups.pod_0100.push( {"stringified": "integral 1\/x dx = log(x)+constant"});
189−
190− } catch(e) { }
191−
192− try {
193−
194− $("#results #pod_0100:not(iframe #pod_0100)")
195− .add("#showsteps #pod_0100:not(iframe #pod_0100)")
196− .add(".results-pod #pod_0100:not(iframe #pod_0100)")
197− .data("tempFileID", 'MSP2051if2202e8bg0757100000d119b05egf583d3')
198− .data("podIdentifier", '\x22IndefiniteIntegral\x22')
199− .data("podShortIdentifier", '\x22IndefiniteIntegral\x22')
200− .data("buttonStates", '\x22Indefinite\x20integral\x22\x20\x2D\x3E\x20\x7B\x7D')
201− .data("scanner", '\x22\x22');
202− $("#results #pod_0100-popup:not(iframe #pod_0100-popup)")
203− .add("#showsteps #pod_0100-popup:not(iframe #pod_0100-popup)")
204− .add(".results-pod #pod_0100-popup:not(iframe #pod_0100-popup)")
205− .data("tempFileID", 'MSP2051if2202e8bg0757100000d119b05egf583d3')
206− .data("podIdentifier", '\x22IndefiniteIntegral\x22')
207− .data("podShortIdentifier", '\x22IndefiniteIntegral\x22')
208− .data("buttonStates", '\x22Indefinite\x20integral\x22\x20\x2D\x3E\x20\x7B\x7D')
209− .data("scanner", '\x22\x22');
210−
211− $("#results #subpod_0100_1")
212− .add("#showsteps #subpod_0100_1:not(iframe #subpod_0100_1)")
213− .add(".results-pod #subpod_0100_1")
214− .data("tempFileID", "MSP2071if2202e8bg0757100004dg60f2a4ca8cf73")
215− .data("cellDataTempFile", "MSP2081if2202e8bg0757100001h18329f72fe90fg")
216− .data("tempFileServer", "")
217− .data("dataSources", "")
218− .data("sources", "")
219− .data("sharetype", "1")
220− .data("shareable", "false");
221−
222− } catch(e){}
89+ context.jsonArray.popups.pod_0100.push( {"stringified": "integral 1\/x dx = log(x)+constant"});
90+ } catch(e) { }
91+ </script>
92+ </body>
93+ </html>
94+ """
95+ # test integral
96+ response = mock.Mock(text=html)
97+ results = wolframalpha_noapi.response(response)
98+ self.assertEqual(type(results), list)
99+ self.assertEqual(len(results), 2)
100+ self.assertIn('log(x)+c', results[0]['answer'])
101+ self.assertIn('integral 1/x - Wolfram|Alpha', results[1]['title'])
102+ self.assertEquals('http://www.wolframalpha.com/input/?i=+integral+1%2Fx', results[1]['url'])
223103
224− //false
225− try {
104+ html = """
105+ <!DOCTYPE html>
106+ <title> ∫1/x x - Wolfram|Alpha</title>
107+ <meta charset="utf-8" />
108+ <body>
109+ <script type="text/javascript">
110+ try {
111+ if (typeof context.jsonArray.popups.pod_0100 == "undefined" ) {
112+ context.jsonArray.popups.pod_0100 = [];
113+ }
114+ context.jsonArray.popups.pod_0100.push( {"stringified": "integral 1\/x dx = log(x)+constant"});
115+ } catch(e) { }
116+ </script>
117+ </body>
118+ </html>
119+ """
120+ # test input in mathematical notation
121+ response = mock.Mock(text=html)
122+ results = wolframalpha_noapi.response(response)
123+ self.assertEqual(type(results), list)
124+ self.assertEqual(len(results), 2)
125+ self.assertIn('log(x)+c', results[0]['answer'])
126+ self.assertIn('∫1/x x - Wolfram|Alpha'.decode('utf-8'), results[1]['title'])
127+ self.assertEquals('http://www.wolframalpha.com/input/?i=+%E2%88%AB1%2Fx+%EF%9D%8Cx', results[1]['url'])
226128
227− $("#results #pod_0200:not(iframe #pod_0200)")
228− .add("#showsteps #pod_0200:not(iframe #pod_0200)")
229− .add(".results-pod #pod_0200:not(iframe #pod_0200)")
230− .data("tempFileID", '')
231− .data("podIdentifier", '\x22Plot\x22')
232− .data("podShortIdentifier", '')
233− .data("buttonStates", '')
234− .data("scanner", '\x22\x22');
235− $("#results #pod_0200-popup:not(iframe #pod_0200-popup)")
236− .add("#showsteps #pod_0200-popup:not(iframe #pod_0200-popup)")
237− .add(".results-pod #pod_0200-popup:not(iframe #pod_0200-popup)")
238− .data("tempFileID", '')
239− .data("podIdentifier", '\x22Plot\x22')
240− .data("podShortIdentifier", '')
241− .data("buttonStates", '')
242− .data("scanner", '\x22\x22');
129+ html = """
130+ <!DOCTYPE html>
131+ <title> 1 euro to yen - Wolfram|Alpha</title>
132+ <meta charset="utf-8" />
133+ <body>
134+ <script type="text/javascript">
135+ try {
136+ if (typeof context.jsonArray.popups.pod_0100 == "undefined" ) {
137+ context.jsonArray.popups.pod_0100 = [];
138+ }
139+ context.jsonArray.popups.pod_0100.push( {"stringified": "convert euro1 (euro) to Japanese yen"});
140+ } catch(e) { }
243141
244− } catch(e){}
142+ try {
143+ if (typeof context.jsonArray.popups.pod_0200 == "undefined" ) {
144+ context.jsonArray.popups.pod_0200 = [];
145+ }
146+ context.jsonArray.popups.pod_0200.push( {"stringified": "¥130.5 (Japanese yen)"});
147+ } catch(e) { }
245148 </script>
246149 </body>
247150 </html>
248151 """
152+ # test output in htmlentity
249153 response = mock.Mock(text=html)
250154 results = wolframalpha_noapi.response(response)
251155 self.assertEqual(type(results), list)
252156 self.assertEqual(len(results), 2)
253− self.assertIn("log(x)+c", results[0]['answer'])
254− self.assertIn("integral 1/x - Wolfram|Alpha", results[1]['title'])
255− self.assertIn("http://www.wolframalpha.com/input/?i=+integral+1%2Fx", results[1]['url'])
157+ self.assertIn("¥".decode('utf-8'), results[0]['answer'])
158+ self.assertIn('1 euro to yen - Wolfram|Alpha', results[1]['title'])
159+ self.assertEquals('http://www.wolframalpha.com/input/?i=+1+euro+to+yen', results[1]['url'])