1
0
mirror of https://github.com/searxng/searxng.git synced 2024-11-15 01:00:12 +01:00
searxng/tests/unit/test_plugins.py

51 lines
1.7 KiB
Python
Raw Normal View History

# SPDX-License-Identifier: AGPL-3.0-or-later
# pylint: disable=missing-module-docstring
import babel
from mock import Mock
from searx import plugins
from tests import SearxTestCase
2015-03-14 22:35:29 +01:00
2015-10-23 23:31:53 +02:00
def get_search_mock(query, **kwargs):
lang = kwargs.get("lang", "en-US")
kwargs["locale"] = babel.Locale.parse(lang, sep="-")
return Mock(search_query=Mock(query=query, **kwargs), result_container=Mock(answers={}))
2015-10-23 23:31:53 +02:00
class PluginMock: # pylint: disable=missing-class-docstring, too-few-public-methods
default_on = False
name = 'Default plugin'
description = 'Default plugin description'
class PluginStoreTest(SearxTestCase): # pylint: disable=missing-class-docstring
def setUp(self):
self.store = plugins.PluginStore()
2015-03-14 22:35:29 +01:00
def test_init(self):
self.assertEqual(0, len(self.store.plugins))
self.assertIsInstance(self.store.plugins, list)
def test_register(self):
testplugin = PluginMock()
self.store.register(testplugin)
self.assertEqual(1, len(self.store.plugins))
2015-03-14 22:35:29 +01:00
def test_call_empty(self):
testplugin = PluginMock()
self.store.register(testplugin)
setattr(testplugin, 'asdf', Mock())
request = Mock()
self.store.call([], 'asdf', request, Mock())
self.assertFalse(getattr(testplugin, 'asdf').called) # pylint: disable=E1101
2015-03-14 22:35:29 +01:00
def test_call_with_plugin(self):
2015-03-14 22:35:29 +01:00
store = plugins.PluginStore()
testplugin = PluginMock()
2015-03-14 22:35:29 +01:00
store.register(testplugin)
setattr(testplugin, 'asdf', Mock())
request = Mock()
store.call([testplugin], 'asdf', request, Mock())
self.assertTrue(getattr(testplugin, 'asdf').called) # pylint: disable=E1101