summaryrefslogtreecommitdiff
path: root/searx/tests/engines
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/engines
parentc7c6c35ccd7373d2107b70b92badb9b70d31905f (diff)
parente98aef6fc4954681e58d774203d522f0ae478004 (diff)
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'searx/tests/engines')
-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
6 files changed, 19 insertions, 222 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)