summaryrefslogtreecommitdiff
path: root/searx/tests
diff options
context:
space:
mode:
authorKang-min Liu <gugod@gugod.org>2015-11-14 00:05:44 +0100
committerKang-min Liu <gugod@gugod.org>2015-11-14 00:05:44 +0100
commitac8759cd3ff99024864fd04d7c4bef5c3a00b971 (patch)
tree30c3f8b61504532df926bbffedcc8df80a8e926e /searx/tests
parentc7c6c35ccd7373d2107b70b92badb9b70d31905f (diff)
parente98aef6fc4954681e58d774203d522f0ae478004 (diff)
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'searx/tests')
-rw-r--r--searx/tests/engines/test_bing.py8
-rw-r--r--searx/tests/engines/test_bing_images.py10
-rw-r--r--searx/tests/engines/test_duckduckgo.py7
-rw-r--r--searx/tests/engines/test_piratebay.py6
-rw-r--r--searx/tests/engines/test_startpage.py6
-rw-r--r--searx/tests/engines/test_youtube.py204
-rw-r--r--searx/tests/test_engines.py1
-rw-r--r--searx/tests/test_plugins.py28
-rw-r--r--searx/tests/test_results.py41
-rw-r--r--searx/tests/test_search.py23
-rw-r--r--searx/tests/test_utils.py10
-rw-r--r--searx/tests/test_webapp.py8
12 files changed, 98 insertions, 254 deletions
diff --git a/searx/tests/engines/test_bing.py b/searx/tests/engines/test_bing.py
index 52a049f01..bce221440 100644
--- a/searx/tests/engines/test_bing.py
+++ b/searx/tests/engines/test_bing.py
@@ -29,10 +29,10 @@ class TestBingEngine(SearxTestCase):
self.assertRaises(AttributeError, bing.response, '')
self.assertRaises(AttributeError, bing.response, '[]')
- response = mock.Mock(content='<html></html>')
+ response = mock.Mock(text='<html></html>')
self.assertEqual(bing.response(response), [])
- response = mock.Mock(content='<html></html>')
+ response = mock.Mock(text='<html></html>')
self.assertEqual(bing.response(response), [])
html = """
@@ -54,7 +54,7 @@ class TestBingEngine(SearxTestCase):
</div>
</div>
"""
- response = mock.Mock(content=html)
+ response = mock.Mock(text=html)
results = bing.response(response)
self.assertEqual(type(results), list)
self.assertEqual(len(results), 1)
@@ -81,7 +81,7 @@ class TestBingEngine(SearxTestCase):
</div>
</li>
"""
- response = mock.Mock(content=html)
+ response = mock.Mock(text=html)
results = bing.response(response)
self.assertEqual(type(results), list)
self.assertEqual(len(results), 1)
diff --git a/searx/tests/engines/test_bing_images.py b/searx/tests/engines/test_bing_images.py
index f869da79d..f42dff7e8 100644
--- a/searx/tests/engines/test_bing_images.py
+++ b/searx/tests/engines/test_bing_images.py
@@ -31,10 +31,10 @@ class TestBingImagesEngine(SearxTestCase):
self.assertRaises(AttributeError, bing_images.response, '')
self.assertRaises(AttributeError, bing_images.response, '[]')
- response = mock.Mock(content='<html></html>')
+ response = mock.Mock(text='<html></html>')
self.assertEqual(bing_images.response(response), [])
- response = mock.Mock(content='<html></html>')
+ response = mock.Mock(text='<html></html>')
self.assertEqual(bing_images.response(response), [])
html = """
@@ -52,7 +52,7 @@ oh:&quot;238&quot;,tft:&quot;0&quot;,oi:&quot;http://www.image.url/Images/Test%2
</div>
"""
html = html.replace('\r\n', '').replace('\n', '').replace('\r', '')
- response = mock.Mock(content=html)
+ response = mock.Mock(text=html)
results = bing_images.response(response)
self.assertEqual(type(results), list)
self.assertEqual(len(results), 1)
@@ -75,7 +75,7 @@ oh:&quot;238&quot;,tft:&quot;0&quot;,oi:&quot;http://www.image.url/Images/Test%2
style="height:144px;" width="178" height="144"/>
</a>
"""
- response = mock.Mock(content=html)
+ response = mock.Mock(text=html)
results = bing_images.response(response)
self.assertEqual(type(results), list)
self.assertEqual(len(results), 0)
@@ -263,7 +263,7 @@ oh:&quot;238&quot;,tft:&quot;0&quot;,oi:&quot;http://www.image.url/Images/Test%2
</div>
"""
html = html.replace('\r\n', '').replace('\n', '').replace('\r', '')
- response = mock.Mock(content=html)
+ response = mock.Mock(text=html)
results = bing_images.response(response)
self.assertEqual(type(results), list)
self.assertEqual(len(results), 10)
diff --git a/searx/tests/engines/test_duckduckgo.py b/searx/tests/engines/test_duckduckgo.py
index 6f085cbc2..14cd9cd87 100644
--- a/searx/tests/engines/test_duckduckgo.py
+++ b/searx/tests/engines/test_duckduckgo.py
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
from collections import defaultdict
import mock
from searx.engines import duckduckgo
@@ -30,7 +31,7 @@ class TestDuckduckgoEngine(SearxTestCase):
response = mock.Mock(text='<html></html>')
self.assertEqual(duckduckgo.response(response), [])
- html = """
+ html = u"""
<div class="results_links results_links_deep web-result">
<div class="icon_fav" style="display: block;">
<a rel="nofollow" href="https://www.test.com/">
@@ -39,7 +40,7 @@ class TestDuckduckgoEngine(SearxTestCase):
</a>
</div>
<div class="links_main links_deep"> <!-- This is the visible part -->
- <a rel="nofollow" class="large" href="http://this.should.be.the.link/">
+ <a rel="nofollow" class="large" href="http://this.should.be.the.link/ű">
This <b>is</b> <b>the</b> title
</a>
<div class="snippet"><b>This</b> should be the content.</div>
@@ -54,7 +55,7 @@ class TestDuckduckgoEngine(SearxTestCase):
self.assertEqual(type(results), list)
self.assertEqual(len(results), 1)
self.assertEqual(results[0]['title'], 'This is the title')
- self.assertEqual(results[0]['url'], 'http://this.should.be.the.link/')
+ self.assertEqual(results[0]['url'], u'http://this.should.be.the.link/ű')
self.assertEqual(results[0]['content'], 'This should be the content.')
html = """
diff --git a/searx/tests/engines/test_piratebay.py b/searx/tests/engines/test_piratebay.py
index 6ebbcf713..5699380be 100644
--- a/searx/tests/engines/test_piratebay.py
+++ b/searx/tests/engines/test_piratebay.py
@@ -15,7 +15,7 @@ class TestPiratebayEngine(SearxTestCase):
params = piratebay.request(query, dicto)
self.assertIn('url', params)
self.assertIn(query, params['url'])
- self.assertIn('piratebay.am', params['url'])
+ self.assertIn('piratebay.se', params['url'])
self.assertIn('0', params['url'])
dicto['category'] = 'music'
@@ -99,7 +99,7 @@ class TestPiratebayEngine(SearxTestCase):
self.assertEqual(type(results), list)
self.assertEqual(len(results), 2)
self.assertEqual(results[0]['title'], 'This is the title')
- self.assertEqual(results[0]['url'], 'https://thepiratebay.am/this.is.the.link')
+ self.assertEqual(results[0]['url'], 'https://thepiratebay.se/this.is.the.link')
self.assertEqual(results[0]['content'], 'This is the content and should be OK')
self.assertEqual(results[0]['seed'], 13)
self.assertEqual(results[0]['leech'], 334)
@@ -149,7 +149,7 @@ class TestPiratebayEngine(SearxTestCase):
self.assertEqual(type(results), list)
self.assertEqual(len(results), 1)
self.assertEqual(results[0]['title'], 'This is the title')
- self.assertEqual(results[0]['url'], 'https://thepiratebay.am/this.is.the.link')
+ self.assertEqual(results[0]['url'], 'https://thepiratebay.se/this.is.the.link')
self.assertEqual(results[0]['content'], 'This is the content and should be OK')
self.assertEqual(results[0]['seed'], 0)
self.assertEqual(results[0]['leech'], 0)
diff --git a/searx/tests/engines/test_startpage.py b/searx/tests/engines/test_startpage.py
index 07f13ee27..9a1a09bc7 100644
--- a/searx/tests/engines/test_startpage.py
+++ b/searx/tests/engines/test_startpage.py
@@ -42,7 +42,7 @@ class TestStartpageEngine(SearxTestCase):
</a>
<span id='title_stars_2' name='title_stars_2'> </span>
</h3>
- <p class='desc'>
+ <p class='desc clk'>
This should be the content.
</p>
<p>
@@ -78,7 +78,7 @@ class TestStartpageEngine(SearxTestCase):
</a>
<span id='title_stars_2' name='title_stars_2'> </span>
</h3>
- <p class='desc'>
+ <p class='desc clk'>
This should be the content.
</p>
<p>
@@ -101,7 +101,7 @@ class TestStartpageEngine(SearxTestCase):
<h3>
<span id='title_stars_2' name='title_stars_2'> </span>
</h3>
- <p class='desc'>
+ <p class='desc clk'>
This should be the content.
</p>
<p>
diff --git a/searx/tests/engines/test_youtube.py b/searx/tests/engines/test_youtube.py
deleted file mode 100644
index 434305228..000000000
--- a/searx/tests/engines/test_youtube.py
+++ /dev/null
@@ -1,204 +0,0 @@
-from collections import defaultdict
-import mock
-from searx.engines import youtube
-from searx.testing import SearxTestCase
-
-
-class TestYoutubeEngine(SearxTestCase):
-
- def test_request(self):
- query = 'test_query'
- dicto = defaultdict(dict)
- dicto['pageno'] = 0
- dicto['language'] = 'fr_FR'
- params = youtube.request(query, dicto)
- self.assertTrue('url' in params)
- self.assertTrue(query in params['url'])
- self.assertTrue('youtube.com' in params['url'])
- self.assertTrue('fr' in params['url'])
-
- dicto['language'] = 'all'
- params = youtube.request(query, dicto)
- self.assertFalse('fr' in params['url'])
-
- def test_response(self):
- self.assertRaises(AttributeError, youtube.response, None)
- self.assertRaises(AttributeError, youtube.response, [])
- self.assertRaises(AttributeError, youtube.response, '')
- self.assertRaises(AttributeError, youtube.response, '[]')
-
- response = mock.Mock(text='{}')
- self.assertEqual(youtube.response(response), [])
-
- response = mock.Mock(text='{"data": []}')
- self.assertEqual(youtube.response(response), [])
-
- json = """
- {"feed":{"entry":[{
- "id":{"$t":"http://gdata.youtube.com/feeds/api/videos/DIVZCPfAOeM"},
- "published":{"$t":"2015-01-23T21:25:00.000Z"},
- "updated":{"$t":"2015-01-26T14:38:15.000Z"},
- "title":{"$t":"Title",
- "type":"text"},"content":{"$t":"Description","type":"text"},
- "link":[{"rel":"alternate","type":"text/html",
- "href":"https://www.youtube.com/watch?v=DIVZCPfAOeM&feature=youtube_gdata"},
- {"rel":"http://gdata.youtube.com/schemas/2007#video.related",
- "type":"application/atom+xml",
- "href":"https://gdata.youtube.com/feeds/api/videos/DIVZCPfAOeM/related"},
- {"rel":"http://gdata.youtube.com/schemas/2007#mobile","type":"text/html",
- "href":"https://m.youtube.com/details?v=DIVZCPfAOeM"},
- {"rel":"self","type":"application/atom+xml",
- "href":"https://gdata.youtube.com/feeds/api/videos/DIVZCPfAOeM"}],
- "author":[{"name":{"$t":"Cauet"},
- "uri":{"$t":"https://gdata.youtube.com/feeds/api/users/cauetofficiel"} }],
- "gd$comments":{"gd$feedLink":{"rel":"http://gdata.youtube.com/schemas/2007#comments",
- "href":"https://gdata.youtube.com/feeds/api/videos/DIVZCPfAOeM/comments",
- "countHint":8} },
- "media$group":{"media$category":[{"$t":"Comedy","label":"Comedy",
- "scheme":"http://gdata.youtube.com/schemas/2007/categories.cat"}],
- "media$content":[{"url":"https://www.youtube.com/v/DIVZCPfAOeM?version=3&f=videos&app=youtube_gdata",
- "type":"application/x-shockwave-flash","medium":"video",
- "isDefault":"true","expression":"full","duration":354,"yt$format":5},
- {"url":"rtsp://r1---sn-cg07luel.c.youtube.com/CiILENy73wIaGQnjOcD3CFmFDBMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp",
- "type":"video/3gpp","medium":"video","expression":"full","duration":354,
- "yt$format":1},
- {"url":"rtsp://r1---sn-cg07luel.c.youtube.com/CiILENy73wIaGQnjOcD3CFmFDBMYESARFEgGUgZ2aWRlb3MM/0/0/0/video.3gp",
- "type":"video/3gpp","medium":"video","expression":"full","duration":354,"yt$format":6}],
- "media$description":{"$t":"Desc","type":"plain"},
- "media$keywords":{},
- "media$player":[{"url":"https://www.youtube.com/watch?v=DIVZCPfAOeM&feature=youtube_gdata_player"}],
- "media$thumbnail":[{"url":"https://i.ytimg.com/vi/DIVZCPfAOeM/0.jpg",
- "height":360,"width":480,"time":"00:02:57"},
- {"url":"https://i.ytimg.com/vi/DIVZCPfAOeM/1.jpg","height":90,"width":120,"time":"00:01:28.500"},
- {"url":"https://i.ytimg.com/vi/DIVZCPfAOeM/2.jpg","height":90,"width":120,"time":"00:02:57"},
- {"url":"https://i.ytimg.com/vi/DIVZCPfAOeM/3.jpg","height":90,"width":120,"time":"00:04:25.500"}],
- "media$title":{"$t":"Title","type":"plain"},
- "yt$duration":{"seconds":"354"} },
- "gd$rating":{"average":4.932159,"max":5,"min":1,"numRaters":1533,
- "rel":"http://schemas.google.com/g/2005#overall"},
- "yt$statistics":{"favoriteCount":"0","viewCount":"92464"} }
- ]
- }
- }
- """
- response = mock.Mock(text=json)
- results = youtube.response(response)
- self.assertEqual(type(results), list)
- self.assertEqual(len(results), 1)
- self.assertEqual(results[0]['title'], 'Title')
- self.assertEqual(results[0]['url'], 'https://www.youtube.com/watch?v=DIVZCPfAOeM')
- self.assertEqual(results[0]['content'], 'Description')
- self.assertEqual(results[0]['thumbnail'], 'https://i.ytimg.com/vi/DIVZCPfAOeM/0.jpg')
- self.assertTrue('DIVZCPfAOeM' in results[0]['embedded'])
-
- json = """
- {"feed":{"entry":[{
- "id":{"$t":"http://gdata.youtube.com/feeds/api/videos/DIVZCPfAOeM"},
- "published":{"$t":"2015-01-23T21:25:00.000Z"},
- "updated":{"$t":"2015-01-26T14:38:15.000Z"},
- "title":{"$t":"Title",
- "type":"text"},"content":{"$t":"Description","type":"text"},
- "link":[{"rel":"http://gdata.youtube.com/schemas/2007#video.related",
- "type":"application/atom+xml",
- "href":"https://gdata.youtube.com/feeds/api/videos/DIVZCPfAOeM/related"},
- {"rel":"self","type":"application/atom+xml",
- "href":"https://gdata.youtube.com/feeds/api/videos/DIVZCPfAOeM"}],
- "author":[{"name":{"$t":"Cauet"},
- "uri":{"$t":"https://gdata.youtube.com/feeds/api/users/cauetofficiel"} }],
- "gd$comments":{"gd$feedLink":{"rel":"http://gdata.youtube.com/schemas/2007#comments",
- "href":"https://gdata.youtube.com/feeds/api/videos/DIVZCPfAOeM/comments",
- "countHint":8} },
- "media$group":{"media$category":[{"$t":"Comedy","label":"Comedy",
- "scheme":"http://gdata.youtube.com/schemas/2007/categories.cat"}],
- "media$content":[{"url":"https://www.youtube.com/v/DIVZCPfAOeM?version=3&f=videos&app=youtube_gdata",
- "type":"application/x-shockwave-flash","medium":"video",
- "isDefault":"true","expression":"full","duration":354,"yt$format":5},
- {"url":"rtsp://r1---sn-cg07luel.c.youtube.com/CiILENy73wIaGQnjOcD3CFmFDBMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp",
- "type":"video/3gpp","medium":"video","expression":"full","duration":354,
- "yt$format":1},
- {"url":"rtsp://r1---sn-cg07luel.c.youtube.com/CiILENy73wIaGQnjOcD3CFmFDBMYESARFEgGUgZ2aWRlb3MM/0/0/0/video.3gp",
- "type":"video/3gpp","medium":"video","expression":"full","duration":354,"yt$format":6}],
- "media$description":{"$t":"Desc","type":"plain"},
- "media$keywords":{},
- "media$player":[{"url":"https://www.youtube.com/watch?v=DIVZCPfAOeM&feature=youtube_gdata_player"}],
- "media$thumbnail":[{"url":"https://i.ytimg.com/vi/DIVZCPfAOeM/0.jpg",
- "height":360,"width":480,"time":"00:02:57"},
- {"url":"https://i.ytimg.com/vi/DIVZCPfAOeM/1.jpg","height":90,"width":120,"time":"00:01:28.500"},
- {"url":"https://i.ytimg.com/vi/DIVZCPfAOeM/2.jpg","height":90,"width":120,"time":"00:02:57"},
- {"url":"https://i.ytimg.com/vi/DIVZCPfAOeM/3.jpg","height":90,"width":120,"time":"00:04:25.500"}],
- "media$title":{"$t":"Title","type":"plain"},
- "yt$duration":{"seconds":"354"} },
- "gd$rating":{"average":4.932159,"max":5,"min":1,"numRaters":1533,
- "rel":"http://schemas.google.com/g/2005#overall"},
- "yt$statistics":{"favoriteCount":"0","viewCount":"92464"} }
- ]
- }
- }
- """
- response = mock.Mock(text=json)
- results = youtube.response(response)
- self.assertEqual(type(results), list)
- self.assertEqual(len(results), 0)
-
- json = """
- {"feed":{"entry":[{
- "id":{"$t":"http://gdata.youtube.com/feeds/api/videos/DIVZCPfAOeM"},
- "published":{"$t":"2015-01-23T21:25:00.000Z"},
- "updated":{"$t":"2015-01-26T14:38:15.000Z"},
- "title":{"$t":"Title",
- "type":"text"},"content":{"$t":"Description","type":"text"},
- "link":[{"rel":"alternate","type":"text/html",
- "href":"https://www.youtube.com/watch?v=DIVZCPfAOeM"},
- {"rel":"http://gdata.youtube.com/schemas/2007#video.related",
- "type":"application/atom+xml",
- "href":"https://gdata.youtube.com/feeds/api/videos/DIVZCPfAOeM/related"},
- {"rel":"http://gdata.youtube.com/schemas/2007#mobile","type":"text/html",
- "href":"https://m.youtube.com/details?v=DIVZCPfAOeM"},
- {"rel":"self","type":"application/atom+xml",
- "href":"https://gdata.youtube.com/feeds/api/videos/DIVZCPfAOeM"}],
- "author":[{"name":{"$t":"Cauet"},
- "uri":{"$t":"https://gdata.youtube.com/feeds/api/users/cauetofficiel"} }],
- "gd$comments":{"gd$feedLink":{"rel":"http://gdata.youtube.com/schemas/2007#comments",
- "href":"https://gdata.youtube.com/feeds/api/videos/DIVZCPfAOeM/comments",
- "countHint":8} },
- "media$group":{"media$category":[{"$t":"Comedy","label":"Comedy",
- "scheme":"http://gdata.youtube.com/schemas/2007/categories.cat"}],
- "media$content":[{"url":"https://www.youtube.com/v/DIVZCPfAOeM?version=3&f=videos&app=youtube_gdata",
- "type":"application/x-shockwave-flash","medium":"video",
- "isDefault":"true","expression":"full","duration":354,"yt$format":5},
- {"url":"rtsp://r1---sn-cg07luel.c.youtube.com/CiILENy73wIaGQnjOcD3CFmFDBMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp",
- "type":"video/3gpp","medium":"video","expression":"full","duration":354,
- "yt$format":1},
- {"url":"rtsp://r1---sn-cg07luel.c.youtube.com/CiILENy73wIaGQnjOcD3CFmFDBMYESARFEgGUgZ2aWRlb3MM/0/0/0/video.3gp",
- "type":"video/3gpp","medium":"video","expression":"full","duration":354,"yt$format":6}],
- "media$description":{"$t":"Desc","type":"plain"},
- "media$keywords":{},
- "media$player":[{"url":"https://www.youtube.com/watch?v=DIVZCPfAOeM&feature=youtube_gdata_player"}],
- "media$title":{"$t":"Title","type":"plain"},
- "yt$duration":{"seconds":"354"} },
- "gd$rating":{"average":4.932159,"max":5,"min":1,"numRaters":1533,
- "rel":"http://schemas.google.com/g/2005#overall"},
- "yt$statistics":{"favoriteCount":"0","viewCount":"92464"} }
- ]
- }
- }
- """
- response = mock.Mock(text=json)
- results = youtube.response(response)
- self.assertEqual(type(results), list)
- self.assertEqual(len(results), 1)
- self.assertEqual(results[0]['title'], 'Title')
- self.assertEqual(results[0]['url'], 'https://www.youtube.com/watch?v=DIVZCPfAOeM')
- self.assertEqual(results[0]['content'], 'Description')
- self.assertEqual(results[0]['thumbnail'], '')
- self.assertTrue('DIVZCPfAOeM' in results[0]['embedded'])
-
- json = """
- {"toto":{"entry":[]
- }
- }
- """
- response = mock.Mock(text=json)
- results = youtube.response(response)
- self.assertEqual(type(results), list)
- self.assertEqual(len(results), 0)
diff --git a/searx/tests/test_engines.py b/searx/tests/test_engines.py
index dc062e95f..793b77460 100644
--- a/searx/tests/test_engines.py
+++ b/searx/tests/test_engines.py
@@ -40,7 +40,6 @@ from searx.tests.engines.test_www1x import * # noqa
from searx.tests.engines.test_www500px import * # noqa
from searx.tests.engines.test_yacy import * # noqa
from searx.tests.engines.test_yahoo import * # noqa
-from searx.tests.engines.test_youtube import * # noqa
from searx.tests.engines.test_youtube_api import * # noqa
from searx.tests.engines.test_youtube_noapi import * # noqa
from searx.tests.engines.test_yahoo_news import * # noqa
diff --git a/searx/tests/test_plugins.py b/searx/tests/test_plugins.py
index c5171127c..98d39ec14 100644
--- a/searx/tests/test_plugins.py
+++ b/searx/tests/test_plugins.py
@@ -5,6 +5,12 @@ from searx import plugins
from mock import Mock
+def get_search_mock(query, **kwargs):
+ return {'search': Mock(query=query,
+ result_container=Mock(answers=set()),
+ **kwargs)}
+
+
class PluginStoreTest(SearxTestCase):
def test_PluginStore_init(self):
@@ -46,23 +52,23 @@ class SelfIPTest(SearxTestCase):
request = Mock(user_plugins=store.plugins,
remote_addr='127.0.0.1')
request.headers.getlist.return_value = []
- ctx = {'search': Mock(answers=set(),
- query='ip')}
+ ctx = get_search_mock(query='ip')
store.call('post_search', request, ctx)
- self.assertTrue('127.0.0.1' in ctx['search'].answers)
+ self.assertTrue('127.0.0.1' in ctx['search'].result_container.answers)
# User agent test
request = Mock(user_plugins=store.plugins,
user_agent='Mock')
request.headers.getlist.return_value = []
- ctx = {'search': Mock(answers=set(),
- query='user-agent')}
+
+ ctx = get_search_mock(query='user-agent')
store.call('post_search', request, ctx)
- self.assertTrue('Mock' in ctx['search'].answers)
- ctx = {'search': Mock(answers=set(),
- query='user agent')}
+ self.assertTrue('Mock' in ctx['search'].result_container.answers)
+
+ ctx = get_search_mock(query='user-agent')
store.call('post_search', request, ctx)
- self.assertTrue('Mock' in ctx['search'].answers)
- ctx = {'search': Mock(answers=set(),
- query='What is my User-Agent?')}
+ self.assertTrue('Mock' in ctx['search'].result_container.answers)
+
+ ctx = get_search_mock(query='What is my User-Agent?')
store.call('post_search', request, ctx)
+ self.assertTrue('Mock' in ctx['search'].result_container.answers)
diff --git a/searx/tests/test_results.py b/searx/tests/test_results.py
new file mode 100644
index 000000000..274b5b37a
--- /dev/null
+++ b/searx/tests/test_results.py
@@ -0,0 +1,41 @@
+# -*- coding: utf-8 -*-
+
+from searx.results import ResultContainer
+from searx.testing import SearxTestCase
+
+
+def fake_result(url='https://aa.bb/cc?dd=ee#ff',
+ title='aaa',
+ content='bbb',
+ engine='wikipedia', **kwargs):
+ result = {'url': url,
+ 'title': title,
+ 'content': content,
+ 'engine': engine}
+ result.update(kwargs)
+ return result
+
+
+# TODO
+class ResultContainerTestCase(SearxTestCase):
+
+ def test_empty(self):
+ c = ResultContainer()
+ self.assertEqual(c.get_ordered_results(), [])
+
+ def test_one_result(self):
+ c = ResultContainer()
+ c.extend('wikipedia', [fake_result()])
+ self.assertEqual(c.results_length(), 1)
+
+ def test_one_suggestion(self):
+ c = ResultContainer()
+ c.extend('wikipedia', [fake_result(suggestion=True)])
+ self.assertEqual(len(c.suggestions), 1)
+ self.assertEqual(c.results_length(), 0)
+
+ def test_result_merge(self):
+ c = ResultContainer()
+ c.extend('wikipedia', [fake_result()])
+ c.extend('wikidata', [fake_result(), fake_result(url='https://example.com/')])
+ self.assertEqual(c.results_length(), 2)
diff --git a/searx/tests/test_search.py b/searx/tests/test_search.py
index 89d0b620d..af5fffd8b 100644
--- a/searx/tests/test_search.py
+++ b/searx/tests/test_search.py
@@ -1,25 +1,10 @@
# -*- coding: utf-8 -*-
-from searx.search import score_results
from searx.testing import SearxTestCase
-def fake_result(url='https://aa.bb/cc?dd=ee#ff',
- title='aaa',
- content='bbb',
- engine='wikipedia'):
- return {'url': url,
- 'title': title,
- 'content': content,
- 'engine': engine}
+# TODO
+class SearchTestCase(SearxTestCase):
-
-class ScoreResultsTestCase(SearxTestCase):
-
- def test_empty(self):
- self.assertEqual(score_results(dict()), [])
-
- def test_urlparse(self):
- results = score_results(dict(a=[fake_result(url='https://aa.bb/cc?dd=ee#ff')]))
- parsed_url = results[0]['parsed_url']
- self.assertEqual(parsed_url.query, 'dd=ee')
+ def test_(self):
+ pass
diff --git a/searx/tests/test_utils.py b/searx/tests/test_utils.py
index abe411c2b..04480791d 100644
--- a/searx/tests/test_utils.py
+++ b/searx/tests/test_utils.py
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
import mock
from searx.testing import SearxTestCase
from searx import utils
@@ -51,6 +52,15 @@ class TestUtils(SearxTestCase):
self.assertIsNotNone(utils.html_to_text(html))
self.assertEqual(utils.html_to_text(html), "Test text")
+ def test_prettify_url(self):
+ data = (('https://searx.me/', 'https://searx.me/'),
+ (u'https://searx.me/ű', u'https://searx.me/ű'),
+ ('https://searx.me/' + (100 * 'a'), 'https://searx.me/[...]aaaaaaaaaaaaaaaaa'),
+ (u'https://searx.me/' + (100 * u'ű'), u'https://searx.me/[...]űűűűűűűűűűűűűűűűű'))
+
+ for test_url, expected in data:
+ self.assertEqual(utils.prettify_url(test_url, max_length=32), expected)
+
class TestHTMLTextExtractor(SearxTestCase):
diff --git a/searx/tests/test_webapp.py b/searx/tests/test_webapp.py
index 471ec2f2d..1d9cc649c 100644
--- a/searx/tests/test_webapp.py
+++ b/searx/tests/test_webapp.py
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
import json
+from mock import Mock
from urlparse import ParseResult
from searx import webapp
from searx.testing import SearxTestCase
@@ -33,7 +34,12 @@ class ViewsTestCase(SearxTestCase):
]
def search_mock(search_self, *args):
- search_self.results = self.test_results
+ search_self.result_container = Mock(get_ordered_results=lambda: self.test_results,
+ answers=set(),
+ suggestions=set(),
+ infoboxes=[],
+ results=self.test_results,
+ results_length=lambda: len(self.test_results))
webapp.Search.search = search_mock