openlp/tests/interfaces/openlp_core/lib/test_pluginmanager.py

100 lines
4.4 KiB
Python
Raw Normal View History

2014-03-14 22:08:44 +00:00
# -*- coding: utf-8 -*-
2019-04-13 13:00:22 +00:00
##########################################################################
# OpenLP - Open Source Lyrics Projection #
# ---------------------------------------------------------------------- #
# Copyright (c) 2008-2020 OpenLP Developers #
2019-04-13 13:00:22 +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, either version 3 of the License, or #
# (at your option) any later version. #
# #
# 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, see <https://www.gnu.org/licenses/>. #
##########################################################################
"""
Package to test the openlp.core.lib.pluginmanager package.
"""
import shutil
2017-12-28 08:27:44 +00:00
import sys
from pathlib import Path
2014-03-14 22:08:44 +00:00
from tempfile import mkdtemp
2019-01-04 18:21:38 +00:00
from unittest import TestCase, skip
from unittest.mock import MagicMock, patch
2015-11-07 00:49:40 +00:00
from PyQt5 import QtWidgets
2019-01-03 21:00:21 +00:00
from openlp.core.common import is_win
2017-10-07 07:05:07 +00:00
from openlp.core.common.registry import Registry
from openlp.core.common.settings import Settings
2019-01-03 21:12:53 +00:00
from openlp.core.state import State
from openlp.core.lib.pluginmanager import PluginManager
2014-03-14 22:08:44 +00:00
from tests.helpers.testmixin import TestMixin
2014-03-14 22:08:44 +00:00
class TestPluginManager(TestCase, TestMixin):
"""
Test the PluginManager class
"""
def setUp(self):
"""
Some pre-test setup required.
"""
2016-03-12 21:23:06 +00:00
self.setup_application()
2014-03-14 22:08:44 +00:00
self.build_settings()
2017-11-18 11:23:15 +00:00
self.temp_dir_path = Path(mkdtemp('openlp'))
Settings().setValue('advanced/data path', self.temp_dir_path)
Registry.create()
2013-08-31 18:17:38 +00:00
Registry().register('service_list', MagicMock())
2015-11-07 00:49:40 +00:00
self.main_window = QtWidgets.QMainWindow()
2013-08-31 18:17:38 +00:00
Registry().register('main_window', self.main_window)
def tearDown(self):
2013-08-31 18:17:38 +00:00
Settings().remove('advanced/data path')
2014-03-14 22:08:44 +00:00
self.destroy_settings()
del self.main_window
# On windows we need to manually garbage collect to close sqlalchemy files
# to avoid errors when temporary files are deleted.
2019-01-03 21:00:21 +00:00
if is_win():
import gc
gc.collect()
shutil.rmtree(self.temp_dir_path)
2019-01-04 18:21:38 +00:00
@skip
# This test is broken but totally unable to debug it.
2019-01-03 21:37:26 +00:00
@patch('openlp.plugins.songusage.songusageplugin.Manager')
2019-01-03 21:43:16 +00:00
@patch('openlp.plugins.songs.songsplugin.Manager')
2019-01-03 21:57:38 +00:00
@patch('openlp.plugins.images.imageplugin.Manager')
2019-01-03 21:43:16 +00:00
@patch('openlp.plugins.custom.customplugin.Manager')
@patch('openlp.plugins.alerts.alertsplugin.Manager')
2019-01-03 21:53:34 +00:00
def test_find_plugins(self, mocked_is1, mocked_is2, mocked_is3, mocked_is4, mocked_is5):
"""
Test the find_plugins() method to ensure it imports the correct plugins
"""
# GIVEN: A plugin manager
2013-02-18 11:09:09 +00:00
plugin_manager = PluginManager()
2019-01-03 21:21:41 +00:00
plugin_manager.bootstrap_initialise()
# WHEN: We mock out sys.platform to make it return "darwin" and then find the plugins
old_platform = sys.platform
2013-08-31 18:17:38 +00:00
sys.platform = 'darwin'
sys.platform = old_platform
# THEN: We should find the "Songs", "Bibles", etc in the plugins list
2019-01-03 21:12:53 +00:00
plugin_names = [plugin.name for plugin in State().list_plugins()]
2017-12-23 09:22:53 +00:00
assert 'songs' in plugin_names, 'There should be a "songs" plugin'
assert 'bibles' in plugin_names, 'There should be a "bibles" plugin'
assert 'presentations' in plugin_names, 'There should be a "presentations" plugin'
assert 'images' in plugin_names, 'There should be a "images" plugin'
assert 'media' in plugin_names, 'There should be a "media" plugin'
assert 'custom' in plugin_names, 'There should be a "custom" plugin'
assert 'songusage' in plugin_names, 'There should be a "songusage" plugin'
2017-12-23 09:22:53 +00:00
assert 'alerts' in plugin_names, 'There should be a "alerts" plugin'