From 0fb24d2233f623031f195865db98d87771cf3d62 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Wed, 17 Apr 2013 20:33:44 +0200 Subject: [PATCH] added tests --- openlp/plugins/custom/forms/editcustomform.py | 2 +- .../custom/forms/test_customform.py | 42 +++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/openlp/plugins/custom/forms/editcustomform.py b/openlp/plugins/custom/forms/editcustomform.py index c78baa974..580fbde07 100644 --- a/openlp/plugins/custom/forms/editcustomform.py +++ b/openlp/plugins/custom/forms/editcustomform.py @@ -257,6 +257,6 @@ class EditCustomForm(QtGui.QDialog, Ui_CustomEditDialog): # We must have at least one slide. if self.slide_list_view.count() == 0: critical_error_message_box(message=translate('CustomPlugin.EditCustomForm', - 'You need to add at least one slide')) + 'You need to add at least one slide.')) return False return True diff --git a/tests/interfaces/openlp_plugins/custom/forms/test_customform.py b/tests/interfaces/openlp_plugins/custom/forms/test_customform.py index 6e6318ca6..dbed244e3 100644 --- a/tests/interfaces/openlp_plugins/custom/forms/test_customform.py +++ b/tests/interfaces/openlp_plugins/custom/forms/test_customform.py @@ -62,3 +62,45 @@ class TestEditCustomForm(TestCase): QtTest.QTest.mouseClick(self.form.add_button, QtCore.Qt.LeftButton) #THEN: One slide should be added. assert self.form.slide_list_view.count() == 1, u'There should be one slide added.' + + def validate_not_valid_part1_test(self): + """ + Test the _validate() method. + """ + # GIVEN: Mocked methods. + with patch(u'openlp.plugins.custom.forms.editcustomform.critical_error_message_box') as \ + mocked_critical_error_message_box: + mocked_displayText = MagicMock() + mocked_displayText.return_value = u'' + self.form.title_edit.displayText = mocked_displayText + mocked_setFocus = MagicMock() + self.form.title_edit.setFocus = mocked_setFocus + + # WHEN: Call the method. + result = self.form._validate() + + # THEN: The validate method should have returned False. + assert not result, u'The _validate() method should have retured False' + mocked_setFocus.assert_called_with() + mocked_critical_error_message_box.assert_called_with(message=u'You need to type in a title.') + + def validate_not_valid_part2_test(self): + """ + Test the _validate() method. + """ + # GIVEN: Mocked methods. + with patch(u'openlp.plugins.custom.forms.editcustomform.critical_error_message_box') as \ + mocked_critical_error_message_box: + mocked_displayText = MagicMock() + mocked_displayText.return_value = u'something' + self.form.title_edit.displayText = mocked_displayText + mocked_count = MagicMock() + mocked_count.return_value = 0 + self.form.slide_list_view.count = mocked_count + + # WHEN: Call the method. + result = self.form._validate() + + # THEN: The validate method should have returned False. + assert not result, u'The _validate() method should have retured False' + mocked_critical_error_message_box.assert_called_with(message=u'You need to add at least one slide.')