2013-03-10 20:19:42 +00:00
|
|
|
"""
|
|
|
|
Package to test the openlp.core.lib.settingsform package.
|
|
|
|
"""
|
|
|
|
from unittest import TestCase
|
|
|
|
|
|
|
|
from mock import MagicMock, patch
|
|
|
|
|
2013-03-18 11:58:52 +00:00
|
|
|
from PyQt4 import QtCore, QtTest, QtGui
|
2013-03-10 20:19:42 +00:00
|
|
|
|
|
|
|
from openlp.core.ui import settingsform
|
|
|
|
from openlp.core.lib import Registry, ScreenList
|
|
|
|
|
|
|
|
|
|
|
|
SCREEN = {
|
|
|
|
u'primary': False,
|
|
|
|
u'number': 1,
|
|
|
|
u'size': QtCore.QRect(0, 0, 1024, 768)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class TestSettingsForm(TestCase):
|
|
|
|
"""
|
|
|
|
Test the PluginManager class
|
|
|
|
"""
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
"""
|
|
|
|
Some pre-test setup required.
|
|
|
|
"""
|
2013-03-17 20:20:43 +00:00
|
|
|
self.dummy1 = MagicMock()
|
|
|
|
self.dummy2 = MagicMock()
|
|
|
|
self.dummy3 = MagicMock()
|
2013-03-10 20:19:42 +00:00
|
|
|
self.desktop = MagicMock()
|
2013-03-18 11:58:52 +00:00
|
|
|
self.app = QtGui.QApplication([])
|
2013-03-10 20:19:42 +00:00
|
|
|
self.desktop.primaryScreen.return_value = SCREEN[u'primary']
|
|
|
|
self.desktop.screenCount.return_value = SCREEN[u'number']
|
|
|
|
self.desktop.screenGeometry.return_value = SCREEN[u'size']
|
|
|
|
self.screens = ScreenList.create(self.desktop)
|
|
|
|
Registry.create()
|
|
|
|
self.form = settingsform.SettingsForm()
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
"""
|
|
|
|
Delete all the C++ objects at the end so that we don't have a segfault
|
|
|
|
"""
|
|
|
|
del self.form
|
2013-03-18 11:58:52 +00:00
|
|
|
del self.app
|
2013-03-10 20:19:42 +00:00
|
|
|
|
|
|
|
def basic_cancel_test(self):
|
|
|
|
"""
|
|
|
|
Test running the settings form and pressing Cancel
|
|
|
|
"""
|
|
|
|
# GIVEN: An initial form
|
|
|
|
|
|
|
|
# WHEN displaying the UI and pressing cancel
|
|
|
|
with patch(u'PyQt4.QtGui.QDialog.reject') as mocked_reject:
|
2013-03-12 09:37:27 +00:00
|
|
|
cancel_widget = self.form.button_box.button(self.form.button_box.Cancel)
|
|
|
|
QtTest.QTest.mouseClick(cancel_widget, QtCore.Qt.LeftButton)
|
2013-03-10 20:19:42 +00:00
|
|
|
|
|
|
|
# THEN the dialog reject should have been called
|
|
|
|
assert mocked_reject.call_count == 1, u'The QDialog.reject should have been called'
|
|
|
|
|
|
|
|
def basic_accept_test(self):
|
|
|
|
"""
|
|
|
|
Test running the settings form and pressing Ok
|
|
|
|
"""
|
|
|
|
# GIVEN: An initial form
|
|
|
|
|
|
|
|
# WHEN displaying the UI and pressing Ok
|
|
|
|
with patch(u'PyQt4.QtGui.QDialog.accept') as mocked_accept:
|
2013-03-12 09:37:27 +00:00
|
|
|
ok_widget = self.form.button_box.button(self.form.button_box.Ok)
|
|
|
|
QtTest.QTest.mouseClick(ok_widget, QtCore.Qt.LeftButton)
|
2013-03-10 20:19:42 +00:00
|
|
|
|
|
|
|
# THEN the dialog reject should have been called
|
|
|
|
assert mocked_accept.call_count == 1, u'The QDialog.accept should have been called'
|
|
|
|
|
|
|
|
def basic_register_test(self):
|
|
|
|
"""
|
|
|
|
Test running the settings form and adding a single function
|
|
|
|
"""
|
|
|
|
# GIVEN: An initial form add a register function
|
|
|
|
self.form.register_post_process(u'function1')
|
|
|
|
|
|
|
|
# WHEN displaying the UI and pressing Ok
|
|
|
|
with patch(u'PyQt4.QtGui.QDialog.accept'):
|
2013-03-12 09:37:27 +00:00
|
|
|
ok_widget = self.form.button_box.button(self.form.button_box.Ok)
|
|
|
|
QtTest.QTest.mouseClick(ok_widget, QtCore.Qt.LeftButton)
|
2013-03-10 20:19:42 +00:00
|
|
|
|
|
|
|
# THEN the processing stack should be empty
|
2013-03-12 09:09:42 +00:00
|
|
|
assert len(self.form.processes) == 0, u'The one requested process should have been removed from the stack'
|
2013-03-10 20:19:42 +00:00
|
|
|
|
|
|
|
def register_multiple_functions_test(self):
|
|
|
|
"""
|
|
|
|
Test running the settings form and adding multiple functions
|
|
|
|
"""
|
|
|
|
# GIVEN: Registering a single function
|
|
|
|
self.form.register_post_process(u'function1')
|
|
|
|
|
|
|
|
# WHEN testing the processing stack
|
|
|
|
# THEN the processing stack should have one item
|
2013-03-12 07:17:14 +00:00
|
|
|
assert len(self.form.processes) == 1, u'The one requested process should have been added to the stack'
|
2013-03-10 20:19:42 +00:00
|
|
|
|
|
|
|
# GIVEN: Registering a new function
|
|
|
|
self.form.register_post_process(u'function2')
|
|
|
|
|
|
|
|
# WHEN testing the processing stack
|
|
|
|
# THEN the processing stack should have two items
|
2013-03-12 07:17:14 +00:00
|
|
|
assert len(self.form.processes) == 2, u'The two requested processes should have been added to the stack'
|
2013-03-10 20:19:42 +00:00
|
|
|
|
|
|
|
# GIVEN: Registering a process for the second time
|
|
|
|
self.form.register_post_process(u'function1')
|
|
|
|
|
|
|
|
# WHEN testing the processing stack
|
|
|
|
# THEN the processing stack should still have two items
|
2013-03-12 07:17:14 +00:00
|
|
|
assert len(self.form.processes) == 2, u'No new processes should have been added to the stack'
|
2013-03-17 17:37:19 +00:00
|
|
|
|
2013-03-17 20:20:43 +00:00
|
|
|
def register_image_manager_trigger_test_one(self):
|
2013-03-17 17:37:19 +00:00
|
|
|
"""
|
2013-03-17 20:20:43 +00:00
|
|
|
Test the triggering of the image manager rebuild event from image background change
|
2013-03-17 17:37:19 +00:00
|
|
|
"""
|
|
|
|
# GIVEN: Three functions registered to be call
|
2013-03-17 20:20:43 +00:00
|
|
|
Registry().register_function(u'images_config_updated', self.dummy1)
|
|
|
|
Registry().register_function(u'config_screen_changed', self.dummy2)
|
|
|
|
Registry().register_function(u'images_regenerate', self.dummy3)
|
2013-03-17 17:37:19 +00:00
|
|
|
|
2013-03-17 20:20:43 +00:00
|
|
|
# WHEN: The Images have been changed and the form submitted
|
2013-03-17 17:37:19 +00:00
|
|
|
self.form.register_post_process(u'images_config_updated')
|
|
|
|
self.form.accept()
|
|
|
|
|
2013-03-17 20:20:43 +00:00
|
|
|
# THEN: images_regenerate should have been added.
|
|
|
|
assert self.dummy1.call_count == 1, u'dummy1 should have been called once'
|
|
|
|
assert self.dummy2.call_count == 0, u'dummy2 should not have been called at all'
|
|
|
|
assert self.dummy3.call_count == 1, u'dummy3 should have been called once'
|
|
|
|
|
|
|
|
def register_image_manager_trigger_test_two(self):
|
|
|
|
"""
|
|
|
|
Test the triggering of the image manager rebuild event from screen dimension change
|
|
|
|
"""
|
|
|
|
# GIVEN: Three functions registered to be call
|
|
|
|
Registry().register_function(u'images_config_updated', self.dummy1)
|
|
|
|
Registry().register_function(u'config_screen_changed', self.dummy2)
|
|
|
|
Registry().register_function(u'images_regenerate', self.dummy3)
|
2013-03-17 17:37:19 +00:00
|
|
|
|
|
|
|
# WHEN: The Images have been changed and the form submitted
|
|
|
|
self.form.register_post_process(u'config_screen_changed')
|
|
|
|
self.form.accept()
|
|
|
|
|
2013-03-17 20:20:43 +00:00
|
|
|
# THEN: images_regenerate should have been added.
|
|
|
|
assert self.dummy1.call_count == 0, u'dummy1 should not have been called at all'
|
|
|
|
assert self.dummy2.call_count == 1, u'dummy2 should have been called once'
|
|
|
|
assert self.dummy3.call_count == 1, u'dummy3 should have been called once'
|
|
|
|
|
|
|
|
def register_image_manager_trigger_test_three(self):
|
|
|
|
"""
|
|
|
|
Test the triggering of the image manager rebuild event from image background change and a change to the
|
|
|
|
screen dimension.
|
|
|
|
"""
|
|
|
|
# GIVEN: Three functions registered to be call
|
|
|
|
Registry().register_function(u'images_config_updated', self.dummy1)
|
|
|
|
Registry().register_function(u'config_screen_changed', self.dummy2)
|
|
|
|
Registry().register_function(u'images_regenerate', self.dummy3)
|
2013-03-17 17:37:19 +00:00
|
|
|
|
|
|
|
# WHEN: The Images have been changed and the form submitted
|
|
|
|
self.form.register_post_process(u'config_screen_changed')
|
|
|
|
self.form.register_post_process(u'images_config_updated')
|
|
|
|
self.form.accept()
|
|
|
|
|
2013-03-17 20:20:43 +00:00
|
|
|
# THEN: Images_regenerate should have been added.
|
|
|
|
assert self.dummy1.call_count == 1, u'dummy1 should have been called once'
|
|
|
|
assert self.dummy2.call_count == 1, u'dummy2 should have been called once'
|
|
|
|
assert self.dummy3.call_count == 1, u'dummy3 should have been called once'
|