summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/engines/test_duckduckgo.py11
-rw-r--r--tests/unit/engines/test_gigablast.py6
-rw-r--r--tests/unit/engines/test_subtitleseeker.py5
-rw-r--r--tests/unit/engines/test_wikipedia.py4
-rw-r--r--tests/unit/test_preferences.py23
5 files changed, 48 insertions, 1 deletions
diff --git a/tests/unit/engines/test_duckduckgo.py b/tests/unit/engines/test_duckduckgo.py
index b5a4fd4f0..2aeaa1880 100644
--- a/tests/unit/engines/test_duckduckgo.py
+++ b/tests/unit/engines/test_duckduckgo.py
@@ -19,6 +19,17 @@ class TestDuckduckgoEngine(SearxTestCase):
self.assertIn('duckduckgo.com', params['url'])
self.assertIn('ch-de', params['url'])
+ # when ddg uses non standard code
+ 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'
+ params = duckduckgo.request(query, dicto)
+ self.assertIn('ch-de', params['url'])
+
def test_no_url_in_request_year_time_range(self):
dicto = defaultdict(dict)
query = 'test_query'
diff --git a/tests/unit/engines/test_gigablast.py b/tests/unit/engines/test_gigablast.py
index cb96f3cd1..0723b064c 100644
--- a/tests/unit/engines/test_gigablast.py
+++ b/tests/unit/engines/test_gigablast.py
@@ -15,6 +15,12 @@ class TestGigablastEngine(SearxTestCase):
self.assertTrue('url' in params)
self.assertTrue(query in params['url'])
self.assertTrue('gigablast.com' in params['url'])
+ self.assertTrue('xx' in params['url'])
+
+ dicto['language'] = 'en-US'
+ params = gigablast.request(query, dicto)
+ self.assertTrue('en' in params['url'])
+ self.assertFalse('en-US' in params['url'])
def test_response(self):
self.assertRaises(AttributeError, gigablast.response, None)
diff --git a/tests/unit/engines/test_subtitleseeker.py b/tests/unit/engines/test_subtitleseeker.py
index e499cd2d6..a22ee74b9 100644
--- a/tests/unit/engines/test_subtitleseeker.py
+++ b/tests/unit/engines/test_subtitleseeker.py
@@ -10,6 +10,7 @@ class TestSubtitleseekerEngine(SearxTestCase):
query = 'test_query'
dicto = defaultdict(dict)
dicto['pageno'] = 1
+ dicto['language'] = 'fr-FR'
params = subtitleseeker.request(query, dicto)
self.assertTrue('url' in params)
self.assertTrue(query in params['url'])
@@ -68,6 +69,10 @@ class TestSubtitleseekerEngine(SearxTestCase):
self.assertIn('1039 Subs', results[0]['content'])
self.assertIn('Alternative Title', results[0]['content'])
+ dicto['language'] = 'pt-BR'
+ results = subtitleseeker.response(response)
+ self.assertEqual(results[0]['url'], 'http://this.is.the.url/Brazilian/')
+
html = """
<div class="boxRows">
<div class="boxRowsInner" style="width:600px;">
diff --git a/tests/unit/engines/test_wikipedia.py b/tests/unit/engines/test_wikipedia.py
index 3e2f47ea9..0057277c5 100644
--- a/tests/unit/engines/test_wikipedia.py
+++ b/tests/unit/engines/test_wikipedia.py
@@ -29,6 +29,10 @@ class TestWikipediaEngine(SearxTestCase):
params = wikipedia.request(query, dicto)
self.assertIn('en', params['url'])
+ dicto['language'] = 'xx'
+ params = wikipedia.request(query, dicto)
+ self.assertIn('en', params['url'])
+
def test_response(self):
dicto = defaultdict(dict)
dicto['language'] = 'fr'
diff --git a/tests/unit/test_preferences.py b/tests/unit/test_preferences.py
index c17350809..885c515e2 100644
--- a/tests/unit/test_preferences.py
+++ b/tests/unit/test_preferences.py
@@ -1,4 +1,4 @@
-from searx.preferences import (EnumStringSetting, MapSetting, MissingArgumentException,
+from searx.preferences import (EnumStringSetting, MapSetting, MissingArgumentException, SearchLanguageSetting,
MultipleChoiceSetting, PluginsSetting, ValidationException)
from searx.testing import SearxTestCase
@@ -88,6 +88,27 @@ class TestSettings(SearxTestCase):
setting.parse('2')
self.assertEquals(setting.get_value(), ['2'])
+ # search language settings
+ def test_lang_setting_valid_choice(self):
+ setting = SearchLanguageSetting('all', choices=['all', 'de', 'en'])
+ setting.parse('de')
+ self.assertEquals(setting.get_value(), 'de')
+
+ def test_lang_setting_invalid_choice(self):
+ setting = SearchLanguageSetting('all', choices=['all', 'de', 'en'])
+ setting.parse('xx')
+ self.assertEquals(setting.get_value(), 'all')
+
+ def test_lang_setting_old_cookie_choice(self):
+ setting = SearchLanguageSetting('all', choices=['all', 'es', 'es-ES'])
+ setting.parse('es_XA')
+ self.assertEquals(setting.get_value(), 'es')
+
+ def test_lang_setting_old_cookie_format(self):
+ setting = SearchLanguageSetting('all', choices=['all', 'es', 'es-ES'])
+ setting.parse('es_ES')
+ self.assertEquals(setting.get_value(), 'es-ES')
+
# plugins settings
def test_plugins_setting_all_default_enabled(self):
plugin1 = PluginStub('plugin1', True)