2013-05-06 07:43:19 +00:00
|
|
|
"""
|
|
|
|
Package to test the openlp.core.ui.mainwindow package.
|
|
|
|
"""
|
|
|
|
from unittest import TestCase
|
|
|
|
from mock import MagicMock, patch
|
|
|
|
|
|
|
|
from PyQt4 import QtCore, QtGui, QtTest
|
|
|
|
|
2013-05-08 20:05:54 +00:00
|
|
|
from openlp.core.lib import Registry
|
2013-05-06 07:43:19 +00:00
|
|
|
from openlp.core.ui.mainwindow import MainWindow
|
|
|
|
|
|
|
|
|
|
|
|
class TestMainWindow(TestCase):
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
"""
|
|
|
|
Create the UI
|
|
|
|
"""
|
|
|
|
Registry.create()
|
|
|
|
self.registry = Registry()
|
|
|
|
self.app = QtGui.QApplication([])
|
2013-05-08 20:05:54 +00:00
|
|
|
# Mock cursor busy/normal methods.
|
|
|
|
self.app.set_busy_cursor = MagicMock()
|
|
|
|
self.app.set_normal_cursor = MagicMock()
|
2013-05-06 07:43:19 +00:00
|
|
|
self.app.args =[]
|
|
|
|
Registry().register(u'application', self.app)
|
2013-05-08 20:05:54 +00:00
|
|
|
# Mock classes and methods used by mainwindow.
|
2013-05-12 09:38:25 +00:00
|
|
|
with patch(u'openlp.core.ui.mainwindow.SettingsForm') as mocked_settings_form, \
|
|
|
|
patch(u'openlp.core.ui.mainwindow.ImageManager') as mocked_image_manager, \
|
2013-05-08 20:05:54 +00:00
|
|
|
patch(u'openlp.core.ui.mainwindow.SlideController') as mocked_slide_controller, \
|
|
|
|
patch(u'openlp.core.ui.mainwindow.OpenLPDockWidget') as mocked_dock_widget, \
|
|
|
|
patch(u'openlp.core.ui.mainwindow.QtGui.QToolBox') as mocked_q_tool_box_class, \
|
|
|
|
patch(u'openlp.core.ui.mainwindow.QtGui.QMainWindow.addDockWidget') as mocked_add_dock_method, \
|
|
|
|
patch(u'openlp.core.ui.mainwindow.ServiceManager') as mocked_slervice_manager, \
|
|
|
|
patch(u'openlp.core.ui.mainwindow.ThemeManager') as mocked_theme_manager, \
|
|
|
|
patch(u'openlp.core.ui.mainwindow.Renderer') as mocked_renderer:
|
|
|
|
self.main_window = MainWindow()
|
2013-05-06 07:43:19 +00:00
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
"""
|
|
|
|
Delete all the C++ objects at the end so that we don't have a segfault
|
|
|
|
"""
|
|
|
|
del self.main_window
|
|
|
|
del self.app
|
|
|
|
|
2013-05-12 09:38:25 +00:00
|
|
|
def restore_current_media_manager_item_test(self):
|
|
|
|
"""
|
|
|
|
Regression test for bug #1152509.
|
|
|
|
"""
|
|
|
|
# GIVEN: Mocked Settings().value method.
|
|
|
|
with patch(u'openlp.core.ui.mainwindow.Settings.value') as mocked_value:
|
|
|
|
# save current plugin: True; current media plugin: 2
|
|
|
|
mocked_value.side_effect = [True, 2]
|
|
|
|
|
|
|
|
# WHEN: Call the restore method.
|
|
|
|
Registry().execute(u'bootstrap_post_set_up')
|
|
|
|
|
|
|
|
# THEN: The current widget should have been set.
|
|
|
|
self.main_window.media_tool_box.setCurrentIndex.assert_called_with(2)
|
|
|
|
|
2013-05-06 07:43:19 +00:00
|
|
|
def on_search_shortcut_triggered_test(self):
|
|
|
|
"""
|
2013-05-08 20:05:54 +00:00
|
|
|
Test if the search edit has focus after CTRL+F has been pressed.
|
2013-05-06 07:43:19 +00:00
|
|
|
"""
|
2013-05-08 20:05:54 +00:00
|
|
|
# GIVEN: Mocked widget.
|
2013-05-09 19:38:57 +00:00
|
|
|
mocked_widget = MagicMock()
|
|
|
|
self.main_window.media_tool_box.currentWidget.return_value = mocked_widget
|
2013-05-11 17:24:03 +00:00
|
|
|
self.main_window.show()
|
2013-05-06 07:43:19 +00:00
|
|
|
|
2013-05-08 20:05:54 +00:00
|
|
|
# WHEN: Press the shortcut.
|
2013-05-11 17:24:03 +00:00
|
|
|
QtTest.QTest.keyPress(self.main_window, QtCore.Qt.Key_F, QtCore.Qt.ControlModifier, 100)
|
2013-05-08 20:13:33 +00:00
|
|
|
QtTest.QTest.keyRelease(self.main_window, QtCore.Qt.Key_F, QtCore.Qt.ControlModifier)
|
2013-05-06 07:43:19 +00:00
|
|
|
|
|
|
|
# THEN: The on_focus method should have been called.
|
2013-05-09 19:38:57 +00:00
|
|
|
mocked_widget.on_focus.assert_called_with()
|