From 772c048d01c7585fd60afca1ce30a1914e6e5b4a Mon Sep 17 00:00:00 2001 From: Marc Abonce Seguin Date: Wed, 28 Feb 2018 22:30:48 -0600 Subject: 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. --- tests/unit/engines/test_archlinux.py | 7 ++++++- tests/unit/engines/test_bing.py | 1 + tests/unit/engines/test_bing_images.py | 1 - tests/unit/engines/test_bing_news.py | 3 ++- tests/unit/engines/test_bing_videos.py | 1 - tests/unit/engines/test_dailymotion.py | 3 ++- tests/unit/engines/test_duckduckgo.py | 18 ++++++++++------ tests/unit/engines/test_duckduckgo_definitions.py | 1 + tests/unit/engines/test_duckduckgo_images.py | 1 - tests/unit/engines/test_google.py | 7 +++++++ tests/unit/engines/test_google_news.py | 1 + tests/unit/engines/test_qwant.py | 2 +- tests/unit/engines/test_swisscows.py | 1 + tests/unit/engines/test_wikidata.py | 1 + tests/unit/engines/test_yahoo.py | 17 ++++++++++++--- tests/unit/engines/test_yahoo_news.py | 3 ++- tests/unit/test_utils.py | 25 +++++++++++++++++++++++ 17 files changed, 76 insertions(+), 17 deletions(-) (limited to 'tests') 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_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..33556cc7a 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 @@ -31,6 +33,11 @@ class TestGoogleEngine(SearxTestCase): self.assertIn('google.co', 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['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_news.py b/tests/unit/engines/test_google_news.py index 3769e3be6..fbc6d344d 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 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..1ad21768c 100644 --- a/tests/unit/engines/test_wikidata.py +++ b/tests/unit/engines/test_wikidata.py @@ -9,6 +9,7 @@ from searx.testing import SearxTestCase class TestWikidataEngine(SearxTestCase): def test_request(self): + wikidata.supported_languages = ['en', 'es'] query = 'test_query' dicto = defaultdict(dict) dicto['language'] = 'en-US' 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): -- cgit v1.2.3 From 96877862269f35aefc0b3ca7a7cb8812b1555dc4 Mon Sep 17 00:00:00 2001 From: Marc Abonce Seguin Date: Sun, 8 Apr 2018 23:31:24 -0500 Subject: update unit tests for google news and wikidata --- tests/unit/engines/test_google_news.py | 4 ++-- tests/unit/engines/test_wikidata.py | 6 +----- 2 files changed, 3 insertions(+), 7 deletions(-) (limited to 'tests') diff --git a/tests/unit/engines/test_google_news.py b/tests/unit/engines/test_google_news.py index fbc6d344d..a041a79b9 100644 --- a/tests/unit/engines/test_google_news.py +++ b/tests/unit/engines/test_google_news.py @@ -42,7 +42,7 @@ class TestGoogleNewsEngine(SearxTestCase):

- Example title + Example title

@@ -63,7 +63,7 @@ class TestGoogleNewsEngine(SearxTestCase):

- Example title 2 + Example title 2

diff --git a/tests/unit/engines/test_wikidata.py b/tests/unit/engines/test_wikidata.py index 1ad21768c..545ef9ed8 100644 --- a/tests/unit/engines/test_wikidata.py +++ b/tests/unit/engines/test_wikidata.py @@ -9,20 +9,15 @@ from searx.testing import SearxTestCase class TestWikidataEngine(SearxTestCase): def test_request(self): - wikidata.supported_languages = ['en', 'es'] 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): @@ -31,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='', search_params={"language": "en"}) self.assertEqual(wikidata.response(response), []) -- cgit v1.2.3 From f7f9c50393785c8d6ad6c40a4c507b292ea438b1 Mon Sep 17 00:00:00 2001 From: Marc Abonce Seguin Date: Wed, 18 Apr 2018 22:55:37 -0500 Subject: [fix] force English results in Google when using en-US --- tests/unit/engines/test_google.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/unit/engines/test_google.py b/tests/unit/engines/test_google.py index 33556cc7a..413b67769 100644 --- a/tests/unit/engines/test_google.py +++ b/tests/unit/engines/test_google.py @@ -26,16 +26,19 @@ 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): -- cgit v1.2.3 From c40d8e1d15cd93e87b3aa254953cee6ba39d79fd Mon Sep 17 00:00:00 2001 From: rinpatch Date: Mon, 23 Apr 2018 11:02:32 +0300 Subject: Unit test --- tests/unit/engines/test_currency_convert.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/unit/engines/test_currency_convert.py b/tests/unit/engines/test_currency_convert.py index 0758e2fc8..0b948eace 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']) @@ -31,7 +31,7 @@ class TestCurrencyConvertEngine(SearxTestCase): response = mock.Mock(text='a,b,c,d', search_params=dicto) self.assertEqual(currency_convert.response(response), []) - body = "0.5 {}".format(dicto['to']) + body = "ddg_spice_currency(\n{\n\"conversion\":{\n\"converted-amount\": \"0.5\"\n}\n\"topConversions\":[\n{\n},\n{\n}\n]\n}\n);" response = mock.Mock(text=body, search_params=dicto) results = currency_convert.response(response) self.assertEqual(type(results), list) @@ -39,6 +39,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) -- cgit v1.2.3 From 06e070aee26a432f176b19c91fb8bae3553415d7 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Mon, 23 Apr 2018 12:55:25 +0300 Subject: Fix string length --- tests/unit/engines/test_currency_convert.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/unit/engines/test_currency_convert.py b/tests/unit/engines/test_currency_convert.py index 0b948eace..fec194103 100644 --- a/tests/unit/engines/test_currency_convert.py +++ b/tests/unit/engines/test_currency_convert.py @@ -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 = "ddg_spice_currency(\n{\n\"conversion\":{\n\"converted-amount\": \"0.5\"\n}\n\"topConversions\":[\n{\n},\n{\n}\n]\n}\n);" + 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) -- cgit v1.2.3 From dcc9fdb47fd16aa65216846dc52470ada016753c Mon Sep 17 00:00:00 2001 From: rinpatch Date: Fri, 27 Apr 2018 15:36:15 +0300 Subject: Added unit test --- tests/unit/engines/test_acgsou.py | 67 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 tests/unit/engines/test_acgsou.py (limited to 'tests') diff --git a/tests/unit/engines/test_acgsou.py b/tests/unit/engines/test_acgsou.py new file mode 100644 index 000000000..2c3e6608f --- /dev/null +++ b/tests/unit/engines/test_acgsou.py @@ -0,0 +1,67 @@ +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='') + self.assertEqual(acgsou.response(resp), []) + + html = """ + + + + tablehead + + + + + + + + + + + + + +
datetestcategory + torrentname + 1MB + + 29 + + + + 211 + + + + 168 + + user
+ """ + + 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'], 'https://www.acgsou.com/show-torrentid.html') + self.assertEqual(r['content'], 'Category: "testcategory".') + self.assertEqual(r['title'], 'torrentname') + self.assertEqual(r['filesize'], 1048576) -- cgit v1.2.3 From 1ac0c90037923c06a337b7236b678d8ca2b45e5f Mon Sep 17 00:00:00 2001 From: rinpatch Date: Fri, 27 Apr 2018 17:33:23 +0300 Subject: Fix unit test --- tests/unit/engines/test_acgsou.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/unit/engines/test_acgsou.py b/tests/unit/engines/test_acgsou.py index 2c3e6608f..d115c532a 100644 --- a/tests/unit/engines/test_acgsou.py +++ b/tests/unit/engines/test_acgsou.py @@ -20,14 +20,22 @@ class TestAcgsouEngine(SearxTestCase): self.assertEqual(acgsou.response(resp), []) html = """ + - tablehead + + + + + + + + - + +
发布时间分类资源名称大小种子下载完成发布者/联盟
date testcategory @@ -51,7 +59,9 @@ class TestAcgsouEngine(SearxTestCase): user
+ """ resp = mock.Mock(text=html) -- cgit v1.2.3 From a79c676f2766c00122695fe74ad42ff89cfdcd07 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Fri, 27 Apr 2018 17:38:52 +0300 Subject: Remove Japanese characters --- tests/unit/engines/test_acgsou.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'tests') diff --git a/tests/unit/engines/test_acgsou.py b/tests/unit/engines/test_acgsou.py index d115c532a..c3ea48057 100644 --- a/tests/unit/engines/test_acgsou.py +++ b/tests/unit/engines/test_acgsou.py @@ -24,14 +24,14 @@ class TestAcgsouEngine(SearxTestCase): - - - - - - - - + + + + + + + + -- cgit v1.2.3 From b7eb05dac68f0488223fd9127e0f5ce4c841e95f Mon Sep 17 00:00:00 2001 From: rinpatch Date: Thu, 3 May 2018 15:20:48 +0300 Subject: Fix unit test url --- tests/unit/engines/test_acgsou.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/unit/engines/test_acgsou.py b/tests/unit/engines/test_acgsou.py index c3ea48057..f97749cc1 100644 --- a/tests/unit/engines/test_acgsou.py +++ b/tests/unit/engines/test_acgsou.py @@ -71,7 +71,7 @@ class TestAcgsouEngine(SearxTestCase): self.assertEqual(len(results), 1) r = results[0] - self.assertEqual(r['url'], 'https://www.acgsou.com/show-torrentid.html') + self.assertEqual(r['url'], 'http://www.acgsou.com/show-torrentid.html') self.assertEqual(r['content'], 'Category: "testcategory".') self.assertEqual(r['title'], 'torrentname') self.assertEqual(r['filesize'], 1048576) -- cgit v1.2.3 From 059c2ccb9576f8aae36b4e1c0bf6a024d75701ea Mon Sep 17 00:00:00 2001 From: rinpatch Date: Sat, 5 May 2018 23:41:13 +0300 Subject: Fix acgsou encoding error on python2 and add unicode characters to unit testt --- tests/unit/engines/test_acgsou.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/unit/engines/test_acgsou.py b/tests/unit/engines/test_acgsou.py index f97749cc1..c01acf5de 100644 --- a/tests/unit/engines/test_acgsou.py +++ b/tests/unit/engines/test_acgsou.py @@ -1,3 +1,4 @@ +# coding=utf-8 from collections import defaultdict import mock from searx.engines import acgsou @@ -19,7 +20,7 @@ class TestAcgsouEngine(SearxTestCase): resp = mock.Mock(text='') self.assertEqual(acgsou.response(resp), []) - html = """ + html = u"""
发布时间分类资源名称大小种子下载完成发布者/联盟testtesttesttesttesttesttesttest
@@ -37,9 +38,9 @@ class TestAcgsouEngine(SearxTestCase): - +
datetestcategorytestcategory テスト - torrentname + torrentname テスト 1MB @@ -72,6 +73,6 @@ class TestAcgsouEngine(SearxTestCase): r = results[0] self.assertEqual(r['url'], 'http://www.acgsou.com/show-torrentid.html') - self.assertEqual(r['content'], 'Category: "testcategory".') - self.assertEqual(r['title'], 'torrentname') + self.assertEqual(r['content'], u'Category: "testcategory テスト".') + self.assertEqual(r['title'], u'torrentname テスト') self.assertEqual(r['filesize'], 1048576) -- cgit v1.2.3 From 7fd7bd75ff6bac2943d31db8a6816a0f8e6f85e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9mi=20V=C3=A1nyi?= Date: Mon, 21 May 2018 18:15:49 +0200 Subject: follow up tests --- tests/unit/engines/test_piratebay.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests') 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) -- cgit v1.2.3 From a3b83b73cbe5f8c04e6a3b04539c04e18c3c2fed Mon Sep 17 00:00:00 2001 From: Adam Tauber Date: Thu, 14 Jun 2018 11:47:42 +0200 Subject: [fix] remove obsolete test --- tests/unit/engines/test_google_images.py | 15 --------------- 1 file changed, 15 deletions(-) (limited to 'tests') 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') -- cgit v1.2.3 From 0a37f909900f3d4a04c963430c93977d2c96f520 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Bourrel?= Date: Fri, 6 Jul 2018 11:15:43 +0200 Subject: Fix wikidata tests with updated path to media --- tests/unit/engines/test_wikidata.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'tests') diff --git a/tests/unit/engines/test_wikidata.py b/tests/unit/engines/test_wikidata.py index 545ef9ed8..62a409781 100644 --- a/tests/unit/engines/test_wikidata.py +++ b/tests/unit/engines/test_wikidata.py @@ -123,9 +123,10 @@ class TestWikidataEngine(SearxTestCase):
- - image.png - +
+ image.png +
2,687 × 3,356; 1.22 MB +
@@ -156,9 +157,10 @@ class TestWikidataEngine(SearxTestCase):
- - icon.png - +
+ icon.png +
671 × 671; 18 KB
+
@@ -179,9 +181,10 @@ class TestWikidataEngine(SearxTestCase):
- - logo.png - +
+ logo.png +
170 × 170; 1 KB +
-- cgit v1.2.3