2013-02-11 21:16:30 +00:00
|
|
|
"""
|
|
|
|
Package to test the openlp.core.lib.pluginmanager package.
|
|
|
|
"""
|
|
|
|
import os
|
|
|
|
import sys
|
2013-03-07 12:34:35 +00:00
|
|
|
import shutil
|
|
|
|
from tempfile import mkstemp, mkdtemp
|
2013-02-11 21:16:30 +00:00
|
|
|
from unittest import TestCase
|
|
|
|
|
|
|
|
from PyQt4 import QtGui
|
|
|
|
|
2013-10-13 20:36:42 +00:00
|
|
|
from openlp.core.common import Settings
|
2013-02-11 21:16:30 +00:00
|
|
|
from openlp.core.lib.pluginmanager import PluginManager
|
2013-10-13 20:36:42 +00:00
|
|
|
from openlp.core.lib import Registry
|
2013-10-04 21:45:38 +00:00
|
|
|
from tests.interfaces import MagicMock
|
2013-02-11 21:16:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestPluginManager(TestCase):
|
|
|
|
"""
|
|
|
|
Test the PluginManager class
|
|
|
|
"""
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
"""
|
|
|
|
Some pre-test setup required.
|
|
|
|
"""
|
2013-08-31 18:17:38 +00:00
|
|
|
fd, self.ini_file = mkstemp('.ini')
|
|
|
|
self.temp_dir = mkdtemp('openlp')
|
2013-02-11 21:16:30 +00:00
|
|
|
Settings().set_filename(self.ini_file)
|
2013-08-31 18:17:38 +00:00
|
|
|
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())
|
2013-03-14 22:22:18 +00:00
|
|
|
self.app = QtGui.QApplication([])
|
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-16 18:06:23 +00:00
|
|
|
del self.app
|
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')
|
2013-03-07 12:34:35 +00:00
|
|
|
shutil.rmtree(self.temp_dir)
|
|
|
|
os.unlink(self.ini_file)
|
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.'
|
|
|
|
assert 'presentations' not in plugin_names, 'There should NOT 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.'
|
|
|
|
assert 'alerts' in plugin_names, 'There should be a "alerts" plugin.'
|
|
|
|
assert 'remotes' in plugin_names, 'There should be a "remotes" plugin.'
|