completed test

This commit is contained in:
Andreas Preikschat 2013-05-08 22:05:54 +02:00
parent 9a068f5144
commit 7e41362ca2
2 changed files with 30 additions and 11 deletions

View File

@ -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.

View File

@ -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()