summaryrefslogtreecommitdiff
path: root/tests/unit/test_plugins.py
blob: 6878228f31eaf672206d1efc8ac0ce272d49a298 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# SPDX-License-Identifier: AGPL-3.0-or-later
# pylint: disable=missing-module-docstring

from mock import Mock
from searx import plugins
from tests import SearxTestCase


def get_search_mock(query, **kwargs):
    return Mock(search_query=Mock(query=query, **kwargs), result_container=Mock(answers={}))


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()

    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))

    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

    def test_call_with_plugin(self):
        store = plugins.PluginStore()
        testplugin = PluginMock()
        store.register(testplugin)
        setattr(testplugin, 'asdf', Mock())
        request = Mock()
        store.call([testplugin], 'asdf', request, Mock())
        self.assertTrue(getattr(testplugin, 'asdf').called)  # pylint: disable=E1101