summaryrefslogtreecommitdiff
path: root/tests/unit
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/engines/test_archlinux.py2
-rw-r--r--tests/unit/engines/test_bing.py6
-rw-r--r--tests/unit/engines/test_bing_news.py4
-rw-r--r--tests/unit/engines/test_dailymotion.py4
-rw-r--r--tests/unit/engines/test_duckduckgo_images.py2
-rw-r--r--tests/unit/engines/test_faroo.py8
-rw-r--r--tests/unit/engines/test_gigablast.py7
-rw-r--r--tests/unit/engines/test_google.py2
-rw-r--r--tests/unit/engines/test_google_news.py7
-rw-r--r--tests/unit/engines/test_mediawiki.py4
-rw-r--r--tests/unit/engines/test_qwant.py3
-rw-r--r--tests/unit/engines/test_startpage.py4
-rw-r--r--tests/unit/engines/test_subtitleseeker.py36
-rw-r--r--tests/unit/engines/test_swisscows.py5
-rw-r--r--tests/unit/engines/test_twitter.py6
-rw-r--r--tests/unit/engines/test_wikidata.py6
-rw-r--r--tests/unit/engines/test_wikipedia.py4
-rw-r--r--tests/unit/engines/test_yacy.py5
-rw-r--r--tests/unit/engines/test_yahoo.py7
-rw-r--r--tests/unit/engines/test_yahoo_news.py7
-rw-r--r--tests/unit/test_preferences.py15
-rw-r--r--tests/unit/test_query.py64
22 files changed, 87 insertions, 121 deletions
diff --git a/tests/unit/engines/test_archlinux.py b/tests/unit/engines/test_archlinux.py
index e4ee0339c..f9e536f4e 100644
--- a/tests/unit/engines/test_archlinux.py
+++ b/tests/unit/engines/test_archlinux.py
@@ -4,7 +4,7 @@ from searx.engines import archlinux
from searx.testing import SearxTestCase
domains = {
- 'all': 'https://wiki.archlinux.org',
+ 'en': 'https://wiki.archlinux.org',
'de': 'https://wiki.archlinux.de',
'fr': 'https://wiki.archlinux.fr',
'ja': 'https://wiki.archlinuxjp.org',
diff --git a/tests/unit/engines/test_bing.py b/tests/unit/engines/test_bing.py
index 523ec57b8..2528dd847 100644
--- a/tests/unit/engines/test_bing.py
+++ b/tests/unit/engines/test_bing.py
@@ -10,17 +10,13 @@ class TestBingEngine(SearxTestCase):
query = u'test_query'
dicto = defaultdict(dict)
dicto['pageno'] = 0
- dicto['language'] = 'fr_FR'
+ dicto['language'] = 'fr-FR'
params = bing.request(query.encode('utf-8'), dicto)
self.assertTrue('url' in params)
self.assertTrue(query in params['url'])
self.assertTrue('language%3AFR' in params['url'])
self.assertTrue('bing.com' in params['url'])
- dicto['language'] = 'all'
- params = bing.request(query.encode('utf-8'), dicto)
- self.assertTrue('language' in params['url'])
-
def test_response(self):
self.assertRaises(AttributeError, bing.response, None)
self.assertRaises(AttributeError, bing.response, [])
diff --git a/tests/unit/engines/test_bing_news.py b/tests/unit/engines/test_bing_news.py
index 1f1aeca1d..3af19fd6d 100644
--- a/tests/unit/engines/test_bing_news.py
+++ b/tests/unit/engines/test_bing_news.py
@@ -19,10 +19,6 @@ class TestBingNewsEngine(SearxTestCase):
self.assertIn('bing.com', params['url'])
self.assertIn('fr', params['url'])
- dicto['language'] = 'all'
- params = bing_news.request(query, dicto)
- self.assertIn('en', 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_dailymotion.py b/tests/unit/engines/test_dailymotion.py
index 72071af66..2009c0e4f 100644
--- a/tests/unit/engines/test_dailymotion.py
+++ b/tests/unit/engines/test_dailymotion.py
@@ -18,10 +18,6 @@ class TestDailymotionEngine(SearxTestCase):
self.assertTrue('dailymotion.com' in params['url'])
self.assertTrue('fr' in params['url'])
- dicto['language'] = 'all'
- params = dailymotion.request(query, dicto)
- self.assertTrue('en' in params['url'])
-
def test_response(self):
self.assertRaises(AttributeError, dailymotion.response, None)
self.assertRaises(AttributeError, dailymotion.response, [])
diff --git a/tests/unit/engines/test_duckduckgo_images.py b/tests/unit/engines/test_duckduckgo_images.py
index a8a57c7fd..582163130 100644
--- a/tests/unit/engines/test_duckduckgo_images.py
+++ b/tests/unit/engines/test_duckduckgo_images.py
@@ -15,7 +15,7 @@ class TestDuckduckgoImagesEngine(SearxTestCase):
dicto['is_test'] = True
dicto['pageno'] = 1
dicto['safesearch'] = 0
- dicto['language'] = 'all'
+ dicto['language'] = 'en-US'
params = duckduckgo_images.request(query, dicto)
self.assertIn('url', params)
self.assertIn(query, params['url'])
diff --git a/tests/unit/engines/test_faroo.py b/tests/unit/engines/test_faroo.py
index ebcde39a7..0cc8bc3e0 100644
--- a/tests/unit/engines/test_faroo.py
+++ b/tests/unit/engines/test_faroo.py
@@ -11,7 +11,7 @@ class TestFarooEngine(SearxTestCase):
query = 'test_query'
dicto = defaultdict(dict)
dicto['pageno'] = 1
- dicto['language'] = 'fr_FR'
+ dicto['language'] = 'fr-FR'
dicto['category'] = 'general'
params = faroo.request(query, dicto)
self.assertIn('url', params)
@@ -20,11 +20,7 @@ class TestFarooEngine(SearxTestCase):
self.assertIn('en', params['url'])
self.assertIn('web', params['url'])
- dicto['language'] = 'all'
- params = faroo.request(query, dicto)
- self.assertIn('en', params['url'])
-
- dicto['language'] = 'de_DE'
+ dicto['language'] = 'de-DE'
params = faroo.request(query, dicto)
self.assertIn('de', params['url'])
diff --git a/tests/unit/engines/test_gigablast.py b/tests/unit/engines/test_gigablast.py
index 6b2d26458..f0ddb63bc 100644
--- a/tests/unit/engines/test_gigablast.py
+++ b/tests/unit/engines/test_gigablast.py
@@ -11,16 +11,11 @@ class TestGigablastEngine(SearxTestCase):
dicto = defaultdict(dict)
dicto['pageno'] = 0
dicto['safesearch'] = 0
- dicto['language'] = 'all'
+ dicto['language'] = 'en-US'
params = gigablast.request(query, dicto)
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):
diff --git a/tests/unit/engines/test_google.py b/tests/unit/engines/test_google.py
index 0498d49b0..ecd1ed4d9 100644
--- a/tests/unit/engines/test_google.py
+++ b/tests/unit/engines/test_google.py
@@ -26,7 +26,7 @@ class TestGoogleEngine(SearxTestCase):
self.assertIn('google.fr', params['url'])
self.assertIn('fr', params['headers']['Accept-Language'])
- dicto['language'] = 'all'
+ dicto['language'] = 'en-US'
params = google.request(query, dicto)
self.assertIn('google.co', params['url'])
self.assertIn('en', params['headers']['Accept-Language'])
diff --git a/tests/unit/engines/test_google_news.py b/tests/unit/engines/test_google_news.py
index 20a75af48..3769e3be6 100644
--- a/tests/unit/engines/test_google_news.py
+++ b/tests/unit/engines/test_google_news.py
@@ -12,18 +12,13 @@ class TestGoogleNewsEngine(SearxTestCase):
query = 'test_query'
dicto = defaultdict(dict)
dicto['pageno'] = 1
- dicto['language'] = 'fr_FR'
+ dicto['language'] = 'fr-FR'
dicto['time_range'] = 'w'
params = google_news.request(query, dicto)
self.assertIn('url', params)
self.assertIn(query, params['url'])
self.assertIn('fr', params['url'])
- dicto['language'] = 'all'
- params = google_news.request(query, dicto)
- self.assertIn('url', params)
- self.assertNotIn('fr', params['url'])
-
def test_response(self):
self.assertRaises(AttributeError, google_news.response, None)
self.assertRaises(AttributeError, google_news.response, [])
diff --git a/tests/unit/engines/test_mediawiki.py b/tests/unit/engines/test_mediawiki.py
index b86372700..1b07dd8f4 100644
--- a/tests/unit/engines/test_mediawiki.py
+++ b/tests/unit/engines/test_mediawiki.py
@@ -18,10 +18,6 @@ class TestMediawikiEngine(SearxTestCase):
self.assertIn('wikipedia.org', params['url'])
self.assertIn('fr', params['url'])
- dicto['language'] = 'all'
- params = mediawiki.request(query, dicto)
- self.assertIn('en', params['url'])
-
mediawiki.base_url = "http://test.url/"
mediawiki.search_url = mediawiki.base_url +\
'w/api.php?action=query'\
diff --git a/tests/unit/engines/test_qwant.py b/tests/unit/engines/test_qwant.py
index b7133c076..46694988c 100644
--- a/tests/unit/engines/test_qwant.py
+++ b/tests/unit/engines/test_qwant.py
@@ -19,10 +19,11 @@ class TestQwantEngine(SearxTestCase):
self.assertIn('qwant.com', params['url'])
self.assertIn('fr_fr', params['url'])
- dicto['language'] = 'all'
+ dicto['language'] = 'en-US'
qwant.categories = ['news']
params = qwant.request(query, dicto)
self.assertFalse('fr' in params['url'])
+ self.assertIn('en_us', params['url'])
self.assertIn('news', params['url'])
qwant.supported_languages = ['en', 'fr-FR', 'fr-CA']
diff --git a/tests/unit/engines/test_startpage.py b/tests/unit/engines/test_startpage.py
index a7a97785e..bdb3356b7 100644
--- a/tests/unit/engines/test_startpage.py
+++ b/tests/unit/engines/test_startpage.py
@@ -21,10 +21,6 @@ class TestStartpageEngine(SearxTestCase):
self.assertIn('with_language', params['data'])
self.assertIn('lang_fr', params['data']['with_language'])
- dicto['language'] = 'all'
- params = startpage.request(query, dicto)
- self.assertNotIn('with_language', params['data'])
-
def test_response(self):
self.assertRaises(AttributeError, startpage.response, None)
self.assertRaises(AttributeError, startpage.response, [])
diff --git a/tests/unit/engines/test_subtitleseeker.py b/tests/unit/engines/test_subtitleseeker.py
index a22ee74b9..96b253943 100644
--- a/tests/unit/engines/test_subtitleseeker.py
+++ b/tests/unit/engines/test_subtitleseeker.py
@@ -99,42 +99,6 @@ class TestSubtitleseekerEngine(SearxTestCase):
<div class="clear"></div>
</div>
"""
- dicto['language'] = 'all'
- response = mock.Mock(text=html, search_params=dicto)
- results = subtitleseeker.response(response)
- self.assertEqual(type(results), list)
- self.assertEqual(len(results), 1)
- self.assertEqual(results[0]['title'], 'This is the Title')
- self.assertEqual(results[0]['url'], 'http://this.is.the.url/')
- self.assertIn('1998', results[0]['content'])
- self.assertIn('1039 Subs', results[0]['content'])
-
- html = """
- <div class="boxRows">
- <div class="boxRowsInner" style="width:600px;">
- <img src="http://static.subtitleseeker.com/images/movie.gif"
- style="width:16px; height:16px;" class="icon">
- <a href="http://this.is.the.url/"
- class="blue" title="Title subtitle" >
- This is the Title
- </a>
- </div>
- <div class="boxRowsInner f12b red" style="width:70px;">
- 1998
- </div>
- <div class="boxRowsInner grey-web f12" style="width:120px;">
- <img src="http://static.subtitleseeker.com/images/basket_put.png"
- style="width:16px; height:16px;" class="icon">
- 1039 Subs
- </div>
- <div class="boxRowsInner grey-web f10" style="width:130px;">
- <img src="http://static.subtitleseeker.com/images/arrow_refresh_small.png"
- style="width:16px; height:16px;" class="icon">
- 1 hours ago
- </div>
- <div class="clear"></div>
- </div>
- """
subtitleseeker.language = 'English'
response = mock.Mock(text=html, search_params=dicto)
results = subtitleseeker.response(response)
diff --git a/tests/unit/engines/test_swisscows.py b/tests/unit/engines/test_swisscows.py
index 492526f94..2715ef52e 100644
--- a/tests/unit/engines/test_swisscows.py
+++ b/tests/unit/engines/test_swisscows.py
@@ -18,11 +18,6 @@ class TestSwisscowsEngine(SearxTestCase):
self.assertTrue('uiLanguage=de' in params['url'])
self.assertTrue('region=de-DE' in params['url'])
- dicto['language'] = 'all'
- params = swisscows.request(query, dicto)
- self.assertTrue('uiLanguage=browser' in params['url'])
- self.assertTrue('region=browser' in params['url'])
-
dicto['category'] = 'images'
params = swisscows.request(query, dicto)
self.assertIn('image', params['url'])
diff --git a/tests/unit/engines/test_twitter.py b/tests/unit/engines/test_twitter.py
index b444b48ee..10e4a0ba9 100644
--- a/tests/unit/engines/test_twitter.py
+++ b/tests/unit/engines/test_twitter.py
@@ -20,12 +20,6 @@ class TestTwitterEngine(SearxTestCase):
self.assertIn('lang', params['cookies'])
self.assertIn('fr', params['cookies']['lang'])
- dicto['language'] = 'all'
- params = twitter.request(query, dicto)
- self.assertIn('cookies', params)
- self.assertIn('lang', params['cookies'])
- self.assertIn('en', params['cookies']['lang'])
-
def test_response(self):
self.assertRaises(AttributeError, twitter.response, None)
self.assertRaises(AttributeError, twitter.response, [])
diff --git a/tests/unit/engines/test_wikidata.py b/tests/unit/engines/test_wikidata.py
index aa69f116e..453133b64 100644
--- a/tests/unit/engines/test_wikidata.py
+++ b/tests/unit/engines/test_wikidata.py
@@ -11,14 +11,14 @@ class TestWikidataEngine(SearxTestCase):
def test_request(self):
query = 'test_query'
dicto = defaultdict(dict)
- dicto['language'] = 'all'
+ 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'
+ dicto['language'] = 'es-ES'
params = wikidata.request(query, dicto)
self.assertIn(query, params['url'])
self.assertIn('es', params['url'])
@@ -30,7 +30,7 @@ class TestWikidataEngine(SearxTestCase):
self.assertRaises(AttributeError, wikidata.response, '')
self.assertRaises(AttributeError, wikidata.response, '[]')
- response = mock.Mock(text='<html></html>', search_params={"language": "all"})
+ response = mock.Mock(text='<html></html>', search_params={"language": "en"})
self.assertEqual(wikidata.response(response), [])
def test_getDetail(self):
diff --git a/tests/unit/engines/test_wikipedia.py b/tests/unit/engines/test_wikipedia.py
index 7a86514c7..21d0225ed 100644
--- a/tests/unit/engines/test_wikipedia.py
+++ b/tests/unit/engines/test_wikipedia.py
@@ -25,10 +25,6 @@ class TestWikipediaEngine(SearxTestCase):
self.assertIn('Test_Query', params['url'])
self.assertNotIn('test_query', params['url'])
- dicto['language'] = 'all'
- params = wikipedia.request(query, dicto)
- self.assertIn('en', params['url'])
-
dicto['language'] = 'xx'
params = wikipedia.request(query, dicto)
self.assertIn('en', params['url'])
diff --git a/tests/unit/engines/test_yacy.py b/tests/unit/engines/test_yacy.py
index f49532cf4..a60614d3d 100644
--- a/tests/unit/engines/test_yacy.py
+++ b/tests/unit/engines/test_yacy.py
@@ -17,11 +17,6 @@ class TestYacyEngine(SearxTestCase):
self.assertIn('localhost', params['url'])
self.assertIn('fr', params['url'])
- dicto['language'] = 'all'
- params = yacy.request(query, dicto)
- self.assertIn('url', params)
- self.assertNotIn('lr=lang_', params['url'])
-
def test_response(self):
self.assertRaises(AttributeError, yacy.response, None)
self.assertRaises(AttributeError, yacy.response, [])
diff --git a/tests/unit/engines/test_yahoo.py b/tests/unit/engines/test_yahoo.py
index 82c4d99bb..921d3e8cd 100644
--- a/tests/unit/engines/test_yahoo.py
+++ b/tests/unit/engines/test_yahoo.py
@@ -39,13 +39,6 @@ class TestYahooEngine(SearxTestCase):
self.assertIn('sB', params['cookies'])
self.assertIn('fr', params['cookies']['sB'])
- dicto['language'] = 'all'
- params = yahoo.request(query, dicto)
- self.assertIn('cookies', params)
- self.assertIn('sB', params['cookies'])
- self.assertIn('en', params['cookies']['sB'])
- self.assertIn('en', 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_yahoo_news.py b/tests/unit/engines/test_yahoo_news.py
index 4d7fc0a10..bc87ec067 100644
--- a/tests/unit/engines/test_yahoo_news.py
+++ b/tests/unit/engines/test_yahoo_news.py
@@ -22,13 +22,6 @@ class TestYahooNewsEngine(SearxTestCase):
self.assertIn('sB', params['cookies'])
self.assertIn('fr', params['cookies']['sB'])
- dicto['language'] = 'all'
- params = yahoo_news.request(query, dicto)
- self.assertIn('cookies', params)
- self.assertIn('sB', params['cookies'])
- self.assertIn('en', params['cookies']['sB'])
- self.assertIn('en', params['url'])
-
def test_sanitize_url(self):
url = "test.url"
self.assertEqual(url, yahoo_news.sanitize_url(url))
diff --git a/tests/unit/test_preferences.py b/tests/unit/test_preferences.py
index 885c515e2..c8f2a4419 100644
--- a/tests/unit/test_preferences.py
+++ b/tests/unit/test_preferences.py
@@ -90,25 +90,30 @@ class TestSettings(SearxTestCase):
# search language settings
def test_lang_setting_valid_choice(self):
- setting = SearchLanguageSetting('all', choices=['all', 'de', 'en'])
+ setting = SearchLanguageSetting('en', choices=['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 = SearchLanguageSetting('en', choices=['de', 'en'])
setting.parse('xx')
- self.assertEquals(setting.get_value(), 'all')
+ self.assertEquals(setting.get_value(), 'en')
def test_lang_setting_old_cookie_choice(self):
- setting = SearchLanguageSetting('all', choices=['all', 'es', 'es-ES'])
+ setting = SearchLanguageSetting('en', choices=['en', '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 = SearchLanguageSetting('en', choices=['en', 'es', 'es-ES'])
setting.parse('es_ES')
self.assertEquals(setting.get_value(), 'es-ES')
+ def test_lang_setting_old_default(self):
+ setting = SearchLanguageSetting('en', choices=['en', 'es', 'de'])
+ setting.parse('all')
+ self.assertEquals(setting.get_value(), 'en')
+
# plugins settings
def test_plugins_setting_all_default_enabled(self):
plugin1 = PluginStub('plugin1', True)
diff --git a/tests/unit/test_query.py b/tests/unit/test_query.py
new file mode 100644
index 000000000..49ccb608f
--- /dev/null
+++ b/tests/unit/test_query.py
@@ -0,0 +1,64 @@
+from searx.query import RawTextQuery
+from searx.testing import SearxTestCase
+
+
+class TestQuery(SearxTestCase):
+
+ def test_simple_query(self):
+ query_text = 'the query'
+ query = RawTextQuery(query_text, [])
+ query.parse_query()
+
+ self.assertEquals(query.getFullQuery(), query_text)
+ self.assertEquals(len(query.query_parts), 1)
+ self.assertEquals(len(query.languages), 0)
+ self.assertFalse(query.specific)
+
+ def test_language_code(self):
+ language = 'es-ES'
+ query_text = 'the query'
+ full_query = ':' + language + ' ' + query_text
+ query = RawTextQuery(full_query, [])
+ query.parse_query()
+
+ self.assertEquals(query.getFullQuery(), full_query)
+ self.assertEquals(len(query.query_parts), 3)
+ self.assertEquals(len(query.languages), 1)
+ self.assertIn(language, query.languages)
+ self.assertFalse(query.specific)
+
+ def test_language_name(self):
+ language = 'english'
+ query_text = 'the query'
+ full_query = ':' + language + ' ' + query_text
+ query = RawTextQuery(full_query, [])
+ query.parse_query()
+
+ self.assertEquals(query.getFullQuery(), full_query)
+ self.assertEquals(len(query.query_parts), 3)
+ self.assertIn('en', query.languages)
+ self.assertFalse(query.specific)
+
+ def test_unlisted_language_code(self):
+ language = 'all'
+ query_text = 'the query'
+ full_query = ':' + language + ' ' + query_text
+ query = RawTextQuery(full_query, [])
+ query.parse_query()
+
+ self.assertEquals(query.getFullQuery(), full_query)
+ self.assertEquals(len(query.query_parts), 3)
+ self.assertIn('all', query.languages)
+ self.assertFalse(query.specific)
+
+ def test_invalid_language_code(self):
+ language = 'not_a_language'
+ query_text = 'the query'
+ full_query = ':' + language + ' ' + query_text
+ query = RawTextQuery(full_query, [])
+ query.parse_query()
+
+ self.assertEquals(query.getFullQuery(), full_query)
+ self.assertEquals(len(query.query_parts), 1)
+ self.assertEquals(len(query.languages), 0)
+ self.assertFalse(query.specific)