mirror of
https://github.com/searxng/searxng.git
synced 2024-11-19 19:00:10 +01:00
[fix] test: avoid HTTP requests
patch engine initialization to skip HTTP request (engine_init function in searx.engines.initialize_engines)
This commit is contained in:
parent
5d5ecdb745
commit
111180705b
@ -13,7 +13,7 @@ class TestEnginesInit(SearxTestCase):
|
|||||||
engine_list = [{'engine': 'dummy', 'name': 'engine1', 'shortcut': 'e1'},
|
engine_list = [{'engine': 'dummy', 'name': 'engine1', 'shortcut': 'e1'},
|
||||||
{'engine': 'dummy', 'name': 'engine2', 'shortcut': 'e2'}]
|
{'engine': 'dummy', 'name': 'engine2', 'shortcut': 'e2'}]
|
||||||
|
|
||||||
engines.initialize_engines(engine_list)
|
engines.load_engines(engine_list)
|
||||||
self.assertEqual(len(engines.engines), 2)
|
self.assertEqual(len(engines.engines), 2)
|
||||||
self.assertIn('engine1', engines.engines)
|
self.assertIn('engine1', engines.engines)
|
||||||
self.assertIn('engine2', engines.engines)
|
self.assertIn('engine2', engines.engines)
|
||||||
|
@ -1,7 +1,11 @@
|
|||||||
|
from mock import patch
|
||||||
|
|
||||||
from searx.search import initialize
|
from searx.search import initialize
|
||||||
from searx.query import RawTextQuery
|
from searx.query import RawTextQuery
|
||||||
from searx.testing import SearxTestCase
|
from searx.testing import SearxTestCase
|
||||||
|
|
||||||
|
import searx.engines
|
||||||
|
|
||||||
|
|
||||||
TEST_ENGINES = [
|
TEST_ENGINES = [
|
||||||
{
|
{
|
||||||
@ -277,9 +281,10 @@ class TestBang(SearxTestCase):
|
|||||||
self.assertEqual(query.getQuery(), '!dum the query')
|
self.assertEqual(query.getQuery(), '!dum the query')
|
||||||
|
|
||||||
def test_bang_autocomplete_empty(self):
|
def test_bang_autocomplete_empty(self):
|
||||||
initialize()
|
with patch.object(searx.engines, 'initialize_engines', searx.engines.load_engines):
|
||||||
query = RawTextQuery('the query !', [])
|
initialize()
|
||||||
self.assertEqual(query.autocomplete_list, ['!images', '!wikipedia', '!osm'])
|
query = RawTextQuery('the query !', [])
|
||||||
|
self.assertEqual(query.autocomplete_list, ['!images', '!wikipedia', '!osm'])
|
||||||
|
|
||||||
query = RawTextQuery('the query ?', ['osm'])
|
query = RawTextQuery('the query ?', ['osm'])
|
||||||
self.assertEqual(query.autocomplete_list, ['?images', '?wikipedia'])
|
self.assertEqual(query.autocomplete_list, ['?images', '?wikipedia'])
|
||||||
|
@ -3,14 +3,19 @@
|
|||||||
import json
|
import json
|
||||||
from urllib.parse import ParseResult
|
from urllib.parse import ParseResult
|
||||||
from mock import Mock
|
from mock import Mock
|
||||||
from searx import webapp
|
|
||||||
from searx.testing import SearxTestCase
|
from searx.testing import SearxTestCase
|
||||||
from searx.search import Search
|
from searx.search import Search
|
||||||
|
import searx.engines
|
||||||
|
|
||||||
|
|
||||||
class ViewsTestCase(SearxTestCase):
|
class ViewsTestCase(SearxTestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
# skip init function (no external HTTP request)
|
||||||
|
self.setattr4test(searx.engines, 'initialize_engines', searx.engines.load_engines)
|
||||||
|
|
||||||
|
from searx import webapp # pylint disable=import-outside-toplevel
|
||||||
|
|
||||||
webapp.app.config['TESTING'] = True # to get better error messages
|
webapp.app.config['TESTING'] = True # to get better error messages
|
||||||
self.app = webapp.app.test_client()
|
self.app = webapp.app.test_client()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user