mirror of
https://github.com/searxng/searxng.git
synced 2025-12-22 19:50:00 +00:00
[format.python] initial formatting of the python code
This patch was generated by black [1]::
make format.python
[1] https://github.com/psf/black
Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
This commit is contained in:
@@ -50,5 +50,6 @@ class SearxTestCase(aiounittest.AsyncTestCase):
|
||||
|
||||
def cleanup_patch():
|
||||
setattr(obj, attr, previous_value)
|
||||
|
||||
self.addCleanup(cleanup_patch)
|
||||
setattr(obj, attr, value)
|
||||
|
||||
@@ -16,7 +16,7 @@ import tests as searx_tests
|
||||
from tests.robot import test_webapp
|
||||
|
||||
|
||||
class SearxRobotLayer():
|
||||
class SearxRobotLayer:
|
||||
"""Searx Robot Test Layer"""
|
||||
|
||||
def setUp(self):
|
||||
@@ -42,9 +42,7 @@ class SearxRobotLayer():
|
||||
|
||||
# run the server
|
||||
self.server = subprocess.Popen( # pylint: disable=consider-using-with
|
||||
[exe, webapp],
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT
|
||||
[exe, webapp], stdout=subprocess.PIPE, stderr=subprocess.STDOUT
|
||||
)
|
||||
if hasattr(self.server.stdout, 'read1'):
|
||||
print(self.server.stdout.read1(1024).decode())
|
||||
|
||||
@@ -2,5 +2,4 @@ import os
|
||||
from os.path import dirname, sep, abspath
|
||||
|
||||
# In unit tests the user settings from unit/settings/test_settings.yml are used.
|
||||
os.environ['SEARXNG_SETTINGS_PATH'] = abspath(
|
||||
dirname(__file__) + sep + 'settings' + sep + 'test_settings.yml')
|
||||
os.environ['SEARXNG_SETTINGS_PATH'] = abspath(dirname(__file__) + sep + 'settings' + sep + 'test_settings.yml')
|
||||
|
||||
@@ -114,7 +114,6 @@ INFO:werkzeug: * Debugger PIN: 299-578-362'''
|
||||
'template': 'key-value.html',
|
||||
'level': 'DEBUG',
|
||||
},
|
||||
|
||||
],
|
||||
[
|
||||
{
|
||||
@@ -136,7 +135,6 @@ INFO:werkzeug: * Debugger PIN: 299-578-362'''
|
||||
'level': 'INFO',
|
||||
},
|
||||
],
|
||||
|
||||
]
|
||||
|
||||
for i in [0, 1]:
|
||||
@@ -171,7 +169,7 @@ commit '''
|
||||
'commit': '\w{40}',
|
||||
'author': '[\w* ]* <\w*@?\w*\.?\w*>',
|
||||
'date': 'Date: .*',
|
||||
'message': '\n\n.*$'
|
||||
'message': '\n\n.*$',
|
||||
}
|
||||
expected_results = [
|
||||
{
|
||||
@@ -195,7 +193,6 @@ commit '''
|
||||
'message': '\n\nthird interesting message',
|
||||
'template': 'key-value.html',
|
||||
},
|
||||
|
||||
]
|
||||
|
||||
results = git_log_engine.search(''.encode('utf-8'), {'pageno': 1})
|
||||
|
||||
@@ -6,7 +6,6 @@ from tests import SearxTestCase
|
||||
|
||||
|
||||
class TestXpathEngine(SearxTestCase):
|
||||
|
||||
def test_request(self):
|
||||
xpath.search_url = 'https://url.com/{query}'
|
||||
xpath.categories = []
|
||||
|
||||
@@ -9,7 +9,6 @@ from tests import SearxTestCase
|
||||
|
||||
|
||||
class TestNetwork(SearxTestCase):
|
||||
|
||||
def setUp(self):
|
||||
initialize()
|
||||
|
||||
@@ -51,23 +50,23 @@ class TestNetwork(SearxTestCase):
|
||||
network = Network(proxies='http://localhost:1337')
|
||||
self.assertEqual(next(network._proxies_cycle), (('all://', 'http://localhost:1337'),))
|
||||
|
||||
network = Network(proxies={
|
||||
'https': 'http://localhost:1337',
|
||||
'http': 'http://localhost:1338'
|
||||
})
|
||||
self.assertEqual(next(network._proxies_cycle),
|
||||
(('https://', 'http://localhost:1337'), ('http://', 'http://localhost:1338')))
|
||||
self.assertEqual(next(network._proxies_cycle),
|
||||
(('https://', 'http://localhost:1337'), ('http://', 'http://localhost:1338')))
|
||||
network = Network(proxies={'https': 'http://localhost:1337', 'http': 'http://localhost:1338'})
|
||||
self.assertEqual(
|
||||
next(network._proxies_cycle), (('https://', 'http://localhost:1337'), ('http://', 'http://localhost:1338'))
|
||||
)
|
||||
self.assertEqual(
|
||||
next(network._proxies_cycle), (('https://', 'http://localhost:1337'), ('http://', 'http://localhost:1338'))
|
||||
)
|
||||
|
||||
network = Network(proxies={
|
||||
'https': ['http://localhost:1337', 'http://localhost:1339'],
|
||||
'http': 'http://localhost:1338'
|
||||
})
|
||||
self.assertEqual(next(network._proxies_cycle),
|
||||
(('https://', 'http://localhost:1337'), ('http://', 'http://localhost:1338')))
|
||||
self.assertEqual(next(network._proxies_cycle),
|
||||
(('https://', 'http://localhost:1339'), ('http://', 'http://localhost:1338')))
|
||||
network = Network(
|
||||
proxies={'https': ['http://localhost:1337', 'http://localhost:1339'], 'http': 'http://localhost:1338'}
|
||||
)
|
||||
self.assertEqual(
|
||||
next(network._proxies_cycle), (('https://', 'http://localhost:1337'), ('http://', 'http://localhost:1338'))
|
||||
)
|
||||
self.assertEqual(
|
||||
next(network._proxies_cycle), (('https://', 'http://localhost:1339'), ('http://', 'http://localhost:1338'))
|
||||
)
|
||||
|
||||
with self.assertRaises(ValueError):
|
||||
Network(proxies=1)
|
||||
@@ -134,6 +133,7 @@ class TestNetworkRequestRetries(SearxTestCase):
|
||||
first = False
|
||||
return httpx.Response(status_code=403, text=TestNetworkRequestRetries.TEXT)
|
||||
return httpx.Response(status_code=200, text=TestNetworkRequestRetries.TEXT)
|
||||
|
||||
return get_response
|
||||
|
||||
async def test_retries_ok(self):
|
||||
@@ -206,6 +206,7 @@ class TestNetworkStreamRetries(SearxTestCase):
|
||||
first = False
|
||||
raise httpx.RequestError('fake exception', request=None)
|
||||
return httpx.Response(status_code=200, text=TestNetworkStreamRetries.TEXT)
|
||||
|
||||
return stream
|
||||
|
||||
async def test_retries_ok(self):
|
||||
|
||||
@@ -7,7 +7,6 @@ from tests import SearxTestCase
|
||||
|
||||
|
||||
class AnswererTest(SearxTestCase):
|
||||
|
||||
def test_unicode_input(self):
|
||||
query = Mock()
|
||||
unicode_payload = 'árvíztűrő tükörfúrógép'
|
||||
|
||||
@@ -3,15 +3,16 @@ from tests import SearxTestCase
|
||||
|
||||
|
||||
class TestEnginesInit(SearxTestCase):
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
settings['outgoing']['using_tor_proxy'] = False
|
||||
settings['outgoing']['extra_proxy_timeout'] = 0
|
||||
|
||||
def test_initialize_engines_default(self):
|
||||
engine_list = [{'engine': 'dummy', 'name': 'engine1', 'shortcut': 'e1'},
|
||||
{'engine': 'dummy', 'name': 'engine2', 'shortcut': 'e2'}]
|
||||
engine_list = [
|
||||
{'engine': 'dummy', 'name': 'engine1', 'shortcut': 'e1'},
|
||||
{'engine': 'dummy', 'name': 'engine2', 'shortcut': 'e2'},
|
||||
]
|
||||
|
||||
engines.load_engines(engine_list)
|
||||
self.assertEqual(len(engines.engines), 2)
|
||||
@@ -20,8 +21,10 @@ class TestEnginesInit(SearxTestCase):
|
||||
|
||||
def test_initialize_engines_exclude_onions(self):
|
||||
settings['outgoing']['using_tor_proxy'] = False
|
||||
engine_list = [{'engine': 'dummy', 'name': 'engine1', 'shortcut': 'e1', 'categories': 'general'},
|
||||
{'engine': 'dummy', 'name': 'engine2', 'shortcut': 'e2', 'categories': 'onions'}]
|
||||
engine_list = [
|
||||
{'engine': 'dummy', 'name': 'engine1', 'shortcut': 'e1', 'categories': 'general'},
|
||||
{'engine': 'dummy', 'name': 'engine2', 'shortcut': 'e2', 'categories': 'onions'},
|
||||
]
|
||||
|
||||
engines.load_engines(engine_list)
|
||||
self.assertEqual(len(engines.engines), 1)
|
||||
@@ -31,9 +34,17 @@ class TestEnginesInit(SearxTestCase):
|
||||
def test_initialize_engines_include_onions(self):
|
||||
settings['outgoing']['using_tor_proxy'] = True
|
||||
settings['outgoing']['extra_proxy_timeout'] = 100.0
|
||||
engine_list = [{'engine': 'dummy', 'name': 'engine1', 'shortcut': 'e1', 'categories': 'general',
|
||||
'timeout': 20.0, 'onion_url': 'http://engine1.onion'},
|
||||
{'engine': 'dummy', 'name': 'engine2', 'shortcut': 'e2', 'categories': 'onions'}]
|
||||
engine_list = [
|
||||
{
|
||||
'engine': 'dummy',
|
||||
'name': 'engine1',
|
||||
'shortcut': 'e1',
|
||||
'categories': 'general',
|
||||
'timeout': 20.0,
|
||||
'onion_url': 'http://engine1.onion',
|
||||
},
|
||||
{'engine': 'dummy', 'name': 'engine2', 'shortcut': 'e2', 'categories': 'onions'},
|
||||
]
|
||||
|
||||
engines.load_engines(engine_list)
|
||||
self.assertEqual(len(engines.engines), 2)
|
||||
|
||||
@@ -18,9 +18,9 @@ TEST_DB = {
|
||||
's': {
|
||||
'on': 'season' + chr(2) + chr(1) + '0',
|
||||
'capes': 'seascape' + chr(2) + chr(1) + '0',
|
||||
}
|
||||
},
|
||||
},
|
||||
'error': ['error in external_bangs.json']
|
||||
'error': ['error in external_bangs.json'],
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +57,6 @@ class TestGetNode(SearxTestCase):
|
||||
|
||||
|
||||
class TestResolveBangDefinition(SearxTestCase):
|
||||
|
||||
def test_https(self):
|
||||
url, rank = resolve_bang_definition('//example.com/' + chr(2) + chr(1) + '42', 'query')
|
||||
self.assertEqual(url, 'https://example.com/query')
|
||||
@@ -70,7 +69,6 @@ class TestResolveBangDefinition(SearxTestCase):
|
||||
|
||||
|
||||
class TestGetBangDefinitionAndAutocomplete(SearxTestCase):
|
||||
|
||||
def test_found(self):
|
||||
bang_definition, new_autocomplete = get_bang_definition_and_autocomplete('exam', external_bangs_db=TEST_DB)
|
||||
self.assertEqual(bang_definition, TEST_DB['trie']['exam']['*'])
|
||||
@@ -103,7 +101,6 @@ class TestGetBangDefinitionAndAutocomplete(SearxTestCase):
|
||||
|
||||
|
||||
class TestExternalBangJson(SearxTestCase):
|
||||
|
||||
def test_no_external_bang_query(self):
|
||||
result = get_bang_url(SearchQuery('test', engineref_list=[EngineRef('wikipedia', 'general')]))
|
||||
self.assertEqual(result, None)
|
||||
|
||||
@@ -6,18 +6,16 @@ from tests import SearxTestCase
|
||||
|
||||
|
||||
def get_search_mock(query, **kwargs):
|
||||
return Mock(search_query=Mock(query=query, **kwargs),
|
||||
result_container=Mock(answers=dict()))
|
||||
return Mock(search_query=Mock(query=query, **kwargs), result_container=Mock(answers=dict()))
|
||||
|
||||
|
||||
class PluginMock():
|
||||
class PluginMock:
|
||||
default_on = False
|
||||
name = 'Default plugin'
|
||||
description = 'Default plugin description'
|
||||
|
||||
|
||||
class PluginStoreTest(SearxTestCase):
|
||||
|
||||
def test_PluginStore_init(self):
|
||||
store = plugins.PluginStore()
|
||||
self.assertTrue(isinstance(store.plugins, list) and len(store.plugins) == 0)
|
||||
@@ -44,7 +42,6 @@ class PluginStoreTest(SearxTestCase):
|
||||
|
||||
|
||||
class SelfIPTest(SearxTestCase):
|
||||
|
||||
def test_PluginStore_init(self):
|
||||
plugin = plugins.load_and_initialize_plugin('searx.plugins.self_info', False, (None, {}))
|
||||
store = plugins.PluginStore()
|
||||
@@ -93,7 +90,6 @@ class SelfIPTest(SearxTestCase):
|
||||
|
||||
|
||||
class HashPluginTest(SearxTestCase):
|
||||
|
||||
def test_PluginStore_init(self):
|
||||
store = plugins.PluginStore()
|
||||
plugin = plugins.load_and_initialize_plugin('searx.plugins.hash_plugin', False, (None, {}))
|
||||
@@ -107,8 +103,9 @@ class HashPluginTest(SearxTestCase):
|
||||
# MD5
|
||||
search = get_search_mock(query='md5 test', pageno=1)
|
||||
store.call(store.plugins, 'post_search', request, search)
|
||||
self.assertTrue('md5 hash digest: 098f6bcd4621d373cade4e832627b4f6'
|
||||
in search.result_container.answers['hash']['answer'])
|
||||
self.assertTrue(
|
||||
'md5 hash digest: 098f6bcd4621d373cade4e832627b4f6' in search.result_container.answers['hash']['answer']
|
||||
)
|
||||
|
||||
search = get_search_mock(query=b'md5 test', pageno=2)
|
||||
store.call(store.plugins, 'post_search', request, search)
|
||||
@@ -117,31 +114,41 @@ class HashPluginTest(SearxTestCase):
|
||||
# SHA1
|
||||
search = get_search_mock(query='sha1 test', pageno=1)
|
||||
store.call(store.plugins, 'post_search', request, search)
|
||||
self.assertTrue('sha1 hash digest: a94a8fe5ccb19ba61c4c0873d391e9879'
|
||||
'82fbbd3' in search.result_container.answers['hash']['answer'])
|
||||
self.assertTrue(
|
||||
'sha1 hash digest: a94a8fe5ccb19ba61c4c0873d391e9879'
|
||||
'82fbbd3' in search.result_container.answers['hash']['answer']
|
||||
)
|
||||
|
||||
# SHA224
|
||||
search = get_search_mock(query='sha224 test', pageno=1)
|
||||
store.call(store.plugins, 'post_search', request, search)
|
||||
self.assertTrue('sha224 hash digest: 90a3ed9e32b2aaf4c61c410eb9254261'
|
||||
'19e1a9dc53d4286ade99a809' in search.result_container.answers['hash']['answer'])
|
||||
self.assertTrue(
|
||||
'sha224 hash digest: 90a3ed9e32b2aaf4c61c410eb9254261'
|
||||
'19e1a9dc53d4286ade99a809' in search.result_container.answers['hash']['answer']
|
||||
)
|
||||
|
||||
# SHA256
|
||||
search = get_search_mock(query='sha256 test', pageno=1)
|
||||
store.call(store.plugins, 'post_search', request, search)
|
||||
self.assertTrue('sha256 hash digest: 9f86d081884c7d659a2feaa0c55ad015a'
|
||||
'3bf4f1b2b0b822cd15d6c15b0f00a08' in search.result_container.answers['hash']['answer'])
|
||||
self.assertTrue(
|
||||
'sha256 hash digest: 9f86d081884c7d659a2feaa0c55ad015a'
|
||||
'3bf4f1b2b0b822cd15d6c15b0f00a08' in search.result_container.answers['hash']['answer']
|
||||
)
|
||||
|
||||
# SHA384
|
||||
search = get_search_mock(query='sha384 test', pageno=1)
|
||||
store.call(store.plugins, 'post_search', request, search)
|
||||
self.assertTrue('sha384 hash digest: 768412320f7b0aa5812fce428dc4706b3c'
|
||||
'ae50e02a64caa16a782249bfe8efc4b7ef1ccb126255d196047dfedf1'
|
||||
'7a0a9' in search.result_container.answers['hash']['answer'])
|
||||
self.assertTrue(
|
||||
'sha384 hash digest: 768412320f7b0aa5812fce428dc4706b3c'
|
||||
'ae50e02a64caa16a782249bfe8efc4b7ef1ccb126255d196047dfedf1'
|
||||
'7a0a9' in search.result_container.answers['hash']['answer']
|
||||
)
|
||||
|
||||
# SHA512
|
||||
search = get_search_mock(query='sha512 test', pageno=1)
|
||||
store.call(store.plugins, 'post_search', request, search)
|
||||
self.assertTrue('sha512 hash digest: ee26b0dd4af7e749aa1a8ee3c10ae9923f6'
|
||||
'18980772e473f8819a5d4940e0db27ac185f8a0e1d5f84f88bc887fd67b143732c304cc5'
|
||||
'fa9ad8e6f57f50028a8ff' in search.result_container.answers['hash']['answer'])
|
||||
self.assertTrue(
|
||||
'sha512 hash digest: ee26b0dd4af7e749aa1a8ee3c10ae9923f6'
|
||||
'18980772e473f8819a5d4940e0db27ac185f8a0e1d5f84f88bc887fd67b143732c304cc5'
|
||||
'fa9ad8e6f57f50028a8ff' in search.result_container.answers['hash']['answer']
|
||||
)
|
||||
|
||||
@@ -1,10 +1,16 @@
|
||||
from searx.preferences import (EnumStringSetting, MapSetting, MissingArgumentException, SearchLanguageSetting,
|
||||
MultipleChoiceSetting, PluginsSetting, ValidationException)
|
||||
from searx.preferences import (
|
||||
EnumStringSetting,
|
||||
MapSetting,
|
||||
MissingArgumentException,
|
||||
SearchLanguageSetting,
|
||||
MultipleChoiceSetting,
|
||||
PluginsSetting,
|
||||
ValidationException,
|
||||
)
|
||||
from tests import SearxTestCase
|
||||
|
||||
|
||||
class PluginStub:
|
||||
|
||||
def __init__(self, plugin_id, default_on):
|
||||
self.id = plugin_id
|
||||
self.default_on = default_on
|
||||
@@ -121,20 +127,23 @@ class TestSettings(SearxTestCase):
|
||||
|
||||
|
||||
class TestPreferences(SearxTestCase):
|
||||
|
||||
def test_encode(self):
|
||||
from searx.preferences import Preferences
|
||||
|
||||
pref = Preferences(['oscar'], ['general'], {}, [])
|
||||
url_params = 'eJx1VMmO2zAM_Zr6YrTocujJh6JF0QEKzKAz7VVgJNohLIseUU7ivy-VcWy5yyGOTVGP73GLKJNPYjiYgGeT4NB8BS9YOSY' \
|
||||
'TUdifMDYM-vmGY1d5CN0EHTYOK88W_PXNkcDBozOjnzoK0vyi4bWnHs2RU4-zvHr_-RF9a-5Cy3GARByy7X7EkKMoBeMp9CuPQ-SzYMx' \
|
||||
'8Vr9P1qKI-XJ_p1fOkRJWNCgVM0a-zAttmBJbHkaPSZlNts-_jiuBFgUh2mPztkpHHLBhsRArDHvm356eHh5vATS0Mqagr0ZsZO_V8hT' \
|
||||
'B9srt54_v6jewJugqL4Nn_hYSdhxnI-jRpi05GDQCStOT7UGVmJY8ZnltRKyF23SGiLWjqNcygKGkpyeGZIywJfD1gI5AjRTAmBM55Aw' \
|
||||
'Q0Tn626lj7jzWo4e5hnEsIlprX6dTgdBRpyRBFKTDgBF8AasVyT4gvSTEoXRpXWRyG3CYQYld65I_V6lboILTMAlZY65_ejRDcHgp0Tv' \
|
||||
'EPtGAsqTiBf3m76g7pP9B84mwjPvuUtASRDei1nDF2ix_JXW91UJkXrPh6RAhznVmKyQl7dwJdMJ6bz1QOmgzYlrEzHDMcEUuo44AgS1' \
|
||||
'CvkjaOb2Q2AyY5oGDTs_OLXE_c2I5cg9hk3kEJZ0fu4SuktsIA2RhuJwP86AdripThCBeO9uVUejyPGmFSxPrqEYcuWi25zOEXV9tc1m' \
|
||||
'_KP1nafYtdfv6Q9hKfWmGm9A_3G635UwiVndLGdFCiLWkONk0xUxGLGGweGWTa2nZYZ0fS1YKlE3Uuw8fPl52E5U8HJYbC7sbjXUsrnT' \
|
||||
url_params = (
|
||||
'eJx1VMmO2zAM_Zr6YrTocujJh6JF0QEKzKAz7VVgJNohLIseUU7ivy-VcWy5yyGOTVGP73GLKJNPYjiYgGeT4NB8BS9YOSY'
|
||||
'TUdifMDYM-vmGY1d5CN0EHTYOK88W_PXNkcDBozOjnzoK0vyi4bWnHs2RU4-zvHr_-RF9a-5Cy3GARByy7X7EkKMoBeMp9CuPQ-SzYMx'
|
||||
'8Vr9P1qKI-XJ_p1fOkRJWNCgVM0a-zAttmBJbHkaPSZlNts-_jiuBFgUh2mPztkpHHLBhsRArDHvm356eHh5vATS0Mqagr0ZsZO_V8hT'
|
||||
'B9srt54_v6jewJugqL4Nn_hYSdhxnI-jRpi05GDQCStOT7UGVmJY8ZnltRKyF23SGiLWjqNcygKGkpyeGZIywJfD1gI5AjRTAmBM55Aw'
|
||||
'Q0Tn626lj7jzWo4e5hnEsIlprX6dTgdBRpyRBFKTDgBF8AasVyT4gvSTEoXRpXWRyG3CYQYld65I_V6lboILTMAlZY65_ejRDcHgp0Tv'
|
||||
'EPtGAsqTiBf3m76g7pP9B84mwjPvuUtASRDei1nDF2ix_JXW91UJkXrPh6RAhznVmKyQl7dwJdMJ6bz1QOmgzYlrEzHDMcEUuo44AgS1'
|
||||
'CvkjaOb2Q2AyY5oGDTs_OLXE_c2I5cg9hk3kEJZ0fu4SuktsIA2RhuJwP86AdripThCBeO9uVUejyPGmFSxPrqEYcuWi25zOEXV9tc1m'
|
||||
'_KP1nafYtdfv6Q9hKfWmGm9A_3G635UwiVndLGdFCiLWkONk0xUxGLGGweGWTa2nZYZ0fS1YKlE3Uuw8fPl52E5U8HJYbC7sbjXUsrnT'
|
||||
'XHXRbELfO-1fGSqskiGnMK7B0dV3t8Lq08pbdtYpuVdoKWA2Yjuyah_vHp2rZWjo0zXL8Gw8DTj0='
|
||||
)
|
||||
pref.parse_encoded_data(url_params)
|
||||
self.assertEqual(
|
||||
vars(pref.key_value_settings['categories']),
|
||||
{'value': ['general'], 'locked': False, 'choices': ['general', 'none']})
|
||||
{'value': ['general'], 'locked': False, 'choices': ['general', 'none']},
|
||||
)
|
||||
|
||||
@@ -17,7 +17,6 @@ TEST_ENGINES = [
|
||||
|
||||
|
||||
class TestQuery(SearxTestCase):
|
||||
|
||||
def test_simple_query(self):
|
||||
query_text = 'the query'
|
||||
query = RawTextQuery(query_text, [])
|
||||
@@ -58,7 +57,6 @@ class TestQuery(SearxTestCase):
|
||||
|
||||
|
||||
class TestLanguageParser(SearxTestCase):
|
||||
|
||||
def test_language_code(self):
|
||||
language = 'es-ES'
|
||||
query_text = 'the query'
|
||||
@@ -136,7 +134,6 @@ class TestLanguageParser(SearxTestCase):
|
||||
|
||||
|
||||
class TestTimeoutParser(SearxTestCase):
|
||||
|
||||
def test_timeout_below100(self):
|
||||
query_text = '<3 the query'
|
||||
query = RawTextQuery(query_text, [])
|
||||
@@ -189,7 +186,6 @@ class TestTimeoutParser(SearxTestCase):
|
||||
|
||||
|
||||
class TestExternalBangParser(SearxTestCase):
|
||||
|
||||
def test_external_bang(self):
|
||||
query_text = '!!ddg the query'
|
||||
query = RawTextQuery(query_text, [])
|
||||
|
||||
@@ -4,10 +4,7 @@ from searx.results import ResultContainer
|
||||
from tests import SearxTestCase
|
||||
|
||||
|
||||
def fake_result(url='https://aa.bb/cc?dd=ee#ff',
|
||||
title='aaa',
|
||||
content='bbb',
|
||||
engine='wikipedia', **kwargs):
|
||||
def fake_result(url='https://aa.bb/cc?dd=ee#ff', title='aaa', content='bbb', engine='wikipedia', **kwargs):
|
||||
result = {
|
||||
# fmt: off
|
||||
'url': url,
|
||||
@@ -22,7 +19,6 @@ def fake_result(url='https://aa.bb/cc?dd=ee#ff',
|
||||
|
||||
# TODO
|
||||
class ResultContainerTestCase(SearxTestCase):
|
||||
|
||||
def test_empty(self):
|
||||
c = ResultContainer()
|
||||
self.assertEqual(c.get_ordered_results(), [])
|
||||
|
||||
@@ -22,11 +22,11 @@ TEST_ENGINES = [
|
||||
|
||||
|
||||
class SearchQueryTestCase(SearxTestCase):
|
||||
|
||||
def test_repr(self):
|
||||
s = SearchQuery('test', [EngineRef('bing', 'general')], 'all', 0, 1, '1', 5.0, 'g')
|
||||
self.assertEqual(repr(s),
|
||||
"SearchQuery('test', [EngineRef('bing', 'general')], 'all', 0, 1, '1', 5.0, 'g')") # noqa
|
||||
self.assertEqual(
|
||||
repr(s), "SearchQuery('test', [EngineRef('bing', 'general')], 'all', 0, 1, '1', 5.0, 'g')"
|
||||
) # noqa
|
||||
|
||||
def test_eq(self):
|
||||
s = SearchQuery('test', [EngineRef('bing', 'general')], 'all', 0, 1, None, None, None)
|
||||
@@ -36,64 +36,80 @@ class SearchQueryTestCase(SearxTestCase):
|
||||
|
||||
|
||||
class SearchTestCase(SearxTestCase):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
searx.search.initialize(TEST_ENGINES)
|
||||
|
||||
def test_timeout_simple(self):
|
||||
settings['outgoing']['max_request_timeout'] = None
|
||||
search_query = SearchQuery('test', [EngineRef(PUBLIC_ENGINE_NAME, 'general')],
|
||||
'en-US', SAFESEARCH, PAGENO, None, None)
|
||||
search_query = SearchQuery(
|
||||
'test', [EngineRef(PUBLIC_ENGINE_NAME, 'general')], 'en-US', SAFESEARCH, PAGENO, None, None
|
||||
)
|
||||
search = searx.search.Search(search_query)
|
||||
search.search()
|
||||
self.assertEqual(search.actual_timeout, 3.0)
|
||||
|
||||
def test_timeout_query_above_default_nomax(self):
|
||||
settings['outgoing']['max_request_timeout'] = None
|
||||
search_query = SearchQuery('test', [EngineRef(PUBLIC_ENGINE_NAME, 'general')],
|
||||
'en-US', SAFESEARCH, PAGENO, None, 5.0)
|
||||
search_query = SearchQuery(
|
||||
'test', [EngineRef(PUBLIC_ENGINE_NAME, 'general')], 'en-US', SAFESEARCH, PAGENO, None, 5.0
|
||||
)
|
||||
search = searx.search.Search(search_query)
|
||||
search.search()
|
||||
self.assertEqual(search.actual_timeout, 3.0)
|
||||
|
||||
def test_timeout_query_below_default_nomax(self):
|
||||
settings['outgoing']['max_request_timeout'] = None
|
||||
search_query = SearchQuery('test', [EngineRef(PUBLIC_ENGINE_NAME, 'general')],
|
||||
'en-US', SAFESEARCH, PAGENO, None, 1.0)
|
||||
search_query = SearchQuery(
|
||||
'test', [EngineRef(PUBLIC_ENGINE_NAME, 'general')], 'en-US', SAFESEARCH, PAGENO, None, 1.0
|
||||
)
|
||||
search = searx.search.Search(search_query)
|
||||
search.search()
|
||||
self.assertEqual(search.actual_timeout, 1.0)
|
||||
|
||||
def test_timeout_query_below_max(self):
|
||||
settings['outgoing']['max_request_timeout'] = 10.0
|
||||
search_query = SearchQuery('test', [EngineRef(PUBLIC_ENGINE_NAME, 'general')],
|
||||
'en-US', SAFESEARCH, PAGENO, None, 5.0)
|
||||
search_query = SearchQuery(
|
||||
'test', [EngineRef(PUBLIC_ENGINE_NAME, 'general')], 'en-US', SAFESEARCH, PAGENO, None, 5.0
|
||||
)
|
||||
search = searx.search.Search(search_query)
|
||||
search.search()
|
||||
self.assertEqual(search.actual_timeout, 5.0)
|
||||
|
||||
def test_timeout_query_above_max(self):
|
||||
settings['outgoing']['max_request_timeout'] = 10.0
|
||||
search_query = SearchQuery('test', [EngineRef(PUBLIC_ENGINE_NAME, 'general')],
|
||||
'en-US', SAFESEARCH, PAGENO, None, 15.0)
|
||||
search_query = SearchQuery(
|
||||
'test', [EngineRef(PUBLIC_ENGINE_NAME, 'general')], 'en-US', SAFESEARCH, PAGENO, None, 15.0
|
||||
)
|
||||
search = searx.search.Search(search_query)
|
||||
search.search()
|
||||
self.assertEqual(search.actual_timeout, 10.0)
|
||||
|
||||
def test_external_bang(self):
|
||||
search_query = SearchQuery('yes yes',
|
||||
[EngineRef(PUBLIC_ENGINE_NAME, 'general')],
|
||||
'en-US', SAFESEARCH, PAGENO, None, None,
|
||||
external_bang="yt")
|
||||
search_query = SearchQuery(
|
||||
'yes yes',
|
||||
[EngineRef(PUBLIC_ENGINE_NAME, 'general')],
|
||||
'en-US',
|
||||
SAFESEARCH,
|
||||
PAGENO,
|
||||
None,
|
||||
None,
|
||||
external_bang="yt",
|
||||
)
|
||||
search = searx.search.Search(search_query)
|
||||
results = search.search()
|
||||
# For checking if the user redirected with the youtube external bang
|
||||
self.assertTrue(results.redirect_url is not None)
|
||||
|
||||
search_query = SearchQuery('youtube never gonna give you up',
|
||||
[EngineRef(PUBLIC_ENGINE_NAME, 'general')],
|
||||
'en-US', SAFESEARCH, PAGENO, None, None)
|
||||
search_query = SearchQuery(
|
||||
'youtube never gonna give you up',
|
||||
[EngineRef(PUBLIC_ENGINE_NAME, 'general')],
|
||||
'en-US',
|
||||
SAFESEARCH,
|
||||
PAGENO,
|
||||
None,
|
||||
None,
|
||||
)
|
||||
|
||||
search = searx.search.Search(search_query)
|
||||
results = search.search()
|
||||
|
||||
@@ -12,7 +12,6 @@ test_dir = abspath(dirname(__file__))
|
||||
|
||||
|
||||
class TestLoad(SearxTestCase):
|
||||
|
||||
def test_load_zero(self):
|
||||
with self.assertRaises(SearxSettingsException):
|
||||
settings_loader.load_yaml('/dev/zero')
|
||||
@@ -31,7 +30,6 @@ class TestLoad(SearxTestCase):
|
||||
|
||||
|
||||
class TestDefaultSettings(SearxTestCase):
|
||||
|
||||
def test_load(self):
|
||||
settings, msg = settings_loader.load_settings(load_user_setttings=False)
|
||||
self.assertTrue(msg.startswith('load the default settings from'))
|
||||
@@ -46,7 +44,6 @@ class TestDefaultSettings(SearxTestCase):
|
||||
|
||||
|
||||
class TestUserSettings(SearxTestCase):
|
||||
|
||||
def test_is_use_default_settings(self):
|
||||
self.assertFalse(settings_loader.is_use_default_settings({}))
|
||||
self.assertTrue(settings_loader.is_use_default_settings({'use_default_settings': True}))
|
||||
@@ -57,23 +54,24 @@ class TestUserSettings(SearxTestCase):
|
||||
self.assertFalse(settings_loader.is_use_default_settings({'use_default_settings': 0}))
|
||||
|
||||
def test_user_settings_not_found(self):
|
||||
with patch.dict(settings_loader.environ,
|
||||
{'SEARXNG_SETTINGS_PATH': '/dev/null'}):
|
||||
with patch.dict(settings_loader.environ, {'SEARXNG_SETTINGS_PATH': '/dev/null'}):
|
||||
settings, msg = settings_loader.load_settings()
|
||||
self.assertTrue(msg.startswith('load the default settings from'))
|
||||
self.assertEqual(settings['server']['secret_key'], "ultrasecretkey")
|
||||
|
||||
def test_user_settings(self):
|
||||
with patch.dict(settings_loader.environ,
|
||||
{'SEARXNG_SETTINGS_PATH': join(test_dir, 'settings/user_settings_simple.yml')}):
|
||||
with patch.dict(
|
||||
settings_loader.environ, {'SEARXNG_SETTINGS_PATH': join(test_dir, 'settings/user_settings_simple.yml')}
|
||||
):
|
||||
settings, msg = settings_loader.load_settings()
|
||||
self.assertTrue(msg.startswith('merge the default settings'))
|
||||
self.assertEqual(settings['server']['secret_key'], "user_secret_key")
|
||||
self.assertEqual(settings['server']['default_http_headers']['Custom-Header'], "Custom-Value")
|
||||
|
||||
def test_user_settings_remove(self):
|
||||
with patch.dict(settings_loader.environ,
|
||||
{'SEARXNG_SETTINGS_PATH': join(test_dir, 'settings/user_settings_remove.yml')}):
|
||||
with patch.dict(
|
||||
settings_loader.environ, {'SEARXNG_SETTINGS_PATH': join(test_dir, 'settings/user_settings_remove.yml')}
|
||||
):
|
||||
settings, msg = settings_loader.load_settings()
|
||||
self.assertTrue(msg.startswith('merge the default settings'))
|
||||
self.assertEqual(settings['server']['secret_key'], "user_secret_key")
|
||||
@@ -84,8 +82,9 @@ class TestUserSettings(SearxTestCase):
|
||||
self.assertIn('wikipedia', engine_names)
|
||||
|
||||
def test_user_settings_remove2(self):
|
||||
with patch.dict(settings_loader.environ,
|
||||
{'SEARXNG_SETTINGS_PATH': join(test_dir, 'settings/user_settings_remove2.yml')}):
|
||||
with patch.dict(
|
||||
settings_loader.environ, {'SEARXNG_SETTINGS_PATH': join(test_dir, 'settings/user_settings_remove2.yml')}
|
||||
):
|
||||
settings, msg = settings_loader.load_settings()
|
||||
self.assertTrue(msg.startswith('merge the default settings'))
|
||||
self.assertEqual(settings['server']['secret_key'], "user_secret_key")
|
||||
@@ -101,8 +100,9 @@ class TestUserSettings(SearxTestCase):
|
||||
self.assertEqual(newengine[0]['engine'], 'dummy')
|
||||
|
||||
def test_user_settings_keep_only(self):
|
||||
with patch.dict(settings_loader.environ,
|
||||
{'SEARXNG_SETTINGS_PATH': join(test_dir, 'settings/user_settings_keep_only.yml')}):
|
||||
with patch.dict(
|
||||
settings_loader.environ, {'SEARXNG_SETTINGS_PATH': join(test_dir, 'settings/user_settings_keep_only.yml')}
|
||||
):
|
||||
settings, msg = settings_loader.load_settings()
|
||||
self.assertTrue(msg.startswith('merge the default settings'))
|
||||
engine_names = [engine['name'] for engine in settings['engines']]
|
||||
@@ -111,8 +111,9 @@ class TestUserSettings(SearxTestCase):
|
||||
self.assertEqual(len(settings['engines'][2]), 1)
|
||||
|
||||
def test_custom_settings(self):
|
||||
with patch.dict(settings_loader.environ,
|
||||
{'SEARXNG_SETTINGS_PATH': join(test_dir, 'settings/user_settings.yml')}):
|
||||
with patch.dict(
|
||||
settings_loader.environ, {'SEARXNG_SETTINGS_PATH': join(test_dir, 'settings/user_settings.yml')}
|
||||
):
|
||||
settings, msg = settings_loader.load_settings()
|
||||
self.assertTrue(msg.startswith('load the user settings from'))
|
||||
self.assertEqual(settings['server']['port'], 9000)
|
||||
|
||||
@@ -23,8 +23,7 @@ class StandaloneSearx(SearxTestCase):
|
||||
|
||||
def test_parse_argument_no_args(self):
|
||||
"""Test parse argument without args."""
|
||||
with patch.object(sys, 'argv', ['standalone_searx']), \
|
||||
self.assertRaises(SystemExit):
|
||||
with patch.object(sys, 'argv', ['standalone_searx']), self.assertRaises(SystemExit):
|
||||
sys.stderr = io.StringIO()
|
||||
sas.parse_argument()
|
||||
sys.stdout = sys.__stderr__
|
||||
@@ -33,8 +32,13 @@ class StandaloneSearx(SearxTestCase):
|
||||
"""Test parse argument with basic args."""
|
||||
query = 'red box'
|
||||
exp_dict = {
|
||||
'query': query, 'category': 'general', 'lang': 'all', 'pageno': 1,
|
||||
'safesearch': '0', 'timerange': None}
|
||||
'query': query,
|
||||
'category': 'general',
|
||||
'lang': 'all',
|
||||
'pageno': 1,
|
||||
'safesearch': '0',
|
||||
'timerange': None,
|
||||
}
|
||||
args = ['standalone_searx', query]
|
||||
with patch.object(sys, 'argv', args):
|
||||
res = sas.parse_argument()
|
||||
@@ -45,16 +49,16 @@ class StandaloneSearx(SearxTestCase):
|
||||
def test_to_dict(self):
|
||||
"""test to_dict."""
|
||||
self.assertEqual(
|
||||
sas.to_dict(
|
||||
sas.get_search_query(sas.parse_argument(['red box']))),
|
||||
sas.to_dict(sas.get_search_query(sas.parse_argument(['red box']))),
|
||||
{
|
||||
'search': {
|
||||
'q': 'red box', 'pageno': 1, 'lang': 'all',
|
||||
'safesearch': 0, 'timerange': None
|
||||
},
|
||||
'results': [], 'infoboxes': [], 'suggestions': [],
|
||||
'answers': [], 'paging': False, 'results_number': 0
|
||||
}
|
||||
'search': {'q': 'red box', 'pageno': 1, 'lang': 'all', 'safesearch': 0, 'timerange': None},
|
||||
'results': [],
|
||||
'infoboxes': [],
|
||||
'suggestions': [],
|
||||
'answers': [],
|
||||
'paging': False,
|
||||
'results_number': 0,
|
||||
},
|
||||
)
|
||||
|
||||
def test_to_dict_with_mock(self):
|
||||
@@ -77,30 +81,28 @@ class StandaloneSearx(SearxTestCase):
|
||||
'safesearch': m_sq.safesearch,
|
||||
'timerange': m_sq.time_range,
|
||||
},
|
||||
'suggestions': []
|
||||
}
|
||||
'suggestions': [],
|
||||
},
|
||||
)
|
||||
|
||||
def test_get_search_query(self):
|
||||
"""test get_search_query."""
|
||||
args = sas.parse_argument(['rain', ])
|
||||
args = sas.parse_argument(
|
||||
[
|
||||
'rain',
|
||||
]
|
||||
)
|
||||
search_q = sas.get_search_query(args)
|
||||
self.assertTrue(search_q)
|
||||
self.assertEqual(search_q, SearchQuery('rain', [EngineRef('engine1', 'general')],
|
||||
'all', 0, 1, None, None, None))
|
||||
self.assertEqual(
|
||||
search_q, SearchQuery('rain', [EngineRef('engine1', 'general')], 'all', 0, 1, None, None, None)
|
||||
)
|
||||
|
||||
def test_no_parsed_url(self):
|
||||
"""test no_parsed_url func"""
|
||||
self.assertEqual(
|
||||
sas.no_parsed_url([{'parsed_url': 'http://example.com'}]),
|
||||
[{}]
|
||||
)
|
||||
self.assertEqual(sas.no_parsed_url([{'parsed_url': 'http://example.com'}]), [{}])
|
||||
|
||||
@params(
|
||||
(datetime.datetime(2020, 1, 1), '2020-01-01T00:00:00'),
|
||||
('a'.encode('utf8'), 'a'),
|
||||
(set([1]), [1])
|
||||
)
|
||||
@params((datetime.datetime(2020, 1, 1), '2020-01-01T00:00:00'), ('a'.encode('utf8'), 'a'), (set([1]), [1]))
|
||||
def test_json_serial(self, arg, exp_res):
|
||||
"""test json_serial func"""
|
||||
self.assertEqual(sas.json_serial(arg), exp_res)
|
||||
|
||||
@@ -9,7 +9,6 @@ from tests import SearxTestCase
|
||||
|
||||
|
||||
class TestUtils(SearxTestCase):
|
||||
|
||||
def test_gen_useragent(self):
|
||||
self.assertIsInstance(utils.gen_useragent(), str)
|
||||
self.assertIsNotNone(utils.gen_useragent())
|
||||
@@ -73,6 +72,7 @@ class TestUtils(SearxTestCase):
|
||||
def test_extract_url(self):
|
||||
def f(html_str, search_url):
|
||||
return utils.extract_url(html.fromstring(html_str), search_url)
|
||||
|
||||
self.assertEqual(f('<span id="42">https://example.com</span>', 'http://example.com/'), 'https://example.com/')
|
||||
self.assertEqual(f('https://example.com', 'http://example.com/'), 'https://example.com/')
|
||||
self.assertEqual(f('//example.com', 'http://example.com/'), 'http://example.com/')
|
||||
@@ -122,14 +122,11 @@ class TestUtils(SearxTestCase):
|
||||
|
||||
def test_ecma_unscape(self):
|
||||
self.assertEqual(utils.ecma_unescape('text%20with%20space'), 'text with space')
|
||||
self.assertEqual(utils.ecma_unescape('text using %xx: %F3'),
|
||||
'text using %xx: ó')
|
||||
self.assertEqual(utils.ecma_unescape('text using %u: %u5409, %u4E16%u754c'),
|
||||
'text using %u: 吉, 世界')
|
||||
self.assertEqual(utils.ecma_unescape('text using %xx: %F3'), 'text using %xx: ó')
|
||||
self.assertEqual(utils.ecma_unescape('text using %u: %u5409, %u4E16%u754c'), 'text using %u: 吉, 世界')
|
||||
|
||||
|
||||
class TestHTMLTextExtractor(SearxTestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.html_text_extractor = utils.HTMLTextExtractor()
|
||||
|
||||
|
||||
@@ -25,7 +25,6 @@ SEARCHQUERY = [EngineRef(PRIVATE_ENGINE_NAME, 'general')]
|
||||
|
||||
|
||||
class ValidateQueryCase(SearxTestCase):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
searx.search.initialize(TEST_ENGINES)
|
||||
|
||||
@@ -10,11 +10,11 @@ from tests import SearxTestCase
|
||||
|
||||
|
||||
class ViewsTestCase(SearxTestCase):
|
||||
|
||||
def setUp(self):
|
||||
# skip init function (no external HTTP request)
|
||||
def dummy(*args, **kwargs):
|
||||
pass
|
||||
|
||||
self.setattr4test(searx.search.processors, 'initialize_processor', dummy)
|
||||
|
||||
from searx import webapp # pylint disable=import-outside-toplevel
|
||||
@@ -30,43 +30,39 @@ class ViewsTestCase(SearxTestCase):
|
||||
'url': 'http://first.test.xyz',
|
||||
'engines': ['youtube', 'startpage'],
|
||||
'engine': 'startpage',
|
||||
'parsed_url': ParseResult(scheme='http', netloc='first.test.xyz', path='/', params='', query='', fragment=''), # noqa
|
||||
}, {
|
||||
'parsed_url': ParseResult(
|
||||
scheme='http', netloc='first.test.xyz', path='/', params='', query='', fragment=''
|
||||
), # noqa
|
||||
},
|
||||
{
|
||||
'content': 'second test content',
|
||||
'title': 'Second Test',
|
||||
'url': 'http://second.test.xyz',
|
||||
'engines': ['youtube', 'startpage'],
|
||||
'engine': 'youtube',
|
||||
'parsed_url': ParseResult(scheme='http', netloc='second.test.xyz', path='/', params='', query='', fragment=''), # noqa
|
||||
'parsed_url': ParseResult(
|
||||
scheme='http', netloc='second.test.xyz', path='/', params='', query='', fragment=''
|
||||
), # noqa
|
||||
},
|
||||
]
|
||||
|
||||
timings = [
|
||||
{
|
||||
'engine': 'startpage',
|
||||
'total': 0.8,
|
||||
'load': 0.7
|
||||
},
|
||||
{
|
||||
'engine': 'youtube',
|
||||
'total': 0.9,
|
||||
'load': 0.6
|
||||
}
|
||||
]
|
||||
timings = [{'engine': 'startpage', 'total': 0.8, 'load': 0.7}, {'engine': 'youtube', 'total': 0.9, 'load': 0.6}]
|
||||
|
||||
def search_mock(search_self, *args):
|
||||
search_self.result_container = Mock(get_ordered_results=lambda: test_results,
|
||||
answers=dict(),
|
||||
corrections=set(),
|
||||
suggestions=set(),
|
||||
infoboxes=[],
|
||||
unresponsive_engines=set(),
|
||||
results=test_results,
|
||||
results_number=lambda: 3,
|
||||
results_length=lambda: len(test_results),
|
||||
get_timings=lambda: timings,
|
||||
redirect_url=None,
|
||||
engine_data={})
|
||||
search_self.result_container = Mock(
|
||||
get_ordered_results=lambda: test_results,
|
||||
answers=dict(),
|
||||
corrections=set(),
|
||||
suggestions=set(),
|
||||
infoboxes=[],
|
||||
unresponsive_engines=set(),
|
||||
results=test_results,
|
||||
results_number=lambda: 3,
|
||||
results_length=lambda: len(test_results),
|
||||
get_timings=lambda: timings,
|
||||
redirect_url=None,
|
||||
engine_data={},
|
||||
)
|
||||
|
||||
self.setattr4test(Search, 'search', search_mock)
|
||||
|
||||
@@ -82,9 +78,12 @@ class ViewsTestCase(SearxTestCase):
|
||||
def test_index_empty(self):
|
||||
result = self.app.post('/')
|
||||
self.assertEqual(result.status_code, 200)
|
||||
self.assertIn(b'<div class="text-hide center-block" id="main-logo">'
|
||||
+ b'<img class="center-block img-responsive" src="/static/themes/oscar/img/searxng.svg"'
|
||||
+ b' alt="searx logo" />SearXNG</div>', result.data)
|
||||
self.assertIn(
|
||||
b'<div class="text-hide center-block" id="main-logo">'
|
||||
+ b'<img class="center-block img-responsive" src="/static/themes/oscar/img/searxng.svg"'
|
||||
+ b' alt="searx logo" />SearXNG</div>',
|
||||
result.data,
|
||||
)
|
||||
|
||||
def test_index_html_post(self):
|
||||
result = self.app.post('/', data={'q': 'test'})
|
||||
@@ -120,11 +119,10 @@ class ViewsTestCase(SearxTestCase):
|
||||
b'<h4 class="result_header" id="result-2"><img width="32" height="32" class="favicon"'
|
||||
+ b' src="/static/themes/oscar/img/icons/youtube.png" alt="youtube" /><a href="http://second.test.xyz"'
|
||||
+ b' rel="noreferrer" aria-labelledby="result-2">Second <span class="highlight">Test</span></a></h4>', # noqa
|
||||
result.data
|
||||
result.data,
|
||||
)
|
||||
self.assertIn(
|
||||
b'<p class="result-content">second <span class="highlight">test</span> content</p>', # noqa
|
||||
result.data
|
||||
b'<p class="result-content">second <span class="highlight">test</span> content</p>', result.data # noqa
|
||||
)
|
||||
|
||||
def test_index_json(self):
|
||||
@@ -151,7 +149,7 @@ class ViewsTestCase(SearxTestCase):
|
||||
b'title,url,content,host,engine,score,type\r\n'
|
||||
b'First Test,http://first.test.xyz,first test content,first.test.xyz,startpage,,result\r\n' # noqa
|
||||
b'Second Test,http://second.test.xyz,second test content,second.test.xyz,youtube,,result\r\n', # noqa
|
||||
result.data
|
||||
result.data,
|
||||
)
|
||||
|
||||
def test_index_rss(self):
|
||||
@@ -161,30 +159,15 @@ class ViewsTestCase(SearxTestCase):
|
||||
def test_search_rss(self):
|
||||
result = self.app.post('/search', data={'q': 'test', 'format': 'rss'})
|
||||
|
||||
self.assertIn(
|
||||
b'<description>Search results for "test" - searx</description>',
|
||||
result.data
|
||||
)
|
||||
self.assertIn(b'<description>Search results for "test" - searx</description>', result.data)
|
||||
|
||||
self.assertIn(
|
||||
b'<opensearch:totalResults>3</opensearch:totalResults>',
|
||||
result.data
|
||||
)
|
||||
self.assertIn(b'<opensearch:totalResults>3</opensearch:totalResults>', result.data)
|
||||
|
||||
self.assertIn(
|
||||
b'<title>First Test</title>',
|
||||
result.data
|
||||
)
|
||||
self.assertIn(b'<title>First Test</title>', result.data)
|
||||
|
||||
self.assertIn(
|
||||
b'<link>http://first.test.xyz</link>',
|
||||
result.data
|
||||
)
|
||||
self.assertIn(b'<link>http://first.test.xyz</link>', result.data)
|
||||
|
||||
self.assertIn(
|
||||
b'<description>first test content</description>',
|
||||
result.data
|
||||
)
|
||||
self.assertIn(b'<description>first test content</description>', result.data)
|
||||
|
||||
def test_about(self):
|
||||
result = self.app.get('/about')
|
||||
@@ -199,18 +182,9 @@ class ViewsTestCase(SearxTestCase):
|
||||
def test_preferences(self):
|
||||
result = self.app.get('/preferences')
|
||||
self.assertEqual(result.status_code, 200)
|
||||
self.assertIn(
|
||||
b'<form method="post" action="/preferences" id="search_form">',
|
||||
result.data
|
||||
)
|
||||
self.assertIn(
|
||||
b'<label class="col-sm-3 col-md-2" for="categories">Default categories</label>',
|
||||
result.data
|
||||
)
|
||||
self.assertIn(
|
||||
b'<label class="col-sm-3 col-md-2" for="locale">Interface language</label>',
|
||||
result.data
|
||||
)
|
||||
self.assertIn(b'<form method="post" action="/preferences" id="search_form">', result.data)
|
||||
self.assertIn(b'<label class="col-sm-3 col-md-2" for="categories">Default categories</label>', result.data)
|
||||
self.assertIn(b'<label class="col-sm-3 col-md-2" for="locale">Interface language</label>', result.data)
|
||||
|
||||
def test_browser_locale(self):
|
||||
result = self.app.get('/preferences', headers={'Accept-Language': 'zh-tw;q=0.8'})
|
||||
@@ -218,30 +192,26 @@ class ViewsTestCase(SearxTestCase):
|
||||
self.assertIn(
|
||||
b'<option value="zh-Hant-TW" selected="selected">',
|
||||
result.data,
|
||||
'Interface locale ignored browser preference.'
|
||||
'Interface locale ignored browser preference.',
|
||||
)
|
||||
self.assertIn(
|
||||
b'<option value="zh-Hant-TW" selected="selected">',
|
||||
result.data,
|
||||
'Search language ignored browser preference.'
|
||||
'Search language ignored browser preference.',
|
||||
)
|
||||
|
||||
def test_brower_empty_locale(self):
|
||||
result = self.app.get('/preferences', headers={'Accept-Language': ''})
|
||||
self.assertEqual(result.status_code, 200)
|
||||
self.assertIn(
|
||||
b'<option value="en" selected="selected">',
|
||||
result.data,
|
||||
'Interface locale ignored browser preference.'
|
||||
b'<option value="en" selected="selected">', result.data, 'Interface locale ignored browser preference.'
|
||||
)
|
||||
|
||||
def test_locale_occitan(self):
|
||||
result = self.app.get('/preferences?locale=oc')
|
||||
self.assertEqual(result.status_code, 200)
|
||||
self.assertIn(
|
||||
b'<option value="oc" selected="selected">',
|
||||
result.data,
|
||||
'Interface locale ignored browser preference.'
|
||||
b'<option value="oc" selected="selected">', result.data, 'Interface locale ignored browser preference.'
|
||||
)
|
||||
|
||||
def test_stats(self):
|
||||
|
||||
@@ -5,12 +5,13 @@ from tests import SearxTestCase
|
||||
|
||||
|
||||
class TestWebUtils(SearxTestCase):
|
||||
|
||||
def test_prettify_url(self):
|
||||
data = (('https://searx.me/', 'https://searx.me/'),
|
||||
('https://searx.me/ű', 'https://searx.me/ű'),
|
||||
('https://searx.me/' + (100 * 'a'), 'https://searx.me/[...]aaaaaaaaaaaaaaaaa'),
|
||||
('https://searx.me/' + (100 * 'ű'), 'https://searx.me/[...]űűűűűűűűűűűűűűűűű'))
|
||||
data = (
|
||||
('https://searx.me/', 'https://searx.me/'),
|
||||
('https://searx.me/ű', 'https://searx.me/ű'),
|
||||
('https://searx.me/' + (100 * 'a'), 'https://searx.me/[...]aaaaaaaaaaaaaaaaa'),
|
||||
('https://searx.me/' + (100 * 'ű'), 'https://searx.me/[...]űűűűűűűűűűűűűűűűű'),
|
||||
)
|
||||
|
||||
for test_url, expected in data:
|
||||
self.assertEqual(webutils.prettify_url(test_url, max_length=32), expected)
|
||||
@@ -21,10 +22,7 @@ class TestWebUtils(SearxTestCase):
|
||||
self.assertEqual(webutils.highlight_content('', None), None)
|
||||
self.assertEqual(webutils.highlight_content(False, None), None)
|
||||
|
||||
contents = [
|
||||
'<html></html>'
|
||||
'not<'
|
||||
]
|
||||
contents = ['<html></html>' 'not<']
|
||||
for content in contents:
|
||||
self.assertEqual(webutils.highlight_content(content, None), content)
|
||||
|
||||
@@ -35,30 +33,35 @@ class TestWebUtils(SearxTestCase):
|
||||
self.assertEqual(webutils.highlight_content(content, query), content)
|
||||
|
||||
data = (
|
||||
('" test "',
|
||||
'a test string',
|
||||
'a <span class="highlight">test</span> string'),
|
||||
('"a"',
|
||||
'this is a test string',
|
||||
'this is<span class="highlight"> a </span>test string'),
|
||||
('a test',
|
||||
'this is a test string that matches entire query',
|
||||
'this is <span class="highlight">a test</span> string that matches entire query'),
|
||||
('this a test',
|
||||
'this is a string to test.',
|
||||
('<span class="highlight">this</span> is<span class="highlight"> a </span>'
|
||||
'string to <span class="highlight">test</span>.')),
|
||||
('match this "exact phrase"',
|
||||
'this string contains the exact phrase we want to match',
|
||||
('<span class="highlight">this</span> string contains the <span class="highlight">exact</span>'
|
||||
' <span class="highlight">phrase</span> we want to <span class="highlight">match</span>'))
|
||||
('" test "', 'a test string', 'a <span class="highlight">test</span> string'),
|
||||
('"a"', 'this is a test string', 'this is<span class="highlight"> a </span>test string'),
|
||||
(
|
||||
'a test',
|
||||
'this is a test string that matches entire query',
|
||||
'this is <span class="highlight">a test</span> string that matches entire query',
|
||||
),
|
||||
(
|
||||
'this a test',
|
||||
'this is a string to test.',
|
||||
(
|
||||
'<span class="highlight">this</span> is<span class="highlight"> a </span>'
|
||||
'string to <span class="highlight">test</span>.'
|
||||
),
|
||||
),
|
||||
(
|
||||
'match this "exact phrase"',
|
||||
'this string contains the exact phrase we want to match',
|
||||
(
|
||||
'<span class="highlight">this</span> string contains the <span class="highlight">exact</span>'
|
||||
' <span class="highlight">phrase</span> we want to <span class="highlight">match</span>'
|
||||
),
|
||||
),
|
||||
)
|
||||
for query, content, expected in data:
|
||||
self.assertEqual(webutils.highlight_content(content, query), expected)
|
||||
|
||||
|
||||
class TestUnicodeWriter(SearxTestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.unicode_writer = webutils.UnicodeWriter(mock.MagicMock())
|
||||
|
||||
@@ -74,7 +77,6 @@ class TestUnicodeWriter(SearxTestCase):
|
||||
|
||||
|
||||
class TestNewHmac(SearxTestCase):
|
||||
|
||||
def test_bytes(self):
|
||||
for secret_key in ['secret', b'secret', 1]:
|
||||
if secret_key == 1:
|
||||
@@ -82,6 +84,4 @@ class TestNewHmac(SearxTestCase):
|
||||
webutils.new_hmac(secret_key, b'http://example.com')
|
||||
continue
|
||||
res = webutils.new_hmac(secret_key, b'http://example.com')
|
||||
self.assertEqual(
|
||||
res,
|
||||
'23e2baa2404012a5cc8e4a18b4aabf0dde4cb9b56f679ddc0fd6d7c24339d819')
|
||||
self.assertEqual(res, '23e2baa2404012a5cc8e4a18b4aabf0dde4cb9b56f679ddc0fd6d7c24339d819')
|
||||
|
||||
Reference in New Issue
Block a user