openlp/tests/interfaces/openlp_core_lib/test_pluginmanager.py

97 lines
4.4 KiB
Python
Raw Normal View History

2014-03-14 22:08:44 +00:00
# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
2016-12-31 11:01:36 +00:00
# Copyright (c) 2008-2017 OpenLP Developers #
2014-03-14 22:08:44 +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 #
###############################################################################
"""
Package to test the openlp.core.lib.pluginmanager package.
"""
import sys
2013-03-07 12:34:35 +00:00
import shutil
import gc
2014-03-14 22:08:44 +00:00
from tempfile import mkdtemp
from unittest import TestCase
from unittest.mock import MagicMock, patch
2015-11-07 00:49:40 +00:00
from PyQt5 import QtWidgets
2013-12-13 17:44:05 +00:00
from openlp.core.common import Registry, Settings
from openlp.core.common.path import Path
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()
self.temp_dir = Path(mkdtemp('openlp'))
2013-08-31 18:17:38 +00:00
Settings().setValue('advanced/data path', self.temp_dir)
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.
gc.collect()
shutil.rmtree(str(self.temp_dir))
2016-03-12 21:23:06 +00:00
@patch('openlp.plugins.songusage.lib.db.init_schema')
@patch('openlp.plugins.songs.lib.db.init_schema')
@patch('openlp.plugins.images.lib.db.init_schema')
@patch('openlp.plugins.custom.lib.db.init_schema')
@patch('openlp.plugins.alerts.lib.db.init_schema')
@patch('openlp.plugins.bibles.lib.db.init_schema')
2016-05-31 21:40:13 +00:00
def test_find_plugins(self, mocked_is1, mocked_is2, mocked_is3, mocked_is4, mocked_is5, mocked_is6):
"""
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()
# 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'
plugin_manager.find_plugins()
sys.platform = old_platform
# THEN: We should find the "Songs", "Bibles", etc in the plugins list
plugin_names = [plugin.name for plugin in plugin_manager.plugins]
2014-11-24 21:18:32 +00:00
self.assertIn('songs', plugin_names, 'There should be a "songs" plugin')
self.assertIn('bibles', plugin_names, 'There should be a "bibles" plugin')
self.assertIn('presentations', plugin_names, 'There should be a "presentations" plugin')
self.assertIn('images', plugin_names, 'There should be a "images" plugin')
self.assertIn('media', plugin_names, 'There should be a "media" plugin')
self.assertIn('custom', plugin_names, 'There should be a "custom" plugin')
self.assertIn('songusage', plugin_names, 'There should be a "songusage" plugin')
self.assertIn('alerts', plugin_names, 'There should be a "alerts" plugin')