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 #
|
|
|
|
# --------------------------------------------------------------------------- #
|
2014-12-31 10:58:13 +00:00
|
|
|
# Copyright (c) 2008-2015 Raoul Snyman #
|
|
|
|
# Portions copyright (c) 2008-2015 Tim Bentley, Gerald Britton, Jonathan #
|
2014-03-14 22:08:44 +00:00
|
|
|
# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
|
|
|
|
# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
|
|
|
|
# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
|
|
|
|
# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
|
|
|
|
# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, #
|
|
|
|
# Frode Woldsund, Martin Zibricky, Patrick Zimmermann #
|
|
|
|
# --------------------------------------------------------------------------- #
|
|
|
|
# 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 21:16:30 +00:00
|
|
|
"""
|
|
|
|
Package to test the openlp.core.lib.pluginmanager package.
|
|
|
|
"""
|
|
|
|
import sys
|
2013-03-07 12:34:35 +00:00
|
|
|
import shutil
|
2014-03-24 16:49:50 +00:00
|
|
|
import gc
|
2014-03-14 22:08:44 +00:00
|
|
|
from tempfile import mkdtemp
|
2013-02-11 21:16:30 +00:00
|
|
|
from unittest import TestCase
|
|
|
|
|
2014-03-14 22:08:44 +00:00
|
|
|
from PyQt4 import QtGui
|
2013-02-11 21:16:30 +00:00
|
|
|
|
2013-12-13 17:44:05 +00:00
|
|
|
from openlp.core.common import Registry, Settings
|
2013-02-11 21:16:30 +00:00
|
|
|
from openlp.core.lib.pluginmanager import PluginManager
|
2013-10-04 21:45:38 +00:00
|
|
|
from tests.interfaces import MagicMock
|
2014-03-14 22:08:44 +00:00
|
|
|
from tests.helpers.testmixin import TestMixin
|
2013-02-11 21:16:30 +00:00
|
|
|
|
|
|
|
|
2014-03-14 22:08:44 +00:00
|
|
|
class TestPluginManager(TestCase, TestMixin):
|
2013-02-11 21:16:30 +00:00
|
|
|
"""
|
|
|
|
Test the PluginManager class
|
|
|
|
"""
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
"""
|
|
|
|
Some pre-test setup required.
|
|
|
|
"""
|
2014-03-12 05:31:19 +00:00
|
|
|
Settings.setDefaultFormat(Settings.IniFormat)
|
2014-03-14 22:08:44 +00:00
|
|
|
self.build_settings()
|
2013-08-31 18:17:38 +00:00
|
|
|
self.temp_dir = mkdtemp('openlp')
|
|
|
|
Settings().setValue('advanced/data path', self.temp_dir)
|
2013-02-11 21:16:30 +00:00
|
|
|
Registry.create()
|
2013-08-31 18:17:38 +00:00
|
|
|
Registry().register('service_list', MagicMock())
|
2014-10-22 20:43:05 +00:00
|
|
|
self.setup_application()
|
2013-02-11 21:16:30 +00:00
|
|
|
self.main_window = QtGui.QMainWindow()
|
2013-08-31 18:17:38 +00:00
|
|
|
Registry().register('main_window', self.main_window)
|
2013-02-11 21:16:30 +00:00
|
|
|
|
|
|
|
def tearDown(self):
|
2013-02-17 07:54:43 +00:00
|
|
|
del self.main_window
|
2013-08-31 18:17:38 +00:00
|
|
|
Settings().remove('advanced/data path')
|
2014-03-14 22:08:44 +00:00
|
|
|
self.destroy_settings()
|
2014-03-24 16:49:50 +00:00
|
|
|
# On windows we need to manually garbage collect to close sqlalchemy files
|
|
|
|
# to avoid errors when temporary files are deleted.
|
|
|
|
gc.collect()
|
2013-03-07 12:34:35 +00:00
|
|
|
shutil.rmtree(self.temp_dir)
|
2013-02-11 21:16:30 +00:00
|
|
|
|
|
|
|
def find_plugins_test(self):
|
|
|
|
"""
|
2013-03-11 21:10:29 +00:00
|
|
|
Test the find_plugins() method to ensure it imports the correct plugins
|
2013-02-11 21:16:30 +00:00
|
|
|
"""
|
|
|
|
# GIVEN: A plugin manager
|
2013-02-18 11:09:09 +00:00
|
|
|
plugin_manager = PluginManager()
|
2013-02-11 21:16:30 +00:00
|
|
|
|
|
|
|
# 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'
|
2013-02-11 21:16:30 +00:00
|
|
|
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]
|
2013-08-31 18:17:38 +00:00
|
|
|
assert 'songs' in plugin_names, 'There should be a "songs" plugin.'
|
|
|
|
assert 'bibles' in plugin_names, 'There should be a "bibles" plugin.'
|
2014-05-30 09:21:26 +00:00
|
|
|
assert 'presentations' in plugin_names, 'There should be a "presentations" plugin.'
|
2013-08-31 18:17:38 +00:00
|
|
|
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.'
|
|
|
|
assert 'alerts' in plugin_names, 'There should be a "alerts" plugin.'
|
|
|
|
assert 'remotes' in plugin_names, 'There should be a "remotes" plugin.'
|