summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAdam Tauber <asciimoo@gmail.com>2018-08-19 13:22:22 +0200
committerGitHub <noreply@github.com>2018-08-19 13:22:22 +0200
commitb75f1b6cc39a94989a74d52eb0f1267c3e3c665e (patch)
treed3bab81ca2071196b1b4223d6d2db7d408b79bf2 /tests
parente7f7eda18cc69287f30c512a98b4e90453bcd8e7 (diff)
parent931c1bb0f663bc13998f5a78ae7cd9485d37453c (diff)
Merge branch 'master' into patch-2
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/engines/test_acgsou.py78
-rw-r--r--tests/unit/engines/test_archlinux.py7
-rw-r--r--tests/unit/engines/test_bing.py1
-rw-r--r--tests/unit/engines/test_bing_images.py1
-rw-r--r--tests/unit/engines/test_bing_news.py3
-rw-r--r--tests/unit/engines/test_bing_videos.py1
-rw-r--r--tests/unit/engines/test_currency_convert.py20
-rw-r--r--tests/unit/engines/test_dailymotion.py3
-rw-r--r--tests/unit/engines/test_duckduckgo.py18
-rw-r--r--tests/unit/engines/test_duckduckgo_definitions.py1
-rw-r--r--tests/unit/engines/test_duckduckgo_images.py1
-rw-r--r--tests/unit/engines/test_google.py12
-rw-r--r--tests/unit/engines/test_google_images.py15
-rw-r--r--tests/unit/engines/test_google_news.py5
-rw-r--r--tests/unit/engines/test_piratebay.py6
-rw-r--r--tests/unit/engines/test_qwant.py2
-rw-r--r--tests/unit/engines/test_swisscows.py1
-rw-r--r--tests/unit/engines/test_wikidata.py26
-rw-r--r--tests/unit/engines/test_yahoo.py17
-rw-r--r--tests/unit/engines/test_yahoo_news.py3
-rw-r--r--tests/unit/test_utils.py25
21 files changed, 191 insertions, 55 deletions
diff --git a/tests/unit/engines/test_acgsou.py b/tests/unit/engines/test_acgsou.py
new file mode 100644
index 000000000..c01acf5de
--- /dev/null
+++ b/tests/unit/engines/test_acgsou.py
@@ -0,0 +1,78 @@
+# coding=utf-8
+from collections import defaultdict
+import mock
+from searx.engines import acgsou
+from searx.testing import SearxTestCase
+
+
+class TestAcgsouEngine(SearxTestCase):
+
+ def test_request(self):
+ query = 'test_query'
+ dic = defaultdict(dict)
+ dic['pageno'] = 1
+ params = acgsou.request(query, dic)
+ self.assertTrue('url' in params)
+ self.assertTrue(query in params['url'])
+ self.assertTrue('acgsou.com' in params['url'])
+
+ def test_response(self):
+ resp = mock.Mock(text='<html></html>')
+ self.assertEqual(acgsou.response(resp), [])
+
+ html = u"""
+ <html>
+<table id="listTable" class="list_style table_fixed">
+ <thead class="tcat">
+ <tr>
+ <th axis="string" class="l1 tableHeaderOver">test</th>
+ <th axis="string" class="l2 tableHeaderOver">test</th>
+ <th axis="string" class="l3 tableHeaderOver">test</th>
+ <th axis="size" class="l4 tableHeaderOver">test</th>
+ <th axis="number" class="l5 tableHeaderOver">test</th>
+ <th axis="number" class="l6 tableHeaderOver">test</th>
+ <th axis="number" class="l7 tableHeaderOver">test</th>
+ <th axis="string" class="l8 tableHeaderOver">test</th>
+ </tr>
+ </thead>
+ <tbody class="tbody" id="data_list">
+ <tr class="alt1 ">
+ <td nowrap="nowrap">date</td>
+ <td><a href="category.html">testcategory テスト</a></td>
+ <td style="text-align:left;">
+ <a href="show-torrentid.html" target="_blank">torrentname テスト</a>
+ </td>
+ <td>1MB</td>
+ <td nowrap="nowrap">
+ <span class="bts_1">
+ 29
+ </span>
+ </td>
+ <td nowrap="nowrap">
+ <span class="btl_1">
+ 211
+ </span>
+ </td>
+ <td nowrap="nowrap">
+ <span class="btc_">
+ 168
+ </span>
+ </td>
+ <td><a href="random.html">user</a></td>
+ </tr>
+ </tbody>
+</table>
+</html>
+ """
+
+ resp = mock.Mock(text=html)
+ results = acgsou.response(resp)
+
+ self.assertEqual(type(results), list)
+ self.assertEqual(len(results), 1)
+
+ r = results[0]
+ self.assertEqual(r['url'], 'http://www.acgsou.com/show-torrentid.html')
+ self.assertEqual(r['content'], u'Category: "testcategory テスト".')
+ self.assertEqual(r['title'], u'torrentname テスト')
+ self.assertEqual(r['filesize'], 1048576)
diff --git a/tests/unit/engines/test_archlinux.py b/tests/unit/engines/test_archlinux.py
index f9e536f4e..f2ba483c1 100644
--- a/tests/unit/engines/test_archlinux.py
+++ b/tests/unit/engines/test_archlinux.py
@@ -19,12 +19,17 @@ class TestArchLinuxEngine(SearxTestCase):
query = 'test_query'
dic = defaultdict(dict)
dic['pageno'] = 1
- dic['language'] = 'en_US'
+ dic['language'] = 'en-US'
params = archlinux.request(query, dic)
self.assertTrue('url' in params)
self.assertTrue(query in params['url'])
self.assertTrue('wiki.archlinux.org' in params['url'])
+ for lang, name in archlinux.main_langs:
+ dic['language'] = lang
+ params = archlinux.request(query, dic)
+ self.assertTrue(name in params['url'])
+
for lang, domain in domains.items():
dic['language'] = lang
params = archlinux.request(query, dic)
diff --git a/tests/unit/engines/test_bing.py b/tests/unit/engines/test_bing.py
index 2528dd847..48a5e744a 100644
--- a/tests/unit/engines/test_bing.py
+++ b/tests/unit/engines/test_bing.py
@@ -7,6 +7,7 @@ from searx.testing import SearxTestCase
class TestBingEngine(SearxTestCase):
def test_request(self):
+ bing.supported_languages = ['en', 'fr', 'zh-CHS', 'zh-CHT', 'pt-PT', 'pt-BR']
query = u'test_query'
dicto = defaultdict(dict)
dicto['pageno'] = 0
diff --git a/tests/unit/engines/test_bing_images.py b/tests/unit/engines/test_bing_images.py
index 3f3006124..afc4cd6f0 100644
--- a/tests/unit/engines/test_bing_images.py
+++ b/tests/unit/engines/test_bing_images.py
@@ -9,7 +9,6 @@ class TestBingImagesEngine(SearxTestCase):
def test_request(self):
bing_images.supported_languages = ['fr-FR', 'en-US']
-
query = 'test_query'
dicto = defaultdict(dict)
dicto['pageno'] = 1
diff --git a/tests/unit/engines/test_bing_news.py b/tests/unit/engines/test_bing_news.py
index 3af19fd6d..8fc26ee32 100644
--- a/tests/unit/engines/test_bing_news.py
+++ b/tests/unit/engines/test_bing_news.py
@@ -8,10 +8,11 @@ import lxml
class TestBingNewsEngine(SearxTestCase):
def test_request(self):
+ bing_news.supported_languages = ['en', 'fr']
query = 'test_query'
dicto = defaultdict(dict)
dicto['pageno'] = 1
- dicto['language'] = 'fr_FR'
+ dicto['language'] = 'fr-FR'
dicto['time_range'] = ''
params = bing_news.request(query, dicto)
self.assertIn('url', params)
diff --git a/tests/unit/engines/test_bing_videos.py b/tests/unit/engines/test_bing_videos.py
index 8b303d637..24387c888 100644
--- a/tests/unit/engines/test_bing_videos.py
+++ b/tests/unit/engines/test_bing_videos.py
@@ -9,7 +9,6 @@ class TestBingVideosEngine(SearxTestCase):
def test_request(self):
bing_videos.supported_languages = ['fr-FR', 'en-US']
-
query = 'test_query'
dicto = defaultdict(dict)
dicto['pageno'] = 1
diff --git a/tests/unit/engines/test_currency_convert.py b/tests/unit/engines/test_currency_convert.py
index 0758e2fc8..fec194103 100644
--- a/tests/unit/engines/test_currency_convert.py
+++ b/tests/unit/engines/test_currency_convert.py
@@ -17,7 +17,7 @@ class TestCurrencyConvertEngine(SearxTestCase):
query = b'convert 10 Pound Sterlings to United States Dollars'
params = currency_convert.request(query, dicto)
self.assertIn('url', params)
- self.assertIn('finance.google.com', params['url'])
+ self.assertIn('duckduckgo.com', params['url'])
self.assertIn('GBP', params['url'])
self.assertIn('USD', params['url'])
@@ -30,8 +30,20 @@ class TestCurrencyConvertEngine(SearxTestCase):
dicto['to_name'] = "United States dollar"
response = mock.Mock(text='a,b,c,d', search_params=dicto)
self.assertEqual(currency_convert.response(response), [])
-
- body = "<span class=bld>0.5 {}</span>".format(dicto['to'])
+ body = """ddg_spice_currency(
+ {
+ "conversion":{
+ "converted-amount": "0.5"
+ },
+ "topConversions":[
+ {
+ },
+ {
+ }
+ ]
+ }
+ );
+ """
response = mock.Mock(text=body, search_params=dicto)
results = currency_convert.response(response)
self.assertEqual(type(results), list)
@@ -39,6 +51,6 @@ class TestCurrencyConvertEngine(SearxTestCase):
self.assertEqual(results[0]['answer'], '10.0 GBP = 5.0 USD, 1 GBP (pound sterling)' +
' = 0.5 USD (United States dollar)')
- target_url = 'https://finance.google.com/finance?q={}{}'.format(
+ target_url = 'https://duckduckgo.com/js/spice/currency/1/{}/{}'.format(
dicto['from'], dicto['to'])
self.assertEqual(results[0]['url'], target_url)
diff --git a/tests/unit/engines/test_dailymotion.py b/tests/unit/engines/test_dailymotion.py
index 2009c0e4f..803b5c4d2 100644
--- a/tests/unit/engines/test_dailymotion.py
+++ b/tests/unit/engines/test_dailymotion.py
@@ -8,10 +8,11 @@ from searx.testing import SearxTestCase
class TestDailymotionEngine(SearxTestCase):
def test_request(self):
+ dailymotion.supported_languages = ['en', 'fr']
query = 'test_query'
dicto = defaultdict(dict)
dicto['pageno'] = 0
- dicto['language'] = 'fr_FR'
+ dicto['language'] = 'fr-FR'
params = dailymotion.request(query, dicto)
self.assertTrue('url' in params)
self.assertTrue(query in params['url'])
diff --git a/tests/unit/engines/test_duckduckgo.py b/tests/unit/engines/test_duckduckgo.py
index eea478971..eb316a404 100644
--- a/tests/unit/engines/test_duckduckgo.py
+++ b/tests/unit/engines/test_duckduckgo.py
@@ -1,18 +1,21 @@
# -*- coding: utf-8 -*-
from collections import defaultdict
import mock
-from searx.engines import duckduckgo
+from searx.engines import load_engine, duckduckgo
from searx.testing import SearxTestCase
class TestDuckduckgoEngine(SearxTestCase):
def test_request(self):
+ duckduckgo = load_engine({'engine': 'duckduckgo', 'name': 'duckduckgo'})
+
query = 'test_query'
dicto = defaultdict(dict)
dicto['pageno'] = 1
- dicto['language'] = 'de-CH'
dicto['time_range'] = ''
+
+ dicto['language'] = 'de-CH'
params = duckduckgo.request(query, dicto)
self.assertIn('url', params)
self.assertIn(query, params['url'])
@@ -20,16 +23,19 @@ class TestDuckduckgoEngine(SearxTestCase):
self.assertIn('ch-de', params['url'])
self.assertIn('s=0', params['url'])
- # when ddg uses non standard code
+ # when ddg uses non standard codes
+ dicto['language'] = 'zh-HK'
+ params = duckduckgo.request(query, dicto)
+ self.assertIn('hk-tzh', params['url'])
+
dicto['language'] = 'en-GB'
params = duckduckgo.request(query, dicto)
self.assertIn('uk-en', params['url'])
# no country given
- duckduckgo.supported_languages = ['de-CH', 'en-US']
- dicto['language'] = 'de'
+ dicto['language'] = 'en'
params = duckduckgo.request(query, dicto)
- self.assertIn('ch-de', params['url'])
+ self.assertIn('us-en', params['url'])
def test_no_url_in_request_year_time_range(self):
dicto = defaultdict(dict)
diff --git a/tests/unit/engines/test_duckduckgo_definitions.py b/tests/unit/engines/test_duckduckgo_definitions.py
index feafe47ba..37587ed8d 100644
--- a/tests/unit/engines/test_duckduckgo_definitions.py
+++ b/tests/unit/engines/test_duckduckgo_definitions.py
@@ -18,6 +18,7 @@ class TestDDGDefinitionsEngine(SearxTestCase):
self.assertEqual(result, 'Text in link')
def test_request(self):
+ duckduckgo_definitions.supported_languages = ['en-US', 'es-ES']
query = 'test_query'
dicto = defaultdict(dict)
dicto['pageno'] = 1
diff --git a/tests/unit/engines/test_duckduckgo_images.py b/tests/unit/engines/test_duckduckgo_images.py
index 582163130..5301057fd 100644
--- a/tests/unit/engines/test_duckduckgo_images.py
+++ b/tests/unit/engines/test_duckduckgo_images.py
@@ -9,7 +9,6 @@ class TestDuckduckgoImagesEngine(SearxTestCase):
def test_request(self):
duckduckgo_images.supported_languages = ['de-CH', 'en-US']
-
query = 'test_query'
dicto = defaultdict(dict)
dicto['is_test'] = True
diff --git a/tests/unit/engines/test_google.py b/tests/unit/engines/test_google.py
index ecd1ed4d9..413b67769 100644
--- a/tests/unit/engines/test_google.py
+++ b/tests/unit/engines/test_google.py
@@ -15,6 +15,8 @@ class TestGoogleEngine(SearxTestCase):
return response
def test_request(self):
+ google.supported_languages = ['en', 'fr', 'zh-CN']
+
query = 'test_query'
dicto = defaultdict(dict)
dicto['pageno'] = 1
@@ -24,13 +26,21 @@ class TestGoogleEngine(SearxTestCase):
self.assertIn('url', params)
self.assertIn(query, params['url'])
self.assertIn('google.fr', params['url'])
+ self.assertIn('fr', params['url'])
self.assertIn('fr', params['headers']['Accept-Language'])
dicto['language'] = 'en-US'
params = google.request(query, dicto)
- self.assertIn('google.co', params['url'])
+ self.assertIn('google.com', params['url'])
+ self.assertIn('en', params['url'])
self.assertIn('en', params['headers']['Accept-Language'])
+ dicto['language'] = 'zh'
+ params = google.request(query, dicto)
+ self.assertIn('google.com', params['url'])
+ self.assertIn('zh-CN', params['url'])
+ self.assertIn('zh-CN', params['headers']['Accept-Language'])
+
def test_response(self):
self.assertRaises(AttributeError, google.response, None)
self.assertRaises(AttributeError, google.response, [])
diff --git a/tests/unit/engines/test_google_images.py b/tests/unit/engines/test_google_images.py
index 493741c44..8366e1b08 100644
--- a/tests/unit/engines/test_google_images.py
+++ b/tests/unit/engines/test_google_images.py
@@ -25,18 +25,3 @@ class TestGoogleImagesEngine(SearxTestCase):
self.assertRaises(AttributeError, google_images.response, [])
self.assertRaises(AttributeError, google_images.response, '')
self.assertRaises(AttributeError, google_images.response, '[]')
-
- html = r"""
-["rg_s",["dom","\u003Cstyle\u003E.rg_kn,.rg_s{}.rg_bx{display:-moz-inline-box;display:inline-block;margin-top:0;margin-right:12px;margin-bottom:12px;margin-left:0;overflow:hidden;position:relative;vertical-align:top;z-index:1}.rg_meta{display:none}.rg_l{display:inline-block;height:100%;position:absolute;text-decoration:none;width:100%}.rg_l:focus{outline:0}.rg_i{border:0;color:rgba(0,0,0,0);display:block;-webkit-touch-callout:none;}.rg_an,.rg_anbg,.rg_ilm,.rg_ilmbg{right:0;bottom:0;box-sizing:border-box;-moz-box-sizing:border-box;color:#fff;font:normal 11px arial,sans-serif;line-height:100%;white-space:nowrap;width:100%}.rg_anbg,.rg_ilmbg{background:rgba(51,51,51,0.8);margin-left:0;padding:2px 4px;position:absolute}.rg_ilmn{bottom:0;display:block;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.rg_ilm{display:none}#rg_s.rg_kn .rg_l:focus .rg_ilm{display:block}.rg_kn .rg_bx:hover .rg_ilm,.rg_bx:hover .rg_anbg{display:none}.rg_bx:hover .rg_ilm,.rg_anbg,.rg_kn .rg_bx:hover .rg_anbg{display:block}\u003C\/style\u003E\u003Cdiv eid=\"qlKuV-T3BoqksAHMnaroAw\" id=\"isr_scm_0\" style=\"display:none\"\u003E\u003C\/div\u003E\u003Cdiv data-cei=\"qlKuV-T3BoqksAHMnaroAw\" class=\"rg_add_chunk\"\u003E\u003C!--m--\u003E\u003Cdiv class=\"rg_di rg_bx rg_el ivg-i\" data-ved=\"0ahUKEwjk9PCm-7zOAhUKEiwKHcyOCj0QMwgCKAAwAA\"\u003E\u003Ca jsaction=\"fire.ivg_o;mouseover:str.hmov;mouseout:str.hmou\" class=\"rg_l\" style=\"background:rgb(170,205,240)\"\u003E\u003Cimg data-sz=\"f\" name=\"5eykIeMjmCk7xM:\" src=\"https:\/\/encrypted-tbn0.gstatic.com\/images?q=tbn\" class=\"rg_i rg_ic\" alt=\"Image result for south\" jsaction=\"load:str.tbn\" onload=\"google.aft\u0026\u0026google.aft(this)\"\u003E\u003Cdiv class=\"_aOd rg_ilm\"\u003E\u003Cdiv class=\"rg_ilmbg\"\u003E\u003Cspan class=\"rg_ilmn\"\u003E 566\u0026nbsp;\u0026#215;\u0026nbsp;365 - en.wikipedia.org \u003C\/span\u003E\u003C\/div\u003E\u003C\/div\u003E\u003C\/a\u003E\u003Cdiv class=\"rg_meta\"\u003E{\"id\":\"5eykIeMjmCk7xM:\",\"isu\":\"en.wikipedia.org\",\"itg\":false,\"ity\":\"png\",\"oh\":365,\"ou\":\"https:\/\/upload.wikimedia.org\/wikipedia\/commons\/e\/e4\/Us_south_census.png\",\"ow\":566,\"pt\":\"Southern United States - Wikipedia, the free encyclopedia\",\"rid\":\"cErfE02-v-VcAM\",\"ru\":\"https:\/\/en.wikipedia.org\/wiki\/Southern_United_States\",\"s\":\"The Southern United States as defined by the United States Census Bureau.\",\"sc\":1,\"th\":180,\"tu\":\"https:\/\/encrypted-tbn0.gstatic.com\/images?q\\u003dtbn\",\"tw\":280}\u003C\/div\u003E\u003C\/div\u003E\u003C!--n--\u003E\u003C!--m--\u003E\u003Cdiv class=\"rg_di rg_bx rg_el ivg-i\" data-ved=\"0ahUKEwjk9PCm-7zOAhUKEiwKHcyOCj0QMwgDKAEwAQ\"\u003E\u003Ca jsaction=\"fire.ivg_o;mouseover:str.hmov;mouseout:str.hmou\" class=\"rg_l\" style=\"background:rgb(249,252,249)\"\u003E\u003Cimg data-sz=\"f\" name=\"eRjGCc0cFyVkKM:\" src=\"https:\/\/encrypted-tbn2.gstatic.com\/images?q=tbn:ANd9GcSI7SZlbDwdMCgGXzJkpwgdn9uL41xUJ1IiIcKs0qW43_Yp0EhEsg\" class=\"rg_i rg_ic\" alt=\"Image result for south\" jsaction=\"load:str.tbn\" onload=\"google.aft\u0026\u0026google.aft(this)\"\u003E\u003Cdiv class=\"_aOd rg_ilm\"\u003E\u003Cdiv class=\"rg_ilmbg\"\u003E\u003Cspan class=\"rg_ilmn\"\u003E 2000\u0026nbsp;\u0026#215;\u0026nbsp;1002 - commons.wikimedia.org \u003C\/span\u003E\u003C\/div\u003E\u003C\/div\u003E\u003C\/a\u003E\u003Cdiv class=\"rg_meta\"\u003E{\"id\":\"eRjGCc0cFyVkKM:\",\"isu\":\"commons.wikimedia.org\",\"itg\":false,\"ity\":\"png\",\"oh\":1002,\"ou\":\"https:\/\/upload.wikimedia.org\/wikipedia\/commons\/thumb\/8\/84\/South_plate.svg\/2000px-South_plate.svg.png\",\"ow\":2000,\"pt\":\"File:South plate.svg - Wikimedia Commons\",\"rid\":\"F8TVsT2GBLb6RM\",\"ru\":\"https:\/\/commons.wikimedia.org\/wiki\/File:South_plate.svg\",\"s\":\"This image rendered as PNG in other widths: 200px, 500px, 1000px, 2000px.\",\"sc\":1,\"th\":159,\"tu\":\"https:\/\/encrypted-tbn2.gstatic.com\/images?q\\u003dtbn:ANd9GcSI7SZlbDwdMCgGXzJkpwgdn9uL41xUJ1IiIcKs0qW43_Yp0EhEsg\",\"tw\":317}\u003C\/div\u003E\u003C\/div\u003E\u003C!--n--\u003E\u003C\/div\u003E"]]""" # noqa
- response = mock.Mock(text=html)
- results = google_images.response(response)
- self.assertEqual(type(results), list)
- self.assertEqual(len(results), 2)
- self.assertEqual(results[0]['title'], u'Southern United States - Wikipedia, the free encyclopedia')
- self.assertEqual(results[0]['url'], 'https://en.wikipedia.org/wiki/Southern_United_States')
- self.assertEqual(results[0]['img_src'],
- 'https://upload.wikimedia.org/wikipedia/commons/e/e4/Us_south_census.png')
- self.assertEqual(results[0]['content'],
- 'The Southern United States as defined by the United States Census Bureau.')
- self.assertEqual(results[0]['thumbnail_src'],
- 'https://encrypted-tbn0.gstatic.com/images?q=tbn')
diff --git a/tests/unit/engines/test_google_news.py b/tests/unit/engines/test_google_news.py
index 3769e3be6..a041a79b9 100644
--- a/tests/unit/engines/test_google_news.py
+++ b/tests/unit/engines/test_google_news.py
@@ -9,6 +9,7 @@ from searx.testing import SearxTestCase
class TestGoogleNewsEngine(SearxTestCase):
def test_request(self):
+ google_news.supported_languages = ['en-US', 'fr-FR']
query = 'test_query'
dicto = defaultdict(dict)
dicto['pageno'] = 1
@@ -41,7 +42,7 @@ class TestGoogleNewsEngine(SearxTestCase):
<div class="ts _JGs _JHs _tJs _KGs _jHs">
<div class="_hJs">
<h3 class="r _gJs">
- <a class="l _PMs" href="https://example.com/" onmousedown="return rwt(this,'','','','11','AFQjCNEyehpzD5cJK1KUfXBx9RmsbqqG9g','','0ahUKEwjB58OR54HWAhWnKJoKHSQhAMY4ChCpAggiKAAwAA','','',event)">Example title</a>
+ <a class="l lLrAF" href="https://example.com/" onmousedown="return rwt(this,'','','','11','AFQjCNEyehpzD5cJK1KUfXBx9RmsbqqG9g','','0ahUKEwjB58OR54HWAhWnKJoKHSQhAMY4ChCpAggiKAAwAA','','',event)">Example title</a>
</h3>
<div class="slp">
<span class="_OHs _PHs">
@@ -62,7 +63,7 @@ class TestGoogleNewsEngine(SearxTestCase):
</a>
<div class="_hJs">
<h3 class="r _gJs">
- <a class="l _PMs" href="https://example2.com/" onmousedown="return rwt(this,'','','','12','AFQjCNHObfH7sYmLWI1SC-YhWXKZFRzRjw','','0ahUKEwjB58OR54HWAhWnKJoKHSQhAMY4ChCpAgglKAAwAQ','','',event)">Example title 2</a>
+ <a class="l lLrAF" href="https://example2.com/" onmousedown="return rwt(this,'','','','12','AFQjCNHObfH7sYmLWI1SC-YhWXKZFRzRjw','','0ahUKEwjB58OR54HWAhWnKJoKHSQhAMY4ChCpAgglKAAwAQ','','',event)">Example title 2</a>
</h3>
<div class="slp">
<span class="_OHs _PHs">
diff --git a/tests/unit/engines/test_piratebay.py b/tests/unit/engines/test_piratebay.py
index 5699380be..89a78e796 100644
--- a/tests/unit/engines/test_piratebay.py
+++ b/tests/unit/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.se', params['url'])
+ self.assertIn('piratebay.org', 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.se/this.is.the.link')
+ self.assertEqual(results[0]['url'], 'https://thepiratebay.org/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.se/this.is.the.link')
+ self.assertEqual(results[0]['url'], 'https://thepiratebay.org/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/tests/unit/engines/test_qwant.py b/tests/unit/engines/test_qwant.py
index 46694988c..86bfb22da 100644
--- a/tests/unit/engines/test_qwant.py
+++ b/tests/unit/engines/test_qwant.py
@@ -7,6 +7,7 @@ from searx.testing import SearxTestCase
class TestQwantEngine(SearxTestCase):
def test_request(self):
+ qwant.supported_languages = ['en-US', 'fr-CA', 'fr-FR']
query = 'test_query'
dicto = defaultdict(dict)
dicto['pageno'] = 0
@@ -26,7 +27,6 @@ class TestQwantEngine(SearxTestCase):
self.assertIn('en_us', params['url'])
self.assertIn('news', params['url'])
- qwant.supported_languages = ['en', 'fr-FR', 'fr-CA']
dicto['language'] = 'fr'
params = qwant.request(query, dicto)
self.assertIn('fr_fr', params['url'])
diff --git a/tests/unit/engines/test_swisscows.py b/tests/unit/engines/test_swisscows.py
index 2715ef52e..133f636de 100644
--- a/tests/unit/engines/test_swisscows.py
+++ b/tests/unit/engines/test_swisscows.py
@@ -7,6 +7,7 @@ from searx.testing import SearxTestCase
class TestSwisscowsEngine(SearxTestCase):
def test_request(self):
+ swisscows.supported_languages = ['de-AT', 'de-DE']
query = 'test_query'
dicto = defaultdict(dict)
dicto['pageno'] = 1
diff --git a/tests/unit/engines/test_wikidata.py b/tests/unit/engines/test_wikidata.py
index 453133b64..62a409781 100644
--- a/tests/unit/engines/test_wikidata.py
+++ b/tests/unit/engines/test_wikidata.py
@@ -11,17 +11,13 @@ class TestWikidataEngine(SearxTestCase):
def test_request(self):
query = 'test_query'
dicto = defaultdict(dict)
- dicto['language'] = 'en-US'
params = wikidata.request(query, dicto)
self.assertIn('url', params)
self.assertIn(query, params['url'])
self.assertIn('wikidata.org', params['url'])
- self.assertIn('en', params['url'])
- dicto['language'] = 'es-ES'
params = wikidata.request(query, dicto)
self.assertIn(query, params['url'])
- self.assertIn('es', params['url'])
# successful cases are not tested here to avoid sending additional requests
def test_response(self):
@@ -30,6 +26,7 @@ class TestWikidataEngine(SearxTestCase):
self.assertRaises(AttributeError, wikidata.response, '')
self.assertRaises(AttributeError, wikidata.response, '[]')
+ wikidata.supported_languages = ['en', 'es']
response = mock.Mock(text='<html></html>', search_params={"language": "en"})
self.assertEqual(wikidata.response(response), [])
@@ -126,9 +123,10 @@ class TestWikidataEngine(SearxTestCase):
<div class="wikibase-statementview-mainsnak">
<div>
<div class="wikibase-snakview-value">
- <a href="https://commons.wikimedia.org/wiki/File:image.png">
- image.png
- </a>
+ <div class="commons-media-caption">
+ <a href="https://commons.wikimedia.org/wiki/File:image.png">image.png</a>
+ <br/>2,687 &#215; 3,356; 1.22 MB
+ </div>
</div>
</div>
</div>
@@ -159,9 +157,10 @@ class TestWikidataEngine(SearxTestCase):
<div class="wikibase-statementview-mainsnak">
<div>
<div class="wikibase-snakview-value">
- <a href="https://commons.wikimedia.org/wiki/File:icon.png">
- icon.png
- </a>
+ <div class="commons-media-caption">
+ <a href="https://commons.wikimedia.org/wiki/File:icon.png">icon.png</a>
+ <br/>671 &#215; 671; 18 KB</div>
+ </div>
</div>
</div>
</div>
@@ -182,9 +181,10 @@ class TestWikidataEngine(SearxTestCase):
<div class="wikibase-statementview-mainsnak">
<div>
<div class="wikibase-snakview-value">
- <a href="https://commons.wikimedia.org/wiki/File:logo.png">
- logo.png
- </a>
+ <div class="commons-media-caption">
+ <a href="https://commons.wikimedia.org/wiki/File:logo.png">logo.png</a>
+ <br/>170 &#215; 170; 1 KB
+ </div>
</div>
</div>
</div>
diff --git a/tests/unit/engines/test_yahoo.py b/tests/unit/engines/test_yahoo.py
index 921d3e8cd..5037bfc7d 100644
--- a/tests/unit/engines/test_yahoo.py
+++ b/tests/unit/engines/test_yahoo.py
@@ -25,11 +25,12 @@ class TestYahooEngine(SearxTestCase):
self.assertEqual('https://this.is.the.url/', url)
def test_request(self):
+ yahoo.supported_languages = ['en', 'fr', 'zh-CHT', 'zh-CHS']
query = 'test_query'
dicto = defaultdict(dict)
dicto['pageno'] = 1
dicto['time_range'] = ''
- dicto['language'] = 'fr_FR'
+ dicto['language'] = 'fr-FR'
params = yahoo.request(query, dicto)
self.assertIn('url', params)
self.assertIn(query, params['url'])
@@ -39,6 +40,16 @@ class TestYahooEngine(SearxTestCase):
self.assertIn('sB', params['cookies'])
self.assertIn('fr', params['cookies']['sB'])
+ dicto['language'] = 'zh'
+ params = yahoo.request(query, dicto)
+ self.assertIn('zh_chs', params['url'])
+ self.assertIn('zh_chs', params['cookies']['sB'])
+
+ dicto['language'] = 'zh-TW'
+ params = yahoo.request(query, dicto)
+ self.assertIn('zh_cht', params['url'])
+ self.assertIn('zh_cht', params['cookies']['sB'])
+
def test_no_url_in_request_year_time_range(self):
dicto = defaultdict(dict)
query = 'test_query'
@@ -168,5 +179,5 @@ class TestYahooEngine(SearxTestCase):
self.assertEqual(type(languages), list)
self.assertEqual(len(languages), 3)
self.assertIn('ar', languages)
- self.assertIn('zh-chs', languages)
- self.assertIn('zh-cht', languages)
+ self.assertIn('zh-CHS', languages)
+ self.assertIn('zh-CHT', languages)
diff --git a/tests/unit/engines/test_yahoo_news.py b/tests/unit/engines/test_yahoo_news.py
index bc87ec067..c3297dacf 100644
--- a/tests/unit/engines/test_yahoo_news.py
+++ b/tests/unit/engines/test_yahoo_news.py
@@ -9,10 +9,11 @@ from searx.testing import SearxTestCase
class TestYahooNewsEngine(SearxTestCase):
def test_request(self):
+ yahoo_news.supported_languages = ['en', 'fr']
query = 'test_query'
dicto = defaultdict(dict)
dicto['pageno'] = 1
- dicto['language'] = 'fr_FR'
+ dicto['language'] = 'fr-FR'
params = yahoo_news.request(query, dicto)
self.assertIn('url', params)
self.assertIn(query, params['url'])
diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py
index eb40e62e2..4854636c7 100644
--- a/tests/unit/test_utils.py
+++ b/tests/unit/test_utils.py
@@ -65,6 +65,31 @@ class TestUtils(SearxTestCase):
for test_url, expected in data:
self.assertEqual(utils.prettify_url(test_url, max_length=32), expected)
+ def test_match_language(self):
+ self.assertEqual(utils.match_language('es', ['es']), 'es')
+ self.assertEqual(utils.match_language('es', [], fallback='fallback'), 'fallback')
+ self.assertEqual(utils.match_language('ja', ['jp'], {'ja': 'jp'}), 'jp')
+
+ aliases = {'en-GB': 'en-UK', 'he': 'iw'}
+
+ # guess country
+ self.assertEqual(utils.match_language('de-DE', ['de']), 'de')
+ self.assertEqual(utils.match_language('de', ['de-DE']), 'de-DE')
+ self.assertEqual(utils.match_language('es-CO', ['es-AR', 'es-ES', 'es-MX']), 'es-ES')
+ self.assertEqual(utils.match_language('es-CO', ['es-MX']), 'es-MX')
+ self.assertEqual(utils.match_language('en-UK', ['en-AU', 'en-GB', 'en-US']), 'en-GB')
+ self.assertEqual(utils.match_language('en-GB', ['en-AU', 'en-UK', 'en-US'], aliases), 'en-UK')
+
+ # language aliases
+ self.assertEqual(utils.match_language('iw', ['he']), 'he')
+ self.assertEqual(utils.match_language('he', ['iw'], aliases), 'iw')
+ self.assertEqual(utils.match_language('iw-IL', ['he']), 'he')
+ self.assertEqual(utils.match_language('he-IL', ['iw'], aliases), 'iw')
+ self.assertEqual(utils.match_language('iw', ['he-IL']), 'he-IL')
+ self.assertEqual(utils.match_language('he', ['iw-IL'], aliases), 'iw-IL')
+ self.assertEqual(utils.match_language('iw-IL', ['he-IL']), 'he-IL')
+ self.assertEqual(utils.match_language('he-IL', ['iw-IL'], aliases), 'iw-IL')
+
class TestHTMLTextExtractor(SearxTestCase):