Merge branch 'fix_song_editor_crash' into 'master'

Fix song editor crash

Closes #459

See merge request openlp/openlp!150
This commit is contained in:
Raoul Snyman 2020-03-09 04:05:21 +00:00
commit 050e49465e
2 changed files with 47 additions and 1 deletions

View File

@ -1330,7 +1330,6 @@ class ServiceManager(QtWidgets.QWidget, RegistryBase, Ui_ServiceManager, LogMixi
"""
for item_count, item in enumerate(self.service_items):
if item['service_item'].edit_id == new_item.edit_id and item['service_item'].name == new_item.name:
new_item.create_slides()
new_item.merge(item['service_item'])
item['service_item'] = new_item
self.repaint_service_list(item_count + 1, 0)

View File

@ -419,6 +419,21 @@ class TestServiceManager(TestCase, TestMixin):
# THEN the on_move_selection_up function should have been called.
self.service_manager.on_move_selection_up.assert_called_once_with()
def test_delete_selection_on_delete_key(self):
"""
Test that a delete key press event calls the on_delete_from_service function
"""
# GIVEN a mocked on_delete_from_service function
self.service_manager.on_delete_from_service = MagicMock()
# WHEN the delete key event is called
self.service_manager.setup_ui(self.service_manager)
event = QtGui.QKeyEvent(QtCore.QEvent.KeyPress, QtCore.Qt.Key_Delete, QtCore.Qt.NoModifier)
self.service_manager.service_manager_list.keyPressEvent(event)
# THEN the on_delete_from_service function should have been called.
self.service_manager.on_delete_from_service.assert_called_once_with()
def _setup_service_manager_list(self):
self.service_manager.expanded = MagicMock()
self.service_manager.collapsed = MagicMock()
@ -496,3 +511,35 @@ class TestServiceManager(TestCase, TestMixin):
assert self.service_manager.service_manager_list.currentItem() == song_item, \
'Top item should have been selected'
self.service_manager.collapsed.assert_called_once_with(song_item)
def test_replace_service_item(self):
"""
Tests that the replace_service_item function replaces items as expected
"""
# GIVEN a service item list and a new item which name and edit_id match a service item
self.service_manager.repaint_service_list = MagicMock()
Registry().register('live_controller', MagicMock())
item1 = MagicMock()
item1.edit_id = 'abcd'
item1.name = 'itemA'
item2 = MagicMock()
item2.edit_id = 'abcd'
item2.name = 'itemB'
item3 = MagicMock()
item3.edit_id = 'cfgh'
item3.name = 'itemA'
self.service_manager.service_items = [
{'service_item': item1},
{'service_item': item2},
{'service_item': item3}
]
new_item = MagicMock()
new_item.edit_id = 'abcd'
new_item.name = 'itemA'
# WHEN replace_service_item is called
self.service_manager.replace_service_item(new_item)
# THEN new_item should replace item1, and only replaces that one item
assert self.service_manager.service_items[0]['service_item'] == new_item
new_item.merge.assert_called_once_with(item1)