2013-03-28 20:03:58 +00:00
|
|
|
"""
|
2013-03-30 09:01:21 +00:00
|
|
|
Module to test the EditCustomForm.
|
2013-03-28 20:03:58 +00:00
|
|
|
"""
|
|
|
|
from unittest import TestCase
|
|
|
|
from mock import MagicMock, patch
|
|
|
|
|
2013-03-28 22:08:14 +00:00
|
|
|
from PyQt4 import QtGui, QtTest, QtCore
|
2013-03-28 20:03:58 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
2013-03-30 09:01:21 +00:00
|
|
|
class TestEditCustomForm(TestCase):
|
2013-03-28 20:03:58 +00:00
|
|
|
"""
|
|
|
|
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
|
|
|
|
|
2013-03-28 22:10:24 +00:00
|
|
|
def load_custom_test(self):
|
2013-03-28 20:03:58 +00:00
|
|
|
"""
|
2013-03-28 22:08:14 +00:00
|
|
|
Test the load_custom() method.
|
2013-03-28 20:03:58 +00:00
|
|
|
"""
|
|
|
|
# GIVEN: A mocked QDialog.exec_() method
|
|
|
|
with patch(u'PyQt4.QtGui.QDialog.exec_') as mocked_exec:
|
2013-03-28 21:24:19 +00:00
|
|
|
# WHEN: Show the dialog and create a new custom item.
|
2013-03-28 20:03:58 +00:00
|
|
|
self.form.exec_()
|
|
|
|
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')
|
|
|
|
|
2013-03-28 22:08:14 +00:00
|
|
|
|
|
|
|
def on_add_button_clicked_test(self):
|
|
|
|
"""
|
|
|
|
Test the on_add_button_clicked_test method / add_button button.
|
|
|
|
"""
|
|
|
|
# GIVEN: A mocked QDialog.exec_() method
|
|
|
|
with patch(u'PyQt4.QtGui.QDialog.exec_') as mocked_exec:
|
|
|
|
# WHEN: Show the dialog and add a new slide.
|
|
|
|
self.form.exec_()
|
|
|
|
QtTest.QTest.mouseClick(self.form.add_button, QtCore.Qt.LeftButton)
|
|
|
|
#THEN: One slide should be added.
|
2013-03-28 22:12:09 +00:00
|
|
|
assert self.form.slide_list_view.count() == 1, u'There should be one slide added.'
|
2013-04-17 18:33:44 +00:00
|
|
|
|
|
|
|
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.')
|