fixed tests

This commit is contained in:
Andreas Preikschat 2013-06-21 12:16:50 +02:00
parent 6b881e312f
commit 6265ce93de
2 changed files with 65 additions and 46 deletions

View File

@ -685,23 +685,31 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
self.verse_edit_button.setEnabled(False) self.verse_edit_button.setEnabled(False)
self.verse_delete_button.setEnabled(False) self.verse_delete_button.setEnabled(False)
def on_verse_order_text_changed(self, text): def on_verse_order_text_changed(self, text):
verses = [] """
verse_names = [] Checks if the verse order is complete or missing. Shows a error message according to the state of the verse
order = self._extract_verse_order(text) order.
``text``
The text of the verse order edit (ignored).
"""
# Extract all verses which were used in the order.
verses_in_order = self._extract_verse_order(self.verse_order_edit.text())
# Find the verses which were not used in the order.
verses_not_used = []
for index in range(self.verse_list_widget.rowCount()): for index in range(self.verse_list_widget.rowCount()):
verse = self.verse_list_widget.item(index, 0) verse = self.verse_list_widget.item(index, 0)
verse = verse.data(QtCore.Qt.UserRole) verse = verse.data(QtCore.Qt.UserRole)
if verse not in verse_names: print(verse)
verses.append(verse) if verse not in verses_in_order:
verse_names.append(u'%s%s' % (VerseType.translated_tag(verse[0]), verse[1:]))
verses_not_used = []
for verse in verses:
if not verse in order:
verses_not_used.append(verse) verses_not_used.append(verse)
# Set the label text.
label_text = u'' label_text = u''
if not self.verse_order_edit.text(): # No verse order was entered.
if not verses_in_order:
label_text = self.no_verse_order_entered_warning label_text = self.no_verse_order_entered_warning
# The verse order does not contain all verses.
elif verses_not_used: elif verses_not_used:
label_text = self.not_all_verses_used_warning label_text = self.not_all_verses_used_warning
self.warning_label.setText(label_text) self.warning_label.setText(label_text)

View File

@ -34,7 +34,7 @@ class TestEditSongForm(TestCase):
del self.main_window del self.main_window
del self.app del self.app
def ui_defaults_(self): def ui_defaults_test(self):
""" """
Test that the EditSongForm defaults are correct Test that the EditSongForm defaults are correct
""" """
@ -43,58 +43,69 @@ class TestEditSongForm(TestCase):
self.assertFalse(self.form.author_remove_button.isEnabled(), u'The author remove button should not be enabled') self.assertFalse(self.form.author_remove_button.isEnabled(), u'The author remove button should not be enabled')
self.assertFalse(self.form.topic_remove_button.isEnabled(), u'The topic remove button should not be enabled') self.assertFalse(self.form.topic_remove_button.isEnabled(), u'The topic remove button should not be enabled')
def is_verse_edit_form_executed_t(self): def is_verse_edit_form_executed_test(self):
pass pass
def verse_order_warning_hidden_test(self): def verse_order_no_warning_test(self):
""" """
Test if the verse order warning lable is visible, when a verse order is specified Test if the verse order warning is not shown
""" """
# GIVEN: Mocked methods. # GIVEN: Mocked methods.
mocked_row_count = MagicMock() given_verse_order = u'V1 V2'
mocked_row_count.return_value = 1 self.form.verse_list_widget.rowCount = MagicMock(return_value=2)
self.form.verse_list_widget.rowCount = mocked_row_count
# Mock out the verse. # Mock out the verse.
mocked_verse = MagicMock() first_verse = MagicMock()
self.form.verse_list_widget.item = mocked_verse first_verse.data = MagicMock(return_value=u'V1')
mocked_verse_data_method = MagicMock() second_verse = MagicMock()
mocked_verse_data_method.return_value = u'V1' second_verse.data = MagicMock(return_value= u'V2')
mocked_verse.data = mocked_verse_data_method self.form.verse_list_widget.item = MagicMock(side_effect=[first_verse, second_verse])
mocked_item_method = MagicMock() self.form._extract_verse_order = MagicMock(return_value=given_verse_order.split())
mocked_item_method.return_value = mocked_verse
mocked_extract_verse_order_method = MagicMock()
mocked_extract_verse_order_method.return_value = [u'V1']
self.form._extract_verse_order = mocked_extract_verse_order_method
# WHEN: Call the method. # WHEN: Call the method.
self.form.on_verse_order_text_changed(u'V1') self.form.on_verse_order_text_changed(given_verse_order)
# THEN: The warning lable should be hidden. # THEN: The warning lable should be hidden.
assert not self.form.warning_label.isVisible(), u'The warning lable should be hidden.' print self.form.warning_label.text()
assert self.form.warning_label.text() == u'', u'There should be no warning.'
def verse_order_incomplete_warning_test(self):
"""
Test if the verse-order-incomple warning is shown
"""
# GIVEN: Mocked methods.
given_verse_order = u'V1'
self.form.verse_list_widget.rowCount = MagicMock(return_value=2)
# Mock out the verse.
first_verse = MagicMock()
first_verse.data = MagicMock(return_value=u'V1')
second_verse = MagicMock()
second_verse.data = MagicMock(return_value= u'V2')
self.form.verse_list_widget.item = MagicMock(side_effect=[first_verse, second_verse])
self.form._extract_verse_order = MagicMock(return_value=[given_verse_order])
# WHEN: Call the method.
self.form.on_verse_order_text_changed(given_verse_order)
# THEN: The warning lable should be hidden.
assert self.form.warning_label.text() == u'<strong>Warning:</strong> Not all of the verses are in use.', \
u'The verse-order-incomplete warning should be shown.'
def bug_1170435_test(self): def bug_1170435_test(self):
""" """
Regression test for bug 1170435 (test if lable hidden, when no verse order is specified) Regression test for bug 1170435 (test if "no verse order" message is shown)
""" """
# GIVEN: Mocked methods. # GIVEN: Mocked methods.
mocked_row_count = MagicMock() given_verse_order = u''
mocked_row_count.return_value = 0 self.form.verse_list_widget.rowCount = MagicMock(return_value=1)
self.form.verse_list_widget.rowCount = mocked_row_count
# Mock out the verse. (We want a verse type to be returned). # Mock out the verse. (We want a verse type to be returned).
mocked_verse = MagicMock() mocked_verse = MagicMock()
self.form.verse_list_widget.item = mocked_verse mocked_verse.data = MagicMock(return_value=u'V1')
mocked_verse_data_method = MagicMock() self.form.verse_list_widget.item = MagicMock(return_value=mocked_verse)
mocked_verse_data_method.return_value = u'V1' self.form._extract_verse_order = MagicMock(return_value=[given_verse_order])
mocked_verse.data = mocked_verse_data_method self.form.verse_order_edit.text = MagicMock(return_value=given_verse_order)
mocked_item_method = MagicMock()
mocked_item_method.return_value = mocked_verse
mocked_extract_verse_order_method = MagicMock()
mocked_extract_verse_order_method.return_value = []
self.form._extract_verse_order = mocked_extract_verse_order_method
# WHEN: Call the method. # WHEN: Call the method.
self.form.on_verse_order_text_changed(u'') self.form.on_verse_order_text_changed(given_verse_order)
# THEN: The warning lable should be hidden. # THEN: The warning lable should be hidden.
assert not self.form.warning_label.isVisible(), \ assert self.form.warning_label.text() == u'<strong>Warning:</strong> You have not entered a verse order.', \
u'The lable should be visible because the verse order was left empty.' u'The no-verse-order message should be shown.'