summaryrefslogtreecommitdiff
path: root/tests/unit
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/engines/test_archlinux.py17
-rw-r--r--tests/unit/engines/test_bing_images.py162
-rw-r--r--tests/unit/engines/test_doku.py79
-rw-r--r--tests/unit/engines/test_google_images.py6
-rw-r--r--tests/unit/test_preferences.py101
-rw-r--r--tests/unit/test_webapp.py6
6 files changed, 203 insertions, 168 deletions
diff --git a/tests/unit/engines/test_archlinux.py b/tests/unit/engines/test_archlinux.py
index 66959857a..d0009d63a 100644
--- a/tests/unit/engines/test_archlinux.py
+++ b/tests/unit/engines/test_archlinux.py
@@ -18,7 +18,7 @@ class TestArchLinuxEngine(SearxTestCase):
def test_request(self):
query = 'test_query'
dic = defaultdict(dict)
- dic['pageno'] = 0
+ dic['pageno'] = 1
dic['language'] = 'en_US'
params = archlinux.request(query, dic)
self.assertTrue('url' in params)
@@ -31,10 +31,8 @@ class TestArchLinuxEngine(SearxTestCase):
self.assertTrue(domain in params['url'])
def test_response(self):
- response = mock.Mock(text='<html></html>')
- response.search_params = {
- 'language': 'en_US'
- }
+ response = mock.Mock(text='<html></html>',
+ search_params={'language': 'en_US'})
self.assertEqual(archlinux.response(response), [])
html = """
@@ -79,18 +77,15 @@ class TestArchLinuxEngine(SearxTestCase):
expected = [
{
'title': 'ATI',
- 'url': 'https://wiki.archlinux.org/index.php/ATI',
- 'content': 'Lorem ipsum dolor sit amet'
+ 'url': 'https://wiki.archlinux.org/index.php/ATI'
},
{
'title': 'Frequently asked questions',
- 'url': 'https://wiki.archlinux.org/index.php/Frequently_asked_questions',
- 'content': 'CPUs with AMDs instruction set "AMD64"'
+ 'url': 'https://wiki.archlinux.org/index.php/Frequently_asked_questions'
},
{
'title': 'CPU frequency scaling',
- 'url': 'https://wiki.archlinux.org/index.php/CPU_frequency_scaling',
- 'content': 'ondemand for AMD and older Intel CPU'
+ 'url': 'https://wiki.archlinux.org/index.php/CPU_frequency_scaling'
}
]
diff --git a/tests/unit/engines/test_bing_images.py b/tests/unit/engines/test_bing_images.py
index 88538d8fa..9d8ec18af 100644
--- a/tests/unit/engines/test_bing_images.py
+++ b/tests/unit/engines/test_bing_images.py
@@ -38,12 +38,12 @@ class TestBingImagesEngine(SearxTestCase):
self.assertEqual(bing_images.response(response), [])
html = """
- <div class="dg_u" style="width:178px;height:144px;left:17px;top:0px">
+ <div class="dg_u" style="width:178px;height:144px;left:17px;top:0px"><div>
<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>
+ </div></div>
""" # noqa
html = html.replace('\r\n', '').replace('\n', '').replace('\r', '')
response = mock.Mock(text=html)
@@ -78,7 +78,7 @@ class TestBingImagesEngine(SearxTestCase):
self.assertEqual(len(results), 0)
html = """
- <div class="dg_u" style="width:178px;height:144px;left:17px;top:0px">
+ <div class="dg_u" style="width:178px;height:144px;left:17px;top:0px"><div>
<a href="#" ihk="HN.608003696942779811"
m="{ns:&quot;images&quot;,k:&quot;5045&quot;,
mid:&quot;659EB92C317974F34517A1CCAEBEF76A578E08DEE&quot;,
@@ -89,8 +89,8 @@ oh:&quot;238&quot;,tft:&quot;0&quot;,oi:&quot;http://www.image.url/Images/Test%2
<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>
- </div>
- <div class="dg_u" style="width:178px;height:144px;left:17px;top:0px">
+ </div></div>
+ <div class="dg_u" style="width:178px;height:144px;left:17px;top:0px"><div>
<a href="#" ihk="HN.608003696942779811"
m="{ns:&quot;images&quot;,k:&quot;5045&quot;,
mid:&quot;659EB92C317974F34517A1CCAEBEF76A578E08DEE&quot;,
@@ -101,8 +101,8 @@ oh:&quot;238&quot;,tft:&quot;0&quot;,oi:&quot;http://www.image.url/Images/Test%2
<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>
- </div>
- <div class="dg_u" style="width:178px;height:144px;left:17px;top:0px">
+ </div></div>
+ <div class="dg_u" style="width:178px;height:144px;left:17px;top:0px"><div>
<a href="#" ihk="HN.608003696942779811"
m="{ns:&quot;images&quot;,k:&quot;5045&quot;,
mid:&quot;659EB92C317974F34517A1CCAEBEF76A578E08DEE&quot;,
@@ -113,154 +113,10 @@ oh:&quot;238&quot;,tft:&quot;0&quot;,oi:&quot;http://www.image.url/Images/Test%2
<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>
- </div>
- <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>
- </div>
- <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>
- </div>
- <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>
- </div>
- <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>
- </div>
- <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>
- </div>
- <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>
- </div>
- <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>
- </div>
- <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>
- </div>
- <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>
- </div>
- <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>
- </div>
- <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>
- </div>
- <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>
- </div>
+ </div></div>
"""
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), 10)
+ self.assertEqual(len(results), 3)
diff --git a/tests/unit/engines/test_doku.py b/tests/unit/engines/test_doku.py
new file mode 100644
index 000000000..22ddb7a7f
--- /dev/null
+++ b/tests/unit/engines/test_doku.py
@@ -0,0 +1,79 @@
+# -*- coding: utf-8 -*-
+from collections import defaultdict
+import mock
+from searx.engines import doku
+from searx.testing import SearxTestCase
+
+
+class TestDokuEngine(SearxTestCase):
+
+ def test_request(self):
+ query = 'test_query'
+ dicto = defaultdict(dict)
+ params = doku.request(query, dicto)
+ self.assertIn('url', params)
+ self.assertIn(query, params['url'])
+
+ def test_response(self):
+ self.assertRaises(AttributeError, doku.response, None)
+ self.assertRaises(AttributeError, doku.response, [])
+ self.assertRaises(AttributeError, doku.response, '')
+ self.assertRaises(AttributeError, doku.response, '[]')
+
+ response = mock.Mock(text='<html></html>')
+ self.assertEqual(doku.response(response), [])
+
+ html = u"""
+ <div class="search_quickresult">
+ <h3>Pages trouvées :</h3>
+ <ul class="search_quickhits">
+ <li> <a href="/xfconf-query" class="wikilink1" title="xfconf-query">xfconf-query</a></li>
+ </ul>
+ <div class="clearer"></div>
+ </div>
+ """
+ response = mock.Mock(text=html)
+ results = doku.response(response)
+ expected = [{'content': '', 'title': 'xfconf-query', 'url': 'http://localhost:8090/xfconf-query'}]
+ self.assertEqual(doku.response(response), expected)
+
+ html = u"""
+ <dl class="search_results">
+ <dt><a href="/xvnc?s[]=query" class="wikilink1" title="xvnc">xvnc</a>: 40 Occurrences trouvées</dt>
+ <dd>er = /usr/bin/Xvnc
+ server_args = -inetd -<strong class="search_hit">query</strong> localhost -geometry 640x480 ... er = /usr/bin/Xvnc
+ server_args = -inetd -<strong class="search_hit">query</strong> localhost -geometry 800x600 ... er = /usr/bin/Xvnc
+ server_args = -inetd -<strong class="search_hit">query</strong> localhost -geometry 1024x768 ... er = /usr/bin/Xvnc
+ server_args = -inetd -<strong class="search_hit">query</strong> localhost -geometry 1280x1024 -depth 8 -Sec</dd>
+ <dt><a href="/postfix_mysql_tls_sasl_1404?s[]=query"
+ class="wikilink1"
+ title="postfix_mysql_tls_sasl_1404">postfix_mysql_tls_sasl_1404</a>: 14 Occurrences trouvées</dt>
+ <dd>tdepasse
+ hosts = 127.0.0.1
+ dbname = postfix
+ <strong class="search_hit">query</strong> = SELECT goto FROM alias WHERE address='%s' AND a... tdepasse
+ hosts = 127.0.0.1
+ dbname = postfix
+ <strong class="search_hit">query</strong> = SELECT domain FROM domain WHERE domain='%s'
+ #optional <strong class="search_hit">query</strong> to use when relaying for backup MX
+ #<strong class="search_hit">query</strong> = SELECT domain FROM domain WHERE domain='%s' and backupmx =</dd>
+ <dt><a href="/bind9?s[]=query" class="wikilink1" title="bind9">bind9</a>: 12 Occurrences trouvées</dt>
+ <dd> printcmd
+;; Got answer:
+;; -&gt;&gt;HEADER&lt;&lt;- opcode: <strong class="search_hit">QUERY</strong>, status: NOERROR, id: 13427
+;; flags: qr aa rd ra; <strong class="search_hit">QUERY</strong>: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1
+
+[...]
+
+;; <strong class="search_hit">Query</strong> time: 1 msec
+;; SERVER: 127.0.0.1#53(127.0.0.1)
+;... par la requête (<strong class="search_hit">Query</strong> time) , entre la première et la deuxième requête.</dd>
+ </dl>
+ """
+ response = mock.Mock(text=html)
+ results = doku.response(response)
+ self.assertEqual(type(results), list)
+ self.assertEqual(len(results), 3)
+ self.assertEqual(results[0]['title'], 'xvnc')
+# FIXME self.assertEqual(results[0]['url'], u'http://this.should.be.the.link/ű')
+# FIXME self.assertEqual(results[0]['content'], 'This should be the content.')
diff --git a/tests/unit/engines/test_google_images.py b/tests/unit/engines/test_google_images.py
index 876d0af1e..5f184e00c 100644
--- a/tests/unit/engines/test_google_images.py
+++ b/tests/unit/engines/test_google_images.py
@@ -41,7 +41,7 @@ class TestGoogleImagesEngine(SearxTestCase):
</div>
</a>
<div class="rg_meta">
- {"id":"bQWQ9wz9loJmjM:","isu":"clker.com","ity":"png","md":"/search?tbs\u003dsbi:AMhZZit7u1mHyop9pQisu-5idR-8W_1Itvwc3afChmsjQYPx_1yYMzBvUZgtkcGoojqekKZ-6n_1rjX9ySH0OWA_1eO5OijFY6BBDw_1GApr6xxb1bXJcBcj-DiguMoXWW7cZSG7MRQbwnI5SoDZNXcv_1xGszy886I7NVb_1oRKSliTHtzqbXAxhvYreM","msu":"/search?q\u003dsouth\u0026biw\u003d1364\u0026bih\u003d235\u0026tbm\u003disch\u0026tbs\u003dsimg:CAQSEgltBZD3DP2WgiG-U42R4G0RFw","oh":598,"os":"13KB","ow":504,"pt":"South Arrow Clip Art at Clker.com - vector clip art online ...","rid":"vlONkeBtERfDuM","s":"Download this image as:","sc":1,"si":"/search?q\u003dsouth\u0026biw\u003d1364\u0026bih\u003d235\u0026tbm\u003disch\u0026tbs\u003dsimg:CAESEgltBZD3DP2WgiG-U42R4G0RFw","th":245,"tu":"https://thumbnail.url/","tw":206}
+ {"id":"bQWQ9wz9loJmjM:","isu":"clker.com","ity":"png","md":"/search?tbs\u003dsbi:AMhZZit7u1mHyop9pQisu-5idR-8W_1Itvwc3afChmsjQYPx_1yYMzBvUZgtkcGoojqekKZ-6n_1rjX9ySH0OWA_1eO5OijFY6BBDw_1GApr6xxb1bXJcBcj-DiguMoXWW7cZSG7MRQbwnI5SoDZNXcv_1xGszy886I7NVb_1oRKSliTHtzqbXAxhvYreM","msu":"/search?q\u003dsouth\u0026biw\u003d1364\u0026bih\u003d235\u0026tbm\u003disch\u0026tbs\u003dsimg:CAQSEgltBZD3DP2WgiG-U42R4G0RFw","oh":598,"os":"13KB","ow":504,"pt":"South Arrow Clip Art at Clker.com - vector clip art online ...","rid":"vlONkeBtERfDuM","s":"Download this image as:","sc":1,"si":"/search?q\u003dsouth\u0026biw\u003d1364\u0026bih\u003d235\u0026tbm\u003disch\u0026tbs\u003dsimg:CAESEgltBZD3DP2WgiG-U42R4G0RFw","th":245,"tu":"https://thumbnail.url/","tw":206,"ru":"a","ou":"b"}
</div>
</div><!--n--><!--m-->
</div>
@@ -52,7 +52,7 @@ class TestGoogleImagesEngine(SearxTestCase):
self.assertEqual(type(results), list)
self.assertEqual(len(results), 1)
self.assertEqual(results[0]['title'], u'South Arrow Clip Art at Clker.com - vector clip art online ...')
- self.assertEqual(results[0]['url'], 'http://www.clker.com/clipart-south-arrow.html')
+ self.assertEqual(results[0]['url'], 'a')
self.assertEqual(results[0]['thumbnail_src'], 'https://thumbnail.url/')
- self.assertEqual(results[0]['img_src'], 'http://www.clker.com/cliparts/H/X/l/b/0/0/south-arrow-hi.png')
+ self.assertEqual(results[0]['img_src'], 'b')
self.assertEqual(results[0]['content'], 'Download this image as:')
diff --git a/tests/unit/test_preferences.py b/tests/unit/test_preferences.py
new file mode 100644
index 000000000..e418c0af4
--- /dev/null
+++ b/tests/unit/test_preferences.py
@@ -0,0 +1,101 @@
+from searx.preferences import (EnumStringSetting, MapSetting, MissingArgumentException,
+ MultipleChoiceSetting, PluginsSetting, ValidationException)
+from searx.testing import SearxTestCase
+
+
+class PluginStub(object):
+ def __init__(self, id, default_on):
+ self.id = id
+ self.default_on = default_on
+
+
+class TestSettings(SearxTestCase):
+ # map settings
+ def test_map_setting_invalid_initialization(self):
+ with self.assertRaises(MissingArgumentException):
+ setting = MapSetting(3, wrong_argument={'0': 0})
+
+ def test_map_setting_invalid_default_value(self):
+ with self.assertRaises(ValidationException):
+ setting = MapSetting(3, map={'dog': 1, 'bat': 2})
+
+ def test_map_setting_invalid_choice(self):
+ setting = MapSetting(2, map={'dog': 1, 'bat': 2})
+ with self.assertRaises(ValidationException):
+ setting.parse('cat')
+
+ def test_map_setting_valid_default(self):
+ setting = MapSetting(3, map={'dog': 1, 'bat': 2, 'cat': 3})
+ self.assertEquals(setting.get_value(), 3)
+
+ def test_map_setting_valid_choice(self):
+ setting = MapSetting(3, map={'dog': 1, 'bat': 2, 'cat': 3})
+ self.assertEquals(setting.get_value(), 3)
+ setting.parse('bat')
+ self.assertEquals(setting.get_value(), 2)
+
+ def test_enum_setting_invalid_initialization(self):
+ with self.assertRaises(MissingArgumentException):
+ setting = EnumStringSetting('cat', wrong_argument=[0, 1, 2])
+
+ # enum settings
+ def test_enum_setting_invalid_initialization(self):
+ with self.assertRaises(MissingArgumentException):
+ setting = EnumStringSetting('cat', wrong_argument=[0, 1, 2])
+
+ def test_enum_setting_invalid_default_value(self):
+ with self.assertRaises(ValidationException):
+ setting = EnumStringSetting(3, choices=[0, 1, 2])
+
+ def test_enum_setting_invalid_choice(self):
+ setting = EnumStringSetting(0, choices=[0, 1, 2])
+ with self.assertRaises(ValidationException):
+ setting.parse(3)
+
+ def test_enum_setting_valid_default(self):
+ setting = EnumStringSetting(3, choices=[1, 2, 3])
+ self.assertEquals(setting.get_value(), 3)
+
+ def test_enum_setting_valid_choice(self):
+ setting = EnumStringSetting(3, choices=[1, 2, 3])
+ self.assertEquals(setting.get_value(), 3)
+ setting.parse(2)
+ self.assertEquals(setting.get_value(), 2)
+
+ # multiple choice settings
+ def test_multiple_setting_invalid_initialization(self):
+ with self.assertRaises(MissingArgumentException):
+ setting = MultipleChoiceSetting(['2'], wrong_argument=['0', '1', '2'])
+
+ def test_multiple_setting_invalid_default_value(self):
+ with self.assertRaises(ValidationException):
+ setting = MultipleChoiceSetting(['3', '4'], choices=['0', '1', '2'])
+
+ def test_multiple_setting_invalid_choice(self):
+ setting = MultipleChoiceSetting(['1', '2'], choices=['0', '1', '2'])
+ with self.assertRaises(ValidationException):
+ setting.parse('4, 3')
+
+ def test_multiple_setting_valid_default(self):
+ setting = MultipleChoiceSetting(['3'], choices=['1', '2', '3'])
+ self.assertEquals(setting.get_value(), ['3'])
+
+ def test_multiple_setting_valid_choice(self):
+ setting = MultipleChoiceSetting(['3'], choices=['1', '2', '3'])
+ self.assertEquals(setting.get_value(), ['3'])
+ setting.parse('2')
+ self.assertEquals(setting.get_value(), ['2'])
+
+ # plugins settings
+ def test_plugins_setting_all_default_enabled(self):
+ plugin1 = PluginStub('plugin1', True)
+ plugin2 = PluginStub('plugin2', True)
+ setting = PluginsSetting(['3'], choices=[plugin1, plugin2])
+ self.assertEquals(setting.get_enabled(), set(['plugin1', 'plugin2']))
+
+ def test_plugins_setting_few_default_enabled(self):
+ plugin1 = PluginStub('plugin1', True)
+ plugin2 = PluginStub('plugin2', False)
+ plugin3 = PluginStub('plugin3', True)
+ setting = PluginsSetting('name', choices=[plugin1, plugin2, plugin3])
+ self.assertEquals(setting.get_enabled(), set(['plugin1', 'plugin3']))
diff --git a/tests/unit/test_webapp.py b/tests/unit/test_webapp.py
index 071c01df3..5697017d9 100644
--- a/tests/unit/test_webapp.py
+++ b/tests/unit/test_webapp.py
@@ -12,7 +12,6 @@ class ViewsTestCase(SearxTestCase):
def setUp(self):
webapp.app.config['TESTING'] = True # to get better error messages
self.app = webapp.app.test_client()
- webapp.default_theme = 'default'
# set some defaults
self.test_results = [
@@ -43,6 +42,11 @@ class ViewsTestCase(SearxTestCase):
webapp.Search.search = search_mock
+ def get_current_theme_name_mock(override=None):
+ return 'default'
+
+ webapp.get_current_theme_name = get_current_theme_name_mock
+
self.maxDiff = None # to see full diffs
def test_index_empty(self):