openlp/tests/interfaces/openlp_core_ui/test_starttimedialog.py

100 lines
4.5 KiB
Python
Raw Normal View History

2013-01-02 21:50:20 +00:00
"""
Package to test the openlp.core.ui package.
2013-01-02 21:50:20 +00:00
"""
from unittest import TestCase
2013-02-16 06:51:25 +00:00
from PyQt4 import QtCore, QtGui, QtTest
2013-12-13 17:44:05 +00:00
from openlp.core.common import Registry
2013-01-02 21:50:20 +00:00
from openlp.core.ui import starttimeform
from tests.interfaces import MagicMock, patch
2013-01-02 21:50:20 +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()
old_app_instance = QtCore.QCoreApplication.instance()
if old_app_instance is None:
self.app = QtGui.QApplication([])
else:
self.app = old_app_instance
2013-01-27 07:36:04 +00:00
self.main_window = QtGui.QMainWindow()
2013-08-31 18:17:38 +00:00
Registry().register('main_window', self.main_window)
2013-01-27 07:36:04 +00:00
self.form = starttimeform.StartTimeForm()
2013-01-02 21:50:20 +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
"""
del self.form
2013-01-27 07:36:04 +00:00
del self.main_window
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
"""
2014-01-01 14:59:57 +00:00
self.assertEqual(self.form.hour_spin_box.minimum(), 0, 'The minimum hour should stay the same as the dialog')
self.assertEqual(self.form.hour_spin_box.maximum(), 4, 'The maximum hour should stay the same as the dialog')
self.assertEqual(self.form.minute_spin_box.minimum(), 0,
'The minimum minute should stay the same as the dialog')
self.assertEqual(self.form.minute_spin_box.maximum(), 59,
'The maximum minute should stay the same as the dialog')
self.assertEqual(self.form.second_spin_box.minimum(), 0,
'The minimum second should stay the same as the dialog')
self.assertEqual(self.form.second_spin_box.maximum(), 59,
'The maximum second should stay the same as the dialog')
self.assertEqual(self.form.hour_finish_spin_box.minimum(), 0,
'The minimum finish hour should stay the same as the dialog')
self.assertEqual(self.form.hour_finish_spin_box.maximum(), 4,
'The maximum finish hour should stay the same as the dialog')
self.assertEqual(self.form.minute_finish_spin_box.minimum(), 0,
'The minimum finish minute should stay the same as the dialog')
self.assertEqual(self.form.minute_finish_spin_box.maximum(), 59,
'The maximum finish minute should stay the same as the dialog')
self.assertEqual(self.form.second_finish_spin_box.minimum(), 0,
'The minimum finish second should stay the same as the dialog')
self.assertEqual(self.form.second_finish_spin_box.maximum(), 59,
'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
mocked_serviceitem = MagicMock()
2013-01-02 21:50:20 +00:00
mocked_serviceitem.start_time = 61
mocked_serviceitem.end_time = 3701
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-08-31 18:17:38 +00:00
self.form.item = {'service_item': mocked_serviceitem}
with patch('PyQt4.QtGui.QDialog.exec_'):
self.form.exec_()
2013-03-12 09:37:27 +00:00
ok_widget = self.form.button_box.button(self.form.button_box.Ok)
QtTest.QTest.mouseClick(ok_widget, 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
2014-01-01 14:59:57 +00:00
self.assertEqual(self.form.hour_spin_box.value(), 0)
self.assertEqual(self.form.minute_spin_box.value(), 1)
self.assertEqual(self.form.second_spin_box.value(), 1)
2013-08-31 18:17:38 +00:00
self.assertEqual(self.form.item['service_item'].start_time, 61, 'The start time should stay the same')
# WHEN displaying the UI, changing the time to 2min 3secs and pressing enter
2013-08-31 18:17:38 +00:00
self.form.item = {'service_item': mocked_serviceitem}
with patch('PyQt4.QtGui.QDialog.exec_'):
self.form.exec_()
2014-01-01 14:59:57 +00:00
self.form.minute_spin_box.setValue(2)
self.form.second_spin_box.setValue(3)
2013-03-12 09:37:27 +00:00
ok_widget = self.form.button_box.button(self.form.button_box.Ok)
QtTest.QTest.mouseClick(ok_widget, QtCore.Qt.LeftButton)
2013-01-27 20:36:18 +00:00
# THEN the following values are returned
2014-01-01 14:59:57 +00:00
self.assertEqual(self.form.hour_spin_box.value(), 0)
self.assertEqual(self.form.minute_spin_box.value(), 2)
self.assertEqual(self.form.second_spin_box.value(), 3)
2013-08-31 18:17:38 +00:00
self.assertEqual(self.form.item['service_item'].start_time, 123, 'The start time should have changed')