summaryrefslogtreecommitdiff
path: root/tests/unit
diff options
context:
space:
mode:
authorGrant Lanham <contact@grantlanham.com>2024-09-29 20:56:59 -0400
committerMarkus Heiser <markus.heiser@darmarIT.de>2024-10-03 13:04:06 +0200
commit2a29e16d25ae19d9216b959f177cdcd71c43511e (patch)
treee41231c4d32c3a9ebca3b21a488d4cfd38cc0578 /tests/unit
parentd48f04e8094c8b9ddb7808a9798f71549146a38e (diff)
downloadsearxng-2a29e16d25ae19d9216b959f177cdcd71c43511e.tar.gz
searxng-2a29e16d25ae19d9216b959f177cdcd71c43511e.zip
[feat] implement mariadb engine
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/test_engine_mariadb_server.py44
-rw-r--r--tests/unit/test_engine_tineye.py (renamed from tests/unit/test_tineye.py)0
2 files changed, 44 insertions, 0 deletions
diff --git a/tests/unit/test_engine_mariadb_server.py b/tests/unit/test_engine_mariadb_server.py
new file mode 100644
index 000000000..423132e34
--- /dev/null
+++ b/tests/unit/test_engine_mariadb_server.py
@@ -0,0 +1,44 @@
+# SPDX-License-Identifier: AGPL-3.0-or-later
+# pylint: disable=missing-module-docstring
+
+from unittest.mock import MagicMock, Mock
+from searx.engines import load_engines, mariadb_server
+from tests import SearxTestCase
+
+
+class MariadbServerTests(SearxTestCase): # pylint: disable=missing-class-docstring
+ def setUp(self):
+ load_engines(
+ [
+ {
+ 'name': 'mariadb server',
+ 'engine': 'mariadb_server',
+ 'shortcut': 'mdb',
+ 'timeout': 9.0,
+ 'disabled': True,
+ }
+ ]
+ )
+
+ def tearDown(self):
+ load_engines([])
+
+ def test_init_no_query_str_raises(self):
+ self.assertRaises(ValueError, lambda: mariadb_server.init({}))
+
+ def test_init_non_select_raises(self):
+ self.assertRaises(ValueError, lambda: mariadb_server.init({'query_str': 'foobar'}))
+
+ def test_search_returns_results(self):
+ test_string = 'FOOBAR'
+ cursor_mock = MagicMock()
+ with cursor_mock as setup: # pylint: disable=not-context-manager
+ setup.__iter__ = Mock(return_value=iter([{test_string, 1}]))
+ setup.description = [[test_string]]
+ conn_mock = Mock()
+ conn_mock.cursor.return_value = cursor_mock
+ mariadb_server._connection = conn_mock # pylint: disable=protected-access
+ results = mariadb_server.search(test_string, {'pageno': 1})
+ self.assertEqual(1, len(results))
+ self.assertIn(test_string, results[0])
+ self.assertEqual(mariadb_server.result_template, results[0]['template'])
diff --git a/tests/unit/test_tineye.py b/tests/unit/test_engine_tineye.py
index 5855a7313..5855a7313 100644
--- a/tests/unit/test_tineye.py
+++ b/tests/unit/test_engine_tineye.py