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-02-13 19:10:41 +00:00
|
|
|
"""
|
2013-02-13 19:22:43 +00:00
|
|
|
Package to test the openlp.core.lib package.
|
2013-02-13 19:10:41 +00:00
|
|
|
"""
|
2013-02-16 06:51:25 +00:00
|
|
|
from unittest import TestCase
|
2017-04-24 05:17:55 +00:00
|
|
|
from unittest.mock import MagicMock, patch
|
2013-02-16 06:51:25 +00:00
|
|
|
|
2017-10-04 07:44:08 +00:00
|
|
|
from PyQt5 import QtCore, QtGui, QtWidgets
|
|
|
|
|
2017-10-07 07:05:07 +00:00
|
|
|
from openlp.core.common.registry import Registry
|
2018-10-02 04:39:42 +00:00
|
|
|
from openlp.core.lib.serviceitem import ItemCapabilities, ServiceItem
|
2017-10-23 22:09:57 +00:00
|
|
|
from openlp.core.ui.servicemanager import ServiceManager
|
2014-03-14 22:08:44 +00:00
|
|
|
from tests.helpers.testmixin import TestMixin
|
2013-02-13 19:10:41 +00:00
|
|
|
|
2018-10-02 04:39:42 +00:00
|
|
|
|
2014-03-14 22:08:44 +00:00
|
|
|
class TestServiceManager(TestCase, TestMixin):
|
2017-10-23 22:09:57 +00:00
|
|
|
"""
|
|
|
|
Test the service manager
|
|
|
|
"""
|
|
|
|
|
|
|
|
def _create_mock_action(self, name, **kwargs):
|
|
|
|
"""
|
|
|
|
Create a fake action with some "real" attributes
|
|
|
|
"""
|
|
|
|
action = QtWidgets.QAction(self.service_manager)
|
|
|
|
action.setObjectName(name)
|
|
|
|
if kwargs.get('triggers'):
|
|
|
|
action.triggered.connect(kwargs.pop('triggers'))
|
|
|
|
self.service_manager.toolbar.actions[name] = action
|
|
|
|
return action
|
2013-02-13 19:10:41 +00:00
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
"""
|
|
|
|
Create the UI
|
|
|
|
"""
|
|
|
|
Registry.create()
|
2014-10-22 20:43:05 +00:00
|
|
|
self.setup_application()
|
2013-08-31 18:17:38 +00:00
|
|
|
Registry().register('application', MagicMock())
|
2017-10-23 22:09:57 +00:00
|
|
|
Registry().register('main_window', MagicMock(service_manager_settings_section='servicemanager'))
|
|
|
|
self.service_manager = ServiceManager()
|
|
|
|
self.add_toolbar_action_patcher = patch('openlp.core.ui.servicemanager.OpenLPToolbar.add_toolbar_action')
|
|
|
|
self.mocked_add_toolbar_action = self.add_toolbar_action_patcher.start()
|
|
|
|
self.mocked_add_toolbar_action.side_effect = self._create_mock_action
|
2013-02-13 19:10:41 +00:00
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
"""
|
|
|
|
Delete all the C++ objects at the end so that we don't have a segfault
|
|
|
|
"""
|
2017-10-23 22:09:57 +00:00
|
|
|
self.add_toolbar_action_patcher.stop()
|
|
|
|
del self.service_manager
|
2013-02-13 19:10:41 +00:00
|
|
|
|
2016-05-31 21:40:13 +00:00
|
|
|
def test_basic_service_manager(self):
|
2013-02-13 19:10:41 +00:00
|
|
|
"""
|
2013-12-31 07:27:07 +00:00
|
|
|
Test the Service Manager UI Functionality
|
2013-02-13 19:10:41 +00:00
|
|
|
"""
|
|
|
|
# GIVEN: A New Service Manager instance
|
2013-12-30 19:50:34 +00:00
|
|
|
# WHEN I have set up the display
|
|
|
|
self.service_manager.setup_ui(self.service_manager)
|
2017-10-23 22:09:57 +00:00
|
|
|
|
2013-02-13 19:10:41 +00:00
|
|
|
# THEN the count of items should be zero
|
2017-12-23 09:09:45 +00:00
|
|
|
assert self.service_manager.service_manager_list.topLevelItemCount() == 0, \
|
|
|
|
'The service manager list should be empty '
|
2013-03-30 14:45:02 +00:00
|
|
|
|
2017-10-23 22:09:57 +00:00
|
|
|
@patch('openlp.core.ui.servicemanager.QtWidgets.QTreeWidget.itemAt')
|
|
|
|
@patch('openlp.core.ui.servicemanager.QtWidgets.QWidget.mapToGlobal')
|
|
|
|
@patch('openlp.core.ui.servicemanager.QtWidgets.QMenu.exec')
|
|
|
|
def test_default_context_menu(self, mocked_exec, mocked_mapToGlobal, mocked_item_at_method):
|
2013-03-30 14:45:02 +00:00
|
|
|
"""
|
2013-12-30 19:50:34 +00:00
|
|
|
Test the context_menu() method with a default service item
|
2013-03-30 14:45:02 +00:00
|
|
|
"""
|
|
|
|
# GIVEN: A service item added
|
2017-10-23 22:09:57 +00:00
|
|
|
mocked_item = MagicMock()
|
|
|
|
mocked_item.parent.return_value = None
|
|
|
|
mocked_item_at_method.return_value = mocked_item
|
|
|
|
mocked_item.data.return_value = 1
|
2013-12-30 19:50:34 +00:00
|
|
|
self.service_manager.setup_ui(self.service_manager)
|
2017-10-23 22:09:57 +00:00
|
|
|
# A service item without capabilities.
|
|
|
|
service_item = ServiceItem()
|
|
|
|
self.service_manager.service_items = [{'service_item': service_item}]
|
|
|
|
q_point = None
|
|
|
|
# Mocked actions.
|
|
|
|
self.service_manager.edit_action.setVisible = MagicMock()
|
|
|
|
self.service_manager.create_custom_action.setVisible = MagicMock()
|
|
|
|
self.service_manager.maintain_action.setVisible = MagicMock()
|
|
|
|
self.service_manager.notes_action.setVisible = MagicMock()
|
|
|
|
self.service_manager.time_action.setVisible = MagicMock()
|
|
|
|
self.service_manager.auto_start_action.setVisible = MagicMock()
|
2013-03-30 14:45:02 +00:00
|
|
|
|
2017-10-23 22:09:57 +00:00
|
|
|
# WHEN: Show the context menu.
|
|
|
|
self.service_manager.context_menu(q_point)
|
2013-03-30 14:45:02 +00:00
|
|
|
|
2017-10-23 22:09:57 +00:00
|
|
|
# THEN: The following actions should be not visible.
|
|
|
|
self.service_manager.edit_action.setVisible.assert_called_once_with(False), \
|
|
|
|
'The action should be set invisible.'
|
|
|
|
self.service_manager.create_custom_action.setVisible.assert_called_once_with(False), \
|
|
|
|
'The action should be set invisible.'
|
|
|
|
self.service_manager.maintain_action.setVisible.assert_called_once_with(False), \
|
|
|
|
'The action should be set invisible.'
|
|
|
|
self.service_manager.notes_action.setVisible.assert_called_with(True), 'The action should be set visible.'
|
|
|
|
self.service_manager.time_action.setVisible.assert_called_once_with(False), \
|
|
|
|
'The action should be set invisible.'
|
|
|
|
self.service_manager.auto_start_action.setVisible.assert_called_once_with(False), \
|
|
|
|
'The action should be set invisible.'
|
2013-12-30 19:50:34 +00:00
|
|
|
|
2016-05-31 21:40:13 +00:00
|
|
|
def test_edit_context_menu(self):
|
2013-12-30 19:50:34 +00:00
|
|
|
"""
|
|
|
|
Test the context_menu() method with a edit service item
|
|
|
|
"""
|
|
|
|
# GIVEN: A service item added
|
|
|
|
self.service_manager.setup_ui(self.service_manager)
|
2015-11-07 00:49:40 +00:00
|
|
|
with patch('PyQt5.QtWidgets.QTreeWidget.itemAt') as mocked_item_at_method, \
|
|
|
|
patch('PyQt5.QtWidgets.QWidget.mapToGlobal'), \
|
|
|
|
patch('PyQt5.QtWidgets.QMenu.exec'):
|
2013-12-30 19:50:34 +00:00
|
|
|
mocked_item = MagicMock()
|
|
|
|
mocked_item.parent.return_value = None
|
|
|
|
mocked_item_at_method.return_value = mocked_item
|
|
|
|
# We want 1 to be returned for the position
|
|
|
|
mocked_item.data.return_value = 1
|
|
|
|
# A service item without capabilities.
|
|
|
|
service_item = ServiceItem()
|
|
|
|
service_item.add_capability(ItemCapabilities.CanEdit)
|
|
|
|
service_item.edit_id = 1
|
|
|
|
self.service_manager.service_items = [{'service_item': service_item}]
|
|
|
|
q_point = None
|
|
|
|
# Mocked actions.
|
|
|
|
self.service_manager.edit_action.setVisible = MagicMock()
|
|
|
|
self.service_manager.create_custom_action.setVisible = MagicMock()
|
|
|
|
self.service_manager.maintain_action.setVisible = MagicMock()
|
|
|
|
self.service_manager.notes_action.setVisible = MagicMock()
|
|
|
|
self.service_manager.time_action.setVisible = MagicMock()
|
|
|
|
self.service_manager.auto_start_action.setVisible = MagicMock()
|
|
|
|
|
|
|
|
# WHEN: Show the context menu.
|
|
|
|
self.service_manager.context_menu(q_point)
|
|
|
|
|
|
|
|
# THEN: The following actions should be not visible.
|
|
|
|
self.service_manager.edit_action.setVisible.assert_called_with(True), \
|
|
|
|
'The action should be set visible.'
|
|
|
|
self.service_manager.create_custom_action.setVisible.assert_called_once_with(False), \
|
|
|
|
'The action should be set invisible.'
|
|
|
|
self.service_manager.maintain_action.setVisible.assert_called_once_with(False), \
|
|
|
|
'The action should be set invisible.'
|
|
|
|
self.service_manager.notes_action.setVisible.assert_called_with(True), 'The action should be set visible.'
|
|
|
|
self.service_manager.time_action.setVisible.assert_called_once_with(False), \
|
|
|
|
'The action should be set invisible.'
|
|
|
|
self.service_manager.auto_start_action.setVisible.assert_called_once_with(False), \
|
|
|
|
'The action should be set invisible.'
|
|
|
|
|
2016-05-31 21:40:13 +00:00
|
|
|
def test_maintain_context_menu(self):
|
2013-12-30 19:50:34 +00:00
|
|
|
"""
|
|
|
|
Test the context_menu() method with a maintain
|
|
|
|
"""
|
|
|
|
# GIVEN: A service item added
|
|
|
|
self.service_manager.setup_ui(self.service_manager)
|
2015-11-07 00:49:40 +00:00
|
|
|
with patch('PyQt5.QtWidgets.QTreeWidget.itemAt') as mocked_item_at_method, \
|
|
|
|
patch('PyQt5.QtWidgets.QWidget.mapToGlobal'), \
|
|
|
|
patch('PyQt5.QtWidgets.QMenu.exec'):
|
2013-12-30 19:50:34 +00:00
|
|
|
mocked_item = MagicMock()
|
|
|
|
mocked_item.parent.return_value = None
|
|
|
|
mocked_item_at_method.return_value = mocked_item
|
|
|
|
# We want 1 to be returned for the position
|
|
|
|
mocked_item.data.return_value = 1
|
|
|
|
# A service item without capabilities.
|
|
|
|
service_item = ServiceItem()
|
|
|
|
service_item.add_capability(ItemCapabilities.CanMaintain)
|
|
|
|
self.service_manager.service_items = [{'service_item': service_item}]
|
|
|
|
q_point = None
|
|
|
|
# Mocked actions.
|
|
|
|
self.service_manager.edit_action.setVisible = MagicMock()
|
|
|
|
self.service_manager.create_custom_action.setVisible = MagicMock()
|
|
|
|
self.service_manager.maintain_action.setVisible = MagicMock()
|
|
|
|
self.service_manager.notes_action.setVisible = MagicMock()
|
|
|
|
self.service_manager.time_action.setVisible = MagicMock()
|
|
|
|
self.service_manager.auto_start_action.setVisible = MagicMock()
|
|
|
|
|
|
|
|
# WHEN: Show the context menu.
|
|
|
|
self.service_manager.context_menu(q_point)
|
|
|
|
|
|
|
|
# THEN: The following actions should be not visible.
|
|
|
|
self.service_manager.edit_action.setVisible.assert_called_once_with(False), \
|
|
|
|
'The action should be set invisible.'
|
|
|
|
self.service_manager.create_custom_action.setVisible.assert_called_once_with(False), \
|
|
|
|
'The action should be set invisible.'
|
|
|
|
self.service_manager.maintain_action.setVisible.assert_called_with(True), \
|
|
|
|
'The action should be set visible.'
|
|
|
|
self.service_manager.notes_action.setVisible.assert_called_with(True), 'The action should be set visible.'
|
|
|
|
self.service_manager.time_action.setVisible.assert_called_once_with(False), \
|
|
|
|
'The action should be set invisible.'
|
|
|
|
self.service_manager.auto_start_action.setVisible.assert_called_once_with(False), \
|
|
|
|
'The action should be set invisible.'
|
|
|
|
|
2016-05-31 21:40:13 +00:00
|
|
|
def test_loopy_context_menu(self):
|
2013-12-30 19:50:34 +00:00
|
|
|
"""
|
|
|
|
Test the context_menu() method with a loop
|
|
|
|
"""
|
|
|
|
# GIVEN: A service item added
|
|
|
|
self.service_manager.setup_ui(self.service_manager)
|
2015-11-07 00:49:40 +00:00
|
|
|
with patch('PyQt5.QtWidgets.QTreeWidget.itemAt') as mocked_item_at_method, \
|
|
|
|
patch('PyQt5.QtWidgets.QWidget.mapToGlobal'), \
|
|
|
|
patch('PyQt5.QtWidgets.QMenu.exec'):
|
2013-12-30 19:50:34 +00:00
|
|
|
mocked_item = MagicMock()
|
|
|
|
mocked_item.parent.return_value = None
|
|
|
|
mocked_item_at_method.return_value = mocked_item
|
|
|
|
# We want 1 to be returned for the position
|
|
|
|
mocked_item.data.return_value = 1
|
|
|
|
# A service item without capabilities.
|
|
|
|
service_item = ServiceItem()
|
|
|
|
service_item.add_capability(ItemCapabilities.CanLoop)
|
|
|
|
service_item._raw_frames.append("One")
|
|
|
|
service_item._raw_frames.append("Two")
|
|
|
|
self.service_manager.service_items = [{'service_item': service_item}]
|
|
|
|
q_point = None
|
|
|
|
# Mocked actions.
|
|
|
|
self.service_manager.edit_action.setVisible = MagicMock()
|
|
|
|
self.service_manager.create_custom_action.setVisible = MagicMock()
|
|
|
|
self.service_manager.maintain_action.setVisible = MagicMock()
|
|
|
|
self.service_manager.notes_action.setVisible = MagicMock()
|
|
|
|
self.service_manager.time_action.setVisible = MagicMock()
|
|
|
|
self.service_manager.auto_start_action.setVisible = MagicMock()
|
|
|
|
|
|
|
|
# WHEN: Show the context menu.
|
|
|
|
self.service_manager.context_menu(q_point)
|
|
|
|
|
|
|
|
# THEN: The following actions should be not visible.
|
|
|
|
self.service_manager.edit_action.setVisible.assert_called_once_with(False), \
|
|
|
|
'The action should be set invisible.'
|
|
|
|
self.service_manager.create_custom_action.setVisible.assert_called_once_with(False), \
|
|
|
|
'The action should be set invisible.'
|
|
|
|
self.service_manager.maintain_action.setVisible.assert_called_once_with(False), \
|
|
|
|
'The action should be set invisible.'
|
|
|
|
self.service_manager.notes_action.setVisible.assert_called_with(True), 'The action should be set visible.'
|
|
|
|
self.service_manager.time_action.setVisible.assert_called_once_with(False), \
|
|
|
|
'The action should be set invisible.'
|
|
|
|
self.service_manager.auto_start_action.setVisible.assert_called_once_with(False), \
|
|
|
|
'The action should be set invisible.'
|
|
|
|
|
2016-05-31 21:40:13 +00:00
|
|
|
def test_start_time_context_menu(self):
|
2013-12-30 19:50:34 +00:00
|
|
|
"""
|
|
|
|
Test the context_menu() method with a start time
|
|
|
|
"""
|
|
|
|
# GIVEN: A service item added
|
|
|
|
self.service_manager.setup_ui(self.service_manager)
|
2015-11-07 00:49:40 +00:00
|
|
|
with patch('PyQt5.QtWidgets.QTreeWidget.itemAt') as mocked_item_at_method, \
|
|
|
|
patch('PyQt5.QtWidgets.QWidget.mapToGlobal'), \
|
|
|
|
patch('PyQt5.QtWidgets.QMenu.exec'):
|
2013-12-30 19:50:34 +00:00
|
|
|
mocked_item = MagicMock()
|
|
|
|
mocked_item.parent.return_value = None
|
|
|
|
mocked_item_at_method.return_value = mocked_item
|
|
|
|
# We want 1 to be returned for the position
|
|
|
|
mocked_item.data.return_value = 1
|
|
|
|
# A service item without capabilities.
|
|
|
|
service_item = ServiceItem()
|
|
|
|
service_item.add_capability(ItemCapabilities.HasVariableStartTime)
|
|
|
|
self.service_manager.service_items = [{'service_item': service_item}]
|
|
|
|
q_point = None
|
|
|
|
# Mocked actions.
|
|
|
|
self.service_manager.edit_action.setVisible = MagicMock()
|
|
|
|
self.service_manager.create_custom_action.setVisible = MagicMock()
|
|
|
|
self.service_manager.maintain_action.setVisible = MagicMock()
|
|
|
|
self.service_manager.notes_action.setVisible = MagicMock()
|
|
|
|
self.service_manager.time_action.setVisible = MagicMock()
|
|
|
|
self.service_manager.auto_start_action.setVisible = MagicMock()
|
|
|
|
|
|
|
|
# WHEN: Show the context menu.
|
|
|
|
self.service_manager.context_menu(q_point)
|
|
|
|
|
|
|
|
# THEN: The following actions should be not visible.
|
|
|
|
self.service_manager.edit_action.setVisible.assert_called_once_with(False), \
|
|
|
|
'The action should be set invisible.'
|
|
|
|
self.service_manager.create_custom_action.setVisible.assert_called_once_with(False), \
|
|
|
|
'The action should be set invisible.'
|
|
|
|
self.service_manager.maintain_action.setVisible.assert_called_once_with(False), \
|
|
|
|
'The action should be set invisible.'
|
|
|
|
self.service_manager.notes_action.setVisible.assert_called_with(True), 'The action should be set visible.'
|
|
|
|
self.service_manager.time_action.setVisible.assert_called_with(True), \
|
|
|
|
'The action should be set visible.'
|
|
|
|
self.service_manager.auto_start_action.setVisible.assert_called_once_with(False), \
|
|
|
|
'The action should be set invisible.'
|
|
|
|
|
2016-05-31 21:40:13 +00:00
|
|
|
def test_auto_start_context_menu(self):
|
2013-12-30 19:50:34 +00:00
|
|
|
"""
|
|
|
|
Test the context_menu() method with can auto start
|
|
|
|
"""
|
|
|
|
# GIVEN: A service item added
|
|
|
|
self.service_manager.setup_ui(self.service_manager)
|
2015-11-07 00:49:40 +00:00
|
|
|
with patch('PyQt5.QtWidgets.QTreeWidget.itemAt') as mocked_item_at_method, \
|
|
|
|
patch('PyQt5.QtWidgets.QWidget.mapToGlobal'), \
|
|
|
|
patch('PyQt5.QtWidgets.QMenu.exec'):
|
2013-12-30 19:50:34 +00:00
|
|
|
mocked_item = MagicMock()
|
|
|
|
mocked_item.parent.return_value = None
|
|
|
|
mocked_item_at_method.return_value = mocked_item
|
|
|
|
# We want 1 to be returned for the position
|
|
|
|
mocked_item.data.return_value = 1
|
|
|
|
# A service item without capabilities.
|
|
|
|
service_item = ServiceItem()
|
|
|
|
service_item.add_capability(ItemCapabilities.CanAutoStartForLive)
|
|
|
|
self.service_manager.service_items = [{'service_item': service_item}]
|
|
|
|
q_point = None
|
|
|
|
# Mocked actions.
|
|
|
|
self.service_manager.edit_action.setVisible = MagicMock()
|
|
|
|
self.service_manager.create_custom_action.setVisible = MagicMock()
|
|
|
|
self.service_manager.maintain_action.setVisible = MagicMock()
|
|
|
|
self.service_manager.notes_action.setVisible = MagicMock()
|
|
|
|
self.service_manager.time_action.setVisible = MagicMock()
|
|
|
|
self.service_manager.auto_start_action.setVisible = MagicMock()
|
2014-03-31 19:07:54 +00:00
|
|
|
self.service_manager.rename_action.setVisible = MagicMock()
|
2013-12-30 19:50:34 +00:00
|
|
|
|
|
|
|
# WHEN: Show the context menu.
|
|
|
|
self.service_manager.context_menu(q_point)
|
|
|
|
|
|
|
|
# THEN: The following actions should be not visible.
|
|
|
|
self.service_manager.edit_action.setVisible.assert_called_once_with(False), \
|
|
|
|
'The action should be set invisible.'
|
|
|
|
self.service_manager.create_custom_action.setVisible.assert_called_once_with(False), \
|
|
|
|
'The action should be set invisible.'
|
|
|
|
self.service_manager.maintain_action.setVisible.assert_called_once_with(False), \
|
|
|
|
'The action should be set invisible.'
|
|
|
|
self.service_manager.notes_action.setVisible.assert_called_with(True), 'The action should be set visible.'
|
|
|
|
self.service_manager.time_action.setVisible.assert_called_once_with(False), \
|
|
|
|
'The action should be set invisible.'
|
|
|
|
self.service_manager.auto_start_action.setVisible.assert_called_with(True), \
|
|
|
|
'The action should be set visible.'
|
2014-03-31 19:07:54 +00:00
|
|
|
self.service_manager.rename_action.setVisible.assert_called_once_with(False), \
|
|
|
|
'The action should be set invisible.'
|
2013-12-30 19:50:34 +00:00
|
|
|
|
2016-05-31 21:40:13 +00:00
|
|
|
def test_click_on_new_service(self):
|
2013-12-31 07:27:07 +00:00
|
|
|
"""
|
2013-12-31 20:29:03 +00:00
|
|
|
Test the on_new_service event handler is called by the UI
|
2013-12-31 07:27:07 +00:00
|
|
|
"""
|
|
|
|
# GIVEN: An initial form
|
2013-12-31 20:29:03 +00:00
|
|
|
mocked_event = MagicMock()
|
|
|
|
self.service_manager.on_new_service_clicked = mocked_event
|
2013-12-31 07:27:07 +00:00
|
|
|
self.service_manager.setup_ui(self.service_manager)
|
|
|
|
|
|
|
|
# WHEN displaying the UI and pressing cancel
|
|
|
|
new_service = self.service_manager.toolbar.actions['newService']
|
|
|
|
new_service.trigger()
|
|
|
|
|
2013-12-31 20:29:03 +00:00
|
|
|
assert mocked_event.call_count == 1, 'The on_new_service_clicked method should have been called once'
|
2017-06-13 15:49:48 +00:00
|
|
|
|
2017-06-15 18:05:38 +00:00
|
|
|
def test_expand_selection_on_right_arrow(self):
|
2017-06-22 20:42:46 +00:00
|
|
|
"""
|
|
|
|
Test that a right arrow key press event calls the on_expand_selection function
|
|
|
|
"""
|
2017-06-22 20:49:14 +00:00
|
|
|
# GIVEN a mocked expand function
|
2017-06-15 18:05:38 +00:00
|
|
|
self.service_manager.on_expand_selection = MagicMock()
|
|
|
|
|
2017-06-22 20:49:14 +00:00
|
|
|
# WHEN the right arrow key event is called
|
2017-06-15 18:05:38 +00:00
|
|
|
self.service_manager.setup_ui(self.service_manager)
|
|
|
|
event = QtGui.QKeyEvent(QtCore.QEvent.KeyPress, QtCore.Qt.Key_Right, QtCore.Qt.NoModifier)
|
|
|
|
self.service_manager.service_manager_list.keyPressEvent(event)
|
|
|
|
|
2017-06-22 20:49:14 +00:00
|
|
|
# THEN the on_expand_selection function should have been called.
|
2017-06-15 18:05:38 +00:00
|
|
|
self.service_manager.on_expand_selection.assert_called_once_with()
|
|
|
|
|
|
|
|
def test_collapse_selection_on_left_arrow(self):
|
2017-06-22 20:42:46 +00:00
|
|
|
"""
|
|
|
|
Test that a left arrow key press event calls the on_collapse_selection function
|
|
|
|
"""
|
2017-06-22 20:49:14 +00:00
|
|
|
# GIVEN a mocked collapse function
|
2017-06-15 18:05:38 +00:00
|
|
|
self.service_manager.on_collapse_selection = MagicMock()
|
|
|
|
|
2017-06-22 20:49:14 +00:00
|
|
|
# WHEN the left arrow key event is called
|
2017-06-15 18:05:38 +00:00
|
|
|
self.service_manager.setup_ui(self.service_manager)
|
|
|
|
event = QtGui.QKeyEvent(QtCore.QEvent.KeyPress, QtCore.Qt.Key_Left, QtCore.Qt.NoModifier)
|
|
|
|
self.service_manager.service_manager_list.keyPressEvent(event)
|
|
|
|
|
2017-06-22 20:49:14 +00:00
|
|
|
# THEN the on_collapse_selection function should have been called.
|
2017-06-15 18:05:38 +00:00
|
|
|
self.service_manager.on_collapse_selection.assert_called_once_with()
|
|
|
|
|
|
|
|
def test_move_selection_down_on_down_arrow(self):
|
2017-06-22 20:42:46 +00:00
|
|
|
"""
|
|
|
|
Test that a down arrow key press event calls the on_move_selection_down function
|
|
|
|
"""
|
2017-06-22 20:49:14 +00:00
|
|
|
# GIVEN a mocked move down function
|
2017-06-15 18:05:38 +00:00
|
|
|
self.service_manager.on_move_selection_down = MagicMock()
|
|
|
|
|
2017-06-22 20:49:14 +00:00
|
|
|
# WHEN the down arrow key event is called
|
2017-06-15 18:05:38 +00:00
|
|
|
self.service_manager.setup_ui(self.service_manager)
|
|
|
|
event = QtGui.QKeyEvent(QtCore.QEvent.KeyPress, QtCore.Qt.Key_Down, QtCore.Qt.NoModifier)
|
|
|
|
self.service_manager.service_manager_list.keyPressEvent(event)
|
|
|
|
|
2017-06-22 20:49:14 +00:00
|
|
|
# THEN the on_move_selection_down function should have been called.
|
2017-06-15 18:05:38 +00:00
|
|
|
self.service_manager.on_move_selection_down.assert_called_once_with()
|
|
|
|
|
|
|
|
def test_move_selection_up_on_up_arrow(self):
|
2017-06-22 20:42:46 +00:00
|
|
|
"""
|
|
|
|
Test that an up arrow key press event calls the on_move_selection_up function
|
|
|
|
"""
|
2017-06-22 20:49:14 +00:00
|
|
|
# GIVEN a mocked move up function
|
2017-06-15 18:05:38 +00:00
|
|
|
self.service_manager.on_move_selection_up = MagicMock()
|
|
|
|
|
2017-06-22 20:49:14 +00:00
|
|
|
# WHEN the up arrow key event is called
|
2017-06-15 18:05:38 +00:00
|
|
|
self.service_manager.setup_ui(self.service_manager)
|
|
|
|
event = QtGui.QKeyEvent(QtCore.QEvent.KeyPress, QtCore.Qt.Key_Up, QtCore.Qt.NoModifier)
|
|
|
|
self.service_manager.service_manager_list.keyPressEvent(event)
|
|
|
|
|
2017-06-22 20:49:14 +00:00
|
|
|
# THEN the on_move_selection_up function should have been called.
|
2017-06-15 18:05:38 +00:00
|
|
|
self.service_manager.on_move_selection_up.assert_called_once_with()
|
|
|
|
|
2017-06-27 17:42:54 +00:00
|
|
|
def _setup_service_manager_list(self):
|
2017-06-15 18:05:38 +00:00
|
|
|
self.service_manager.expanded = MagicMock()
|
2017-06-27 17:42:54 +00:00
|
|
|
self.service_manager.collapsed = MagicMock()
|
2017-06-15 18:05:38 +00:00
|
|
|
verse_1 = QtWidgets.QTreeWidgetItem(0)
|
|
|
|
verse_2 = QtWidgets.QTreeWidgetItem(0)
|
|
|
|
song_item = QtWidgets.QTreeWidgetItem(0)
|
|
|
|
song_item.addChild(verse_1)
|
|
|
|
song_item.addChild(verse_2)
|
2017-06-13 15:49:48 +00:00
|
|
|
self.service_manager.setup_ui(self.service_manager)
|
2017-06-15 18:05:38 +00:00
|
|
|
self.service_manager.service_manager_list.addTopLevelItem(song_item)
|
2017-06-27 17:42:54 +00:00
|
|
|
return verse_1, verse_2, song_item
|
2017-06-15 18:05:38 +00:00
|
|
|
|
2017-06-27 17:42:54 +00:00
|
|
|
def test_on_expand_selection(self):
|
|
|
|
"""
|
|
|
|
Test that the on_expand_selection function successfully expands an item and moves to its first child
|
|
|
|
"""
|
|
|
|
# GIVEN a mocked servicemanager list
|
|
|
|
verse_1, verse_2, song_item = self._setup_service_manager_list()
|
2017-06-15 18:05:38 +00:00
|
|
|
self.service_manager.service_manager_list.setCurrentItem(song_item)
|
2017-06-22 20:49:14 +00:00
|
|
|
# Reset expanded function in case it has been called and/or changed in initialisation of the service manager.
|
2017-06-15 18:05:38 +00:00
|
|
|
self.service_manager.expanded = MagicMock()
|
2017-06-13 15:49:48 +00:00
|
|
|
|
2017-06-22 20:49:14 +00:00
|
|
|
# WHEN on_expand_selection is called
|
2017-06-15 18:05:38 +00:00
|
|
|
self.service_manager.on_expand_selection()
|
|
|
|
|
2017-06-22 20:49:14 +00:00
|
|
|
# THEN selection should be expanded
|
2017-06-15 18:05:38 +00:00
|
|
|
selected_index = self.service_manager.service_manager_list.currentIndex()
|
|
|
|
above_selected_index = self.service_manager.service_manager_list.indexAbove(selected_index)
|
2017-12-23 09:10:43 +00:00
|
|
|
assert self.service_manager.service_manager_list.isExpanded(above_selected_index) is True, \
|
2017-12-23 09:09:45 +00:00
|
|
|
'Item should have been expanded'
|
2017-06-22 20:24:43 +00:00
|
|
|
self.service_manager.expanded.assert_called_once_with(song_item)
|
2017-06-15 18:05:38 +00:00
|
|
|
|
|
|
|
def test_on_collapse_selection_with_parent_selected(self):
|
2017-06-22 20:42:46 +00:00
|
|
|
"""
|
|
|
|
Test that the on_collapse_selection function successfully collapses an item
|
|
|
|
"""
|
2017-06-15 18:05:38 +00:00
|
|
|
# GIVEN a mocked servicemanager list
|
2017-06-27 17:42:54 +00:00
|
|
|
verse_1, verse_2, song_item = self._setup_service_manager_list()
|
2017-06-15 18:05:38 +00:00
|
|
|
self.service_manager.service_manager_list.setCurrentItem(song_item)
|
|
|
|
self.service_manager.service_manager_list.expandItem(song_item)
|
2017-06-13 15:49:48 +00:00
|
|
|
|
2017-06-15 18:05:38 +00:00
|
|
|
# Reset collapsed function in case it has been called and/or changed in initialisation of the service manager.
|
|
|
|
self.service_manager.collapsed = MagicMock()
|
2017-06-13 15:49:48 +00:00
|
|
|
|
2017-06-15 18:05:38 +00:00
|
|
|
# WHEN on_expand_selection is called
|
|
|
|
self.service_manager.on_collapse_selection()
|
2017-06-13 15:49:48 +00:00
|
|
|
|
2017-06-15 18:05:38 +00:00
|
|
|
# THEN selection should be expanded
|
2017-06-13 15:49:48 +00:00
|
|
|
selected_index = self.service_manager.service_manager_list.currentIndex()
|
2017-12-23 09:09:45 +00:00
|
|
|
assert self.service_manager.service_manager_list.isExpanded(selected_index) is False, \
|
|
|
|
'Item should have been collapsed'
|
2017-12-23 09:22:53 +00:00
|
|
|
assert self.service_manager.service_manager_list.currentItem() == song_item, \
|
2017-12-23 09:09:45 +00:00
|
|
|
'Top item should have been selected'
|
2017-06-22 20:24:43 +00:00
|
|
|
self.service_manager.collapsed.assert_called_once_with(song_item)
|
2017-06-15 18:05:38 +00:00
|
|
|
|
|
|
|
def test_on_collapse_selection_with_child_selected(self):
|
2017-06-22 20:42:46 +00:00
|
|
|
"""
|
|
|
|
Test that the on_collapse_selection function successfully collapses child's parent item
|
|
|
|
and moves selection to its parent.
|
|
|
|
"""
|
2017-06-15 18:05:38 +00:00
|
|
|
# GIVEN a mocked servicemanager list
|
2017-06-27 17:42:54 +00:00
|
|
|
verse_1, verse_2, song_item = self._setup_service_manager_list()
|
2017-06-15 18:05:38 +00:00
|
|
|
self.service_manager.service_manager_list.setCurrentItem(verse_2)
|
|
|
|
self.service_manager.service_manager_list.expandItem(song_item)
|
|
|
|
# Reset collapsed function in case it has been called and/or changed in initialisation of the service manager.
|
|
|
|
self.service_manager.collapsed = MagicMock()
|
|
|
|
|
|
|
|
# WHEN on_expand_selection is called
|
|
|
|
self.service_manager.on_collapse_selection()
|
|
|
|
|
|
|
|
# THEN selection should be expanded
|
|
|
|
selected_index = self.service_manager.service_manager_list.currentIndex()
|
2017-12-23 09:09:45 +00:00
|
|
|
assert self.service_manager.service_manager_list.isExpanded(selected_index) is False, \
|
|
|
|
'Item should have been collapsed'
|
2017-12-23 09:22:53 +00:00
|
|
|
assert self.service_manager.service_manager_list.currentItem() == song_item, \
|
2017-12-23 09:09:45 +00:00
|
|
|
'Top item should have been selected'
|
2017-06-22 20:57:36 +00:00
|
|
|
self.service_manager.collapsed.assert_called_once_with(song_item)
|