summaryrefslogtreecommitdiff
path: root/tests/unit
diff options
context:
space:
mode:
authorAlexandre Flament <alex@al-f.net>2021-05-05 13:08:54 +0200
committerAlexandre Flament <alex@al-f.net>2021-05-05 13:12:42 +0200
commit8c1a65d32fb6a0859c0052d668d01f08325f11ad (patch)
tree8837e952d67fb8a4755ce2c732ada76474da75c2 /tests/unit
parentd36adfa59f242a8775ad74245c696d62b7727a36 (diff)
downloadsearxng-8c1a65d32fb6a0859c0052d668d01f08325f11ad.tar.gz
searxng-8c1a65d32fb6a0859c0052d668d01f08325f11ad.zip
[mod] multithreading only in searx.search.* packages
it prepares the new architecture change, everything about multithreading in moved in the searx.search.* packages previously the call to the "init" function of the engines was done in searx.engines: * the network was not set (request not sent using the defined proxy) * it requires to monkey patch the code to avoid HTTP requests during the tests
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/test_engines_init.py4
-rw-r--r--tests/unit/test_query.py24
-rw-r--r--tests/unit/test_webapp.py6
3 files changed, 16 insertions, 18 deletions
diff --git a/tests/unit/test_engines_init.py b/tests/unit/test_engines_init.py
index c75637f20..d2aee41f2 100644
--- a/tests/unit/test_engines_init.py
+++ b/tests/unit/test_engines_init.py
@@ -23,7 +23,7 @@ class TestEnginesInit(SearxTestCase):
engine_list = [{'engine': 'dummy', 'name': 'engine1', 'shortcut': 'e1', 'categories': 'general'},
{'engine': 'dummy', 'name': 'engine2', 'shortcut': 'e2', 'categories': 'onions'}]
- engines.initialize_engines(engine_list)
+ engines.load_engines(engine_list)
self.assertEqual(len(engines.engines), 1)
self.assertIn('engine1', engines.engines)
self.assertNotIn('onions', engines.categories)
@@ -35,7 +35,7 @@ class TestEnginesInit(SearxTestCase):
'timeout': 20.0, 'onion_url': 'http://engine1.onion'},
{'engine': 'dummy', 'name': 'engine2', 'shortcut': 'e2', 'categories': 'onions'}]
- engines.initialize_engines(engine_list)
+ engines.load_engines(engine_list)
self.assertEqual(len(engines.engines), 2)
self.assertIn('engine1', engines.engines)
self.assertIn('engine2', engines.engines)
diff --git a/tests/unit/test_query.py b/tests/unit/test_query.py
index 7a79ce242..dd7ff0766 100644
--- a/tests/unit/test_query.py
+++ b/tests/unit/test_query.py
@@ -1,11 +1,8 @@
-from mock import patch
-
-from searx.search import initialize
+from searx import settings
+from searx.engines import load_engines
from searx.query import RawTextQuery
from searx.testing import SearxTestCase
-import searx.engines
-
TEST_ENGINES = [
{
@@ -241,7 +238,7 @@ class TestBang(SearxTestCase):
THE_QUERY = 'the query'
def test_bang(self):
- initialize(TEST_ENGINES)
+ load_engines(TEST_ENGINES)
for bang in TestBang.SPECIFIC_BANGS + TestBang.NOT_SPECIFIC_BANGS:
with self.subTest(msg="Check bang", bang=bang):
@@ -267,12 +264,12 @@ class TestBang(SearxTestCase):
self.assertFalse(query.specific)
def test_bang_not_found(self):
- initialize(TEST_ENGINES)
+ load_engines(TEST_ENGINES)
query = RawTextQuery('the query !bang_not_found', [])
self.assertEqual(query.getFullQuery(), 'the query !bang_not_found')
def test_bang_autocomplete(self):
- initialize(TEST_ENGINES)
+ load_engines(TEST_ENGINES)
query = RawTextQuery('the query !dum', [])
self.assertEqual(query.autocomplete_list, ['!dummy_engine'])
@@ -281,10 +278,9 @@ class TestBang(SearxTestCase):
self.assertEqual(query.getQuery(), '!dum the query')
def test_bang_autocomplete_empty(self):
- with patch.object(searx.engines, 'initialize_engines', searx.engines.load_engines):
- initialize()
- query = RawTextQuery('the query !', [])
- self.assertEqual(query.autocomplete_list, ['!images', '!wikipedia', '!osm'])
+ load_engines(settings['engines'])
+ query = RawTextQuery('the query !', [])
+ self.assertEqual(query.autocomplete_list, ['!images', '!wikipedia', '!osm'])
- query = RawTextQuery('the query ?', ['osm'])
- self.assertEqual(query.autocomplete_list, ['?images', '?wikipedia'])
+ query = RawTextQuery('the query ?', ['osm'])
+ self.assertEqual(query.autocomplete_list, ['?images', '?wikipedia'])
diff --git a/tests/unit/test_webapp.py b/tests/unit/test_webapp.py
index 9d83b7596..2cbdc83d6 100644
--- a/tests/unit/test_webapp.py
+++ b/tests/unit/test_webapp.py
@@ -5,14 +5,16 @@ from urllib.parse import ParseResult
from mock import Mock
from searx.testing import SearxTestCase
from searx.search import Search
-import searx.engines
+import searx.search.processors
class ViewsTestCase(SearxTestCase):
def setUp(self):
# skip init function (no external HTTP request)
- self.setattr4test(searx.engines, 'initialize_engines', searx.engines.load_engines)
+ def dummy(*args, **kwargs):
+ pass
+ self.setattr4test(searx.search.processors, 'initialize_processor', dummy)
from searx import webapp # pylint disable=import-outside-toplevel