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
|
|
|
|
|
2013-12-31 07:27:07 +00:00
|
|
|
from PyQt4 import QtGui, QtTest, QtCore
|
2013-02-16 06:51:25 +00:00
|
|
|
|
2013-12-13 17:44:05 +00:00
|
|
|
from openlp.core.common import Registry
|
2013-12-30 19:50:34 +00:00
|
|
|
from openlp.core.lib import ScreenList, ServiceItem, ItemCapabilities
|
2013-02-13 19:10:41 +00:00
|
|
|
from openlp.core.ui.mainwindow import MainWindow
|
2013-10-04 21:45:38 +00:00
|
|
|
from tests.interfaces import MagicMock, patch
|
2013-02-13 19:10:41 +00:00
|
|
|
|
|
|
|
|
2013-02-17 20:11:37 +00:00
|
|
|
class TestServiceManager(TestCase):
|
2013-02-13 19:10:41 +00:00
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
"""
|
|
|
|
Create the UI
|
|
|
|
"""
|
|
|
|
Registry.create()
|
2013-03-14 22:22:18 +00:00
|
|
|
self.app = QtGui.QApplication([])
|
2013-02-13 19:10:41 +00:00
|
|
|
ScreenList.create(self.app.desktop())
|
2013-08-31 18:17:38 +00:00
|
|
|
Registry().register('application', MagicMock())
|
|
|
|
with patch('openlp.core.lib.PluginManager'):
|
2013-02-18 21:36:36 +00:00
|
|
|
self.main_window = MainWindow()
|
2013-08-31 18:17:38 +00:00
|
|
|
self.service_manager = Registry().get('service_manager')
|
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
|
|
|
|
"""
|
2013-02-18 21:36:36 +00:00
|
|
|
del self.main_window
|
2013-02-13 19:10:41 +00:00
|
|
|
del self.app
|
|
|
|
|
|
|
|
def basic_service_manager_test(self):
|
|
|
|
"""
|
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)
|
2013-02-13 19:10:41 +00:00
|
|
|
# THEN the count of items should be zero
|
2013-02-18 21:36:36 +00:00
|
|
|
self.assertEqual(self.service_manager.service_manager_list.topLevelItemCount(), 0,
|
2013-10-04 21:45:38 +00:00
|
|
|
'The service manager list should be empty ')
|
2013-03-30 14:45:02 +00:00
|
|
|
|
2013-12-30 19:50:34 +00:00
|
|
|
def default_context_menu_test(self):
|
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
|
2013-12-30 19:50:34 +00:00
|
|
|
self.service_manager.setup_ui(self.service_manager)
|
2013-08-31 18:17:38 +00:00
|
|
|
with patch('PyQt4.QtGui.QTreeWidget.itemAt') as mocked_item_at_method, \
|
2013-10-04 21:45:38 +00:00
|
|
|
patch('PyQt4.QtGui.QWidget.mapToGlobal'), \
|
|
|
|
patch('PyQt4.QtGui.QMenu.exec_'):
|
2013-03-30 14:45:02 +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()
|
2013-08-31 18:17:38 +00:00
|
|
|
self.service_manager.service_items = [{'service_item': service_item}]
|
2013-03-30 14:45:02 +00:00
|
|
|
q_point = None
|
|
|
|
# Mocked actions.
|
2013-10-04 21:45:38 +00:00
|
|
|
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
|
|
|
|
|
|
|
# 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), \
|
2013-08-31 18:17:38 +00:00
|
|
|
'The action should be set invisible.'
|
2013-03-30 14:47:38 +00:00
|
|
|
self.service_manager.create_custom_action.setVisible.assert_called_once_with(False), \
|
2013-08-31 18:17:38 +00:00
|
|
|
'The action should be set invisible.'
|
2013-03-30 14:47:38 +00:00
|
|
|
self.service_manager.maintain_action.setVisible.assert_called_once_with(False), \
|
2013-08-31 18:17:38 +00:00
|
|
|
'The action should be set invisible.'
|
|
|
|
self.service_manager.notes_action.setVisible.assert_called_with(True), 'The action should be set visible.'
|
2013-03-30 14:47:38 +00:00
|
|
|
self.service_manager.time_action.setVisible.assert_called_once_with(False), \
|
2013-08-31 18:17:38 +00:00
|
|
|
'The action should be set invisible.'
|
2013-03-30 14:47:38 +00:00
|
|
|
self.service_manager.auto_start_action.setVisible.assert_called_once_with(False), \
|
2013-08-31 18:17:38 +00:00
|
|
|
'The action should be set invisible.'
|
2013-12-30 19:50:34 +00:00
|
|
|
|
|
|
|
def edit_context_menu_test(self):
|
|
|
|
"""
|
|
|
|
Test the context_menu() method with a edit service item
|
|
|
|
"""
|
|
|
|
# GIVEN: A service item added
|
|
|
|
self.service_manager.setup_ui(self.service_manager)
|
|
|
|
with patch('PyQt4.QtGui.QTreeWidget.itemAt') as mocked_item_at_method, \
|
|
|
|
patch('PyQt4.QtGui.QWidget.mapToGlobal'), \
|
|
|
|
patch('PyQt4.QtGui.QMenu.exec_'):
|
|
|
|
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.'
|
|
|
|
|
|
|
|
def maintain_context_menu_test(self):
|
|
|
|
"""
|
|
|
|
Test the context_menu() method with a maintain
|
|
|
|
"""
|
|
|
|
# GIVEN: A service item added
|
|
|
|
self.service_manager.setup_ui(self.service_manager)
|
|
|
|
with patch('PyQt4.QtGui.QTreeWidget.itemAt') as mocked_item_at_method, \
|
|
|
|
patch('PyQt4.QtGui.QWidget.mapToGlobal'), \
|
|
|
|
patch('PyQt4.QtGui.QMenu.exec_'):
|
|
|
|
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.'
|
|
|
|
|
|
|
|
def loopy_context_menu_test(self):
|
|
|
|
"""
|
|
|
|
Test the context_menu() method with a loop
|
|
|
|
"""
|
|
|
|
# GIVEN: A service item added
|
|
|
|
self.service_manager.setup_ui(self.service_manager)
|
|
|
|
with patch('PyQt4.QtGui.QTreeWidget.itemAt') as mocked_item_at_method, \
|
|
|
|
patch('PyQt4.QtGui.QWidget.mapToGlobal'), \
|
|
|
|
patch('PyQt4.QtGui.QMenu.exec_'):
|
|
|
|
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.'
|
|
|
|
|
|
|
|
def start_time_context_menu_test(self):
|
|
|
|
"""
|
|
|
|
Test the context_menu() method with a start time
|
|
|
|
"""
|
|
|
|
# GIVEN: A service item added
|
|
|
|
self.service_manager.setup_ui(self.service_manager)
|
|
|
|
with patch('PyQt4.QtGui.QTreeWidget.itemAt') as mocked_item_at_method, \
|
|
|
|
patch('PyQt4.QtGui.QWidget.mapToGlobal'), \
|
|
|
|
patch('PyQt4.QtGui.QMenu.exec_'):
|
|
|
|
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.'
|
|
|
|
|
|
|
|
def auto_start_context_menu_test(self):
|
|
|
|
"""
|
|
|
|
Test the context_menu() method with can auto start
|
|
|
|
"""
|
|
|
|
# GIVEN: A service item added
|
|
|
|
self.service_manager.setup_ui(self.service_manager)
|
|
|
|
with patch('PyQt4.QtGui.QTreeWidget.itemAt') as mocked_item_at_method, \
|
|
|
|
patch('PyQt4.QtGui.QWidget.mapToGlobal'), \
|
|
|
|
patch('PyQt4.QtGui.QMenu.exec_'):
|
|
|
|
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()
|
|
|
|
|
|
|
|
# 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.'
|
|
|
|
|
2013-12-31 20:29:03 +00:00
|
|
|
def click_on_new_service_test(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'
|