diff options
author | Marc Abonce Seguin <marc-abonce@mailbox.org> | 2018-02-28 22:30:48 -0600 |
---|---|---|
committer | Marc Abonce Seguin <marc-abonce@mailbox.org> | 2018-03-27 00:08:03 -0600 |
commit | 772c048d01c7585fd60afca1ce30a1914e6e5b4a (patch) | |
tree | 96a5662897df2bcf0ab53456e0a67ace998f2169 /tests/unit/engines/test_duckduckgo.py | |
parent | d1eae9359f8c5920632a730744ea2208070f06da (diff) | |
download | searxng-772c048d01c7585fd60afca1ce30a1914e6e5b4a.tar.gz searxng-772c048d01c7585fd60afca1ce30a1914e6e5b4a.zip |
refactor engine's search language handling
Add match_language function in utils to match any user given
language code with a list of engine's supported languages.
Also add language_aliases dict on each engine to translate
standard language codes into the custom codes used by the engine.
Diffstat (limited to 'tests/unit/engines/test_duckduckgo.py')
-rw-r--r-- | tests/unit/engines/test_duckduckgo.py | 18 |
1 files changed, 12 insertions, 6 deletions
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) |