summaryrefslogtreecommitdiff
path: root/searx/tests
diff options
context:
space:
mode:
Diffstat (limited to 'searx/tests')
-rw-r--r--searx/tests/engines/test_blekko_images.py11
-rw-r--r--searx/tests/engines/test_deezer.py8
-rw-r--r--searx/tests/engines/test_google_images.py11
-rw-r--r--searx/tests/engines/test_kickass.py1
-rw-r--r--searx/tests/engines/test_piratebay.py31
-rw-r--r--searx/tests/engines/test_spotify.py124
-rw-r--r--searx/tests/engines/test_yahoo.py107
-rw-r--r--searx/tests/test_engines.py1
-rw-r--r--searx/tests/test_plugins.py51
-rw-r--r--searx/tests/test_webapp.py44
10 files changed, 283 insertions, 106 deletions
diff --git a/searx/tests/engines/test_blekko_images.py b/searx/tests/engines/test_blekko_images.py
index 793fadbad..beb0853e3 100644
--- a/searx/tests/engines/test_blekko_images.py
+++ b/searx/tests/engines/test_blekko_images.py
@@ -12,9 +12,14 @@ class TestBlekkoImagesEngine(SearxTestCase):
dicto['pageno'] = 0
dicto['safesearch'] = 1
params = blekko_images.request(query, dicto)
- self.assertTrue('url' in params)
- self.assertTrue(query in params['url'])
- self.assertTrue('blekko.com' in params['url'])
+ self.assertIn('url', params)
+ self.assertIn(query, params['url'])
+ self.assertIn('blekko.com', params['url'])
+ self.assertIn('page', params['url'])
+
+ dicto['pageno'] = 1
+ params = blekko_images.request(query, dicto)
+ self.assertNotIn('page', params['url'])
def test_response(self):
self.assertRaises(AttributeError, blekko_images.response, None)
diff --git a/searx/tests/engines/test_deezer.py b/searx/tests/engines/test_deezer.py
index c8c2c90f2..ad09d2a2c 100644
--- a/searx/tests/engines/test_deezer.py
+++ b/searx/tests/engines/test_deezer.py
@@ -30,9 +30,9 @@ class TestDeezerEngine(SearxTestCase):
json = """
{"data":[
{"id":100, "title":"Title of track",
- "link":"http:\/\/www.deezer.com\/track\/1094042","duration":232,
+ "link":"https:\/\/www.deezer.com\/track\/1094042","duration":232,
"artist":{"id":200,"name":"Artist Name",
- "link":"http:\/\/www.deezer.com\/artist\/1217","type":"artist"},
+ "link":"https:\/\/www.deezer.com\/artist\/1217","type":"artist"},
"album":{"id":118106,"title":"Album Title","type":"album"},"type":"track"}
]}
"""
@@ -41,14 +41,14 @@ class TestDeezerEngine(SearxTestCase):
self.assertEqual(type(results), list)
self.assertEqual(len(results), 1)
self.assertEqual(results[0]['title'], 'Title of track')
- self.assertEqual(results[0]['url'], 'http://www.deezer.com/track/1094042')
+ self.assertEqual(results[0]['url'], 'https://www.deezer.com/track/1094042')
self.assertEqual(results[0]['content'], 'Artist Name • Album Title • Title of track')
self.assertTrue('100' in results[0]['embedded'])
json = """
{"data":[
{"id":200,"name":"Artist Name",
- "link":"http:\/\/www.deezer.com\/artist\/1217","type":"artist"}
+ "link":"https:\/\/www.deezer.com\/artist\/1217","type":"artist"}
]}
"""
response = mock.Mock(text=json)
diff --git a/searx/tests/engines/test_google_images.py b/searx/tests/engines/test_google_images.py
index 6870ff52f..32d133334 100644
--- a/searx/tests/engines/test_google_images.py
+++ b/searx/tests/engines/test_google_images.py
@@ -11,9 +11,14 @@ class TestGoogleImagesEngine(SearxTestCase):
dicto = defaultdict(dict)
dicto['pageno'] = 1
params = google_images.request(query, dicto)
- self.assertTrue('url' in params)
- self.assertTrue(query in params['url'])
- self.assertTrue('googleapis.com' in params['url'])
+ self.assertIn('url', params)
+ self.assertIn(query, params['url'])
+ self.assertIn('googleapis.com', params['url'])
+ self.assertIn('safe=on', params['url'])
+
+ dicto['safesearch'] = 0
+ params = google_images.request(query, dicto)
+ self.assertIn('safe=off', params['url'])
def test_response(self):
self.assertRaises(AttributeError, google_images.response, None)
diff --git a/searx/tests/engines/test_kickass.py b/searx/tests/engines/test_kickass.py
index 971d0847e..4cfcaa63c 100644
--- a/searx/tests/engines/test_kickass.py
+++ b/searx/tests/engines/test_kickass.py
@@ -15,7 +15,6 @@ class TestKickassEngine(SearxTestCase):
self.assertIn('url', params)
self.assertIn(query, params['url'])
self.assertIn('kickass.to', params['url'])
- self.assertIn('verify', params)
self.assertFalse(params['verify'])
def test_response(self):
diff --git a/searx/tests/engines/test_piratebay.py b/searx/tests/engines/test_piratebay.py
index 17bc3a526..5699380be 100644
--- a/searx/tests/engines/test_piratebay.py
+++ b/searx/tests/engines/test_piratebay.py
@@ -65,12 +65,39 @@ class TestPiratebayEngine(SearxTestCase):
<td align="right">13</td>
<td align="right">334</td>
</tr>
+ <tr>
+ <td class="vertTh">
+ <center>
+ <a href="#" title="More from this category">Anime</a><br/>
+ (<a href="#" title="More from this category">Anime</a>)
+ </center>
+ </td>
+ <td>
+ <div class="detName">
+ <a href="/this.is.the.link" class="detLink" title="Title">
+ This is the title
+ </a>
+ </div>
+ <a href="magnet:?xt=urn:btih:MAGNETLINK" title="Download this torrent using magnet">
+ <img src="/static/img/icon-magnet.gif" alt="Magnet link"/>
+ </a>
+ <a href="/user/HorribleSubs">
+ <img src="/static/img/vip.gif" alt="VIP" title="VIP" style="width:11px;" border='0'/>
+ </a>
+ <img src="/static/img/11x11p.png"/>
+ <font class="detDesc">
+ This is the content <span>and should be</span> OK
+ </font>
+ </td>
+ <td align="right">13</td>
+ <td align="right">334</td>
+ </tr>
</table>
"""
response = mock.Mock(text=html)
results = piratebay.response(response)
self.assertEqual(type(results), list)
- self.assertEqual(len(results), 1)
+ self.assertEqual(len(results), 2)
self.assertEqual(results[0]['title'], 'This is the title')
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')
@@ -79,6 +106,8 @@ class TestPiratebayEngine(SearxTestCase):
self.assertEqual(results[0]['magnetlink'], 'magnet:?xt=urn:btih:MAGNETLINK')
self.assertEqual(results[0]['torrentfile'], 'http://torcache.net/torrent/TORRENTFILE.torrent')
+ self.assertEqual(results[1]['torrentfile'], None)
+
html = """
<table id="searchResult">
<tr>
diff --git a/searx/tests/engines/test_spotify.py b/searx/tests/engines/test_spotify.py
new file mode 100644
index 000000000..fd274abbd
--- /dev/null
+++ b/searx/tests/engines/test_spotify.py
@@ -0,0 +1,124 @@
+from collections import defaultdict
+import mock
+from searx.engines import spotify
+from searx.testing import SearxTestCase
+
+
+class TestSpotifyEngine(SearxTestCase):
+
+ def test_request(self):
+ query = 'test_query'
+ dicto = defaultdict(dict)
+ dicto['pageno'] = 0
+ params = spotify.request(query, dicto)
+ self.assertIn('url', params)
+ self.assertIn(query, params['url'])
+ self.assertIn('spotify.com', params['url'])
+
+ def test_response(self):
+ self.assertRaises(AttributeError, spotify.response, None)
+ self.assertRaises(AttributeError, spotify.response, [])
+ self.assertRaises(AttributeError, spotify.response, '')
+ self.assertRaises(AttributeError, spotify.response, '[]')
+
+ response = mock.Mock(text='{}')
+ self.assertEqual(spotify.response(response), [])
+
+ response = mock.Mock(text='{"data": []}')
+ self.assertEqual(spotify.response(response), [])
+
+ json = """
+ {
+ "tracks": {
+ "href": "https://api.spotify.com/v1/search?query=nosfell&offset=0&limit=20&type=track",
+ "items": [
+ {
+ "album": {
+ "album_type": "album",
+ "external_urls": {
+ "spotify": "https://open.spotify.com/album/5c9ap1PBkSGLxT3J73toxA"
+ },
+ "href": "https://api.spotify.com/v1/albums/5c9ap1PBkSGLxT3J73toxA",
+ "id": "5c9ap1PBkSGLxT3J73toxA",
+ "name": "Album Title",
+ "type": "album",
+ "uri": "spotify:album:5c9ap1PBkSGLxT3J73toxA"
+ },
+ "artists": [
+ {
+ "external_urls": {
+ "spotify": "https://open.spotify.com/artist/0bMc6b75FfZEpQHG1jifKu"
+ },
+ "href": "https://api.spotify.com/v1/artists/0bMc6b75FfZEpQHG1jifKu",
+ "id": "0bMc6b75FfZEpQHG1jifKu",
+ "name": "Artist Name",
+ "type": "artist",
+ "uri": "spotify:artist:0bMc6b75FfZEpQHG1jifKu"
+ }
+ ],
+ "disc_number": 1,
+ "duration_ms": 202386,
+ "explicit": false,
+ "external_ids": {
+ "isrc": "FRV640600067"
+ },
+ "external_urls": {
+ "spotify": "https://open.spotify.com/track/2GzvFiedqW8hgqUpWcASZa"
+ },
+ "href": "https://api.spotify.com/v1/tracks/2GzvFiedqW8hgqUpWcASZa",
+ "id": "1000",
+ "is_playable": true,
+ "name": "Title of track",
+ "popularity": 6,
+ "preview_url": "https://p.scdn.co/mp3-preview/7b8ecda580965a066b768c2647f877e43f7b1a0a",
+ "track_number": 3,
+ "type": "track",
+ "uri": "spotify:track:2GzvFiedqW8hgqUpWcASZa"
+ }
+ ],
+ "limit": 20,
+ "next": "https://api.spotify.com/v1/search?query=nosfell&offset=20&limit=20&type=track",
+ "offset": 0,
+ "previous": null,
+ "total": 107
+ }
+ }
+ """
+ response = mock.Mock(text=json)
+ results = spotify.response(response)
+ self.assertEqual(type(results), list)
+ self.assertEqual(len(results), 1)
+ self.assertEqual(results[0]['title'], 'Title of track')
+ self.assertEqual(results[0]['url'], 'https://open.spotify.com/track/2GzvFiedqW8hgqUpWcASZa')
+ self.assertEqual(results[0]['content'], 'Artist Name &bull; Album Title &bull; Title of track')
+ self.assertIn('1000', results[0]['embedded'])
+
+ json = """
+ {
+ "tracks": {
+ "href": "https://api.spotify.com/v1/search?query=nosfell&offset=0&limit=20&type=track",
+ "items": [
+ {
+ "href": "https://api.spotify.com/v1/tracks/2GzvFiedqW8hgqUpWcASZa",
+ "id": "1000",
+ "is_playable": true,
+ "name": "Title of track",
+ "popularity": 6,
+ "preview_url": "https://p.scdn.co/mp3-preview/7b8ecda580965a066b768c2647f877e43f7b1a0a",
+ "track_number": 3,
+ "type": "album",
+ "uri": "spotify:track:2GzvFiedqW8hgqUpWcASZa"
+ }
+ ],
+ "limit": 20,
+ "next": "https://api.spotify.com/v1/search?query=nosfell&offset=20&limit=20&type=track",
+ "offset": 0,
+ "previous": null,
+ "total": 107
+ }
+ }
+ """
+ response = mock.Mock(text=json)
+ results = spotify.response(response)
+ self.assertEqual(type(results), list)
+ self.assertEqual(len(results), 0)
diff --git a/searx/tests/engines/test_yahoo.py b/searx/tests/engines/test_yahoo.py
index e5c78701d..11ef9db22 100644
--- a/searx/tests/engines/test_yahoo.py
+++ b/searx/tests/engines/test_yahoo.py
@@ -55,37 +55,44 @@ class TestYahooEngine(SearxTestCase):
self.assertEqual(yahoo.response(response), [])
html = """
- <div class="res">
- <div>
- <h3>
- <a id="link-1" class="yschttl spt" href="http://r.search.yahoo.com/_ylt=A0LEVzClb9JUSKcAEGRXNyoA;
- _ylu=X3oDMTEzZm1qazYwBHNlYwNzcgRwb3MDMQRjb2xvA2JmMQR2dGlkA1NNRTcwM18x/RV=2/RE=1423106085/RO=10
- /RU=https%3a%2f%2fthis.is.the.url%2f/RK=0/RS=dtcJsfP4mEeBOjnVfUQ-"target="_blank" data-bk="5063.1">
- <b>This</b> is the title
- </a>
+<ol class="reg mb-15 searchCenterMiddle">
+ <li class="first">
+ <div class="dd algo fst Sr">
+ <div class="compTitle">
+ <h3 class="title"><a class=" td-u" href="http://r.search.yahoo.com/_ylt=A0LEb9JUSKcAEGRXNyoA;
+ _ylu=X3oDMTEzZm1qazYwBHNlYwNzcgRwb3MDMQRjb2xvA2Jm2dGlkA1NNRTcwM18x/RV=2/RE=1423106085/RO=10
+ /RU=https%3a%2f%2fthis.is.the.url%2f/RK=0/RS=dtcJsfP4mEeBOjnVfUQ-"
+ target="_blank" data-bid="54e712e13671c">
+ <b><b>This is the title</b></b></a>
</h3>
</div>
- <span class="url" dir="ltr">www.<b>test</b>.com</span>
- <div class="abstr">
- <b>This</b> is the content
+ <div class="compText aAbs">
+ <p class="lh-18"><b><b>This is the </b>content</b>
+ </p>
</div>
</div>
- <div id="satat" data-bns="Yahoo" data-bk="124.1">
- <h2>Also Try</h2>
- <table>
- <tbody>
- <tr>
- <td>
- <a id="srpnat0" class="" href="https://search.yahoo.com/search=rs-bottom" >
- <span>
- <b></b>This is <b>the suggestion</b>
- </span>
- </a>
- </td>
- </tr>
- </tbody>
- </table>
+ </li>
+ <li>
+ <div class="dd algo lst Sr">
+ <div class="compTitle">
+ </div>
+ <div class="compText aAbs">
+ <p class="lh-18">This is the second content</p>
+ </div>
</div>
+ </li>
+</ol>
+<div class="dd assist fst lst AlsoTry" data-bid="54e712e138d04">
+ <div class="compTitle mb-4 h-17">
+ <h3 class="title">Also Try</h3> </div>
+ <table class="compTable m-0 ac-1st td-u fz-ms">
+ <tbody>
+ <tr>
+ <td class="w-50p pr-28"><a href="https://search.yahoo.com/"><B>This is the </B>suggestion<B></B></a>
+ </td>
+ </tr>
+ </table>
+</div>
"""
response = mock.Mock(text=html)
results = yahoo.response(response)
@@ -97,44 +104,24 @@ class TestYahooEngine(SearxTestCase):
self.assertEqual(results[1]['suggestion'], 'This is the suggestion')
html = """
- <div class="res">
- <div>
- <h3>
- <a id="link-1" class="yschttl spt" href="http://r.search.yahoo.com/_ylt=A0LEVzClb9JUSKcAEGRXNyoA;
- _ylu=X3oDMTEzZm1qazYwBHNlYwNzcgRwb3MDMQRjb2xvA2JmMQR2dGlkA1NNRTcwM18x/RV=2/RE=1423106085/RO=10
- /RU=https%3a%2f%2fthis.is.the.url%2f/RK=0/RS=dtcJsfP4mEeBOjnVfUQ-"target="_blank" data-bk="5063.1">
- <b>This</b> is the title
- </a>
- </h3>
- </div>
- <span class="url" dir="ltr">www.<b>test</b>.com</span>
- <div class="abstr">
- <b>This</b> is the content
- </div>
- </div>
- <div class="res">
- <div>
- <h3>
- <a id="link-1" class="yschttl spt">
- <b>This</b> is the title
- </a>
- </h3>
- </div>
- <span class="url" dir="ltr">www.<b>test</b>.com</span>
- <div class="abstr">
- <b>This</b> is the content
- </div>
- </div>
- <div class="res">
- <div>
- <h3>
+<ol class="reg mb-15 searchCenterMiddle">
+ <li class="first">
+ <div class="dd algo fst Sr">
+ <div class="compTitle">
+ <h3 class="title"><a class=" td-u" href="http://r.search.yahoo.com/_ylt=A0LEb9JUSKcAEGRXNyoA;
+ _ylu=X3oDMTEzZm1qazYwBHNlYwNzcgRwb3MDMQRjb2xvA2Jm2dGlkA1NNRTcwM18x/RV=2/RE=1423106085/RO=10
+ /RU=https%3a%2f%2fthis.is.the.url%2f/RK=0/RS=dtcJsfP4mEeBOjnVfUQ-"
+ target="_blank" data-bid="54e712e13671c">
+ <b><b>This is the title</b></b></a>
</h3>
</div>
- <span class="url" dir="ltr">www.<b>test</b>.com</span>
- <div class="abstr">
- <b>This</b> is the content
+ <div class="compText aAbs">
+ <p class="lh-18"><b><b>This is the </b>content</b>
+ </p>
</div>
</div>
+ </li>
+</ol>
"""
response = mock.Mock(text=html)
results = yahoo.response(response)
diff --git a/searx/tests/test_engines.py b/searx/tests/test_engines.py
index 9b1c12cb1..5770458f3 100644
--- a/searx/tests/test_engines.py
+++ b/searx/tests/test_engines.py
@@ -28,6 +28,7 @@ from searx.tests.engines.test_piratebay import * # noqa
from searx.tests.engines.test_searchcode_code import * # noqa
from searx.tests.engines.test_searchcode_doc import * # noqa
from searx.tests.engines.test_soundcloud import * # noqa
+from searx.tests.engines.test_spotify import * # noqa
from searx.tests.engines.test_stackoverflow import * # noqa
from searx.tests.engines.test_startpage import * # noqa
from searx.tests.engines.test_subtitleseeker import * # noqa
diff --git a/searx/tests/test_plugins.py b/searx/tests/test_plugins.py
new file mode 100644
index 000000000..8dcad1142
--- /dev/null
+++ b/searx/tests/test_plugins.py
@@ -0,0 +1,51 @@
+# -*- coding: utf-8 -*-
+
+from searx.testing import SearxTestCase
+from searx import plugins
+from mock import Mock
+
+
+class PluginStoreTest(SearxTestCase):
+
+ def test_PluginStore_init(self):
+ store = plugins.PluginStore()
+ self.assertTrue(isinstance(store.plugins, list) and len(store.plugins) == 0)
+
+ def test_PluginStore_register(self):
+ store = plugins.PluginStore()
+ testplugin = plugins.Plugin()
+ store.register(testplugin)
+
+ self.assertTrue(len(store.plugins) == 1)
+
+ def test_PluginStore_call(self):
+ store = plugins.PluginStore()
+ testplugin = plugins.Plugin()
+ store.register(testplugin)
+ setattr(testplugin, 'asdf', Mock())
+ request = Mock(user_plugins=[])
+ store.call('asdf', request, Mock())
+
+ self.assertFalse(testplugin.asdf.called)
+
+ request.user_plugins.append(testplugin)
+ store.call('asdf', request, Mock())
+
+ self.assertTrue(testplugin.asdf.called)
+
+
+class SelfIPTest(SearxTestCase):
+
+ def test_PluginStore_init(self):
+ store = plugins.PluginStore()
+ store.register(plugins.self_ip)
+
+ self.assertTrue(len(store.plugins) == 1)
+
+ request = Mock(user_plugins=store.plugins,
+ remote_addr='127.0.0.1')
+ request.headers.getlist.return_value = []
+ ctx = {'search': Mock(answers=set(),
+ query='ip')}
+ store.call('post_search', request, ctx)
+ self.assertTrue('127.0.0.1' in ctx['search'].answers)
diff --git a/searx/tests/test_webapp.py b/searx/tests/test_webapp.py
index 8bbe5d056..471ec2f2d 100644
--- a/searx/tests/test_webapp.py
+++ b/searx/tests/test_webapp.py
@@ -2,7 +2,6 @@
import json
from urlparse import ParseResult
-from mock import patch
from searx import webapp
from searx.testing import SearxTestCase
@@ -33,6 +32,11 @@ class ViewsTestCase(SearxTestCase):
},
]
+ def search_mock(search_self, *args):
+ search_self.results = self.test_results
+
+ webapp.Search.search = search_mock
+
self.maxDiff = None # to see full diffs
def test_index_empty(self):
@@ -40,17 +44,10 @@ class ViewsTestCase(SearxTestCase):
self.assertEqual(result.status_code, 200)
self.assertIn('<div class="title"><h1>searx</h1></div>', result.data)
- @patch('searx.search.Search.search')
- def test_index_html(self, search):
- search.return_value = (
- self.test_results,
- set(),
- set(),
- set()
- )
+ def test_index_html(self):
result = self.app.post('/', data={'q': 'test'})
self.assertIn(
- '<h3 class="result_title"><img width="14" height="14" class="favicon" src="/static/themes/default/img/icons/icon_youtube.ico" alt="youtube" /><a href="http://second.test.xyz">Second <span class="highlight">Test</span></a></h3>', # noqa
+ '<h3 class="result_title"><img width="14" height="14" class="favicon" src="/static/themes/default/img/icons/icon_youtube.ico" alt="youtube" /><a href="http://second.test.xyz" rel="noreferrer">Second <span class="highlight">Test</span></a></h3>', # noqa
result.data
)
self.assertIn(
@@ -58,14 +55,7 @@ class ViewsTestCase(SearxTestCase):
result.data
)
- @patch('searx.search.Search.search')
- def test_index_json(self, search):
- search.return_value = (
- self.test_results,
- set(),
- set(),
- set()
- )
+ def test_index_json(self):
result = self.app.post('/', data={'q': 'test', 'format': 'json'})
result_dict = json.loads(result.data)
@@ -76,14 +66,7 @@ class ViewsTestCase(SearxTestCase):
self.assertEqual(
result_dict['results'][0]['url'], 'http://first.test.xyz')
- @patch('searx.search.Search.search')
- def test_index_csv(self, search):
- search.return_value = (
- self.test_results,
- set(),
- set(),
- set()
- )
+ def test_index_csv(self):
result = self.app.post('/', data={'q': 'test', 'format': 'csv'})
self.assertEqual(
@@ -93,14 +76,7 @@ class ViewsTestCase(SearxTestCase):
result.data
)
- @patch('searx.search.Search.search')
- def test_index_rss(self, search):
- search.return_value = (
- self.test_results,
- set(),
- set(),
- set()
- )
+ def test_index_rss(self):
result = self.app.post('/', data={'q': 'test', 'format': 'rss'})
self.assertIn(