← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~phill-ridout/openlp/bug1067251 into lp:openlp

 

Phill has proposed merging lp:~phill-ridout/openlp/bug1067251 into lp:openlp.

Requested reviews:
  OpenLP Core (openlp-core)
Related bugs:
  Bug #1067251 in OpenLP: "Correct focus of theme manager's dialogs"
  https://bugs.launchpad.net/openlp/+bug/1067251

For more details, see:
https://code.launchpad.net/~phill-ridout/openlp/bug1067251/+merge/147772

Fixes #1067251
Adds a test
-- 
https://code.launchpad.net/~phill-ridout/openlp/bug1067251/+merge/147772
Your team OpenLP Core is requested to review the proposed merge of lp:~phill-ridout/openlp/bug1067251 into lp:openlp.
=== modified file 'openlp/core/ui/filerenameform.py'
--- openlp/core/ui/filerenameform.py	2013-02-01 20:36:27 +0000
+++ openlp/core/ui/filerenameform.py	2013-02-11 20:52:40 +0000
@@ -34,18 +34,18 @@
 
 from filerenamedialog import Ui_FileRenameDialog
 
-from openlp.core.lib import translate
+from openlp.core.lib import translate, Registry
 
 
 class FileRenameForm(QtGui.QDialog, Ui_FileRenameDialog):
     """
     The file rename dialog
     """
-    def __init__(self, parent):
+    def __init__(self):
         """
         Constructor
         """
-        QtGui.QDialog.__init__(self, parent)
+        QtGui.QDialog.__init__(self, self.main_window)
         self.setupUi(self)
 
     def exec_(self, copy=False):
@@ -56,4 +56,15 @@
             self.setWindowTitle(translate('OpenLP.FileRenameForm', 'File Copy'))
         else:
             self.setWindowTitle(translate('OpenLP.FileRenameForm', 'File Rename'))
+        self.fileNameEdit.setFocus()
         return QtGui.QDialog.exec_(self)
+
+    def _get_main_window(self):
+        """
+        Adds the main window to the class dynamically
+        """
+        if not hasattr(self, u'_main_window'):
+            self._main_window = Registry().get(u'main_window')
+        return self._main_window
+
+    main_window = property(_get_main_window)

=== modified file 'openlp/core/ui/thememanager.py'
--- openlp/core/ui/thememanager.py	2013-02-09 15:27:35 +0000
+++ openlp/core/ui/thememanager.py	2013-02-11 20:52:40 +0000
@@ -62,7 +62,7 @@
         Registry().register(u'theme_manager', self)
         self.settingsSection = u'themes'
         self.themeForm = ThemeForm(self)
-        self.fileRenameForm = FileRenameForm(self)
+        self.fileRenameForm = FileRenameForm()
         # start with the layout
         self.layout = QtGui.QVBoxLayout(self)
         self.layout.setSpacing(0)

=== added file 'tests/interfaces/openlp_core_ui/test_filerenamedialog.py'
--- tests/interfaces/openlp_core_ui/test_filerenamedialog.py	1970-01-01 00:00:00 +0000
+++ tests/interfaces/openlp_core_ui/test_filerenamedialog.py	2013-02-11 20:52:40 +0000
@@ -0,0 +1,83 @@
+"""
+    Package to test the openlp.core.ui package.
+"""
+from unittest import TestCase
+
+from mock import MagicMock, patch
+from openlp.core.lib import Registry
+from openlp.core.ui import filerenameform
+from PyQt4 import QtGui, QtTest
+
+class TestStartFileRenameForm(TestCase):
+
+    def setUp(self):
+        """
+        Create the UI
+        """
+        registry = Registry.create()
+        self.app = QtGui.QApplication([])
+        self.main_window = QtGui.QMainWindow()
+        Registry().register(u'main_window', self.main_window)
+        self.form = filerenameform.FileRenameForm()
+
+    def tearDown(self):
+        """
+        Delete all the C++ objects at the end so that we don't have a segfault
+        """
+        del self.form
+        del self.main_window
+        del self.app
+
+    def window_title_test(self):
+        """
+        Test the windowTitle of the FileRenameDialog
+        """
+        # GIVEN: A mocked QDialog.exec_() method
+        with patch(u'PyQt4.QtGui.QDialog.exec_') as mocked_exec:
+
+            # WHEN: The form is executed with no args
+            self.form.exec_()
+
+            # THEN: the window title is set correctly
+            self.assertEqual(self.form.windowTitle(), u'File Rename', u'The window title should be "File Rename"')
+
+            # WHEN: The form is executed with False arg
+            self.form.exec_(False)
+
+            # THEN: the window title is set correctly
+            self.assertEqual(self.form.windowTitle(), u'File Rename', u'The window title should be "File Rename"')
+
+            # WHEN: The form is executed with True arg
+            self.form.exec_(True)
+
+            # THEN: the window title is set correctly
+            self.assertEqual(self.form.windowTitle(), u'File Copy', u'The window title should be "File Copy"')
+
+    def line_edit_focus_test(self):
+        """
+        Regression test for bug1067251
+        Test that the fileNameEdit setFocus has called with True when executed
+        """
+        # GIVEN: A mocked QDialog.exec_() method and mocked fileNameEdit.setFocus() method.
+        with patch(u'PyQt4.QtGui.QDialog.exec_') as mocked_exec:
+            mocked_set_focus = MagicMock()
+            self.form.fileNameEdit.setFocus = mocked_set_focus
+
+            # WHEN: The form is executed
+            self.form.exec_()
+
+            # THEN: the setFocus method of the fileNameEdit has been called with True
+            mocked_set_focus.assert_called_with()
+
+    def file_name_validation_test(self):
+        """
+        Test the fileNameEdit validation
+        """
+        # GIVEN: QLineEdit with a validator set with illegal file name characters.
+
+        # WHEN: 'Typing' a string containing invalid file characters.
+        QtTest.QTest.keyClicks(self.form.fileNameEdit, u'I/n\\v?a*l|i<d> \F[i\l]e" :N+a%me')
+
+        # THEN: The text in the QLineEdit should be the same as the input string with the invalid chatacters filtered
+        #       out.
+        self.assertEqual(self.form.fileNameEdit.text(), u'Invalid File Name')


Follow ups