2013-01-02 21:50:20 +00:00
|
|
|
"""
|
2013-02-10 20:04:47 +00:00
|
|
|
Package to test the openlp.core.ui package.
|
2013-01-02 21:50:20 +00:00
|
|
|
"""
|
|
|
|
from unittest import TestCase
|
2013-01-21 06:52:55 +00:00
|
|
|
from mock import MagicMock, patch
|
2013-02-16 06:51:25 +00:00
|
|
|
|
|
|
|
from PyQt4 import QtCore, QtGui, QtTest
|
|
|
|
|
2013-01-27 07:36:04 +00:00
|
|
|
from openlp.core.lib import Registry
|
2013-01-02 21:50:20 +00:00
|
|
|
from openlp.core.ui import starttimeform
|
2013-02-18 21:05:08 +00:00
|
|
|
|
2013-01-02 21:50:20 +00:00
|
|
|
|
2013-02-10 20:09:39 +00:00
|
|
|
|
2013-01-02 21:50:20 +00:00
|
|
|
class TestStartTimeDialog(TestCase):
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
"""
|
|
|
|
Create the UI
|
|
|
|
"""
|
2013-02-09 17:07:33 +00:00
|
|
|
Registry.create()
|
2013-03-14 22:22:18 +00:00
|
|
|
self.app = QtGui.QApplication([])
|
2013-01-27 07:36:04 +00:00
|
|
|
self.main_window = QtGui.QMainWindow()
|
|
|
|
Registry().register(u'main_window', self.main_window)
|
|
|
|
self.form = starttimeform.StartTimeForm()
|
2013-01-02 21:50:20 +00:00
|
|
|
|
2013-01-21 07:26:36 +00:00
|
|
|
def tearDown(self):
|
2013-01-21 13:04:18 +00:00
|
|
|
"""
|
|
|
|
Delete all the C++ objects at the end so that we don't have a segfault
|
|
|
|
"""
|
2013-01-21 07:26:36 +00:00
|
|
|
del self.form
|
2013-01-27 07:36:04 +00:00
|
|
|
del self.main_window
|
2013-01-21 07:26:36 +00:00
|
|
|
del self.app
|
|
|
|
|
2013-01-02 21:50:20 +00:00
|
|
|
def ui_defaults_test(self):
|
|
|
|
"""
|
2013-01-27 07:36:04 +00:00
|
|
|
Test StartTimeDialog are defaults correct
|
2013-01-02 21:50:20 +00:00
|
|
|
"""
|
2013-01-30 18:55:46 +00:00
|
|
|
self.assertEqual(self.form.hourSpinBox.minimum(), 0, u'The minimum hour should stay the same as the dialog')
|
|
|
|
self.assertEqual(self.form.hourSpinBox.maximum(), 4, u'The maximum hour should stay the same as the dialog')
|
2013-01-30 18:18:28 +00:00
|
|
|
self.assertEqual(self.form.minuteSpinBox.minimum(), 0,
|
2013-01-30 18:55:46 +00:00
|
|
|
u'The minimum minute should stay the same as the dialog')
|
2013-01-30 18:18:28 +00:00
|
|
|
self.assertEqual(self.form.minuteSpinBox.maximum(), 59,
|
2013-01-30 18:55:46 +00:00
|
|
|
u'The maximum minute should stay the same as the dialog')
|
2013-01-30 18:18:28 +00:00
|
|
|
self.assertEqual(self.form.secondSpinBox.minimum(), 0,
|
2013-01-30 18:55:46 +00:00
|
|
|
u'The minimum second should stay the same as the dialog')
|
2013-01-30 18:18:28 +00:00
|
|
|
self.assertEqual(self.form.secondSpinBox.maximum(), 59,
|
2013-01-30 18:55:46 +00:00
|
|
|
u'The maximum second should stay the same as the dialog')
|
2013-01-30 18:18:28 +00:00
|
|
|
self.assertEqual(self.form.hourFinishSpinBox.minimum(), 0,
|
2013-01-30 18:55:46 +00:00
|
|
|
u'The minimum finish hour should stay the same as the dialog')
|
2013-01-30 18:18:28 +00:00
|
|
|
self.assertEqual(self.form.hourFinishSpinBox.maximum(), 4,
|
2013-01-30 18:55:46 +00:00
|
|
|
u'The maximum finish hour should stay the same as the dialog')
|
2013-01-30 18:18:28 +00:00
|
|
|
self.assertEqual(self.form.minuteFinishSpinBox.minimum(), 0,
|
2013-01-30 18:55:46 +00:00
|
|
|
u'The minimum finish minute should stay the same as the dialog')
|
2013-01-30 18:18:28 +00:00
|
|
|
self.assertEqual(self.form.minuteFinishSpinBox.maximum(), 59,
|
2013-01-30 18:55:46 +00:00
|
|
|
u'The maximum finish minute should stay the same as the dialog')
|
2013-01-30 18:18:28 +00:00
|
|
|
self.assertEqual(self.form.secondFinishSpinBox.minimum(), 0,
|
2013-01-30 18:55:46 +00:00
|
|
|
u'The minimum finish second should stay the same as the dialog')
|
2013-01-30 18:18:28 +00:00
|
|
|
self.assertEqual(self.form.secondFinishSpinBox.maximum(), 59,
|
2013-01-30 18:55:46 +00:00
|
|
|
u'The maximum finish second should stay the same as the dialog')
|
2013-01-02 21:50:20 +00:00
|
|
|
|
|
|
|
def time_display_test(self):
|
|
|
|
"""
|
2013-01-27 20:36:18 +00:00
|
|
|
Test StartTimeDialog display functionality
|
2013-01-02 21:50:20 +00:00
|
|
|
"""
|
2013-01-21 06:52:55 +00:00
|
|
|
# GIVEN: A service item with with time
|
2013-01-21 07:26:36 +00:00
|
|
|
mocked_serviceitem = MagicMock()
|
2013-01-02 21:50:20 +00:00
|
|
|
mocked_serviceitem.start_time = 61
|
|
|
|
mocked_serviceitem.end_time = 3701
|
2013-01-25 20:50:18 +00:00
|
|
|
mocked_serviceitem.media_length = 3701
|
2013-01-02 21:50:20 +00:00
|
|
|
|
2013-01-21 06:52:55 +00:00
|
|
|
# WHEN displaying the UI and pressing enter
|
2013-01-25 20:50:18 +00:00
|
|
|
self.form.item = {u'service_item': mocked_serviceitem}
|
2013-02-09 17:07:33 +00:00
|
|
|
with patch(u'PyQt4.QtGui.QDialog.exec_'):
|
2013-01-25 20:50:18 +00:00
|
|
|
self.form.exec_()
|
2013-01-27 20:59:02 +00:00
|
|
|
okWidget = self.form.button_box.button(self.form.button_box.Ok)
|
2013-01-25 20:50:18 +00:00
|
|
|
QtTest.QTest.mouseClick(okWidget, QtCore.Qt.LeftButton)
|
2013-01-21 06:52:55 +00:00
|
|
|
|
2013-01-27 20:36:18 +00:00
|
|
|
# THEN the following input values are returned
|
2013-01-24 19:08:47 +00:00
|
|
|
self.assertEqual(self.form.hourSpinBox.value(), 0)
|
2013-01-25 20:50:18 +00:00
|
|
|
self.assertEqual(self.form.minuteSpinBox.value(), 1)
|
|
|
|
self.assertEqual(self.form.secondSpinBox.value(), 1)
|
2013-01-30 18:55:46 +00:00
|
|
|
self.assertEqual(self.form.item[u'service_item'].start_time, 61, u'The start time should stay the same')
|
2013-01-25 20:50:18 +00:00
|
|
|
|
|
|
|
# WHEN displaying the UI, changing the time to 2min 3secs and pressing enter
|
|
|
|
self.form.item = {u'service_item': mocked_serviceitem}
|
2013-02-09 17:07:33 +00:00
|
|
|
with patch(u'PyQt4.QtGui.QDialog.exec_'):
|
2013-01-25 20:50:18 +00:00
|
|
|
self.form.exec_()
|
|
|
|
self.form.minuteSpinBox.setValue(2)
|
|
|
|
self.form.secondSpinBox.setValue(3)
|
2013-01-27 20:59:02 +00:00
|
|
|
okWidget = self.form.button_box.button(self.form.button_box.Ok)
|
2013-01-25 20:50:18 +00:00
|
|
|
QtTest.QTest.mouseClick(okWidget, QtCore.Qt.LeftButton)
|
|
|
|
|
2013-01-27 20:36:18 +00:00
|
|
|
# THEN the following values are returned
|
2013-01-25 20:50:18 +00:00
|
|
|
self.assertEqual(self.form.hourSpinBox.value(), 0)
|
|
|
|
self.assertEqual(self.form.minuteSpinBox.value(), 2)
|
|
|
|
self.assertEqual(self.form.secondSpinBox.value(), 3)
|
2013-02-10 20:04:47 +00:00
|
|
|
self.assertEqual(self.form.item[u'service_item'].start_time, 123, u'The start time should have changed')
|