summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/engines/test_bing_images.py25
-rw-r--r--tests/unit/engines/test_frinkiac.py49
-rw-r--r--tests/unit/engines/test_gigablast.py81
-rw-r--r--tests/unit/engines/test_wolframalpha_api.py307
-rw-r--r--tests/unit/engines/test_wolframalpha_noapi.py193
5 files changed, 614 insertions, 41 deletions
diff --git a/tests/unit/engines/test_bing_images.py b/tests/unit/engines/test_bing_images.py
index f42dff7e8..88538d8fa 100644
--- a/tests/unit/engines/test_bing_images.py
+++ b/tests/unit/engines/test_bing_images.py
@@ -39,28 +39,25 @@ class TestBingImagesEngine(SearxTestCase):
html = """
<div class="dg_u" style="width:178px;height:144px;left:17px;top:0px">
- <a href="#" ihk="HN.608003696942779811"
- m="{ns:&quot;images&quot;,k:&quot;5045&quot;,
-mid:&quot;659EB92C317974F34517A1CCAEBEF76A578E08DEE&quot;,
-surl:&quot;http://www.page.url/&quot;,imgurl:&quot;http://test.url/Test%20Query.jpg&quot;,
-oh:&quot;238&quot;,tft:&quot;0&quot;,oi:&quot;http://www.image.url/Images/Test%20Query.jpg&quot;}"
- mid="59EB92C317974F34517A1CCAEBEF76A578E08DEE" onclick="return false;"
- t1="Test Query" t2="650 x 517 · 31 kB · jpeg" t3="www.short.url" h="ID=images,5045.1">
- <img src="https://tse4.mm.bing.net/th?id=HN.608003696942779811&amp;o=4&amp;pid=1.7"
- style="height:144px;" width="178" height="144"/>
+ <a href="/images/search?q=south&amp;view=detailv2&amp;&amp;id=7E92863981CCFB89FBDD55205C742DFDA3290CF6&amp;selectedIndex=9&amp;ccid=vzvIfv5u&amp;simid=608055786735667000&amp;thid=OIP.Mbf3bc87efe6e0e476be8cc34bf6cd80eH0" ihk="OIP.Mbf3bc87efe6e0e476be8cc34bf6cd80eH0" t1="South Carolina" t2="747 x 589 &#183; 29 kB &#183; gif" t3="www.digital-topo-maps.com/county-map/south-carolina.shtml" hh="236" hw="300" m='{ns:"images",k:"5117",mid:"7E92863981CCFB89FBDD55205C742DFDA3290CF6",md5:"bf3bc87efe6e0e476be8cc34bf6cd80e",surl:"http://www.digital-topo-maps.com/county-map/south-carolina.shtml",imgurl:"http://www.digital-topo-maps.com/county-map/south-carolina-county-map.gif",tid:"OIP.Mbf3bc87efe6e0e476be8cc34bf6cd80eH0",ow:"480",docid:"608055786735667000",oh:"378",tft:"45"}' mid="7E92863981CCFB89FBDD55205C742DFDA3290CF6" h="ID=images,5117.1">
+ <img class="img_hid" src2="https://tse4.mm.bing.net/th?id=OIP.Mbf3bc87efe6e0e476be8cc34bf6cd80eH0&amp;w=210&amp;h=154&amp;c=7&amp;rs=1&amp;qlt=90&amp;o=4&amp;pid=1.1" style="width:210px;height:154px;" width="210" height="154">
</a>
+
</div>
- """
+ """ # noqa
html = html.replace('\r\n', '').replace('\n', '').replace('\r', '')
response = mock.Mock(text=html)
results = bing_images.response(response)
self.assertEqual(type(results), list)
self.assertEqual(len(results), 1)
- self.assertEqual(results[0]['title'], 'Test Query')
- self.assertEqual(results[0]['url'], 'http://www.page.url/')
+ self.assertEqual(results[0]['title'], 'South Carolina')
+ self.assertEqual(results[0]['url'],
+ 'http://www.digital-topo-maps.com/county-map/south-carolina.shtml')
self.assertEqual(results[0]['content'], '')
- self.assertEqual(results[0]['thumbnail_src'], 'https://www.bing.com/th?id=HN.608003696942779811')
- self.assertEqual(results[0]['img_src'], 'http://test.url/Test%20Query.jpg')
+ self.assertEqual(results[0]['thumbnail_src'],
+ 'https://www.bing.com/th?id=OIP.Mbf3bc87efe6e0e476be8cc34bf6cd80eH0')
+ self.assertEqual(results[0]['img_src'],
+ 'http://www.digital-topo-maps.com/county-map/south-carolina-county-map.gif')
html = """
<a href="#" ihk="HN.608003696942779811"
diff --git a/tests/unit/engines/test_frinkiac.py b/tests/unit/engines/test_frinkiac.py
new file mode 100644
index 000000000..f3eb021d2
--- /dev/null
+++ b/tests/unit/engines/test_frinkiac.py
@@ -0,0 +1,49 @@
+# -*- coding: utf-8 -*-
+from collections import defaultdict
+import mock
+from json import dumps
+from searx.engines import frinkiac
+from searx.testing import SearxTestCase
+
+
+class TestFrinkiacEngine(SearxTestCase):
+
+ def test_request(self):
+ query = 'test_query'
+ request_dict = defaultdict(dict)
+ params = frinkiac.request(query, request_dict)
+ self.assertTrue('url' in params)
+
+ def test_response(self):
+ self.assertRaises(AttributeError, frinkiac.response, None)
+ self.assertRaises(AttributeError, frinkiac.response, [])
+ self.assertRaises(AttributeError, frinkiac.response, '')
+ self.assertRaises(AttributeError, frinkiac.response, '[]')
+
+ text = """
+[{"Id":770931,
+ "Episode":"S06E18",
+ "Timestamp":534616,
+ "Filename":""},
+ {"Id":1657080,
+ "Episode":"S12E14",
+ "Timestamp":910868,
+ "Filename":""},
+ {"Id":1943753,
+ "Episode":"S14E21",
+ "Timestamp":773439,
+ "Filename":""},
+ {"Id":107835,
+ "Episode":"S02E03",
+ "Timestamp":531709,
+ "Filename":""}]
+ """
+
+ response = mock.Mock(text=text)
+ results = frinkiac.response(response)
+ self.assertEqual(type(results), list)
+ self.assertEqual(len(results), 4)
+ self.assertEqual(results[0]['title'], u'S06E18')
+ self.assertEqual(results[0]['url'], 'https://frinkiac.com/?p=caption&e=S06E18&t=534616')
+ self.assertEqual(results[0]['thumbnail_src'], 'https://frinkiac.com/img/S06E18/534616/medium.jpg')
+ self.assertEqual(results[0]['img_src'], 'https://frinkiac.com/img/S06E18/534616.jpg')
diff --git a/tests/unit/engines/test_gigablast.py b/tests/unit/engines/test_gigablast.py
index 4ae0c51a9..cb96f3cd1 100644
--- a/tests/unit/engines/test_gigablast.py
+++ b/tests/unit/engines/test_gigablast.py
@@ -22,37 +22,64 @@ class TestGigablastEngine(SearxTestCase):
self.assertRaises(AttributeError, gigablast.response, '')
self.assertRaises(AttributeError, gigablast.response, '[]')
- response = mock.Mock(content='<response></response>')
+ response = mock.Mock(text='{"results": []}')
self.assertEqual(gigablast.response(response), [])
- response = mock.Mock(content='<response></response>')
- self.assertEqual(gigablast.response(response), [])
-
- xml = """<?xml version="1.0" encoding="UTF-8" ?>
- <response>
- <hits>5941888</hits>
- <moreResultsFollow>1</moreResultsFollow>
- <result>
- <title><![CDATA[This should be the title]]></title>
- <sum><![CDATA[This should be the content.]]></sum>
- <url><![CDATA[http://this.should.be.the.link/]]></url>
- <size>90.5</size>
- <docId>145414002633</docId>
- <siteId>2660021087</siteId>
- <domainId>2660021087</domainId>
- <spidered>1320519373</spidered>
- <indexed>1320519373</indexed>
- <pubdate>4294967295</pubdate>
- <isModDate>0</isModDate>
- <language><![CDATA[English]]></language>
- <charset><![CDATA[UTF-8]]></charset>
- </result>
- </response>
+ json = """{"results": [
+ {
+ "title":"South by Southwest 2016",
+ "dmozEntry":{
+ "dmozCatId":1041152,
+ "directCatId":1,
+ "dmozCatStr":"Top: Regional: North America: United States",
+ "dmozTitle":"South by Southwest (SXSW)",
+ "dmozSum":"Annual music, film, and interactive conference.",
+ "dmozAnchor":""
+ },
+ "dmozEntry":{
+ "dmozCatId":763945,
+ "directCatId":1,
+ "dmozCatStr":"Top: Regional: North America: United States",
+ "dmozTitle":"South by Southwest (SXSW)",
+ "dmozSum":"",
+ "dmozAnchor":"www.sxsw.com"
+ },
+ "dmozEntry":{
+ "dmozCatId":761446,
+ "directCatId":1,
+ "dmozCatStr":"Top: Regional: North America: United States",
+ "dmozTitle":"South by Southwest (SXSW)",
+ "dmozSum":"Music, film, and interactive conference and festival.",
+ "dmozAnchor":""
+ },
+ "indirectDmozCatId":1041152,
+ "indirectDmozCatId":763945,
+ "indirectDmozCatId":761446,
+ "contentType":"html",
+ "sum":"This should be the content.",
+ "url":"www.sxsw.com",
+ "hopCount":0,
+ "size":" 102k",
+ "sizeInBytes":104306,
+ "bytesUsedToComputeSummary":70000,
+ "docId":269411794364,
+ "docScore":586571136.000000,
+ "summaryGenTimeMS":12,
+ "summaryTagdbLookupTimeMS":0,
+ "summaryTitleRecLoadTimeMS":1,
+ "site":"www.sxsw.com",
+ "spidered":1452203608,
+ "firstIndexedDateUTC":1444167123,
+ "contentHash32":2170650347,
+ "language":"English",
+ "langAbbr":"en"
+ }
+]}
"""
- response = mock.Mock(content=xml)
+ response = mock.Mock(text=json)
results = gigablast.response(response)
self.assertEqual(type(results), list)
self.assertEqual(len(results), 1)
- self.assertEqual(results[0]['title'], 'This should be the title')
- self.assertEqual(results[0]['url'], 'http://this.should.be.the.link/')
+ self.assertEqual(results[0]['title'], 'South by Southwest 2016')
+ self.assertEqual(results[0]['url'], 'www.sxsw.com')
self.assertEqual(results[0]['content'], 'This should be the content.')
diff --git a/tests/unit/engines/test_wolframalpha_api.py b/tests/unit/engines/test_wolframalpha_api.py
new file mode 100644
index 000000000..c80775795
--- /dev/null
+++ b/tests/unit/engines/test_wolframalpha_api.py
@@ -0,0 +1,307 @@
+# -*- coding: utf-8 -*-
+from collections import defaultdict
+import mock
+from searx.engines import wolframalpha_api
+from searx.testing import SearxTestCase
+
+
+class TestWolframAlphaAPIEngine(SearxTestCase):
+
+ def test_request(self):
+ query = 'test_query'
+ api_key = 'XXXXXX-XXXXXXXXXX'
+ dicto = defaultdict(dict)
+ dicto['api_key'] = api_key
+ params = wolframalpha_api.request(query, dicto)
+
+ self.assertIn('url', params)
+ self.assertIn(query, params['url'])
+ self.assertIn('wolframalpha.com', params['url'])
+
+ self.assertIn('api_key', params)
+ self.assertIn(api_key, params['api_key'])
+
+ def test_response(self):
+ self.assertRaises(AttributeError, wolframalpha_api.response, None)
+ self.assertRaises(AttributeError, wolframalpha_api.response, [])
+ self.assertRaises(AttributeError, wolframalpha_api.response, '')
+ self.assertRaises(AttributeError, wolframalpha_api.response, '[]')
+
+ xml = '''<?xml version='1.0' encoding='UTF-8'?>
+ <queryresult success='false' error='false' />
+ '''
+ # test failure
+ response = mock.Mock(content=xml)
+ self.assertEqual(wolframalpha_api.response(response), [])
+
+ xml = """<?xml version='1.0' encoding='UTF-8'?>
+ <queryresult success='true'
+ error='false'
+ numpods='6'
+ datatypes=''
+ timedout=''
+ timedoutpods=''
+ timing='0.684'
+ parsetiming='0.138'
+ parsetimedout='false'
+ recalculate=''
+ id='MSPa416020a7966dachc463600000f9c66cc21444cfg'
+ host='http://www3.wolframalpha.com'
+ server='6'
+ related='http://www3.wolframalpha.com/api/v2/relatedQueries.jsp?...'
+ version='2.6'>
+ <pod title='Input'
+ scanner='Identity'
+ id='Input'
+ position='100'
+ error='false'
+ numsubpods='1'>
+ <subpod title=''>
+ <plaintext>sqrt(-1)</plaintext>
+ </subpod>
+ </pod>
+ <pod title='Result'
+ scanner='Simplification'
+ id='Result'
+ position='200'
+ error='false'
+ numsubpods='1'
+ primary='true'>
+ <subpod title=''>
+ <plaintext></plaintext>
+ </subpod>
+ <states count='1'>
+ <state name='Step-by-step solution'
+ input='Result__Step-by-step solution' />
+ </states>
+ </pod>
+ <pod title='Polar coordinates'
+ scanner='Numeric'
+ id='PolarCoordinates'
+ position='300'
+ error='false'
+ numsubpods='1'>
+ <subpod title=''>
+ <plaintext>r1 (radius), θ90° (angle)</plaintext>
+ </subpod>
+ </pod>
+ <pod title='Position in the complex plane'
+ scanner='Numeric'
+ id='PositionInTheComplexPlane'
+ position='400'
+ error='false'
+ numsubpods='1'>
+ <subpod title=''>
+ <plaintext></plaintext>
+ </subpod>
+ </pod>
+ <pod title='All 2nd roots of -1'
+ scanner='RootsOfUnity'
+ id=''
+ position='500'
+ error='false'
+ numsubpods='2'>
+ <subpod title=''>
+ <plaintext> (principal root)</plaintext>
+ </subpod>
+ <subpod title=''>
+ <plaintext>-</plaintext>
+ </subpod>
+ </pod>
+ <pod title='Plot of all roots in the complex plane'
+ scanner='RootsOfUnity'
+ id='PlotOfAllRootsInTheComplexPlane'
+ position='600'
+ error='false'
+ numsubpods='1'>
+ <subpod title=''>
+ <plaintext></plaintext>
+ </subpod>
+ </pod>
+ </queryresult>
+ """
+ # test private user area char in response
+ response = mock.Mock(content=xml)
+ results = wolframalpha_api.response(response)
+ self.assertEqual(type(results), list)
+ self.assertEqual(len(results), 2)
+ self.assertIn('i', results[0]['answer'])
+ self.assertIn('sqrt(-1) - Wolfram|Alpha', results[1]['title'])
+ self.assertEquals('http://www.wolframalpha.com/input/?i=sqrt%28-1%29', results[1]['url'])
+
+ xml = """<?xml version='1.0' encoding='UTF-8'?>
+ <queryresult success='true'
+ error='false'
+ numpods='2'
+ datatypes=''
+ timedout=''
+ timedoutpods=''
+ timing='1.286'
+ parsetiming='0.255'
+ parsetimedout='false'
+ recalculate=''
+ id='MSPa195222ad740ede5214h30000480ca61h003d3gd6'
+ host='http://www3.wolframalpha.com'
+ server='20'
+ related='http://www3.wolframalpha.com/api/v2/relatedQueries.jsp?id=...'
+ version='2.6'>
+ <pod title='Indefinite integral'
+ scanner='Integral'
+ id='IndefiniteIntegral'
+ position='100'
+ error='false'
+ numsubpods='1'
+ primary='true'>
+ <subpod title=''>
+ <plaintext>∫1/xxlog(x)+constant</plaintext>
+ </subpod>
+ <states count='1'>
+ <state name='Step-by-step solution'
+ input='IndefiniteIntegral__Step-by-step solution' />
+ </states>
+ <infos count='1'>
+ <info text='log(x) is the natural logarithm'>
+ <link url='http://reference.wolfram.com/mathematica/ref/Log.html'
+ text='Documentation'
+ title='Mathematica' />
+ <link url='http://functions.wolfram.com/ElementaryFunctions/Log'
+ text='Properties'
+ title='Wolfram Functions Site' />
+ <link url='http://mathworld.wolfram.com/NaturalLogarithm.html'
+ text='Definition'
+ title='MathWorld' />
+ </info>
+ </infos>
+ </pod>
+ <pod title='Plots of the integral'
+ scanner='Integral'
+ id='Plot'
+ position='200'
+ error='false'
+ numsubpods='2'>
+ <subpod title=''>
+ <plaintext></plaintext>
+ <states count='1'>
+ <statelist count='2'
+ value='Complex-valued plot'
+ delimiters=''>
+ <state name='Complex-valued plot'
+ input='Plot__1_Complex-valued plot' />
+ <state name='Real-valued plot'
+ input='Plot__1_Real-valued plot' />
+ </statelist>
+ </states>
+ </subpod>
+ <subpod title=''>
+ <plaintext></plaintext>
+ <states count='1'>
+ <statelist count='2'
+ value='Complex-valued plot'
+ delimiters=''>
+ <state name='Complex-valued plot'
+ input='Plot__2_Complex-valued plot' />
+ <state name='Real-valued plot'
+ input='Plot__2_Real-valued plot' />
+ </statelist>
+ </states>
+ </subpod>
+ </pod>
+ <assumptions count='1'>
+ <assumption type='Clash'
+ word='integral'
+ template='Assuming &quot;${word}&quot; is ${desc1}. Use as ${desc2} instead'
+ count='2'>
+ <value name='IntegralsWord'
+ desc='an integral'
+ input='*C.integral-_*IntegralsWord-' />
+ <value name='MathematicalFunctionIdentityPropertyClass'
+ desc='a function property'
+ input='*C.integral-_*MathematicalFunctionIdentityPropertyClass-' />
+ </assumption>
+ </assumptions>
+ </queryresult>
+ """
+ # test integral
+ response = mock.Mock(content=xml)
+ results = wolframalpha_api.response(response)
+ self.assertEqual(type(results), list)
+ self.assertEqual(len(results), 2)
+ self.assertIn('log(x)+c', results[0]['answer'])
+ self.assertIn('∫1/xx - Wolfram|Alpha'.decode('utf-8'), results[1]['title'])
+ self.assertEquals('http://www.wolframalpha.com/input/?i=%E2%88%AB1%2Fx%EF%9D%8Cx', results[1]['url'])
+
+ xml = """<?xml version='1.0' encoding='UTF-8'?>
+ <queryresult success='true'
+ error='false'
+ numpods='4'
+ datatypes='Solve'
+ timedout=''
+ timedoutpods=''
+ timing='0.79'
+ parsetiming='0.338'
+ parsetimedout='false'
+ recalculate=''
+ id='MSPa7481f7i06d25h3deh2900004810i3a78d9b4fdc'
+ host='http://www5b.wolframalpha.com'
+ server='23'
+ related='http://www5b.wolframalpha.com/api/v2/relatedQueries.jsp?id=...'
+ version='2.6'>
+ <pod title='Input interpretation'
+ scanner='Identity'
+ id='Input'
+ position='100'
+ error='false'
+ numsubpods='1'>
+ <subpod title=''>
+ <plaintext>solve x^2+x0</plaintext>
+ </subpod>
+ </pod>
+ <pod title='Results'
+ scanner='Solve'
+ id='Result'
+ position='200'
+ error='false'
+ numsubpods='2'
+ primary='true'>
+ <subpod title=''>
+ <plaintext>x-1</plaintext>
+ </subpod>
+ <subpod title=''>
+ <plaintext>x0</plaintext>
+ </subpod>
+ <states count='1'>
+ <state name='Step-by-step solution'
+ input='Result__Step-by-step solution' />
+ </states>
+ </pod>
+ <pod title='Root plot'
+ scanner='Solve'
+ id='RootPlot'
+ position='300'
+ error='false'
+ numsubpods='1'>
+ <subpod title=''>
+ <plaintext></plaintext>
+ </subpod>
+ </pod>
+ <pod title='Number line'
+ scanner='Solve'
+ id='NumberLine'
+ position='400'
+ error='false'
+ numsubpods='1'>
+ <subpod title=''>
+ <plaintext></plaintext>
+ </subpod>
+ </pod>
+ </queryresult>
+ """
+ # test ecuation with multiple answers
+ response = mock.Mock(content=xml)
+ results = wolframalpha_api.response(response)
+ self.assertEqual(type(results), list)
+ self.assertEqual(len(results), 3)
+ self.assertIn('x=-1', results[0]['answer'])
+ self.assertIn('x=0', results[1]['answer'])
+ self.assertIn('solve x^2+x0 - Wolfram|Alpha'.decode('utf-8'), results[2]['title'])
+ self.assertEquals('http://www.wolframalpha.com/input/?i=solve+x%5E2%2Bx%EF%9F%990', results[2]['url'])
diff --git a/tests/unit/engines/test_wolframalpha_noapi.py b/tests/unit/engines/test_wolframalpha_noapi.py
new file mode 100644
index 000000000..cad9593f2
--- /dev/null
+++ b/tests/unit/engines/test_wolframalpha_noapi.py
@@ -0,0 +1,193 @@
+# -*- coding: utf-8 -*-
+from collections import defaultdict
+import mock
+from searx.engines import wolframalpha_noapi
+from searx.testing import SearxTestCase
+
+
+class TestWolframAlphaNoAPIEngine(SearxTestCase):
+
+ def test_request(self):
+ query = 'test_query'
+ dicto = defaultdict(dict)
+ dicto['pageno'] = 1
+ params = wolframalpha_noapi.request(query, dicto)
+ self.assertIn('url', params)
+ self.assertIn(query, params['url'])
+ self.assertIn('wolframalpha.com', params['url'])
+
+ def test_response(self):
+ self.assertRaises(AttributeError, wolframalpha_noapi.response, None)
+ self.assertRaises(AttributeError, wolframalpha_noapi.response, [])
+ self.assertRaises(AttributeError, wolframalpha_noapi.response, '')
+ self.assertRaises(AttributeError, wolframalpha_noapi.response, '[]')
+
+ html = """
+ <!DOCTYPE html>
+ <title> Parangaricutirimícuaro - Wolfram|Alpha</title>
+ <meta charset="utf-8" />
+ <body>
+ <div id="closest">
+ <p class="pfail">Wolfram|Alpha doesn't know how to interpret your input.</p>
+ <div id="dtips">
+ <div class="tip">
+ <span class="tip-title">Tip:&nbsp;</span>
+ Check your spelling, and use English
+ <span class="tip-extra"></span>
+ </div>
+ </div>
+ </div>
+ </body>
+ </html>
+ """
+ # test failed query
+ response = mock.Mock(text=html)
+ self.assertEqual(wolframalpha_noapi.response(response), [])
+
+ html = """
+ <!DOCTYPE html>
+ <title> sqrt(-1) - Wolfram|Alpha</title>
+ <meta charset="utf-8" />
+ <body>
+ <script type="text/javascript">
+ try {
+ if (typeof context.jsonArray.popups.pod_0100 == "undefined" ) {
+ context.jsonArray.popups.pod_0100 = [];
+ }
+ context.jsonArray.popups.pod_0100.push( {"stringified": "sqrt(-1)","mInput": "","mOutput": ""});
+ } catch(e) { }
+
+ try {
+ if (typeof context.jsonArray.popups.pod_0200 == "undefined" ) {
+ context.jsonArray.popups.pod_0200 = [];
+ }
+ context.jsonArray.popups.pod_0200.push( {"stringified": "i","mInput": "","mOutput": ""});
+ } catch(e) { }
+ </script>
+ </body>
+ </html>
+ """
+ # test plaintext
+ response = mock.Mock(text=html)
+ results = wolframalpha_noapi.response(response)
+ self.assertEqual(type(results), list)
+ self.assertEqual(len(results), 2)
+ self.assertEquals('i', results[0]['answer'])
+ self.assertIn('sqrt(-1) - Wolfram|Alpha', results[1]['title'])
+ self.assertEquals('http://www.wolframalpha.com/input/?i=+sqrt%28-1%29', results[1]['url'])
+
+ html = """
+ <!DOCTYPE html>
+ <title> integral 1/x - Wolfram|Alpha</title>
+ <meta charset="utf-8" />
+ <body>
+ <script type="text/javascript">
+ try {
+ if (typeof context.jsonArray.popups.pod_0100 == "undefined" ) {
+ context.jsonArray.popups.pod_0100 = [];
+ }
+ context.jsonArray.popups.pod_0100.push( {"stringified": "integral 1\/x dx = log(x)+constant"});
+ } catch(e) { }
+ </script>
+ </body>
+ </html>
+ """
+ # test integral
+ response = mock.Mock(text=html)
+ results = wolframalpha_noapi.response(response)
+ self.assertEqual(type(results), list)
+ self.assertEqual(len(results), 2)
+ self.assertIn('log(x)+c', results[0]['answer'])
+ self.assertIn('integral 1/x - Wolfram|Alpha', results[1]['title'])
+ self.assertEquals('http://www.wolframalpha.com/input/?i=+integral+1%2Fx', results[1]['url'])
+
+ html = """
+ <!DOCTYPE html>
+ <title> &int;1&#x2f;x &#xf74c;x - Wolfram|Alpha</title>
+ <meta charset="utf-8" />
+ <body>
+ <script type="text/javascript">
+ try {
+ if (typeof context.jsonArray.popups.pod_0100 == "undefined" ) {
+ context.jsonArray.popups.pod_0100 = [];
+ }
+ context.jsonArray.popups.pod_0100.push( {"stringified": "integral 1\/x dx = log(x)+constant"});
+ } catch(e) { }
+ </script>
+ </body>
+ </html>
+ """
+ # test input in mathematical notation
+ response = mock.Mock(text=html)
+ results = wolframalpha_noapi.response(response)
+ self.assertEqual(type(results), list)
+ self.assertEqual(len(results), 2)
+ self.assertIn('log(x)+c', results[0]['answer'])
+ self.assertIn('∫1/x x - Wolfram|Alpha'.decode('utf-8'), results[1]['title'])
+ self.assertEquals('http://www.wolframalpha.com/input/?i=+%E2%88%AB1%2Fx+%EF%9D%8Cx', results[1]['url'])
+
+ html = """
+ <!DOCTYPE html>
+ <title> 1 euro to yen - Wolfram|Alpha</title>
+ <meta charset="utf-8" />
+ <body>
+ <script type="text/javascript">
+ try {
+ if (typeof context.jsonArray.popups.pod_0100 == "undefined" ) {
+ context.jsonArray.popups.pod_0100 = [];
+ }
+ context.jsonArray.popups.pod_0100.push( {"stringified": "convert euro1 (euro) to Japanese yen"});
+ } catch(e) { }
+
+ try {
+ if (typeof context.jsonArray.popups.pod_0200 == "undefined" ) {
+ context.jsonArray.popups.pod_0200 = [];
+ }
+ context.jsonArray.popups.pod_0200.push( {"stringified": "&yen;130.5 (Japanese yen)"});
+ } catch(e) { }
+ </script>
+ </body>
+ </html>
+ """
+ # test output with htmlentity
+ response = mock.Mock(text=html)
+ results = wolframalpha_noapi.response(response)
+ self.assertEqual(type(results), list)
+ self.assertEqual(len(results), 2)
+ self.assertIn('¥'.decode('utf-8'), results[0]['answer'])
+ self.assertIn('1 euro to yen - Wolfram|Alpha', results[1]['title'])
+ self.assertEquals('http://www.wolframalpha.com/input/?i=+1+euro+to+yen', results[1]['url'])
+
+ html = """
+ <!DOCTYPE html>
+ <title> distance from nairobi to kyoto in inches - Wolfram|Alpha</title>
+ <meta charset="utf-8" />
+ <body>
+ <script type="text/javascript">
+ try {
+ if (typeof context.jsonArray.popups.pod_0100 == "undefined" ) {
+ context.jsonArray.popups.pod_0100 = [];
+ }
+[...].pod_0100.push( {"stringified": "convert distance | from | Nairobi, Kenya\nto | Kyoto, Japan to inches"});
+ } catch(e) { }
+
+ try {
+ if (typeof context.jsonArray.popups.pod_0200 == "undefined" ) {
+ context.jsonArray.popups.pod_0200 = [];
+ }
+pod_0200.push({"stringified": "4.295&times;10^8 inches","mOutput": "Quantity[4.295×10^8,&amp;quot;Inches&amp;quot;]"});
+
+ } catch(e) { }
+ </script>
+ </body>
+ </html>
+ """
+ # test output with utf-8 character
+ response = mock.Mock(text=html)
+ results = wolframalpha_noapi.response(response)
+ self.assertEqual(type(results), list)
+ self.assertEqual(len(results), 2)
+ self.assertIn('4.295×10^8 inches'.decode('utf-8'), results[0]['answer'])
+ self.assertIn('distance from nairobi to kyoto in inches - Wolfram|Alpha', results[1]['title'])
+ self.assertEquals('http://www.wolframalpha.com/input/?i=+distance+from+nairobi+to+kyoto+in+inches',
+ results[1]['url'])