openlp/tests/interfaces/openlp_core/ui/test_starttimedialog.py

114 lines
5.5 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
2019-04-13 13:00:22 +00:00
##########################################################################
# OpenLP - Open Source Lyrics Projection #
# ---------------------------------------------------------------------- #
# Copyright (c) 2008-2019 OpenLP Developers #
# ---------------------------------------------------------------------- #
# 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, either version 3 of the License, or #
# (at your option) any later version. #
# #
# 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, see <https://www.gnu.org/licenses/>. #
##########################################################################
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
from unittest.mock import MagicMock, patch
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
2017-10-07 07:05:07 +00:00
from openlp.core.common.registry import Registry
2013-01-02 21:50:20 +00:00
from openlp.core.ui import starttimeform
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
"""
2017-12-23 09:09:45 +00:00
assert self.form.hour_spin_box.minimum() == 0, 'The minimum hour should stay the same as the dialog'
assert self.form.hour_spin_box.maximum() == 4, 'The maximum hour should stay the same as the dialog'
assert self.form.minute_spin_box.minimum() == 0, 'The minimum minute should stay the same as the dialog'
assert self.form.minute_spin_box.maximum() == 59, 'The maximum minute should stay the same as the dialog'
assert self.form.second_spin_box.minimum() == 0, 'The minimum second should stay the same as the dialog'
assert self.form.second_spin_box.maximum() == 59, 'The maximum second should stay the same as the dialog'
assert self.form.hour_finish_spin_box.minimum() == 0, \
'The minimum finish hour should stay the same as the dialog'
assert self.form.hour_finish_spin_box.maximum() == 4, \
'The maximum finish hour should stay the same as the dialog'
assert self.form.minute_finish_spin_box.minimum() == 0, \
'The minimum finish minute should stay the same as the dialog'
assert self.form.minute_finish_spin_box.maximum() == 59, \
'The maximum finish minute should stay the same as the dialog'
assert self.form.second_finish_spin_box.minimum() == 0, \
'The minimum finish second should stay the same as the dialog'
assert 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
2017-12-23 09:09:45 +00:00
assert self.form.hour_spin_box.value() == 0
assert self.form.minute_spin_box.value() == 1
assert self.form.second_spin_box.value() == 1
assert 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
2017-12-23 09:09:45 +00:00
assert self.form.hour_spin_box.value() == 0
assert self.form.minute_spin_box.value() == 2
assert self.form.second_spin_box.value() == 3
assert self.form.item['service_item'].start_time == 123, 'The start time should have changed'