2013-09-19 21:02:28 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
# OpenLP - Open Source Lyrics Projection #
|
|
|
|
# --------------------------------------------------------------------------- #
|
2019-02-14 15:09:09 +00:00
|
|
|
# Copyright (c) 2008-2019 OpenLP Developers #
|
2013-09-19 21:02:28 +00:00
|
|
|
# --------------------------------------------------------------------------- #
|
|
|
|
# This program is free software; you can redistribute it and/or modify it #
|
|
|
|
# under the terms of the GNU General Public License as published by the Free #
|
|
|
|
# Software Foundation; version 2 of the License. #
|
|
|
|
# #
|
|
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT #
|
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
|
|
|
|
# more details. #
|
|
|
|
# #
|
|
|
|
# You should have received a copy of the GNU General Public License along #
|
|
|
|
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
|
|
|
|
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
|
|
|
###############################################################################
|
2013-02-11 13:22:13 +00:00
|
|
|
"""
|
|
|
|
Package to test the openlp.core.lib.pluginmanager package.
|
|
|
|
"""
|
|
|
|
from unittest import TestCase
|
2018-01-13 23:24:26 +00:00
|
|
|
from unittest.mock import MagicMock, patch
|
2013-02-11 13:22:13 +00:00
|
|
|
|
2018-12-02 14:00:17 +00:00
|
|
|
from openlp.core.state import State
|
2017-10-07 07:05:07 +00:00
|
|
|
from openlp.core.common.registry import Registry
|
|
|
|
from openlp.core.common.settings import Settings
|
2018-08-25 14:08:19 +00:00
|
|
|
from openlp.core.lib.plugin import PluginStatus
|
2017-12-28 08:22:55 +00:00
|
|
|
from openlp.core.lib.pluginmanager import PluginManager
|
2013-02-11 13:22:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestPluginManager(TestCase):
|
|
|
|
"""
|
|
|
|
Test the PluginManager class
|
|
|
|
"""
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
"""
|
|
|
|
Some pre-test setup required.
|
|
|
|
"""
|
2013-02-21 14:23:33 +00:00
|
|
|
self.mocked_main_window = MagicMock()
|
2013-02-27 21:11:43 +00:00
|
|
|
self.mocked_main_window.file_import_menu.return_value = None
|
|
|
|
self.mocked_main_window.file_export_menu.return_value = None
|
|
|
|
self.mocked_main_window.file_export_menu.return_value = None
|
2013-02-21 14:23:33 +00:00
|
|
|
self.mocked_settings_form = MagicMock()
|
2013-02-11 13:22:13 +00:00
|
|
|
Registry.create()
|
2018-12-11 19:35:35 +00:00
|
|
|
State().load_settings()
|
2013-08-31 18:17:38 +00:00
|
|
|
Registry().register('service_list', MagicMock())
|
|
|
|
Registry().register('main_window', self.mocked_main_window)
|
|
|
|
Registry().register('settings_form', self.mocked_settings_form)
|
2013-02-11 13:22:13 +00:00
|
|
|
|
2018-01-13 23:24:26 +00:00
|
|
|
def test_bootstrap_initialise(self):
|
|
|
|
"""
|
|
|
|
Test the PluginManager.bootstrap_initialise() method
|
|
|
|
"""
|
|
|
|
# GIVEN: A plugin manager with some mocked out methods
|
|
|
|
manager = PluginManager()
|
|
|
|
|
2018-12-02 10:19:07 +00:00
|
|
|
with patch.object(manager, 'hook_settings_tabs') as mocked_hook_settings_tabs, \
|
2018-01-13 23:24:26 +00:00
|
|
|
patch.object(manager, 'hook_media_manager') as mocked_hook_media_manager, \
|
|
|
|
patch.object(manager, 'hook_import_menu') as mocked_hook_import_menu, \
|
|
|
|
patch.object(manager, 'hook_export_menu') as mocked_hook_export_menu, \
|
|
|
|
patch.object(manager, 'hook_tools_menu') as mocked_hook_tools_menu, \
|
|
|
|
patch.object(manager, 'initialise_plugins') as mocked_initialise_plugins:
|
|
|
|
# WHEN: bootstrap_initialise() is called
|
|
|
|
manager.bootstrap_initialise()
|
2018-12-02 13:51:24 +00:00
|
|
|
manager.bootstrap_post_set_up()
|
2018-01-13 23:24:26 +00:00
|
|
|
|
|
|
|
# THEN: The hook methods should have been called
|
|
|
|
mocked_hook_settings_tabs.assert_called_with()
|
|
|
|
mocked_hook_media_manager.assert_called_with()
|
|
|
|
mocked_hook_import_menu.assert_called_with()
|
|
|
|
mocked_hook_export_menu.assert_called_with()
|
|
|
|
mocked_hook_tools_menu.assert_called_with()
|
|
|
|
mocked_initialise_plugins.assert_called_with()
|
|
|
|
|
2016-05-31 21:40:13 +00:00
|
|
|
def test_hook_media_manager_with_disabled_plugin(self):
|
2013-02-11 13:22:13 +00:00
|
|
|
"""
|
|
|
|
Test running the hook_media_manager() method with a disabled plugin
|
|
|
|
"""
|
|
|
|
# GIVEN: A PluginManager instance and a list with a mocked up plugin whose status is set to Disabled
|
|
|
|
mocked_plugin = MagicMock()
|
|
|
|
mocked_plugin.status = PluginStatus.Disabled
|
2013-02-17 13:03:59 +00:00
|
|
|
plugin_manager = PluginManager()
|
2018-12-11 20:00:33 +00:00
|
|
|
Registry().register('mock_plugin', mocked_plugin)
|
2018-12-15 08:07:11 +00:00
|
|
|
State().add_service("mock", 1, is_plugin=True, status=PluginStatus.Disabled)
|
|
|
|
State().flush_preconditions()
|
2013-02-11 13:22:13 +00:00
|
|
|
|
|
|
|
# WHEN: We run hook_media_manager()
|
|
|
|
plugin_manager.hook_media_manager()
|
|
|
|
|
2013-03-19 17:53:32 +00:00
|
|
|
# THEN: The create_media_manager_item() method should have been called
|
2017-12-17 17:52:17 +00:00
|
|
|
assert 0 == mocked_plugin.create_media_manager_item.call_count, \
|
|
|
|
'The create_media_manager_item() method should not have been called.'
|
2013-02-11 13:22:13 +00:00
|
|
|
|
2016-05-31 21:40:13 +00:00
|
|
|
def test_hook_media_manager_with_active_plugin(self):
|
2013-02-11 13:22:13 +00:00
|
|
|
"""
|
|
|
|
Test running the hook_media_manager() method with an active plugin
|
|
|
|
"""
|
|
|
|
# GIVEN: A PluginManager instance and a list with a mocked up plugin whose status is set to Active
|
|
|
|
mocked_plugin = MagicMock()
|
|
|
|
mocked_plugin.status = PluginStatus.Active
|
2013-02-17 13:03:59 +00:00
|
|
|
plugin_manager = PluginManager()
|
2018-12-11 20:00:33 +00:00
|
|
|
Registry().register('mock_plugin', mocked_plugin)
|
|
|
|
State().add_service("mock", 1, is_plugin=True, status=PluginStatus.Active)
|
|
|
|
State().flush_preconditions()
|
2018-12-15 08:07:11 +00:00
|
|
|
|
|
|
|
# WHEN: We run hook_media_manager()
|
2013-02-11 13:22:13 +00:00
|
|
|
plugin_manager.hook_media_manager()
|
|
|
|
|
2013-03-19 17:53:32 +00:00
|
|
|
# THEN: The create_media_manager_item() method should have been called
|
|
|
|
mocked_plugin.create_media_manager_item.assert_called_with()
|
2013-02-11 13:22:13 +00:00
|
|
|
|
2016-05-31 21:40:13 +00:00
|
|
|
def test_hook_settings_tabs_with_disabled_plugin_and_no_form(self):
|
2013-02-11 13:22:13 +00:00
|
|
|
"""
|
|
|
|
Test running the hook_settings_tabs() method with a disabled plugin and no form
|
|
|
|
"""
|
|
|
|
# GIVEN: A PluginManager instance and a list with a mocked up plugin whose status is set to Disabled
|
|
|
|
mocked_plugin = MagicMock()
|
|
|
|
mocked_plugin.status = PluginStatus.Disabled
|
2013-02-17 13:03:59 +00:00
|
|
|
plugin_manager = PluginManager()
|
2018-12-11 20:00:33 +00:00
|
|
|
Registry().register('mock_plugin', mocked_plugin)
|
|
|
|
State().add_service("mock", 1, is_plugin=True, status=PluginStatus.Active)
|
|
|
|
State().flush_preconditions()
|
2018-12-15 08:07:11 +00:00
|
|
|
|
|
|
|
# WHEN: We run hook_settings_tabs()
|
2013-02-11 13:22:13 +00:00
|
|
|
plugin_manager.hook_settings_tabs()
|
|
|
|
|
2013-04-05 19:37:15 +00:00
|
|
|
# THEN: The hook_settings_tabs() method should have been called
|
2017-12-17 17:52:17 +00:00
|
|
|
assert 0 == mocked_plugin.create_media_manager_item.call_count, \
|
|
|
|
'The create_media_manager_item() method should not have been called.'
|
2013-02-11 13:22:13 +00:00
|
|
|
|
2016-05-31 21:40:13 +00:00
|
|
|
def test_hook_settings_tabs_with_disabled_plugin_and_mocked_form(self):
|
2013-02-27 21:42:21 +00:00
|
|
|
"""
|
|
|
|
Test running the hook_settings_tabs() method with a disabled plugin and a mocked form
|
|
|
|
"""
|
|
|
|
# GIVEN: A PluginManager instance and a list with a mocked up plugin whose status is set to Disabled
|
|
|
|
mocked_plugin = MagicMock()
|
|
|
|
mocked_plugin.status = PluginStatus.Disabled
|
|
|
|
plugin_manager = PluginManager()
|
2018-12-11 20:00:33 +00:00
|
|
|
Registry().register('mock_plugin', mocked_plugin)
|
2013-02-28 21:19:01 +00:00
|
|
|
mocked_settings_form = MagicMock()
|
|
|
|
# Replace the autoloaded plugin with the version for testing in real code this would error
|
|
|
|
mocked_settings_form.plugin_manager = plugin_manager
|
2018-12-11 20:00:33 +00:00
|
|
|
State().add_service("mock", 1, is_plugin=True, status=PluginStatus.Active)
|
|
|
|
State().flush_preconditions()
|
2018-12-15 08:07:11 +00:00
|
|
|
|
|
|
|
# WHEN: We run hook_settings_tabs()
|
2013-02-27 21:42:21 +00:00
|
|
|
plugin_manager.hook_settings_tabs()
|
|
|
|
|
2013-04-05 19:37:15 +00:00
|
|
|
# THEN: The create_settings_tab() method should not have been called, but the plugins lists should be the same
|
2017-12-17 17:52:17 +00:00
|
|
|
assert 0 == mocked_plugin.create_settings_tab.call_count, \
|
|
|
|
'The create_media_manager_item() method should not have been called.'
|
|
|
|
assert mocked_settings_form.plugin_manager.plugins == plugin_manager.plugins, \
|
|
|
|
'The plugins on the settings form should be the same as the plugins in the plugin manager'
|
2013-02-28 21:19:01 +00:00
|
|
|
|
2016-05-31 21:40:13 +00:00
|
|
|
def test_hook_settings_tabs_with_active_plugin_and_mocked_form(self):
|
2013-02-28 21:19:01 +00:00
|
|
|
"""
|
|
|
|
Test running the hook_settings_tabs() method with an active plugin and a mocked settings form
|
|
|
|
"""
|
|
|
|
# GIVEN: A PluginManager instance and a list with a mocked up plugin whose status is set to Active
|
|
|
|
mocked_plugin = MagicMock()
|
|
|
|
mocked_plugin.status = PluginStatus.Active
|
|
|
|
plugin_manager = PluginManager()
|
2018-12-11 20:00:33 +00:00
|
|
|
Registry().register('mock_plugin', mocked_plugin)
|
2013-02-28 21:19:01 +00:00
|
|
|
mocked_settings_form = MagicMock()
|
|
|
|
# Replace the autoloaded plugin with the version for testing in real code this would error
|
|
|
|
mocked_settings_form.plugin_manager = plugin_manager
|
2018-12-11 20:00:33 +00:00
|
|
|
State().add_service("mock", 1, is_plugin=True, status=PluginStatus.Active)
|
|
|
|
State().flush_preconditions()
|
2018-12-15 08:07:11 +00:00
|
|
|
|
|
|
|
# WHEN: We run hook_settings_tabs()
|
2013-02-28 21:19:01 +00:00
|
|
|
plugin_manager.hook_settings_tabs()
|
|
|
|
|
2013-03-19 17:53:32 +00:00
|
|
|
# THEN: The create_media_manager_item() method should have been called with the mocked settings form
|
2017-12-17 17:52:17 +00:00
|
|
|
assert 1 == mocked_plugin.create_settings_tab.call_count, \
|
|
|
|
'The create_media_manager_item() method should have been called once.'
|
|
|
|
assert plugin_manager.plugins == mocked_settings_form.plugin_manager.plugins, \
|
|
|
|
'The plugins on the settings form should be the same as the plugins in the plugin manager'
|
2013-02-27 21:42:21 +00:00
|
|
|
|
2016-05-31 21:40:13 +00:00
|
|
|
def test_hook_settings_tabs_with_active_plugin_and_no_form(self):
|
2013-02-11 13:22:13 +00:00
|
|
|
"""
|
2013-02-27 21:27:32 +00:00
|
|
|
Test running the hook_settings_tabs() method with an active plugin and no settings form
|
2013-02-11 13:22:13 +00:00
|
|
|
"""
|
2013-02-27 21:27:32 +00:00
|
|
|
# GIVEN: A PluginManager instance and a list with a mocked up plugin whose status is set to Active
|
2013-02-11 13:22:13 +00:00
|
|
|
mocked_plugin = MagicMock()
|
2013-02-27 21:27:32 +00:00
|
|
|
mocked_plugin.status = PluginStatus.Active
|
2013-02-17 13:03:59 +00:00
|
|
|
plugin_manager = PluginManager()
|
2018-12-11 20:00:33 +00:00
|
|
|
Registry().register('mock_plugin', mocked_plugin)
|
|
|
|
State().add_service("mock", 1, is_plugin=True, status=PluginStatus.Active)
|
|
|
|
State().flush_preconditions()
|
2018-12-15 08:07:11 +00:00
|
|
|
|
|
|
|
# WHEN: We run hook_settings_tabs()
|
2013-02-19 19:50:14 +00:00
|
|
|
plugin_manager.hook_settings_tabs()
|
2013-02-11 13:22:13 +00:00
|
|
|
|
2013-04-05 19:37:15 +00:00
|
|
|
# THEN: The create_settings_tab() method should have been called
|
|
|
|
mocked_plugin.create_settings_tab.assert_called_with(self.mocked_settings_form)
|
2013-02-27 21:27:32 +00:00
|
|
|
|
2016-05-31 21:40:13 +00:00
|
|
|
def test_hook_import_menu_with_disabled_plugin(self):
|
2013-02-11 13:22:13 +00:00
|
|
|
"""
|
|
|
|
Test running the hook_import_menu() method with a disabled plugin
|
|
|
|
"""
|
|
|
|
# GIVEN: A PluginManager instance and a list with a mocked up plugin whose status is set to Disabled
|
|
|
|
mocked_plugin = MagicMock()
|
|
|
|
mocked_plugin.status = PluginStatus.Disabled
|
2013-02-17 13:03:59 +00:00
|
|
|
plugin_manager = PluginManager()
|
2018-12-11 20:00:33 +00:00
|
|
|
Registry().register('mock_plugin', mocked_plugin)
|
|
|
|
State().add_service("mock", 1, is_plugin=True, status=PluginStatus.Active)
|
|
|
|
State().flush_preconditions()
|
2018-12-15 08:07:11 +00:00
|
|
|
|
|
|
|
# WHEN: We run hook_import_menu()
|
2013-02-19 19:50:14 +00:00
|
|
|
plugin_manager.hook_import_menu()
|
2013-02-11 13:22:13 +00:00
|
|
|
|
2013-03-19 17:53:32 +00:00
|
|
|
# THEN: The create_media_manager_item() method should have been called
|
2017-12-17 17:52:17 +00:00
|
|
|
assert 0 == mocked_plugin.add_import_menu_item.call_count, \
|
|
|
|
'The add_import_menu_item() method should not have been called.'
|
2013-02-11 13:22:13 +00:00
|
|
|
|
2016-05-31 21:40:13 +00:00
|
|
|
def test_hook_import_menu_with_active_plugin(self):
|
2013-02-11 13:22:13 +00:00
|
|
|
"""
|
|
|
|
Test running the hook_import_menu() method with an active plugin
|
|
|
|
"""
|
|
|
|
# GIVEN: A PluginManager instance and a list with a mocked up plugin whose status is set to Active
|
|
|
|
mocked_plugin = MagicMock()
|
|
|
|
mocked_plugin.status = PluginStatus.Active
|
2013-02-17 13:03:59 +00:00
|
|
|
plugin_manager = PluginManager()
|
2018-12-11 20:00:33 +00:00
|
|
|
Registry().register('mock_plugin', mocked_plugin)
|
|
|
|
State().add_service("mock", 1, is_plugin=True, status=PluginStatus.Active)
|
|
|
|
State().flush_preconditions()
|
2018-12-15 08:07:11 +00:00
|
|
|
|
|
|
|
# WHEN: We run hook_import_menu()
|
2013-02-19 19:50:14 +00:00
|
|
|
plugin_manager.hook_import_menu()
|
2013-02-11 13:22:13 +00:00
|
|
|
|
2013-03-19 19:43:22 +00:00
|
|
|
# THEN: The add_import_menu_item() method should have been called
|
|
|
|
mocked_plugin.add_import_menu_item.assert_called_with(self.mocked_main_window.file_import_menu)
|
2013-02-11 13:22:13 +00:00
|
|
|
|
2016-05-31 21:40:13 +00:00
|
|
|
def test_hook_export_menu_with_disabled_plugin(self):
|
2013-02-11 13:22:13 +00:00
|
|
|
"""
|
|
|
|
Test running the hook_export_menu() method with a disabled plugin
|
|
|
|
"""
|
|
|
|
# GIVEN: A PluginManager instance and a list with a mocked up plugin whose status is set to Disabled
|
|
|
|
mocked_plugin = MagicMock()
|
|
|
|
mocked_plugin.status = PluginStatus.Disabled
|
2013-02-17 13:03:59 +00:00
|
|
|
plugin_manager = PluginManager()
|
2018-12-11 20:19:30 +00:00
|
|
|
Registry().register('mock_plugin', mocked_plugin)
|
|
|
|
State().add_service("mock", 1, is_plugin=True, status=PluginStatus.Active)
|
|
|
|
State().flush_preconditions()
|
2018-12-15 08:07:11 +00:00
|
|
|
|
|
|
|
# WHEN: We run hook_export_menu()
|
2013-02-19 19:50:14 +00:00
|
|
|
plugin_manager.hook_export_menu()
|
2013-02-11 13:22:13 +00:00
|
|
|
|
2014-04-12 20:19:22 +00:00
|
|
|
# THEN: The add_export_menu_item() method should not have been called
|
2017-12-17 17:52:17 +00:00
|
|
|
assert 0 == mocked_plugin.add_export_menu_item.call_count, \
|
|
|
|
'The add_export_menu_item() method should not have been called.'
|
2013-02-11 13:22:13 +00:00
|
|
|
|
2016-05-31 21:40:13 +00:00
|
|
|
def test_hook_export_menu_with_active_plugin(self):
|
2013-02-11 13:22:13 +00:00
|
|
|
"""
|
|
|
|
Test running the hook_export_menu() method with an active plugin
|
|
|
|
"""
|
|
|
|
# GIVEN: A PluginManager instance and a list with a mocked up plugin whose status is set to Active
|
|
|
|
mocked_plugin = MagicMock()
|
|
|
|
mocked_plugin.status = PluginStatus.Active
|
2013-02-17 13:03:59 +00:00
|
|
|
plugin_manager = PluginManager()
|
2018-12-11 20:19:30 +00:00
|
|
|
Registry().register('mock_plugin', mocked_plugin)
|
|
|
|
State().add_service("mock", 1, is_plugin=True, status=PluginStatus.Active)
|
|
|
|
State().flush_preconditions()
|
2018-12-15 08:07:11 +00:00
|
|
|
|
|
|
|
# WHEN: We run hook_export_menu()
|
2013-02-19 19:50:14 +00:00
|
|
|
plugin_manager.hook_export_menu()
|
2013-02-11 13:22:13 +00:00
|
|
|
|
2014-04-12 20:19:22 +00:00
|
|
|
# THEN: The add_export_menu_item() method should have been called
|
|
|
|
mocked_plugin.add_export_menu_item.assert_called_with(self.mocked_main_window.file_export_menu)
|
2013-02-11 13:22:13 +00:00
|
|
|
|
2016-05-31 21:40:13 +00:00
|
|
|
def test_hook_upgrade_plugin_settings_with_disabled_plugin(self):
|
2013-03-18 14:35:19 +00:00
|
|
|
"""
|
|
|
|
Test running the hook_upgrade_plugin_settings() method with a disabled plugin
|
|
|
|
"""
|
|
|
|
# GIVEN: A PluginManager instance and a list with a mocked up plugin whose status is set to Disabled
|
|
|
|
mocked_plugin = MagicMock()
|
|
|
|
mocked_plugin.status = PluginStatus.Disabled
|
|
|
|
plugin_manager = PluginManager()
|
2018-12-11 20:19:30 +00:00
|
|
|
Registry().register('mock_plugin', mocked_plugin)
|
2018-12-15 08:07:11 +00:00
|
|
|
State().add_service("mock", 1, is_plugin=True, status=PluginStatus.Active)
|
|
|
|
State().flush_preconditions()
|
2013-03-18 14:35:19 +00:00
|
|
|
settings = Settings()
|
|
|
|
|
|
|
|
# WHEN: We run hook_upgrade_plugin_settings()
|
|
|
|
plugin_manager.hook_upgrade_plugin_settings(settings)
|
|
|
|
|
|
|
|
# THEN: The upgrade_settings() method should not have been called
|
2017-12-17 17:52:17 +00:00
|
|
|
assert 0 == mocked_plugin.upgrade_settings.call_count, \
|
|
|
|
'The upgrade_settings() method should not have been called.'
|
2013-03-18 14:35:19 +00:00
|
|
|
|
2016-05-31 21:40:13 +00:00
|
|
|
def test_hook_upgrade_plugin_settings_with_active_plugin(self):
|
2013-03-18 14:35:19 +00:00
|
|
|
"""
|
|
|
|
Test running the hook_upgrade_plugin_settings() method with an active plugin
|
|
|
|
"""
|
|
|
|
# GIVEN: A PluginManager instance and a list with a mocked up plugin whose status is set to Active
|
|
|
|
mocked_plugin = MagicMock()
|
|
|
|
mocked_plugin.status = PluginStatus.Active
|
|
|
|
plugin_manager = PluginManager()
|
2018-12-11 20:19:30 +00:00
|
|
|
Registry().register('mock_plugin', mocked_plugin)
|
2018-12-15 08:07:11 +00:00
|
|
|
State().add_service("mock", 1, is_plugin=True, status=PluginStatus.Active)
|
|
|
|
State().flush_preconditions()
|
2013-03-18 14:35:19 +00:00
|
|
|
settings = Settings()
|
|
|
|
|
|
|
|
# WHEN: We run hook_upgrade_plugin_settings()
|
|
|
|
plugin_manager.hook_upgrade_plugin_settings(settings)
|
|
|
|
|
2014-04-12 20:19:22 +00:00
|
|
|
# THEN: The add_export_menu_item() method should have been called
|
2013-03-18 14:35:19 +00:00
|
|
|
mocked_plugin.upgrade_settings.assert_called_with(settings)
|
|
|
|
|
2016-05-31 21:40:13 +00:00
|
|
|
def test_hook_tools_menu_with_disabled_plugin(self):
|
2013-02-11 13:22:13 +00:00
|
|
|
"""
|
|
|
|
Test running the hook_tools_menu() method with a disabled plugin
|
|
|
|
"""
|
|
|
|
# GIVEN: A PluginManager instance and a list with a mocked up plugin whose status is set to Disabled
|
|
|
|
mocked_plugin = MagicMock()
|
|
|
|
mocked_plugin.status = PluginStatus.Disabled
|
2013-02-17 13:03:59 +00:00
|
|
|
plugin_manager = PluginManager()
|
2018-12-11 20:19:30 +00:00
|
|
|
Registry().register('mock_plugin', mocked_plugin)
|
|
|
|
State().add_service("mock", 1, is_plugin=True, status=PluginStatus.Active)
|
|
|
|
State().flush_preconditions()
|
2018-12-15 08:07:11 +00:00
|
|
|
|
|
|
|
# WHEN: We run hook_tools_menu()
|
2013-02-19 19:50:14 +00:00
|
|
|
plugin_manager.hook_tools_menu()
|
2013-02-11 13:22:13 +00:00
|
|
|
|
2013-03-19 19:43:22 +00:00
|
|
|
# THEN: The add_tools_menu_item() method should have been called
|
2017-12-17 17:52:17 +00:00
|
|
|
assert 0 == mocked_plugin.add_tools_menu_item.call_count, \
|
|
|
|
'The add_tools_menu_item() method should not have been called.'
|
2013-02-11 13:22:13 +00:00
|
|
|
|
2016-05-31 21:40:13 +00:00
|
|
|
def test_hook_tools_menu_with_active_plugin(self):
|
2013-02-11 13:22:13 +00:00
|
|
|
"""
|
|
|
|
Test running the hook_tools_menu() method with an active plugin
|
|
|
|
"""
|
|
|
|
# GIVEN: A PluginManager instance and a list with a mocked up plugin whose status is set to Active
|
|
|
|
mocked_plugin = MagicMock()
|
|
|
|
mocked_plugin.status = PluginStatus.Active
|
2013-02-17 13:03:59 +00:00
|
|
|
plugin_manager = PluginManager()
|
2018-12-11 20:19:30 +00:00
|
|
|
Registry().register('mock_plugin', mocked_plugin)
|
|
|
|
State().add_service("mock", 1, is_plugin=True, status=PluginStatus.Active)
|
|
|
|
State().flush_preconditions()
|
2018-12-15 08:07:11 +00:00
|
|
|
|
|
|
|
# WHEN: We run hook_tools_menu()
|
2013-02-19 19:50:14 +00:00
|
|
|
plugin_manager.hook_tools_menu()
|
2013-02-11 13:22:13 +00:00
|
|
|
|
2013-03-19 19:43:22 +00:00
|
|
|
# THEN: The add_tools_menu_item() method should have been called
|
|
|
|
mocked_plugin.add_tools_menu_item.assert_called_with(self.mocked_main_window.tools_menu)
|
2013-02-11 13:22:13 +00:00
|
|
|
|
2016-05-31 21:40:13 +00:00
|
|
|
def test_initialise_plugins_with_disabled_plugin(self):
|
2013-02-11 13:22:13 +00:00
|
|
|
"""
|
|
|
|
Test running the initialise_plugins() method with a disabled plugin
|
|
|
|
"""
|
|
|
|
# GIVEN: A PluginManager instance and a list with a mocked up plugin whose status is set to Disabled
|
|
|
|
mocked_plugin = MagicMock()
|
|
|
|
mocked_plugin.status = PluginStatus.Disabled
|
2013-03-19 17:53:32 +00:00
|
|
|
mocked_plugin.is_active.return_value = False
|
2013-02-17 13:03:59 +00:00
|
|
|
plugin_manager = PluginManager()
|
2018-12-11 20:19:30 +00:00
|
|
|
Registry().register('mock_plugin', mocked_plugin)
|
|
|
|
State().add_service("mock", 1, is_plugin=True, status=PluginStatus.Active)
|
|
|
|
State().flush_preconditions()
|
2018-12-15 08:07:11 +00:00
|
|
|
|
|
|
|
# WHEN: We run initialise_plugins()
|
2013-02-11 13:22:13 +00:00
|
|
|
plugin_manager.initialise_plugins()
|
|
|
|
|
2013-03-19 17:53:32 +00:00
|
|
|
# THEN: The is_active() method should have been called, and initialise() method should NOT have been called
|
|
|
|
mocked_plugin.is_active.assert_called_with()
|
2017-12-17 17:52:17 +00:00
|
|
|
assert 0 == mocked_plugin.initialise.call_count, 'The initialise() method should not have been called.'
|
2013-02-11 13:22:13 +00:00
|
|
|
|
2016-05-31 21:40:13 +00:00
|
|
|
def test_initialise_plugins_with_active_plugin(self):
|
2013-02-11 13:22:13 +00:00
|
|
|
"""
|
|
|
|
Test running the initialise_plugins() method with an active plugin
|
|
|
|
"""
|
|
|
|
# GIVEN: A PluginManager instance and a list with a mocked up plugin whose status is set to Active
|
|
|
|
mocked_plugin = MagicMock()
|
|
|
|
mocked_plugin.status = PluginStatus.Active
|
2013-03-19 17:53:32 +00:00
|
|
|
mocked_plugin.is_active.return_value = True
|
2013-02-17 13:03:59 +00:00
|
|
|
plugin_manager = PluginManager()
|
2018-12-11 20:19:30 +00:00
|
|
|
Registry().register('mock_plugin', mocked_plugin)
|
|
|
|
State().add_service("mock", 1, is_plugin=True, status=PluginStatus.Active)
|
|
|
|
State().flush_preconditions()
|
2018-12-15 08:07:11 +00:00
|
|
|
|
|
|
|
# WHEN: We run initialise_plugins()
|
2013-02-11 13:22:13 +00:00
|
|
|
plugin_manager.initialise_plugins()
|
|
|
|
|
2013-03-19 17:53:32 +00:00
|
|
|
# THEN: The is_active() and initialise() methods should have been called
|
|
|
|
mocked_plugin.is_active.assert_called_with()
|
2013-02-11 13:22:13 +00:00
|
|
|
mocked_plugin.initialise.assert_called_with()
|
|
|
|
|
2016-05-31 21:40:13 +00:00
|
|
|
def test_finalise_plugins_with_disabled_plugin(self):
|
2013-02-11 13:22:13 +00:00
|
|
|
"""
|
|
|
|
Test running the finalise_plugins() method with a disabled plugin
|
|
|
|
"""
|
|
|
|
# GIVEN: A PluginManager instance and a list with a mocked up plugin whose status is set to Disabled
|
|
|
|
mocked_plugin = MagicMock()
|
|
|
|
mocked_plugin.status = PluginStatus.Disabled
|
2013-03-19 17:53:32 +00:00
|
|
|
mocked_plugin.is_active.return_value = False
|
2013-02-17 13:03:59 +00:00
|
|
|
plugin_manager = PluginManager()
|
2018-12-11 19:35:35 +00:00
|
|
|
Registry().register('mock_plugin', mocked_plugin)
|
|
|
|
State().add_service("mock", 1, is_plugin=True, status=PluginStatus.Active)
|
|
|
|
State().flush_preconditions()
|
2018-12-15 08:07:11 +00:00
|
|
|
|
|
|
|
# WHEN: We run finalise_plugins()
|
2013-02-11 13:22:13 +00:00
|
|
|
plugin_manager.finalise_plugins()
|
|
|
|
|
2013-03-19 17:53:32 +00:00
|
|
|
# THEN: The is_active() method should have been called, and initialise() method should NOT have been called
|
|
|
|
mocked_plugin.is_active.assert_called_with()
|
2017-12-17 17:52:17 +00:00
|
|
|
assert 0 == mocked_plugin.finalise.call_count, 'The finalise() method should not have been called.'
|
2013-02-11 13:22:13 +00:00
|
|
|
|
2016-05-31 21:40:13 +00:00
|
|
|
def test_finalise_plugins_with_active_plugin(self):
|
2013-02-11 13:22:13 +00:00
|
|
|
"""
|
|
|
|
Test running the finalise_plugins() method with an active plugin
|
|
|
|
"""
|
|
|
|
# GIVEN: A PluginManager instance and a list with a mocked up plugin whose status is set to Active
|
|
|
|
mocked_plugin = MagicMock()
|
|
|
|
mocked_plugin.status = PluginStatus.Active
|
2013-03-19 17:53:32 +00:00
|
|
|
mocked_plugin.is_active.return_value = True
|
2013-02-17 13:03:59 +00:00
|
|
|
plugin_manager = PluginManager()
|
2018-12-11 19:35:35 +00:00
|
|
|
Registry().register('mock_plugin', mocked_plugin)
|
|
|
|
State().add_service("mock", 1, is_plugin=True, status=PluginStatus.Active)
|
|
|
|
State().flush_preconditions()
|
2018-12-15 08:07:11 +00:00
|
|
|
|
|
|
|
# WHEN: We run finalise_plugins()
|
2013-02-11 13:22:13 +00:00
|
|
|
plugin_manager.finalise_plugins()
|
|
|
|
|
2013-03-19 17:53:32 +00:00
|
|
|
# THEN: The is_active() and finalise() methods should have been called
|
|
|
|
mocked_plugin.is_active.assert_called_with()
|
2013-02-11 13:22:13 +00:00
|
|
|
mocked_plugin.finalise.assert_called_with()
|
|
|
|
|
2016-05-31 21:40:13 +00:00
|
|
|
def test_get_plugin_by_name_does_not_exist(self):
|
2013-02-11 13:22:13 +00:00
|
|
|
"""
|
|
|
|
Test running the get_plugin_by_name() method to find a plugin that does not exist
|
|
|
|
"""
|
|
|
|
# GIVEN: A PluginManager instance and a list with a mocked up plugin whose status is set to Active
|
|
|
|
mocked_plugin = MagicMock()
|
|
|
|
mocked_plugin.name = 'Mocked Plugin'
|
2013-02-17 13:03:59 +00:00
|
|
|
plugin_manager = PluginManager()
|
2018-12-11 20:39:56 +00:00
|
|
|
Registry().register('mock_plugin', mocked_plugin)
|
|
|
|
State().add_service("mock", 1, is_plugin=True, status=PluginStatus.Active)
|
|
|
|
State().flush_preconditions()
|
2013-02-11 13:22:13 +00:00
|
|
|
|
|
|
|
# WHEN: We run finalise_plugins()
|
|
|
|
result = plugin_manager.get_plugin_by_name('Missing Plugin')
|
|
|
|
|
2013-03-19 17:53:32 +00:00
|
|
|
# THEN: The is_active() and finalise() methods should have been called
|
2017-12-17 17:52:17 +00:00
|
|
|
assert result is None, 'The result for get_plugin_by_name should be None'
|
2013-02-11 13:22:13 +00:00
|
|
|
|
2016-05-31 21:40:13 +00:00
|
|
|
def test_get_plugin_by_name_exists(self):
|
2013-02-11 13:22:13 +00:00
|
|
|
"""
|
|
|
|
Test running the get_plugin_by_name() method to find a plugin that exists
|
|
|
|
"""
|
|
|
|
# GIVEN: A PluginManager instance and a list with a mocked up plugin whose status is set to Active
|
|
|
|
mocked_plugin = MagicMock()
|
|
|
|
mocked_plugin.name = 'Mocked Plugin'
|
2013-02-17 13:03:59 +00:00
|
|
|
plugin_manager = PluginManager()
|
2018-12-11 19:45:27 +00:00
|
|
|
Registry().register('mock_plugin', mocked_plugin)
|
|
|
|
State().add_service("mock", 1, is_plugin=True, status=PluginStatus.Active)
|
|
|
|
State().flush_preconditions()
|
2018-12-11 20:52:17 +00:00
|
|
|
|
|
|
|
# WHEN: We run finalise_plugins()
|
2013-02-11 13:22:13 +00:00
|
|
|
result = plugin_manager.get_plugin_by_name('Mocked Plugin')
|
|
|
|
|
2013-03-19 17:53:32 +00:00
|
|
|
# THEN: The is_active() and finalise() methods should have been called
|
2017-12-17 17:52:17 +00:00
|
|
|
assert result == mocked_plugin, 'The result for get_plugin_by_name should be the mocked plugin'
|
2013-02-11 13:22:13 +00:00
|
|
|
|
2016-05-31 21:40:13 +00:00
|
|
|
def test_new_service_created_with_disabled_plugin(self):
|
2013-02-11 13:22:13 +00:00
|
|
|
"""
|
|
|
|
Test running the new_service_created() method with a disabled plugin
|
|
|
|
"""
|
|
|
|
# GIVEN: A PluginManager instance and a list with a mocked up plugin whose status is set to Disabled
|
|
|
|
mocked_plugin = MagicMock()
|
|
|
|
mocked_plugin.status = PluginStatus.Disabled
|
2013-03-19 17:53:32 +00:00
|
|
|
mocked_plugin.is_active.return_value = False
|
2013-02-17 13:03:59 +00:00
|
|
|
plugin_manager = PluginManager()
|
2018-12-11 20:52:17 +00:00
|
|
|
Registry().register('mock_plugin', mocked_plugin)
|
|
|
|
State().add_service("mock", 1, is_plugin=True, status=PluginStatus.Active)
|
|
|
|
State().flush_preconditions()
|
2013-02-11 13:22:13 +00:00
|
|
|
|
|
|
|
# WHEN: We run finalise_plugins()
|
|
|
|
plugin_manager.new_service_created()
|
|
|
|
|
|
|
|
# THEN: The isActive() method should have been called, and initialise() method should NOT have been called
|
2013-03-19 17:53:32 +00:00
|
|
|
mocked_plugin.is_active.assert_called_with()
|
2017-12-17 17:52:17 +00:00
|
|
|
assert 0 == mocked_plugin.new_service_created.call_count, \
|
|
|
|
'The new_service_created() method should not have been called.'
|
2013-02-11 13:22:13 +00:00
|
|
|
|
2016-05-31 21:40:13 +00:00
|
|
|
def test_new_service_created_with_active_plugin(self):
|
2013-02-11 13:22:13 +00:00
|
|
|
"""
|
|
|
|
Test running the new_service_created() method with an active plugin
|
|
|
|
"""
|
|
|
|
# GIVEN: A PluginManager instance and a list with a mocked up plugin whose status is set to Active
|
|
|
|
mocked_plugin = MagicMock()
|
|
|
|
mocked_plugin.status = PluginStatus.Active
|
2013-03-19 17:53:32 +00:00
|
|
|
mocked_plugin.is_active.return_value = True
|
2013-02-17 13:03:59 +00:00
|
|
|
plugin_manager = PluginManager()
|
2018-12-11 20:52:17 +00:00
|
|
|
Registry().register('mock_plugin', mocked_plugin)
|
|
|
|
State().add_service("mock", 1, is_plugin=True, status=PluginStatus.Active)
|
|
|
|
State().flush_preconditions()
|
2013-02-11 13:22:13 +00:00
|
|
|
|
|
|
|
# WHEN: We run new_service_created()
|
|
|
|
plugin_manager.new_service_created()
|
|
|
|
|
2013-03-19 17:53:32 +00:00
|
|
|
# THEN: The is_active() and finalise() methods should have been called
|
|
|
|
mocked_plugin.is_active.assert_called_with()
|
2013-02-11 13:22:13 +00:00
|
|
|
mocked_plugin.new_service_created.assert_called_with()
|