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

116 lines
5.2 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 #
# --------------------------------------------------------------------------- #
2017-12-29 09:15:48 +00:00
# Copyright (c) 2008-2018 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-05-06 07:43:19 +00:00
"""
Package to test the openlp.core.ui.mainwindow package.
"""
from unittest import TestCase
from unittest.mock import MagicMock, patch
2013-05-06 07:43:19 +00:00
2018-12-22 14:54:35 +00:00
from PyQt5 import QtGui
from openlp.core.state import State
2017-10-07 07:05:07 +00:00
from openlp.core.common.registry import Registry
2018-12-22 14:54:35 +00:00
from openlp.core.lib.plugin import PluginStatus
2013-05-06 07:43:19 +00:00
from openlp.core.ui.mainwindow import MainWindow
2014-03-14 22:08:44 +00:00
from tests.helpers.testmixin import TestMixin
2013-05-06 07:43:19 +00:00
2014-03-14 22:08:44 +00:00
class TestMainWindow(TestCase, TestMixin):
2013-05-06 07:43:19 +00:00
def setUp(self):
"""
Create the UI
"""
Registry.create()
self.registry = Registry()
self.setup_application()
2013-05-08 20:05:54 +00:00
# Mock cursor busy/normal methods.
self.app.set_busy_cursor = MagicMock()
self.app.set_normal_cursor = MagicMock()
2014-01-01 14:59:57 +00:00
self.app.args = []
2013-08-31 18:17:38 +00:00
Registry().register('application', self.app)
2018-01-07 05:24:55 +00:00
Registry().set_flag('no_web_server', True)
2018-12-22 14:54:35 +00:00
mocked_plugin = MagicMock()
mocked_plugin.status = PluginStatus.Active
mocked_plugin.icon = QtGui.QIcon()
Registry().register('mock_plugin', mocked_plugin)
State().add_service("mock", 1, is_plugin=True, status=PluginStatus.Active)
2013-05-08 20:05:54 +00:00
# Mock classes and methods used by mainwindow.
2018-01-07 05:24:55 +00:00
with patch('openlp.core.ui.mainwindow.SettingsForm'), \
patch('openlp.core.ui.mainwindow.OpenLPDockWidget'), \
patch('openlp.core.ui.mainwindow.QtWidgets.QToolBox'), \
patch('openlp.core.ui.mainwindow.QtWidgets.QMainWindow.addDockWidget'), \
patch('openlp.core.ui.mainwindow.ServiceManager'), \
patch('openlp.core.ui.mainwindow.ThemeManager'), \
patch('openlp.core.ui.mainwindow.ProjectorManager'), \
patch('openlp.core.ui.mainwindow.websockets.WebSocketServer'), \
2019-01-03 20:46:11 +00:00
patch('openlp.core.ui.mainwindow.PluginForm'), \
2019-01-03 20:39:53 +00:00
patch('openlp.core.ui.mainwindow.server.HttpServer'):
2013-05-08 20:05:54 +00:00
self.main_window = MainWindow()
2013-05-06 07:43:19 +00:00
def tearDown(self):
"""
Delete all the C++ objects at the end so that we don't have a segfault
"""
del self.main_window
2016-05-31 21:40:13 +00:00
def test_restore_current_media_manager_item(self):
2013-05-12 09:38:25 +00:00
"""
Regression test for bug #1152509.
"""
# GIVEN: Mocked Settings().value method.
2013-08-31 18:17:38 +00:00
with patch('openlp.core.ui.mainwindow.Settings.value') as mocked_value:
2013-05-12 09:38:25 +00:00
# save current plugin: True; current media plugin: 2
mocked_value.side_effect = [True, 2]
# WHEN: Call the restore method.
2014-01-01 14:59:57 +00:00
self.main_window.restore_current_media_manager_item()
2013-05-12 09:38:25 +00:00
# THEN: The current widget should have been set.
self.main_window.media_tool_box.setCurrentIndex.assert_called_with(2)
2014-11-09 02:54:08 +00:00
2016-05-31 21:40:13 +00:00
def test_projector_manager_dock_locked(self):
2014-11-09 02:54:08 +00:00
"""
Projector Manager enable UI options - bug #1390702
"""
# GIVEN: A mocked projector manager dock item:
projector_dock = self.main_window.projector_manager_dock
# WHEN: main_window.lock_panel action is triggered
self.main_window.lock_panel.triggered.emit(True)
# THEN: Projector manager dock should have been called with disable UI features
projector_dock.setFeatures.assert_called_with(0)
2016-05-31 21:40:13 +00:00
def test_projector_manager_dock_unlocked(self):
2014-11-09 02:54:08 +00:00
"""
Projector Manager disable UI options - bug #1390702
"""
# GIVEN: A mocked projector manager dock item:
projector_dock = self.main_window.projector_manager_dock
# WHEN: main_window.lock_panel action is triggered
self.main_window.lock_panel.triggered.emit(False)
# THEN: Projector manager dock should have been called with enable UI features
projector_dock.setFeatures.assert_called_with(7)