diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit/test_answerers.py | 4 | ||||
-rw-r--r-- | tests/unit/test_plugins.py | 16 | ||||
-rw-r--r-- | tests/unit/test_preferences.py | 32 | ||||
-rw-r--r-- | tests/unit/test_query.py | 52 | ||||
-rw-r--r-- | tests/unit/test_search.py | 16 | ||||
-rw-r--r-- | tests/unit/test_utils.py | 20 | ||||
-rw-r--r-- | tests/unit/test_webapp.py | 4 |
7 files changed, 70 insertions, 74 deletions
diff --git a/tests/unit/test_answerers.py b/tests/unit/test_answerers.py index bd8789a7e..73d8d26f2 100644 --- a/tests/unit/test_answerers.py +++ b/tests/unit/test_answerers.py @@ -10,7 +10,7 @@ class AnswererTest(SearxTestCase): def test_unicode_input(self): query = Mock() - unicode_payload = u'árvíztűrő tükörfúrógép' + unicode_payload = 'árvíztűrő tükörfúrógép' for answerer in answerers: - query.query = u'{} {}'.format(answerer.keywords[0], unicode_payload) + query.query = '{} {}'.format(answerer.keywords[0], unicode_payload) self.assertTrue(isinstance(answerer.answer(query), list)) diff --git a/tests/unit/test_plugins.py b/tests/unit/test_plugins.py index 10de8475a..838c1d574 100644 --- a/tests/unit/test_plugins.py +++ b/tests/unit/test_plugins.py @@ -48,11 +48,11 @@ class SelfIPTest(SearxTestCase): # IP test request = Mock(remote_addr='127.0.0.1') request.headers.getlist.return_value = [] - search = get_search_mock(query=b'ip', pageno=1) + search = get_search_mock(query='ip', pageno=1) store.call(store.plugins, 'post_search', request, search) self.assertTrue('127.0.0.1' in search.result_container.answers["ip"]["answer"]) - search = get_search_mock(query=b'ip', pageno=2) + search = get_search_mock(query='ip', pageno=2) store.call(store.plugins, 'post_search', request, search) self.assertFalse('ip' in search.result_container.answers) @@ -60,26 +60,26 @@ class SelfIPTest(SearxTestCase): request = Mock(user_agent='Mock') request.headers.getlist.return_value = [] - search = get_search_mock(query=b'user-agent', pageno=1) + search = get_search_mock(query='user-agent', pageno=1) store.call(store.plugins, 'post_search', request, search) self.assertTrue('Mock' in search.result_container.answers["user-agent"]["answer"]) - search = get_search_mock(query=b'user-agent', pageno=2) + search = get_search_mock(query='user-agent', pageno=2) store.call(store.plugins, 'post_search', request, search) self.assertFalse('user-agent' in search.result_container.answers) - search = get_search_mock(query=b'user-agent', pageno=1) + search = get_search_mock(query='user-agent', pageno=1) store.call(store.plugins, 'post_search', request, search) self.assertTrue('Mock' in search.result_container.answers["user-agent"]["answer"]) - search = get_search_mock(query=b'user-agent', pageno=2) + search = get_search_mock(query='user-agent', pageno=2) store.call(store.plugins, 'post_search', request, search) self.assertFalse('user-agent' in search.result_container.answers) - search = get_search_mock(query=b'What is my User-Agent?', pageno=1) + search = get_search_mock(query='What is my User-Agent?', pageno=1) store.call(store.plugins, 'post_search', request, search) self.assertTrue('Mock' in search.result_container.answers["user-agent"]["answer"]) - search = get_search_mock(query=b'What is my User-Agent?', pageno=2) + search = get_search_mock(query='What is my User-Agent?', pageno=2) store.call(store.plugins, 'post_search', request, search) self.assertFalse('user-agent' in search.result_container.answers) diff --git a/tests/unit/test_preferences.py b/tests/unit/test_preferences.py index 61ac0e8e4..32f50c60b 100644 --- a/tests/unit/test_preferences.py +++ b/tests/unit/test_preferences.py @@ -3,7 +3,7 @@ from searx.preferences import (EnumStringSetting, MapSetting, MissingArgumentExc from searx.testing import SearxTestCase -class PluginStub(object): +class PluginStub: def __init__(self, id, default_on): self.id = id @@ -28,13 +28,13 @@ class TestSettings(SearxTestCase): def test_map_setting_valid_default(self): setting = MapSetting(3, map={'dog': 1, 'bat': 2, 'cat': 3}) - self.assertEquals(setting.get_value(), 3) + self.assertEqual(setting.get_value(), 3) def test_map_setting_valid_choice(self): setting = MapSetting(3, map={'dog': 1, 'bat': 2, 'cat': 3}) - self.assertEquals(setting.get_value(), 3) + self.assertEqual(setting.get_value(), 3) setting.parse('bat') - self.assertEquals(setting.get_value(), 2) + self.assertEqual(setting.get_value(), 2) def test_enum_setting_invalid_initialization(self): with self.assertRaises(MissingArgumentException): @@ -56,13 +56,13 @@ class TestSettings(SearxTestCase): def test_enum_setting_valid_default(self): setting = EnumStringSetting(3, choices=[1, 2, 3]) - self.assertEquals(setting.get_value(), 3) + self.assertEqual(setting.get_value(), 3) def test_enum_setting_valid_choice(self): setting = EnumStringSetting(3, choices=[1, 2, 3]) - self.assertEquals(setting.get_value(), 3) + self.assertEqual(setting.get_value(), 3) setting.parse(2) - self.assertEquals(setting.get_value(), 2) + self.assertEqual(setting.get_value(), 2) # multiple choice settings def test_multiple_setting_invalid_initialization(self): @@ -80,48 +80,48 @@ class TestSettings(SearxTestCase): def test_multiple_setting_valid_default(self): setting = MultipleChoiceSetting(['3'], choices=['1', '2', '3']) - self.assertEquals(setting.get_value(), ['3']) + self.assertEqual(setting.get_value(), ['3']) def test_multiple_setting_valid_choice(self): setting = MultipleChoiceSetting(['3'], choices=['1', '2', '3']) - self.assertEquals(setting.get_value(), ['3']) + self.assertEqual(setting.get_value(), ['3']) setting.parse('2') - self.assertEquals(setting.get_value(), ['2']) + self.assertEqual(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') + self.assertEqual(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') + self.assertEqual(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') + self.assertEqual(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') + self.assertEqual(setting.get_value(), 'es-ES') # plugins settings def test_plugins_setting_all_default_enabled(self): plugin1 = PluginStub('plugin1', True) plugin2 = PluginStub('plugin2', True) setting = PluginsSetting(['3'], choices=[plugin1, plugin2]) - self.assertEquals(setting.get_enabled(), set(['plugin1', 'plugin2'])) + self.assertEqual(setting.get_enabled(), set(['plugin1', 'plugin2'])) def test_plugins_setting_few_default_enabled(self): plugin1 = PluginStub('plugin1', True) plugin2 = PluginStub('plugin2', False) plugin3 = PluginStub('plugin3', True) setting = PluginsSetting('name', choices=[plugin1, plugin2, plugin3]) - self.assertEquals(setting.get_enabled(), set(['plugin1', 'plugin3'])) + self.assertEqual(setting.get_enabled(), set(['plugin1', 'plugin3'])) class TestPreferences(SearxTestCase): diff --git a/tests/unit/test_query.py b/tests/unit/test_query.py index e4c0bdeed..86bf445e3 100644 --- a/tests/unit/test_query.py +++ b/tests/unit/test_query.py @@ -9,9 +9,9 @@ class TestQuery(SearxTestCase): 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.assertEqual(query.getFullQuery(), query_text) + self.assertEqual(len(query.query_parts), 1) + self.assertEqual(len(query.languages), 0) self.assertFalse(query.specific) def test_language_code(self): @@ -21,9 +21,9 @@ class TestQuery(SearxTestCase): 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.assertEqual(query.getFullQuery(), full_query) + self.assertEqual(len(query.query_parts), 3) + self.assertEqual(len(query.languages), 1) self.assertIn(language, query.languages) self.assertFalse(query.specific) @@ -34,8 +34,8 @@ class TestQuery(SearxTestCase): query = RawTextQuery(full_query, []) query.parse_query() - self.assertEquals(query.getFullQuery(), full_query) - self.assertEquals(len(query.query_parts), 3) + self.assertEqual(query.getFullQuery(), full_query) + self.assertEqual(len(query.query_parts), 3) self.assertIn('en', query.languages) self.assertFalse(query.specific) @@ -46,8 +46,8 @@ class TestQuery(SearxTestCase): query = RawTextQuery(full_query, []) query.parse_query() - self.assertEquals(query.getFullQuery(), full_query) - self.assertEquals(len(query.query_parts), 3) + self.assertEqual(query.getFullQuery(), full_query) + self.assertEqual(len(query.query_parts), 3) self.assertIn('all', query.languages) self.assertFalse(query.specific) @@ -58,9 +58,9 @@ class TestQuery(SearxTestCase): 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.assertEqual(query.getFullQuery(), full_query) + self.assertEqual(len(query.query_parts), 1) + self.assertEqual(len(query.languages), 0) self.assertFalse(query.specific) def test_timeout_below100(self): @@ -68,9 +68,9 @@ class TestQuery(SearxTestCase): query = RawTextQuery(query_text, []) query.parse_query() - self.assertEquals(query.getFullQuery(), query_text) - self.assertEquals(len(query.query_parts), 3) - self.assertEquals(query.timeout_limit, 3) + self.assertEqual(query.getFullQuery(), query_text) + self.assertEqual(len(query.query_parts), 3) + self.assertEqual(query.timeout_limit, 3) self.assertFalse(query.specific) def test_timeout_above100(self): @@ -78,9 +78,9 @@ class TestQuery(SearxTestCase): query = RawTextQuery(query_text, []) query.parse_query() - self.assertEquals(query.getFullQuery(), query_text) - self.assertEquals(len(query.query_parts), 3) - self.assertEquals(query.timeout_limit, 0.35) + self.assertEqual(query.getFullQuery(), query_text) + self.assertEqual(len(query.query_parts), 3) + self.assertEqual(query.timeout_limit, 0.35) self.assertFalse(query.specific) def test_timeout_above1000(self): @@ -88,9 +88,9 @@ class TestQuery(SearxTestCase): query = RawTextQuery(query_text, []) query.parse_query() - self.assertEquals(query.getFullQuery(), query_text) - self.assertEquals(len(query.query_parts), 3) - self.assertEquals(query.timeout_limit, 3.5) + self.assertEqual(query.getFullQuery(), query_text) + self.assertEqual(len(query.query_parts), 3) + self.assertEqual(query.timeout_limit, 3.5) self.assertFalse(query.specific) def test_timeout_invalid(self): @@ -99,8 +99,8 @@ class TestQuery(SearxTestCase): query = RawTextQuery(query_text, []) query.parse_query() - self.assertEquals(query.getFullQuery(), query_text) - self.assertEquals(len(query.query_parts), 1) - self.assertEquals(query.query_parts[0], query_text) - self.assertEquals(query.timeout_limit, None) + self.assertEqual(query.getFullQuery(), query_text) + self.assertEqual(len(query.query_parts), 1) + self.assertEqual(query.query_parts[0], query_text) + self.assertEqual(query.timeout_limit, None) self.assertFalse(query.specific) diff --git a/tests/unit/test_search.py b/tests/unit/test_search.py index ca9fe862a..a15d2c899 100644 --- a/tests/unit/test_search.py +++ b/tests/unit/test_search.py @@ -45,7 +45,7 @@ class SearchTestCase(SearxTestCase): preferences=Preferences(['oscar'], ['general'], engines, [])) search = searx.search.Search(search_query) search.search() - self.assertEquals(search.actual_timeout, 3.0) + self.assertEqual(search.actual_timeout, 3.0) def test_timeout_query_above_default_nomax(self): searx.search.max_request_timeout = None @@ -54,7 +54,7 @@ class SearchTestCase(SearxTestCase): preferences=Preferences(['oscar'], ['general'], engines, [])) search = searx.search.Search(search_query) search.search() - self.assertEquals(search.actual_timeout, 3.0) + self.assertEqual(search.actual_timeout, 3.0) def test_timeout_query_below_default_nomax(self): searx.search.max_request_timeout = None @@ -63,7 +63,7 @@ class SearchTestCase(SearxTestCase): preferences=Preferences(['oscar'], ['general'], engines, [])) search = searx.search.Search(search_query) search.search() - self.assertEquals(search.actual_timeout, 1.0) + self.assertEqual(search.actual_timeout, 1.0) def test_timeout_query_below_max(self): searx.search.max_request_timeout = 10.0 @@ -72,7 +72,7 @@ class SearchTestCase(SearxTestCase): preferences=Preferences(['oscar'], ['general'], engines, [])) search = searx.search.Search(search_query) search.search() - self.assertEquals(search.actual_timeout, 5.0) + self.assertEqual(search.actual_timeout, 5.0) def test_timeout_query_above_max(self): searx.search.max_request_timeout = 10.0 @@ -81,7 +81,7 @@ class SearchTestCase(SearxTestCase): preferences=Preferences(['oscar'], ['general'], engines, [])) search = searx.search.Search(search_query) search.search() - self.assertEquals(search.actual_timeout, 10.0) + self.assertEqual(search.actual_timeout, 10.0) def test_query_private_engine_without_token(self): search_query = searx.query.SearchQuery('test', [{'category': 'general', 'name': PRIVATE_ENGINE_NAME}], @@ -89,7 +89,7 @@ class SearchTestCase(SearxTestCase): preferences=Preferences(['oscar'], ['general'], engines, [])) search = searx.search.Search(search_query) results = search.search() - self.assertEquals(results.results_length(), 0) + self.assertEqual(results.results_length(), 0) def test_query_private_engine_with_incorrect_token(self): preferences_with_tokens = Preferences(['oscar'], ['general'], engines, []) @@ -99,7 +99,7 @@ class SearchTestCase(SearxTestCase): preferences=preferences_with_tokens) search = searx.search.Search(search_query) results = search.search() - self.assertEquals(results.results_length(), 0) + self.assertEqual(results.results_length(), 0) def test_query_private_engine_with_correct_token(self): preferences_with_tokens = Preferences(['oscar'], ['general'], engines, []) @@ -109,7 +109,7 @@ class SearchTestCase(SearxTestCase): preferences=preferences_with_tokens) search = searx.search.Search(search_query) results = search.search() - self.assertEquals(results.results_length(), 1) + self.assertEqual(results.results_length(), 1) def test_external_bang(self): search_query = searx.query.SearchQuery('yes yes', diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py index b09b9d414..5f98511c3 100644 --- a/tests/unit/test_utils.py +++ b/tests/unit/test_utils.py @@ -1,12 +1,8 @@ # -*- coding: utf-8 -*- import mock -import sys from searx.testing import SearxTestCase from searx import utils -if sys.version_info[0] == 3: - unicode = str - class TestUtils(SearxTestCase): @@ -34,9 +30,9 @@ class TestUtils(SearxTestCase): self.assertEqual(utils.highlight_content(content, None), content) content = 'a' - query = b'test' + query = 'test' self.assertEqual(utils.highlight_content(content, query), content) - query = b'a test' + query = 'a test' self.assertEqual(utils.highlight_content(content, query), content) def test_html_to_text(self): @@ -52,15 +48,15 @@ class TestUtils(SearxTestCase): </span> </a> """ - self.assertIsInstance(utils.html_to_text(html), unicode) + self.assertIsInstance(utils.html_to_text(html), str) self.assertIsNotNone(utils.html_to_text(html)) self.assertEqual(utils.html_to_text(html), "Test text") def test_prettify_url(self): data = (('https://searx.me/', 'https://searx.me/'), - (u'https://searx.me/ű', u'https://searx.me/ű'), + ('https://searx.me/ű', 'https://searx.me/ű'), ('https://searx.me/' + (100 * 'a'), 'https://searx.me/[...]aaaaaaaaaaaaaaaaa'), - (u'https://searx.me/' + (100 * u'ű'), u'https://searx.me/[...]űűűűűűűűűűűűűűűűű')) + ('https://searx.me/' + (100 * 'ű'), 'https://searx.me/[...]űűűűűűűűűűűűűűűűű')) for test_url, expected in data: self.assertEqual(utils.prettify_url(test_url, max_length=32), expected) @@ -108,12 +104,12 @@ class TestHTMLTextExtractor(SearxTestCase): def test_handle_charref(self): self.html_text_extractor.handle_charref('xF') - self.assertIn(u'\x0f', self.html_text_extractor.result) + self.assertIn('\x0f', self.html_text_extractor.result) self.html_text_extractor.handle_charref('XF') - self.assertIn(u'\x0f', self.html_text_extractor.result) + self.assertIn('\x0f', self.html_text_extractor.result) self.html_text_extractor.handle_charref('97') - self.assertIn(u'a', self.html_text_extractor.result) + self.assertIn('a', self.html_text_extractor.result) def test_handle_entityref(self): entity = 'test' diff --git a/tests/unit/test_webapp.py b/tests/unit/test_webapp.py index 8eed607e3..7dd465898 100644 --- a/tests/unit/test_webapp.py +++ b/tests/unit/test_webapp.py @@ -1,11 +1,11 @@ # -*- coding: utf-8 -*- import json +from urllib.parse import ParseResult from mock import Mock from searx import webapp from searx.testing import SearxTestCase from searx.search import Search -from searx.url_utils import ParseResult class ViewsTestCase(SearxTestCase): @@ -89,7 +89,7 @@ class ViewsTestCase(SearxTestCase): def test_index_json(self): result = self.app.post('/', data={'q': 'test', 'format': 'json'}) - result_dict = json.loads(result.data.decode('utf-8')) + result_dict = json.loads(result.data.decode()) self.assertEqual('test', result_dict['query']) self.assertEqual(len(result_dict['results']), 2) |