From 6e17ff9d9e4d4e1239dd48e06434b5ce1ffd6b29 Mon Sep 17 00:00:00 2001 From: phill-ridout Date: Tue, 5 Feb 2013 19:57:08 +0000 Subject: [PATCH 1/7] Set lineEdit focus when displaying form --- openlp/core/ui/filerenameform.py | 1 + 1 file changed, 1 insertion(+) diff --git a/openlp/core/ui/filerenameform.py b/openlp/core/ui/filerenameform.py index 0743578a1..ccdca9928 100644 --- a/openlp/core/ui/filerenameform.py +++ b/openlp/core/ui/filerenameform.py @@ -56,4 +56,5 @@ class FileRenameForm(QtGui.QDialog, Ui_FileRenameDialog): self.setWindowTitle(translate('OpenLP.FileRenameForm', 'File Copy')) else: self.setWindowTitle(translate('OpenLP.FileRenameForm', 'File Rename')) + self.fileNameEdit.setFocus() return QtGui.QDialog.exec_(self) From 589d335d3941a6b3b43c6e68a482cc8c055a112c Mon Sep 17 00:00:00 2001 From: phill-ridout Date: Thu, 7 Feb 2013 21:55:22 +0000 Subject: [PATCH 2/7] Changed filerenamefor to registry. Started on test for filerenameform --- openlp/core/ui/filerenameform.py | 16 +++++++++++++--- openlp/core/ui/thememanager.py | 2 +- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/openlp/core/ui/filerenameform.py b/openlp/core/ui/filerenameform.py index ccdca9928..934a8dee8 100644 --- a/openlp/core/ui/filerenameform.py +++ b/openlp/core/ui/filerenameform.py @@ -34,18 +34,18 @@ from PyQt4 import QtGui 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): @@ -58,3 +58,13 @@ class FileRenameForm(QtGui.QDialog, Ui_FileRenameDialog): 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) diff --git a/openlp/core/ui/thememanager.py b/openlp/core/ui/thememanager.py index a482a3c44..666f80dbe 100644 --- a/openlp/core/ui/thememanager.py +++ b/openlp/core/ui/thememanager.py @@ -62,7 +62,7 @@ class ThemeManager(QtGui.QWidget): 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) From e1552ddce19c23acd957de4aa58042e869041526 Mon Sep 17 00:00:00 2001 From: phill-ridout Date: Fri, 8 Feb 2013 19:13:18 +0000 Subject: [PATCH 3/7] actually added test file --- .../openlp_core_ui/test_filerenamedialog.py | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 tests/interfaces/openlp_core_ui/test_filerenamedialog.py diff --git a/tests/interfaces/openlp_core_ui/test_filerenamedialog.py b/tests/interfaces/openlp_core_ui/test_filerenamedialog.py new file mode 100644 index 000000000..cc4f2b1c5 --- /dev/null +++ b/tests/interfaces/openlp_core_ui/test_filerenamedialog.py @@ -0,0 +1,83 @@ +""" + Package to test the openlp.core.ui package. +""" +from unittest import TestCase + +from mock import patch +from openlp.core.lib import Registry +from openlp.core.ui import filerenameform +from PyQt4 import QtCore, 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 basic_display_test(self): + """ + Test FileRenameForm functionality + """ + # GIVEN: FileRenameForm with no ARGS + + # WHEN displaying the UI + with patch(u'PyQt4.QtGui.QDialog') as mocked_exec: + self.form.exec_() + + # THEN the window title is set as + self.assertEqual(self.form.windowTitle(), u'File Rename', u'The window title should be "File Rename"') + + # GIVEN: FileRenameForm with False ARG + false_arg = False + + # WHEN displaying the UI + with patch(u'PyQt4.QtGui.QDialog') as mocked_exec: + self.form.exec_(false_arg) + + # THEN the window title is set as + self.assertEqual(self.form.windowTitle(), u'File Rename', u'The window title should be "File Rename"') + + # GIVEN: FileRenameForm with False ARG + true_arg = True + + # WHEN displaying the UI and pressing enter + with patch(u'PyQt4.QtGui.QDialog') as mocked_exec: + self.form.exec_(true_arg) + + # THEN the window title is set as + self.assertEqual(self.form.windowTitle(), u'File Copy', u'The window title should be "File Copy"') + + # GIVEN: FileRenameForm with defaults + + # WHEN displaying the UI + with patch(u'PyQt4.QtGui.QDialog') as mocked_exec: + self.form.exec_() + + # THEN the lineEdit should have focus + self.assertEqual(self.form.fileNameEdit.hasFocus(), True, u'fileNameEdit should have focus.') + + + + # Regression test for bug1067251 + # GIVEN: FileRenameForm with defaults + + # WHEN displaying the UI + # with patch(u'PyQt4.QtGui.QDialog') as mocked_exec: + # self.form.exec_() + + # THEN the lineEdit should have focus + #self.assertEqual(self.form.fileNameEdit.hasFocus(), u'File Rename', u'The window title should be "File Rename"') \ No newline at end of file From 7d7da00848bedb375f2557b611b0e2fc00079b4f Mon Sep 17 00:00:00 2001 From: phill-ridout Date: Fri, 8 Feb 2013 21:49:26 +0000 Subject: [PATCH 4/7] made changes according to Superfly's instructions. --- tests/interfaces/openlp_core_ui/test_filerenamedialog.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/interfaces/openlp_core_ui/test_filerenamedialog.py b/tests/interfaces/openlp_core_ui/test_filerenamedialog.py index cc4f2b1c5..0f5cfb9cf 100644 --- a/tests/interfaces/openlp_core_ui/test_filerenamedialog.py +++ b/tests/interfaces/openlp_core_ui/test_filerenamedialog.py @@ -35,7 +35,7 @@ class TestStartFileRenameForm(TestCase): # GIVEN: FileRenameForm with no ARGS # WHEN displaying the UI - with patch(u'PyQt4.QtGui.QDialog') as mocked_exec: + with patch(u'PyQt4.QtGui.QDialog.exec_') as mocked_exec: self.form.exec_() # THEN the window title is set as @@ -45,7 +45,7 @@ class TestStartFileRenameForm(TestCase): false_arg = False # WHEN displaying the UI - with patch(u'PyQt4.QtGui.QDialog') as mocked_exec: + with patch(u'PyQt4.QtGui.QDialog.exec_') as mocked_exec: self.form.exec_(false_arg) # THEN the window title is set as @@ -55,7 +55,7 @@ class TestStartFileRenameForm(TestCase): true_arg = True # WHEN displaying the UI and pressing enter - with patch(u'PyQt4.QtGui.QDialog') as mocked_exec: + with patch(u'PyQt4.QtGui.QDialog.exec_') as mocked_exec: self.form.exec_(true_arg) # THEN the window title is set as @@ -64,7 +64,7 @@ class TestStartFileRenameForm(TestCase): # GIVEN: FileRenameForm with defaults # WHEN displaying the UI - with patch(u'PyQt4.QtGui.QDialog') as mocked_exec: + with patch(u'PyQt4.QtGui.QDialog.exec_') as mocked_exec: self.form.exec_() # THEN the lineEdit should have focus From 17200d85fc94f51f2accf73aa69ea94f14989c87 Mon Sep 17 00:00:00 2001 From: phill-ridout Date: Sat, 9 Feb 2013 21:23:43 +0000 Subject: [PATCH 5/7] some more changes to the test --- .../openlp_core_ui/test_filerenamedialog.py | 66 ++++++++----------- 1 file changed, 26 insertions(+), 40 deletions(-) diff --git a/tests/interfaces/openlp_core_ui/test_filerenamedialog.py b/tests/interfaces/openlp_core_ui/test_filerenamedialog.py index 0f5cfb9cf..9e242f0d5 100644 --- a/tests/interfaces/openlp_core_ui/test_filerenamedialog.py +++ b/tests/interfaces/openlp_core_ui/test_filerenamedialog.py @@ -28,56 +28,42 @@ class TestStartFileRenameForm(TestCase): del self.main_window del self.app - def basic_display_test(self): + def window_title_test(self): """ - Test FileRenameForm functionality + Test the windowTitle of the FileRenameDialog """ - # GIVEN: FileRenameForm with no ARGS - - # WHEN displaying the UI + # 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 as - self.assertEqual(self.form.windowTitle(), u'File Rename', u'The window title should be "File Rename"') + # THEN: the window title is set correctly + self.assertEqual(self.form.windowTitle(), u'File Rename', u'The window title should be "File Rename"') - # GIVEN: FileRenameForm with False ARG - false_arg = False + # WHEN: The form is executed with False arg + self.form.exec_(False) - # WHEN displaying the UI - with patch(u'PyQt4.QtGui.QDialog.exec_') as mocked_exec: - self.form.exec_(false_arg) + # THEN: the window title is set correctly + self.assertEqual(self.form.windowTitle(), u'File Rename', u'The window title should be "File Rename"') - # THEN the window title is set as - 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) - # GIVEN: FileRenameForm with False ARG - true_arg = True + # THEN: the window title is set correctly + self.assertEqual(self.form.windowTitle(), u'File Copy', u'The window title should be "File Copy"') - # WHEN displaying the UI and pressing enter - with patch(u'PyQt4.QtGui.QDialog.exec_') as mocked_exec: - self.form.exec_(true_arg) + def line_edit_focus_test(self): + """ + Regression test for bug1067251 + Test that the fileNameEdit setFocus has called with True when executed + """ + # GIVEN: A mocked QLineEdit class + with patch(u'PyQt4.QtGui.QDialog.exec_') as mocked_exec, \ + patch(u'PyQt4.QtGui.QLineEdit') as mocked_line_edit: - # THEN the window title is set as - self.assertEqual(self.form.windowTitle(), u'File Copy', u'The window title should be "File Copy"') - - # GIVEN: FileRenameForm with defaults - - # WHEN displaying the UI - with patch(u'PyQt4.QtGui.QDialog.exec_') as mocked_exec: + # WHEN: The form is executed with no args self.form.exec_() - # THEN the lineEdit should have focus - self.assertEqual(self.form.fileNameEdit.hasFocus(), True, u'fileNameEdit should have focus.') - - - - # Regression test for bug1067251 - # GIVEN: FileRenameForm with defaults - - # WHEN displaying the UI - # with patch(u'PyQt4.QtGui.QDialog') as mocked_exec: - # self.form.exec_() - - # THEN the lineEdit should have focus - #self.assertEqual(self.form.fileNameEdit.hasFocus(), u'File Rename', u'The window title should be "File Rename"') \ No newline at end of file + # THEN: the setFocus method of the fileNameEdit has been called with True + mocked_line_edit.setFocus.assert_called_with() From 35eebb2a8eec6dd6f0807b1e793b528c7da334e2 Mon Sep 17 00:00:00 2001 From: phill-ridout Date: Mon, 11 Feb 2013 20:47:53 +0000 Subject: [PATCH 6/7] Added validator test --- .../openlp_core_ui/test_filerenamedialog.py | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/tests/interfaces/openlp_core_ui/test_filerenamedialog.py b/tests/interfaces/openlp_core_ui/test_filerenamedialog.py index 9e242f0d5..3e22b11e1 100644 --- a/tests/interfaces/openlp_core_ui/test_filerenamedialog.py +++ b/tests/interfaces/openlp_core_ui/test_filerenamedialog.py @@ -3,10 +3,10 @@ """ from unittest import TestCase -from mock import patch +from mock import MagicMock, patch from openlp.core.lib import Registry from openlp.core.ui import filerenameform -from PyQt4 import QtCore, QtGui, QtTest +from PyQt4 import QtGui, QtTest class TestStartFileRenameForm(TestCase): @@ -58,12 +58,26 @@ class TestStartFileRenameForm(TestCase): Regression test for bug1067251 Test that the fileNameEdit setFocus has called with True when executed """ - # GIVEN: A mocked QLineEdit class - with patch(u'PyQt4.QtGui.QDialog.exec_') as mocked_exec, \ - patch(u'PyQt4.QtGui.QLineEdit') as mocked_line_edit: + # 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 with no args + # WHEN: The form is executed self.form.exec_() # THEN: the setFocus method of the fileNameEdit has been called with True - mocked_line_edit.setFocus.assert_called_with() + 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 \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') From f419108e61440d018d97b2d0c351b42064f41c55 Mon Sep 17 00:00:00 2001 From: phill-ridout Date: Tue, 12 Feb 2013 19:26:19 +0000 Subject: [PATCH 7/7] Removed spacing from comments. --- tests/interfaces/openlp_core_ui/test_filerenamedialog.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/interfaces/openlp_core_ui/test_filerenamedialog.py b/tests/interfaces/openlp_core_ui/test_filerenamedialog.py index 3e22b11e1..74fe83b26 100644 --- a/tests/interfaces/openlp_core_ui/test_filerenamedialog.py +++ b/tests/interfaces/openlp_core_ui/test_filerenamedialog.py @@ -79,5 +79,5 @@ class TestStartFileRenameForm(TestCase): QtTest.QTest.keyClicks(self.form.fileNameEdit, u'I/n\\v?a*l|i \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. + # out. self.assertEqual(self.form.fileNameEdit.text(), u'Invalid File Name')