2015-06-16 19:56:16 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
from searx.testing import SearxTestCase
|
|
|
|
|
2019-08-02 13:50:51 +02:00
|
|
|
import searx.preferences
|
|
|
|
import searx.search
|
|
|
|
import searx.engines
|
|
|
|
|
2015-06-16 19:56:16 +02:00
|
|
|
|
2015-10-03 17:26:07 +02:00
|
|
|
class SearchTestCase(SearxTestCase):
|
2015-06-16 19:56:16 +02:00
|
|
|
|
2019-08-02 13:50:51 +02:00
|
|
|
@classmethod
|
|
|
|
def setUpClass(cls):
|
|
|
|
searx.engines.initialize_engines([{
|
|
|
|
'name': 'general dummy',
|
|
|
|
'engine': 'dummy',
|
|
|
|
'categories': 'general',
|
|
|
|
'shortcut': 'gd',
|
|
|
|
'timeout': 3.0
|
|
|
|
}])
|
|
|
|
|
|
|
|
def test_timeout_simple(self):
|
|
|
|
searx.search.max_request_timeout = None
|
|
|
|
search_query = searx.query.SearchQuery('test', [{'category': 'general', 'name': 'general dummy'}],
|
|
|
|
['general'], 'en-US', 0, 1, None, None)
|
|
|
|
search = searx.search.Search(search_query)
|
|
|
|
search.search()
|
|
|
|
self.assertEquals(search.actual_timeout, 3.0)
|
|
|
|
|
|
|
|
def test_timeout_query_above_default_nomax(self):
|
|
|
|
searx.search.max_request_timeout = None
|
|
|
|
search_query = searx.query.SearchQuery('test', [{'category': 'general', 'name': 'general dummy'}],
|
|
|
|
['general'], 'en-US', 0, 1, None, 5.0)
|
|
|
|
search = searx.search.Search(search_query)
|
|
|
|
search.search()
|
|
|
|
self.assertEquals(search.actual_timeout, 3.0)
|
|
|
|
|
|
|
|
def test_timeout_query_below_default_nomax(self):
|
|
|
|
searx.search.max_request_timeout = None
|
|
|
|
search_query = searx.query.SearchQuery('test', [{'category': 'general', 'name': 'general dummy'}],
|
|
|
|
['general'], 'en-US', 0, 1, None, 1.0)
|
|
|
|
search = searx.search.Search(search_query)
|
|
|
|
search.search()
|
|
|
|
self.assertEquals(search.actual_timeout, 1.0)
|
|
|
|
|
|
|
|
def test_timeout_query_below_max(self):
|
|
|
|
searx.search.max_request_timeout = 10.0
|
|
|
|
search_query = searx.query.SearchQuery('test', [{'category': 'general', 'name': 'general dummy'}],
|
|
|
|
['general'], 'en-US', 0, 1, None, 5.0)
|
|
|
|
search = searx.search.Search(search_query)
|
|
|
|
search.search()
|
|
|
|
self.assertEquals(search.actual_timeout, 5.0)
|
|
|
|
|
|
|
|
def test_timeout_query_above_max(self):
|
|
|
|
searx.search.max_request_timeout = 10.0
|
|
|
|
search_query = searx.query.SearchQuery('test', [{'category': 'general', 'name': 'general dummy'}],
|
|
|
|
['general'], 'en-US', 0, 1, None, 15.0)
|
|
|
|
search = searx.search.Search(search_query)
|
|
|
|
search.search()
|
|
|
|
self.assertEquals(search.actual_timeout, 10.0)
|