mirror of
https://github.com/searxng/searxng.git
synced 2025-08-02 10:02:20 +02:00
[refactor] unit tests (continued) - plugins
This commit includes some refactoring in unit tests. As we test more plugins, it seems unweildy to include every test class in the test_plugins.py file. This patch split apart all of the test plugins to their own respective files, including the new test_plugin_calculator.py file.
This commit is contained in:
parent
8ba203c72b
commit
d448def1a6
5 changed files with 194 additions and 104 deletions
70
tests/unit/test_plugin_calculator.py
Normal file
70
tests/unit/test_plugin_calculator.py
Normal file
|
@ -0,0 +1,70 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
# pylint: disable=missing-module-docstring
|
||||
|
||||
from mock import Mock
|
||||
from parameterized.parameterized import parameterized
|
||||
from searx import plugins
|
||||
from tests import SearxTestCase
|
||||
from .test_utils import random_string
|
||||
|
||||
from .test_plugins import get_search_mock
|
||||
|
||||
|
||||
class PluginCalculator(SearxTestCase): # pylint: disable=missing-class-docstring
|
||||
def setUp(self):
|
||||
self.store = plugins.PluginStore()
|
||||
plugin = plugins.load_and_initialize_plugin('searx.plugins.calculator', False, (None, {}))
|
||||
self.store.register(plugin)
|
||||
|
||||
def test_plugin_store_init(self):
|
||||
self.assertEqual(1, len(self.store.plugins))
|
||||
|
||||
def test_single_page_number_true(self):
|
||||
request = Mock(remote_addr='127.0.0.1')
|
||||
search = get_search_mock(query=random_string(10), pageno=2)
|
||||
result = self.store.call(self.store.plugins, 'post_search', request, search)
|
||||
self.assertTrue(result)
|
||||
self.assertNotIn('calculate', search.result_container.answers)
|
||||
|
||||
def test_long_query_true(self):
|
||||
request = Mock(remote_addr='127.0.0.1')
|
||||
search = get_search_mock(query=random_string(101), pageno=1)
|
||||
result = self.store.call(self.store.plugins, 'post_search', request, search)
|
||||
self.assertTrue(result)
|
||||
self.assertNotIn('calculate', search.result_container.answers)
|
||||
|
||||
def test_alpha_true(self):
|
||||
request = Mock(remote_addr='127.0.0.1')
|
||||
search = get_search_mock(query=random_string(10), pageno=1)
|
||||
result = self.store.call(self.store.plugins, 'post_search', request, search)
|
||||
self.assertTrue(result)
|
||||
self.assertNotIn('calculate', search.result_container.answers)
|
||||
|
||||
@parameterized.expand(
|
||||
[
|
||||
"1+1",
|
||||
"1-1",
|
||||
"1*1",
|
||||
"1/1",
|
||||
"1**1",
|
||||
"1^1",
|
||||
]
|
||||
)
|
||||
def test_int_operations(self, operation):
|
||||
request = Mock(remote_addr='127.0.0.1')
|
||||
search = get_search_mock(query=operation, pageno=1)
|
||||
result = self.store.call(self.store.plugins, 'post_search', request, search)
|
||||
self.assertTrue(result)
|
||||
self.assertIn('calculate', search.result_container.answers)
|
||||
|
||||
@parameterized.expand(
|
||||
[
|
||||
"1/0",
|
||||
]
|
||||
)
|
||||
def test_invalid_operations(self, operation):
|
||||
request = Mock(remote_addr='127.0.0.1')
|
||||
search = get_search_mock(query=operation, pageno=1)
|
||||
result = self.store.call(self.store.plugins, 'post_search', request, search)
|
||||
self.assertTrue(result)
|
||||
self.assertNotIn('calculate', search.result_container.answers)
|
Loading…
Add table
Add a link
Reference in a new issue