mirror of
https://github.com/searxng/searxng.git
synced 2025-08-03 10:32:21 +02:00
[enh] py3 compatibility
This commit is contained in:
parent
46a2c63f8e
commit
52e615dede
115 changed files with 517 additions and 513 deletions
|
@ -25,7 +25,7 @@ class TestArchLinuxEngine(SearxTestCase):
|
|||
self.assertTrue(query in params['url'])
|
||||
self.assertTrue('wiki.archlinux.org' in params['url'])
|
||||
|
||||
for lang, domain in domains.iteritems():
|
||||
for lang, domain in domains.items():
|
||||
dic['language'] = lang
|
||||
params = archlinux.request(query, dic)
|
||||
self.assertTrue(domain in params['url'])
|
||||
|
@ -102,5 +102,5 @@ class TestArchLinuxEngine(SearxTestCase):
|
|||
for exp in expected:
|
||||
res = results[i]
|
||||
i += 1
|
||||
for key, value in exp.iteritems():
|
||||
for key, value in exp.items():
|
||||
self.assertEqual(res[key], value)
|
||||
|
|
|
@ -7,18 +7,18 @@ from searx.testing import SearxTestCase
|
|||
class TestBingEngine(SearxTestCase):
|
||||
|
||||
def test_request(self):
|
||||
query = 'test_query'
|
||||
query = u'test_query'
|
||||
dicto = defaultdict(dict)
|
||||
dicto['pageno'] = 0
|
||||
dicto['language'] = 'fr_FR'
|
||||
params = bing.request(query, dicto)
|
||||
params = bing.request(query.encode('utf-8'), dicto)
|
||||
self.assertTrue('url' in params)
|
||||
self.assertTrue(query in params['url'])
|
||||
self.assertTrue('language%3AFR' in params['url'])
|
||||
self.assertTrue('bing.com' in params['url'])
|
||||
|
||||
dicto['language'] = 'all'
|
||||
params = bing.request(query, dicto)
|
||||
params = bing.request(query.encode('utf-8'), dicto)
|
||||
self.assertTrue('language' in params['url'])
|
||||
|
||||
def test_response(self):
|
||||
|
|
|
@ -36,10 +36,10 @@ class TestBingNewsEngine(SearxTestCase):
|
|||
self.assertRaises(AttributeError, bing_news.response, '')
|
||||
self.assertRaises(AttributeError, bing_news.response, '[]')
|
||||
|
||||
response = mock.Mock(content='<html></html>')
|
||||
response = mock.Mock(text='<html></html>')
|
||||
self.assertEqual(bing_news.response(response), [])
|
||||
|
||||
response = mock.Mock(content='<html></html>')
|
||||
response = mock.Mock(text='<html></html>')
|
||||
self.assertEqual(bing_news.response(response), [])
|
||||
|
||||
html = """<?xml version="1.0" encoding="utf-8" ?>
|
||||
|
@ -74,7 +74,7 @@ class TestBingNewsEngine(SearxTestCase):
|
|||
</item>
|
||||
</channel>
|
||||
</rss>""" # noqa
|
||||
response = mock.Mock(content=html)
|
||||
response = mock.Mock(text=html.encode('utf-8'))
|
||||
results = bing_news.response(response)
|
||||
self.assertEqual(type(results), list)
|
||||
self.assertEqual(len(results), 2)
|
||||
|
@ -113,7 +113,7 @@ class TestBingNewsEngine(SearxTestCase):
|
|||
</item>
|
||||
</channel>
|
||||
</rss>""" # noqa
|
||||
response = mock.Mock(content=html)
|
||||
response = mock.Mock(text=html.encode('utf-8'))
|
||||
results = bing_news.response(response)
|
||||
self.assertEqual(type(results), list)
|
||||
self.assertEqual(len(results), 1)
|
||||
|
@ -136,11 +136,11 @@ class TestBingNewsEngine(SearxTestCase):
|
|||
</channel>
|
||||
</rss>""" # noqa
|
||||
|
||||
response = mock.Mock(content=html)
|
||||
response = mock.Mock(text=html.encode('utf-8'))
|
||||
results = bing_news.response(response)
|
||||
self.assertEqual(type(results), list)
|
||||
self.assertEqual(len(results), 0)
|
||||
|
||||
html = """<?xml version="1.0" encoding="utf-8" ?>gabarge"""
|
||||
response = mock.Mock(content=html)
|
||||
response = mock.Mock(text=html.encode('utf-8'))
|
||||
self.assertRaises(lxml.etree.XMLSyntaxError, bing_news.response, response)
|
||||
|
|
|
@ -22,10 +22,10 @@ class TestBtdiggEngine(SearxTestCase):
|
|||
self.assertRaises(AttributeError, btdigg.response, '')
|
||||
self.assertRaises(AttributeError, btdigg.response, '[]')
|
||||
|
||||
response = mock.Mock(content='<html></html>')
|
||||
response = mock.Mock(text='<html></html>')
|
||||
self.assertEqual(btdigg.response(response), [])
|
||||
|
||||
html = """
|
||||
html = u"""
|
||||
<div id="search_res">
|
||||
<table>
|
||||
<tr>
|
||||
|
@ -82,7 +82,7 @@ class TestBtdiggEngine(SearxTestCase):
|
|||
</table>
|
||||
</div>
|
||||
"""
|
||||
response = mock.Mock(content=html)
|
||||
response = mock.Mock(text=html.encode('utf-8'))
|
||||
results = btdigg.response(response)
|
||||
self.assertEqual(type(results), list)
|
||||
self.assertEqual(len(results), 1)
|
||||
|
@ -101,12 +101,12 @@ class TestBtdiggEngine(SearxTestCase):
|
|||
</table>
|
||||
</div>
|
||||
"""
|
||||
response = mock.Mock(content=html)
|
||||
response = mock.Mock(text=html.encode('utf-8'))
|
||||
results = btdigg.response(response)
|
||||
self.assertEqual(type(results), list)
|
||||
self.assertEqual(len(results), 0)
|
||||
|
||||
html = """
|
||||
html = u"""
|
||||
<div id="search_res">
|
||||
<table>
|
||||
<tr>
|
||||
|
@ -367,7 +367,7 @@ class TestBtdiggEngine(SearxTestCase):
|
|||
</table>
|
||||
</div>
|
||||
"""
|
||||
response = mock.Mock(content=html)
|
||||
response = mock.Mock(text=html.encode('utf-8'))
|
||||
results = btdigg.response(response)
|
||||
self.assertEqual(type(results), list)
|
||||
self.assertEqual(len(results), 5)
|
||||
|
|
|
@ -8,13 +8,13 @@ from searx.testing import SearxTestCase
|
|||
class TestCurrencyConvertEngine(SearxTestCase):
|
||||
|
||||
def test_request(self):
|
||||
query = 'test_query'
|
||||
query = b'test_query'
|
||||
dicto = defaultdict(dict)
|
||||
dicto['pageno'] = 1
|
||||
params = currency_convert.request(query, dicto)
|
||||
self.assertNotIn('url', params)
|
||||
|
||||
query = 'convert 10 Pound Sterlings to United States Dollars'
|
||||
query = b'convert 10 Pound Sterlings to United States Dollars'
|
||||
params = currency_convert.request(query, dicto)
|
||||
self.assertIn('url', params)
|
||||
self.assertIn('finance.yahoo.com', params['url'])
|
||||
|
|
|
@ -21,7 +21,7 @@ class TestDigBTEngine(SearxTestCase):
|
|||
self.assertRaises(AttributeError, digbt.response, '')
|
||||
self.assertRaises(AttributeError, digbt.response, '[]')
|
||||
|
||||
response = mock.Mock(content='<html></html>')
|
||||
response = mock.Mock(text='<html></html>')
|
||||
self.assertEqual(digbt.response(response), [])
|
||||
|
||||
html = """
|
||||
|
@ -50,7 +50,7 @@ class TestDigBTEngine(SearxTestCase):
|
|||
</td></tr>
|
||||
</table>
|
||||
"""
|
||||
response = mock.Mock(content=html)
|
||||
response = mock.Mock(text=html.encode('utf-8'))
|
||||
results = digbt.response(response)
|
||||
self.assertEqual(type(results), list)
|
||||
self.assertEqual(len(results), 1)
|
||||
|
|
|
@ -90,8 +90,7 @@ class TestDuckduckgoEngine(SearxTestCase):
|
|||
"wt-wt":"All Results","ar-es":"Argentina","au-en":"Australia","at-de":"Austria","be-fr":"Belgium (fr)"
|
||||
}some more code..."""
|
||||
response = mock.Mock(text=js)
|
||||
languages = duckduckgo._fetch_supported_languages(response)
|
||||
self.assertEqual(type(languages), list)
|
||||
languages = list(duckduckgo._fetch_supported_languages(response))
|
||||
self.assertEqual(len(languages), 5)
|
||||
self.assertIn('wt-WT', languages)
|
||||
self.assertIn('es-AR', languages)
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from collections import defaultdict
|
||||
import mock
|
||||
from json import dumps
|
||||
from searx.engines import frinkiac
|
||||
from searx.testing import SearxTestCase
|
||||
|
||||
|
@ -44,6 +43,8 @@ class TestFrinkiacEngine(SearxTestCase):
|
|||
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.assertIn('p=caption', results[0]['url'])
|
||||
self.assertIn('e=S06E18', results[0]['url'])
|
||||
self.assertIn('t=534616', results[0]['url'])
|
||||
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')
|
||||
|
|
|
@ -10,6 +10,7 @@ class TestGigablastEngine(SearxTestCase):
|
|||
query = 'test_query'
|
||||
dicto = defaultdict(dict)
|
||||
dicto['pageno'] = 0
|
||||
dicto['safesearch'] = 0
|
||||
dicto['language'] = 'all'
|
||||
params = gigablast.request(query, dicto)
|
||||
self.assertTrue('url' in params)
|
||||
|
|
|
@ -2,7 +2,7 @@ from collections import defaultdict
|
|||
import mock
|
||||
from searx.engines import soundcloud
|
||||
from searx.testing import SearxTestCase
|
||||
from urllib import quote_plus
|
||||
from searx.url_utils import quote_plus
|
||||
|
||||
|
||||
class TestSoundcloudEngine(SearxTestCase):
|
||||
|
|
|
@ -31,7 +31,7 @@ class TestStartpageEngine(SearxTestCase):
|
|||
self.assertRaises(AttributeError, startpage.response, '')
|
||||
self.assertRaises(AttributeError, startpage.response, '[]')
|
||||
|
||||
response = mock.Mock(content='<html></html>')
|
||||
response = mock.Mock(text='<html></html>')
|
||||
self.assertEqual(startpage.response(response), [])
|
||||
|
||||
html = """
|
||||
|
@ -62,7 +62,7 @@ class TestStartpageEngine(SearxTestCase):
|
|||
</p>
|
||||
</div>
|
||||
"""
|
||||
response = mock.Mock(content=html)
|
||||
response = mock.Mock(text=html.encode('utf-8'))
|
||||
results = startpage.response(response)
|
||||
self.assertEqual(type(results), list)
|
||||
self.assertEqual(len(results), 1)
|
||||
|
@ -133,7 +133,7 @@ class TestStartpageEngine(SearxTestCase):
|
|||
</p>
|
||||
</div>
|
||||
"""
|
||||
response = mock.Mock(content=html)
|
||||
response = mock.Mock(text=html.encode('utf-8'))
|
||||
results = startpage.response(response)
|
||||
self.assertEqual(type(results), list)
|
||||
self.assertEqual(len(results), 1)
|
||||
|
|
|
@ -33,13 +33,13 @@ class TestSwisscowsEngine(SearxTestCase):
|
|||
self.assertRaises(AttributeError, swisscows.response, '')
|
||||
self.assertRaises(AttributeError, swisscows.response, '[]')
|
||||
|
||||
response = mock.Mock(content='<html></html>')
|
||||
response = mock.Mock(text=b'<html></html>')
|
||||
self.assertEqual(swisscows.response(response), [])
|
||||
|
||||
response = mock.Mock(content='<html></html>')
|
||||
response = mock.Mock(text=b'<html></html>')
|
||||
self.assertEqual(swisscows.response(response), [])
|
||||
|
||||
html = u"""
|
||||
html = b"""
|
||||
<script>
|
||||
App.Dispatcher.dispatch("initialize", {
|
||||
html5history: true,
|
||||
|
@ -111,7 +111,7 @@ class TestSwisscowsEngine(SearxTestCase):
|
|||
});
|
||||
</script>
|
||||
"""
|
||||
response = mock.Mock(content=html)
|
||||
response = mock.Mock(text=html)
|
||||
results = swisscows.response(response)
|
||||
self.assertEqual(type(results), list)
|
||||
self.assertEqual(len(results), 3)
|
||||
|
|
|
@ -91,7 +91,7 @@ class TestTokyotoshokanEngine(SearxTestCase):
|
|||
self.assertEqual(r['title'], 'Koyomimonogatari')
|
||||
self.assertEqual(r['magnetlink'], 'magnet:?xt=urn:btih:4c19eb46b5113685fbd2288ed2531b0b')
|
||||
self.assertEqual(r['filesize'], int(1024 * 1024 * 10.5))
|
||||
self.assertEqual(r['publishedDate'], datetime(2016, 03, 26, 16, 41))
|
||||
self.assertEqual(r['publishedDate'], datetime(2016, 3, 26, 16, 41))
|
||||
self.assertEqual(r['content'], 'Comment: sample comment')
|
||||
self.assertEqual(r['seed'], 53)
|
||||
self.assertEqual(r['leech'], 18)
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from json import loads
|
||||
from lxml.html import fromstring
|
||||
from collections import defaultdict
|
||||
import mock
|
||||
|
@ -31,7 +30,7 @@ class TestWikidataEngine(SearxTestCase):
|
|||
self.assertRaises(AttributeError, wikidata.response, '')
|
||||
self.assertRaises(AttributeError, wikidata.response, '[]')
|
||||
|
||||
response = mock.Mock(content='<html></html>', search_params={"language": "all"})
|
||||
response = mock.Mock(text='<html></html>', search_params={"language": "all"})
|
||||
self.assertEqual(wikidata.response(response), [])
|
||||
|
||||
def test_getDetail(self):
|
||||
|
|
|
@ -13,15 +13,15 @@ class TestWikipediaEngine(SearxTestCase):
|
|||
query = 'test_query'
|
||||
dicto = defaultdict(dict)
|
||||
dicto['language'] = 'fr-FR'
|
||||
params = wikipedia.request(query, dicto)
|
||||
params = wikipedia.request(query.encode('utf-8'), dicto)
|
||||
self.assertIn('url', params)
|
||||
self.assertIn(query, params['url'])
|
||||
self.assertIn('test_query', params['url'])
|
||||
self.assertIn('Test_Query', params['url'])
|
||||
self.assertIn('fr.wikipedia.org', params['url'])
|
||||
|
||||
query = 'Test_Query'
|
||||
params = wikipedia.request(query, dicto)
|
||||
query = u'Test_Query'
|
||||
params = wikipedia.request(query.encode('utf-8'), dicto)
|
||||
self.assertIn('Test_Query', params['url'])
|
||||
self.assertNotIn('test_query', params['url'])
|
||||
|
||||
|
@ -57,7 +57,7 @@ class TestWikipediaEngine(SearxTestCase):
|
|||
}
|
||||
}
|
||||
}"""
|
||||
response = mock.Mock(content=json, search_params=dicto)
|
||||
response = mock.Mock(text=json, search_params=dicto)
|
||||
self.assertEqual(wikipedia.response(response), [])
|
||||
|
||||
# normal case
|
||||
|
@ -80,7 +80,7 @@ class TestWikipediaEngine(SearxTestCase):
|
|||
}
|
||||
}
|
||||
}"""
|
||||
response = mock.Mock(content=json, search_params=dicto)
|
||||
response = mock.Mock(text=json, search_params=dicto)
|
||||
results = wikipedia.response(response)
|
||||
self.assertEqual(type(results), list)
|
||||
self.assertEqual(len(results), 2)
|
||||
|
@ -108,10 +108,10 @@ class TestWikipediaEngine(SearxTestCase):
|
|||
}
|
||||
}
|
||||
}"""
|
||||
response = mock.Mock(content=json, search_params=dicto)
|
||||
response = mock.Mock(text=json, search_params=dicto)
|
||||
results = wikipedia.response(response)
|
||||
self.assertEqual(type(results), list)
|
||||
self.assertEqual(len(results), 0)
|
||||
self.assertEqual(len(results), 2)
|
||||
|
||||
# no image
|
||||
json = """
|
||||
|
@ -130,7 +130,7 @@ class TestWikipediaEngine(SearxTestCase):
|
|||
}
|
||||
}
|
||||
}"""
|
||||
response = mock.Mock(content=json, search_params=dicto)
|
||||
response = mock.Mock(text=json, search_params=dicto)
|
||||
results = wikipedia.response(response)
|
||||
self.assertEqual(type(results), list)
|
||||
self.assertEqual(len(results), 2)
|
||||
|
@ -158,7 +158,7 @@ class TestWikipediaEngine(SearxTestCase):
|
|||
}
|
||||
}
|
||||
}"""
|
||||
response = mock.Mock(content=json, search_params=dicto)
|
||||
response = mock.Mock(text=json, search_params=dicto)
|
||||
results = wikipedia.response(response)
|
||||
self.assertEqual(type(results), list)
|
||||
self.assertEqual(len(results), 2)
|
||||
|
|
|
@ -35,11 +35,11 @@ class TestWolframAlphaAPIEngine(SearxTestCase):
|
|||
xml = '''<?xml version='1.0' encoding='UTF-8'?>
|
||||
<queryresult success='false' error='false' />
|
||||
'''
|
||||
response = mock.Mock(content=xml)
|
||||
response = mock.Mock(text=xml.encode('utf-8'))
|
||||
self.assertEqual(wolframalpha_api.response(response), [])
|
||||
|
||||
# test basic case
|
||||
xml = """<?xml version='1.0' encoding='UTF-8'?>
|
||||
xml = b"""<?xml version='1.0' encoding='UTF-8'?>
|
||||
<queryresult success='true'
|
||||
error='false'
|
||||
numpods='3'
|
||||
|
@ -83,7 +83,7 @@ class TestWolframAlphaAPIEngine(SearxTestCase):
|
|||
</pod>
|
||||
</queryresult>
|
||||
"""
|
||||
response = mock.Mock(content=xml, request=request)
|
||||
response = mock.Mock(text=xml, request=request)
|
||||
results = wolframalpha_api.response(response)
|
||||
self.assertEqual(type(results), list)
|
||||
self.assertEqual(len(results), 2)
|
||||
|
@ -107,7 +107,7 @@ class TestWolframAlphaAPIEngine(SearxTestCase):
|
|||
self.assertIn('result_plaintext', results[1]['content'])
|
||||
|
||||
# test calc
|
||||
xml = """<?xml version='1.0' encoding='UTF-8'?>
|
||||
xml = b"""<?xml version='1.0' encoding='UTF-8'?>
|
||||
<queryresult success='true'
|
||||
error='false'
|
||||
numpods='2'
|
||||
|
@ -144,7 +144,7 @@ class TestWolframAlphaAPIEngine(SearxTestCase):
|
|||
</pod>
|
||||
</queryresult>
|
||||
"""
|
||||
response = mock.Mock(content=xml, request=request)
|
||||
response = mock.Mock(text=xml, request=request)
|
||||
results = wolframalpha_api.response(response)
|
||||
self.assertEqual(type(results), list)
|
||||
self.assertEqual(len(results), 2)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue