fixed regression + added test for it

This commit is contained in:
Andreas Preikschat 2013-03-28 21:03:58 +01:00
parent fa43759d8d
commit 30a7034ac9
5 changed files with 60 additions and 10 deletions

View File

@ -26,6 +26,3 @@
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
###############################################################################
from editcustomform import EditCustomForm
from editcustomslideform import EditCustomSlideForm

View File

@ -35,8 +35,8 @@ from openlp.core.lib import Registry, translate
from openlp.core.lib.ui import critical_error_message_box, find_and_set_in_combo_box
from openlp.plugins.custom.lib import CustomXMLBuilder, CustomXMLParser
from openlp.plugins.custom.lib.db import CustomSlide
from editcustomdialog import Ui_CustomEditDialog
from editcustomslideform import EditCustomSlideForm
from editcustomdialog import Ui_CustomEditDialog
log = logging.getLogger(__name__)
@ -91,8 +91,8 @@ class EditCustomForm(QtGui.QDialog, Ui_CustomEditDialog):
self.slide_list_view.clear()
if id == 0:
self.custom_slide = CustomSlide()
self.title_edit.set_text(u'')
self.credit_edit.set_text(u'')
self.title_edit.setText(u'')
self.credit_edit.setText(u'')
self.theme_combo_box.setCurrentIndex(0)
else:
self.custom_slide = self.manager.get_object(CustomSlide, id)
@ -158,7 +158,7 @@ class EditCustomForm(QtGui.QDialog, Ui_CustomEditDialog):
"""
Add a new blank slide.
"""
self.edit_slide_form.set_text(u'')
self.edit_slide_form.setText(u'')
if self.edit_slide_form.exec_():
self.slide_list_view.addItems(self.edit_slide_form.get_text())
@ -166,7 +166,7 @@ class EditCustomForm(QtGui.QDialog, Ui_CustomEditDialog):
"""
Edit the currently selected slide.
"""
self.edit_slide_form.set_text(self.slide_list_view.currentItem().text())
self.edit_slide_form.setText(self.slide_list_view.currentItem().text())
if self.edit_slide_form.exec_():
self.update_slide_list(self.edit_slide_form.get_text())
@ -180,7 +180,7 @@ class EditCustomForm(QtGui.QDialog, Ui_CustomEditDialog):
slide_text += item.text()
if row != self.slide_list_view.count() - 1:
slide_text += u'\n[===]\n'
self.edit_slide_form.set_text(slide_text)
self.edit_slide_form.setText(slide_text)
if self.edit_slide_form.exec_():
self.update_slide_list(self.edit_slide_form.get_text(), True)

View File

@ -34,7 +34,7 @@ from sqlalchemy.sql import or_, func, and_
from openlp.core.lib import Registry, MediaManagerItem, ItemCapabilities, ServiceItemContext, Settings, PluginStatus,\
UiStrings, check_item_selected, translate
from openlp.plugins.custom.forms import EditCustomForm
from openlp.plugins.custom.forms.editcustomform import EditCustomForm
from openlp.plugins.custom.lib import CustomXMLParser, CustomXMLBuilder
from openlp.plugins.custom.lib.db import CustomSlide

View File

@ -0,0 +1,53 @@
"""
Module to the custom edit form.
"""
from unittest import TestCase
from mock import MagicMock, patch
from PyQt4 import QtGui
from openlp.core.lib import Registry
# Import needed due to import problems.
from openlp.plugins.custom.lib.mediaitem import CustomMediaItem
from openlp.plugins.custom.forms.editcustomform import EditCustomForm
class TestCustomFrom(TestCase):
"""
Test the EditCustomForm.
"""
def setUp(self):
"""
Create the UI
"""
Registry.create()
self.app = QtGui.QApplication([])
self.main_window = QtGui.QMainWindow()
Registry().register(u'main_window', self.main_window)
media_item = MagicMock()
manager = MagicMock()
self.form = EditCustomForm(media_item, self.main_window, manager)
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 load_custom_test(self):
"""
Test the EditCustomForm defaults are correct
"""
# GIVEN: A mocked QDialog.exec_() method
with patch(u'PyQt4.QtGui.QDialog.exec_') as mocked_exec:
# WHEN: Show the dialog.
self.form.exec_()
# Create a new custom item.
self.form.load_custom(0)
#THEN: The line edits should not contain any text.
self.assertEqual(self.form.title_edit.text(), u'', u'The title edit should be empty')
self.assertEqual(self.form.credit_edit.text(), u'', u'The credit edit should be empty')