mirror of https://github.com/searxng/searxng.git
tests for language support in engines
This commit is contained in:
parent
1b46ecd21a
commit
e0c270bd72
Binary file not shown.
|
@ -53,14 +53,16 @@ def request(query, params):
|
||||||
locale = None
|
locale = None
|
||||||
elif params['language'][:2] == 'ja':
|
elif params['language'][:2] == 'ja':
|
||||||
locale = 'jp-jp'
|
locale = 'jp-jp'
|
||||||
|
elif params['language'][:2] == 'sl':
|
||||||
|
locale = 'sl-sl'
|
||||||
elif params['language'] == 'zh-TW':
|
elif params['language'] == 'zh-TW':
|
||||||
locale = 'tw-tzh'
|
locale = 'tw-tzh'
|
||||||
elif params['language'] == 'zh-HK':
|
elif params['language'] == 'zh-HK':
|
||||||
locale = 'hk-tzh'
|
locale = 'hk-tzh'
|
||||||
elif params['language'][-2:] == 'SA':
|
elif params['language'][-2:] == 'SA':
|
||||||
locale = 'xa' + params['language'].split('-')[0]
|
locale = 'xa-' + params['language'].split('-')[0]
|
||||||
elif params['language'][-2:] == 'GB':
|
elif params['language'][-2:] == 'GB':
|
||||||
locale = 'uk' + params['language'].split('-')[0]
|
locale = 'uk-' + params['language'].split('-')[0]
|
||||||
else:
|
else:
|
||||||
locale = params['language'].split('-')
|
locale = params['language'].split('-')
|
||||||
if len(locale) == 2:
|
if len(locale) == 2:
|
||||||
|
|
|
@ -46,7 +46,7 @@ def response(resp):
|
||||||
# dirty fix for languages named differenly in their site
|
# dirty fix for languages named differenly in their site
|
||||||
if resp.search_params['language'][:2] == 'fa':
|
if resp.search_params['language'][:2] == 'fa':
|
||||||
search_lang = 'Farsi'
|
search_lang = 'Farsi'
|
||||||
elif resp.search_params['language'] == 'pt_BR':
|
elif resp.search_params['language'] == 'pt-BR':
|
||||||
search_lang = 'Brazilian'
|
search_lang = 'Brazilian'
|
||||||
elif resp.search_params['language'] != 'all':
|
elif resp.search_params['language'] != 'all':
|
||||||
search_lang = [lc[3]
|
search_lang = [lc[3]
|
||||||
|
|
|
@ -110,7 +110,7 @@ class SearchLanguageSetting(EnumStringSetting):
|
||||||
elif data == 'ar-XA':
|
elif data == 'ar-XA':
|
||||||
data = 'ar-SA'
|
data = 'ar-SA'
|
||||||
else:
|
else:
|
||||||
data = 'all'
|
data = self.value
|
||||||
self.value = data
|
self.value = data
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,17 @@ class TestDuckduckgoEngine(SearxTestCase):
|
||||||
self.assertIn('duckduckgo.com', params['url'])
|
self.assertIn('duckduckgo.com', params['url'])
|
||||||
self.assertIn('ch-de', 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):
|
def test_no_url_in_request_year_time_range(self):
|
||||||
dicto = defaultdict(dict)
|
dicto = defaultdict(dict)
|
||||||
query = 'test_query'
|
query = 'test_query'
|
||||||
|
|
|
@ -15,6 +15,12 @@ class TestGigablastEngine(SearxTestCase):
|
||||||
self.assertTrue('url' in params)
|
self.assertTrue('url' in params)
|
||||||
self.assertTrue(query in params['url'])
|
self.assertTrue(query in params['url'])
|
||||||
self.assertTrue('gigablast.com' 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):
|
def test_response(self):
|
||||||
self.assertRaises(AttributeError, gigablast.response, None)
|
self.assertRaises(AttributeError, gigablast.response, None)
|
||||||
|
|
|
@ -10,6 +10,7 @@ class TestSubtitleseekerEngine(SearxTestCase):
|
||||||
query = 'test_query'
|
query = 'test_query'
|
||||||
dicto = defaultdict(dict)
|
dicto = defaultdict(dict)
|
||||||
dicto['pageno'] = 1
|
dicto['pageno'] = 1
|
||||||
|
dicto['language'] = 'fr-FR'
|
||||||
params = subtitleseeker.request(query, dicto)
|
params = subtitleseeker.request(query, dicto)
|
||||||
self.assertTrue('url' in params)
|
self.assertTrue('url' in params)
|
||||||
self.assertTrue(query in params['url'])
|
self.assertTrue(query in params['url'])
|
||||||
|
@ -68,6 +69,10 @@ class TestSubtitleseekerEngine(SearxTestCase):
|
||||||
self.assertIn('1039 Subs', results[0]['content'])
|
self.assertIn('1039 Subs', results[0]['content'])
|
||||||
self.assertIn('Alternative Title', 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 = """
|
html = """
|
||||||
<div class="boxRows">
|
<div class="boxRows">
|
||||||
<div class="boxRowsInner" style="width:600px;">
|
<div class="boxRowsInner" style="width:600px;">
|
||||||
|
|
|
@ -29,6 +29,10 @@ class TestWikipediaEngine(SearxTestCase):
|
||||||
params = wikipedia.request(query, dicto)
|
params = wikipedia.request(query, dicto)
|
||||||
self.assertIn('en', params['url'])
|
self.assertIn('en', params['url'])
|
||||||
|
|
||||||
|
dicto['language'] = 'xx'
|
||||||
|
params = wikipedia.request(query, dicto)
|
||||||
|
self.assertIn('en', params['url'])
|
||||||
|
|
||||||
def test_response(self):
|
def test_response(self):
|
||||||
dicto = defaultdict(dict)
|
dicto = defaultdict(dict)
|
||||||
dicto['language'] = 'fr'
|
dicto['language'] = 'fr'
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from searx.preferences import (EnumStringSetting, MapSetting, MissingArgumentException,
|
from searx.preferences import (EnumStringSetting, MapSetting, MissingArgumentException, SearchLanguageSetting,
|
||||||
MultipleChoiceSetting, PluginsSetting, ValidationException)
|
MultipleChoiceSetting, PluginsSetting, ValidationException)
|
||||||
from searx.testing import SearxTestCase
|
from searx.testing import SearxTestCase
|
||||||
|
|
||||||
|
@ -88,6 +88,27 @@ class TestSettings(SearxTestCase):
|
||||||
setting.parse('2')
|
setting.parse('2')
|
||||||
self.assertEquals(setting.get_value(), ['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
|
# plugins settings
|
||||||
def test_plugins_setting_all_default_enabled(self):
|
def test_plugins_setting_all_default_enabled(self):
|
||||||
plugin1 = PluginStub('plugin1', True)
|
plugin1 = PluginStub('plugin1', True)
|
||||||
|
|
Loading…
Reference in New Issue