From 7e41362ca2deb404f28d9337ad52be6649ace6a8 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Wed, 8 May 2013 22:05:54 +0200 Subject: [PATCH] completed test --- openlp/core/ui/mainwindow.py | 16 ++++++++---- .../openlp_core_ui/test_mainwindow.py | 25 ++++++++++++++----- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index 9c03dc2b2..f28d4996d 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -543,15 +543,21 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): Registry().register_function(u'theme_update_global', self.default_theme_changed) Registry().register_function(u'openlp_version_check', self.version_notice) Registry().register_function(u'config_screen_changed', self.screen_changed) + Registry().register_function(u'bootstrap_post_set_up', self.restore_current_media_manager_item) self.renderer = Renderer() - log.info(u'Load data from Settings') - if Settings().value(u'advanced/save current plugin'): - savedPlugin = Settings().value(u'advanced/current media plugin') - if savedPlugin != -1: - self.media_tool_box.setCurrentIndex(savedPlugin) # Reset the cursor self.application.set_normal_cursor() + def restore_current_media_manager_item(self): + """ + + """ + log.info(u'Load data from Settings') + if Settings().value(u'advanced/save current plugin'): + saved_plugin = Settings().value(u'advanced/current media plugin') + if saved_plugin != -1: + self.media_tool_box.setCurrentIndex(saved_plugin) + def on_search_shortcut_triggered(self): """ Called when the search shotcut has been pressed. diff --git a/tests/interfaces/openlp_core_ui/test_mainwindow.py b/tests/interfaces/openlp_core_ui/test_mainwindow.py index e2f523ee0..821c6f980 100644 --- a/tests/interfaces/openlp_core_ui/test_mainwindow.py +++ b/tests/interfaces/openlp_core_ui/test_mainwindow.py @@ -6,7 +6,7 @@ from mock import MagicMock, patch from PyQt4 import QtCore, QtGui, QtTest -from openlp.core.lib import Registry, ScreenList +from openlp.core.lib import Registry from openlp.core.ui.mainwindow import MainWindow @@ -18,12 +18,22 @@ class TestMainWindow(TestCase): """ Registry.create() self.registry = Registry() - ScreenList.create(MagicMock()) self.app = QtGui.QApplication([]) + # Mock cursor busy/normal methods. + self.app.set_busy_cursor = MagicMock() + self.app.set_normal_cursor = MagicMock() self.app.args =[] Registry().register(u'application', self.app) - self.main_window = MainWindow() - Registry().register(u'main_window', self.main_window) + # Mock classes and methods used by mainwindow. + with patch(u'openlp.core.ui.mainwindow.ImageManager') as mocked_image_manager, \ + 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() def tearDown(self): """ @@ -34,12 +44,15 @@ class TestMainWindow(TestCase): def on_search_shortcut_triggered_test(self): """ + Test if the search edit has focus after CTRL+F has been pressed. """ - # GIVEN: Mocked mehtod. + # GIVEN: Mocked widget. mocked_current_widget = MagicMock() self.main_window.media_tool_box.currentWidget = mocked_current_widget - # WHEN: Press the shortcut + # WHEN: Press the shortcut. + QtTest.QTest.keyPress(self.main_window, QtCore.Qt.Key_F, QtCore.Qt.ControlModifier) + QtTest.QTest.keyPress(self.main_window, QtCore.Qt.Key_F, QtCore.Qt.ControlModifier) # THEN: The on_focus method should have been called. mocked_current_widget.on_focus.assert_called_with()