openlp/tests/interfaces/openlp_core_ui/test_settings_form.py

192 lines
8.4 KiB
Python
Raw Normal View History

2014-03-14 20:06:24 +00:00
# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
2015-01-18 13:39:21 +00:00
# Copyright (c) 2008-2015 OpenLP Developers #
2014-03-14 20:06:24 +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 #
###############################################################################
2013-03-10 20:19:42 +00:00
"""
Package to test the openlp.core.lib.settingsform package.
"""
from unittest import TestCase
2014-03-14 22:08:44 +00:00
from PyQt4 import QtCore, QtTest
2013-03-10 20:19:42 +00:00
2013-12-13 17:44:05 +00:00
from openlp.core.common import Registry
2013-03-10 20:19:42 +00:00
from openlp.core.ui import settingsform
2013-12-13 17:44:05 +00:00
from openlp.core.lib import ScreenList
from tests.interfaces import MagicMock, patch
2014-03-14 22:08:44 +00:00
from tests.helpers.testmixin import TestMixin
2013-03-10 20:19:42 +00:00
SCREEN = {
2013-08-31 18:17:38 +00:00
'primary': False,
'number': 1,
'size': QtCore.QRect(0, 0, 1024, 768)
2013-03-10 20:19:42 +00:00
}
2014-03-14 22:08:44 +00:00
class TestSettingsForm(TestCase, TestMixin):
2013-03-10 20:19:42 +00:00
"""
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()
self.setup_application()
2013-08-31 18:17:38 +00:00
self.desktop.primaryScreen.return_value = SCREEN['primary']
self.desktop.screenCount.return_value = SCREEN['number']
self.desktop.screenGeometry.return_value = SCREEN['size']
2013-03-10 20:19:42 +00:00
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
def basic_cancel_test(self):
"""
Test running the settings form and pressing Cancel
"""
# GIVEN: An initial form
# WHEN displaying the UI and pressing cancel
2013-08-31 18:17:38 +00:00
with patch('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
2013-08-31 18:17:38 +00:00
assert mocked_reject.call_count == 1, 'The QDialog.reject should have been called'
2013-03-10 20:19:42 +00:00
def basic_accept_test(self):
"""
Test running the settings form and pressing Ok
"""
# GIVEN: An initial form
# WHEN displaying the UI and pressing Ok
2013-08-31 18:17:38 +00:00
with patch('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
2013-08-31 18:17:38 +00:00
assert mocked_accept.call_count == 1, 'The QDialog.accept should have been called'
2013-03-10 20:19:42 +00:00
def basic_register_test(self):
"""
Test running the settings form and adding a single function
"""
# GIVEN: An initial form add a register function
2013-08-31 18:17:38 +00:00
self.form.register_post_process('function1')
2013-03-10 20:19:42 +00:00
# WHEN displaying the UI and pressing Ok
2013-08-31 18:17:38 +00:00
with patch('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-08-31 18:17:38 +00:00
assert len(self.form.processes) == 0, '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
2013-08-31 18:17:38 +00:00
self.form.register_post_process('function1')
2013-03-10 20:19:42 +00:00
# WHEN testing the processing stack
# THEN the processing stack should have one item
2013-08-31 18:17:38 +00:00
assert len(self.form.processes) == 1, 'The one requested process should have been added to the stack'
2013-03-10 20:19:42 +00:00
# GIVEN: Registering a new function
2013-08-31 18:17:38 +00:00
self.form.register_post_process('function2')
2013-03-10 20:19:42 +00:00
# WHEN testing the processing stack
# THEN the processing stack should have two items
2013-08-31 18:17:38 +00:00
assert len(self.form.processes) == 2, '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
2013-08-31 18:17:38 +00:00
self.form.register_post_process('function1')
2013-03-10 20:19:42 +00:00
# WHEN testing the processing stack
# THEN the processing stack should still have two items
2013-08-31 18:17:38 +00:00
assert len(self.form.processes) == 2, '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-08-31 18:17:38 +00:00
Registry().register_function('images_config_updated', self.dummy1)
Registry().register_function('config_screen_changed', self.dummy2)
Registry().register_function('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-08-31 18:17:38 +00:00
self.form.register_post_process('images_config_updated')
2013-03-17 17:37:19 +00:00
self.form.accept()
2013-03-17 20:20:43 +00:00
# THEN: images_regenerate should have been added.
2013-08-31 18:17:38 +00:00
assert self.dummy1.call_count == 1, 'dummy1 should have been called once'
assert self.dummy2.call_count == 0, 'dummy2 should not have been called at all'
assert self.dummy3.call_count == 1, 'dummy3 should have been called once'
2013-03-17 20:20:43 +00:00
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
2013-08-31 18:17:38 +00:00
Registry().register_function('images_config_updated', self.dummy1)
Registry().register_function('config_screen_changed', self.dummy2)
Registry().register_function('images_regenerate', self.dummy3)
2013-03-17 17:37:19 +00:00
# WHEN: The Images have been changed and the form submitted
2013-08-31 18:17:38 +00:00
self.form.register_post_process('config_screen_changed')
2013-03-17 17:37:19 +00:00
self.form.accept()
2013-03-17 20:20:43 +00:00
# THEN: images_regenerate should have been added.
2013-08-31 18:17:38 +00:00
assert self.dummy1.call_count == 0, 'dummy1 should not have been called at all'
assert self.dummy2.call_count == 1, 'dummy2 should have been called once'
assert self.dummy3.call_count == 1, 'dummy3 should have been called once'
2013-03-17 20:20:43 +00:00
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
2013-08-31 18:17:38 +00:00
Registry().register_function('images_config_updated', self.dummy1)
Registry().register_function('config_screen_changed', self.dummy2)
Registry().register_function('images_regenerate', self.dummy3)
2013-03-17 17:37:19 +00:00
# WHEN: The Images have been changed and the form submitted
2013-08-31 18:17:38 +00:00
self.form.register_post_process('config_screen_changed')
self.form.register_post_process('images_config_updated')
2013-03-17 17:37:19 +00:00
self.form.accept()
2013-03-17 20:20:43 +00:00
# THEN: Images_regenerate should have been added.
2013-08-31 18:17:38 +00:00
assert self.dummy1.call_count == 1, 'dummy1 should have been called once'
assert self.dummy2.call_count == 1, 'dummy2 should have been called once'
assert self.dummy3.call_count == 1, 'dummy3 should have been called once'