summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorGrant Lanham <contact@grantlanham.com>2024-06-09 14:22:20 -0400
committerMarkus Heiser <markus.heiser@darmarIT.de>2024-06-23 11:51:41 +0200
commit9a9ca307fe53ea8ed9d18a06a1a7da9fa4a1c28f (patch)
tree34742219f3ea3a90f0b20b9cbf792e6318c2f734 /tests
parent1f908a6222638b547016f5c21472ae26a76adbd2 (diff)
downloadsearxng-9a9ca307fe53ea8ed9d18a06a1a7da9fa4a1c28f.tar.gz
searxng-9a9ca307fe53ea8ed9d18a06a1a7da9fa4a1c28f.zip
[fix] implement tests and remove usage of gen_useragent in engines
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/processors/__init__.py2
-rw-r--r--tests/unit/processors/test_online.py53
2 files changed, 55 insertions, 0 deletions
diff --git a/tests/unit/processors/__init__.py b/tests/unit/processors/__init__.py
new file mode 100644
index 000000000..9ed59c825
--- /dev/null
+++ b/tests/unit/processors/__init__.py
@@ -0,0 +1,2 @@
+# SPDX-License-Identifier: AGPL-3.0-or-later
+# pylint: disable=missing-module-docstring
diff --git a/tests/unit/processors/test_online.py b/tests/unit/processors/test_online.py
new file mode 100644
index 000000000..10e0deb97
--- /dev/null
+++ b/tests/unit/processors/test_online.py
@@ -0,0 +1,53 @@
+# SPDX-License-Identifier: AGPL-3.0-or-later
+# pylint: disable=missing-module-docstring
+
+from searx.search import SearchQuery, EngineRef
+from searx.search.processors import online
+from searx.engines import load_engines
+from searx import engines
+
+from tests import SearxTestCase
+
+TEST_ENGINE_NAME = 'dummy engine'
+TEST_ENGINE = {
+ 'name': TEST_ENGINE_NAME,
+ 'engine': 'dummy',
+ 'categories': 'general',
+ 'shortcut': 'du',
+ 'timeout': 3.0,
+ 'tokens': [],
+}
+
+
+class TestOnlineProcessor(SearxTestCase): # pylint: disable=missing-class-docstring
+
+ def setUp(self):
+ load_engines([TEST_ENGINE])
+
+ def tearDown(self):
+ load_engines([])
+
+ def _get_params(self, online_processor, search_query, engine_category):
+ params = online_processor.get_params(search_query, engine_category)
+ self.assertIsNotNone(params)
+ assert params is not None
+ return params
+
+ def test_get_params_default_params(self):
+ engine = engines.engines[TEST_ENGINE_NAME]
+ online_processor = online.OnlineProcessor(engine, TEST_ENGINE_NAME)
+ search_query = SearchQuery('test', [EngineRef(TEST_ENGINE_NAME, 'general')], 'all', 0, 1, None, None, None)
+ params = self._get_params(online_processor, search_query, 'general')
+ self.assertIn('method', params)
+ self.assertIn('headers', params)
+ self.assertIn('data', params)
+ self.assertIn('url', params)
+ self.assertIn('cookies', params)
+ self.assertIn('auth', params)
+
+ def test_get_params_useragent(self):
+ engine = engines.engines[TEST_ENGINE_NAME]
+ online_processor = online.OnlineProcessor(engine, TEST_ENGINE_NAME)
+ search_query = SearchQuery('test', [EngineRef(TEST_ENGINE_NAME, 'general')], 'all', 0, 1, None, None, None)
+ params = self._get_params(online_processor, search_query, 'general')
+ self.assertIn('User-Agent', params['headers'])