summaryrefslogtreecommitdiff
path: root/tests/unit/engines
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit/engines')
-rw-r--r--tests/unit/engines/test_archlinux.py4
-rw-r--r--tests/unit/engines/test_bing.py6
-rw-r--r--tests/unit/engines/test_bing_news.py12
-rw-r--r--tests/unit/engines/test_btdigg.py12
-rw-r--r--tests/unit/engines/test_currency_convert.py4
-rw-r--r--tests/unit/engines/test_digbt.py4
-rw-r--r--tests/unit/engines/test_duckduckgo.py3
-rw-r--r--tests/unit/engines/test_frinkiac.py5
-rw-r--r--tests/unit/engines/test_gigablast.py1
-rw-r--r--tests/unit/engines/test_soundcloud.py2
-rw-r--r--tests/unit/engines/test_startpage.py6
-rw-r--r--tests/unit/engines/test_swisscows.py8
-rw-r--r--tests/unit/engines/test_tokyotoshokan.py2
-rw-r--r--tests/unit/engines/test_wikidata.py3
-rw-r--r--tests/unit/engines/test_wikipedia.py18
-rw-r--r--tests/unit/engines/test_wolframalpha_api.py10
16 files changed, 50 insertions, 50 deletions
diff --git a/tests/unit/engines/test_archlinux.py b/tests/unit/engines/test_archlinux.py
index d0009d63a..e4ee0339c 100644
--- a/tests/unit/engines/test_archlinux.py
+++ b/tests/unit/engines/test_archlinux.py
@@ -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)
diff --git a/tests/unit/engines/test_bing.py b/tests/unit/engines/test_bing.py
index a63b2e333..523ec57b8 100644
--- a/tests/unit/engines/test_bing.py
+++ b/tests/unit/engines/test_bing.py
@@ -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):
diff --git a/tests/unit/engines/test_bing_news.py b/tests/unit/engines/test_bing_news.py
index b6793f7be..e571adcee 100644
--- a/tests/unit/engines/test_bing_news.py
+++ b/tests/unit/engines/test_bing_news.py
@@ -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)
diff --git a/tests/unit/engines/test_btdigg.py b/tests/unit/engines/test_btdigg.py
index 2721f4e7c..6a88e3f75 100644
--- a/tests/unit/engines/test_btdigg.py
+++ b/tests/unit/engines/test_btdigg.py
@@ -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)
diff --git a/tests/unit/engines/test_currency_convert.py b/tests/unit/engines/test_currency_convert.py
index b7720569f..2814d791d 100644
--- a/tests/unit/engines/test_currency_convert.py
+++ b/tests/unit/engines/test_currency_convert.py
@@ -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'])
diff --git a/tests/unit/engines/test_digbt.py b/tests/unit/engines/test_digbt.py
index 31a1b03a4..31c2ecabb 100644
--- a/tests/unit/engines/test_digbt.py
+++ b/tests/unit/engines/test_digbt.py
@@ -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)
diff --git a/tests/unit/engines/test_duckduckgo.py b/tests/unit/engines/test_duckduckgo.py
index 7d6abad22..8502a2e51 100644
--- a/tests/unit/engines/test_duckduckgo.py
+++ b/tests/unit/engines/test_duckduckgo.py
@@ -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)
diff --git a/tests/unit/engines/test_frinkiac.py b/tests/unit/engines/test_frinkiac.py
index f3eb021d2..5ea220cd3 100644
--- a/tests/unit/engines/test_frinkiac.py
+++ b/tests/unit/engines/test_frinkiac.py
@@ -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')
diff --git a/tests/unit/engines/test_gigablast.py b/tests/unit/engines/test_gigablast.py
index 127b974b5..6b2d26458 100644
--- a/tests/unit/engines/test_gigablast.py
+++ b/tests/unit/engines/test_gigablast.py
@@ -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)
diff --git a/tests/unit/engines/test_soundcloud.py b/tests/unit/engines/test_soundcloud.py
index 85495dc57..3077d3b4b 100644
--- a/tests/unit/engines/test_soundcloud.py
+++ b/tests/unit/engines/test_soundcloud.py
@@ -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):
diff --git a/tests/unit/engines/test_startpage.py b/tests/unit/engines/test_startpage.py
index 9a1a09bc7..a7a97785e 100644
--- a/tests/unit/engines/test_startpage.py
+++ b/tests/unit/engines/test_startpage.py
@@ -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)
diff --git a/tests/unit/engines/test_swisscows.py b/tests/unit/engines/test_swisscows.py
index 27f33d70a..53890be78 100644
--- a/tests/unit/engines/test_swisscows.py
+++ b/tests/unit/engines/test_swisscows.py
@@ -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)
diff --git a/tests/unit/engines/test_tokyotoshokan.py b/tests/unit/engines/test_tokyotoshokan.py
index efe7dbfc2..b5c6fad17 100644
--- a/tests/unit/engines/test_tokyotoshokan.py
+++ b/tests/unit/engines/test_tokyotoshokan.py
@@ -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)
diff --git a/tests/unit/engines/test_wikidata.py b/tests/unit/engines/test_wikidata.py
index ec5f52ef9..aa69f116e 100644
--- a/tests/unit/engines/test_wikidata.py
+++ b/tests/unit/engines/test_wikidata.py
@@ -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):
diff --git a/tests/unit/engines/test_wikipedia.py b/tests/unit/engines/test_wikipedia.py
index 988080b6a..7a86514c7 100644
--- a/tests/unit/engines/test_wikipedia.py
+++ b/tests/unit/engines/test_wikipedia.py
@@ -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)
diff --git a/tests/unit/engines/test_wolframalpha_api.py b/tests/unit/engines/test_wolframalpha_api.py
index 64a64ceb3..30d337645 100644
--- a/tests/unit/engines/test_wolframalpha_api.py
+++ b/tests/unit/engines/test_wolframalpha_api.py
@@ -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)