openlp/tests/interfaces/openlp_core_ui/test_starttimedialog.py

118 lines
5.9 KiB
Python
Raw Normal View History

2014-03-14 22:08:44 +00:00
# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
2016-12-31 11:01:36 +00:00
# Copyright (c) 2008-2017 OpenLP Developers #
2014-03-14 22:08:44 +00:00
# --------------------------------------------------------------------------- #
# This program is free software; you can redistribute it and/or modify it #
# under the terms of the GNU General Public License as published by the Free #
# Software Foundation; version 2 of the License. #
# #
# This program is distributed in the hope that it will be useful, but WITHOUT #
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
# more details. #
# #
# You should have received a copy of the GNU General Public License along #
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
###############################################################################
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
2015-11-07 00:49:40 +00:00
from PyQt5 import QtCore, QtTest, QtWidgets
2013-02-16 06:51:25 +00:00
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
2014-03-14 22:08:44 +00:00
from tests.helpers.testmixin import TestMixin
2013-01-02 21:50:20 +00:00
2014-03-14 22:08:44 +00:00
class TestStartTimeDialog(TestCase, TestMixin):
2013-01-02 21:50:20 +00:00
def setUp(self):
"""
Create the UI
"""
2013-02-09 17:07:33 +00:00
Registry.create()
self.setup_application()
2015-11-07 00:49:40 +00:00
self.main_window = QtWidgets.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
2016-05-31 21:40:13 +00:00
def test_ui_defaults(self):
2013-01-02 21:50:20 +00:00
"""
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
2016-05-31 21:40:13 +00:00
def test_time_display(self):
2013-01-02 21:50:20 +00:00
"""
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}
2015-11-07 00:49:40 +00:00
with patch('PyQt5.QtWidgets.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}
2015-11-07 00:49:40 +00:00
with patch('PyQt5.QtWidgets.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')