From 3390323d4fd151eccf693d9c6e590feceb241109 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Sat, 9 Apr 2022 08:00:35 +0000 Subject: [PATCH] Fix some bugs in Bibles and PresentationManager --- openlp/plugins/bibles/lib/mediaitem.py | 3 +++ .../songs/lib/importers/presentationmanager.py | 1 + tests/openlp_plugins/bibles/test_mediaitem.py | 14 ++++++++++++++ 3 files changed, 18 insertions(+) diff --git a/openlp/plugins/bibles/lib/mediaitem.py b/openlp/plugins/bibles/lib/mediaitem.py index 8446f454d..f2dd30df6 100755 --- a/openlp/plugins/bibles/lib/mediaitem.py +++ b/openlp/plugins/bibles/lib/mediaitem.py @@ -608,6 +608,9 @@ class BibleMediaItem(MediaManagerItem): :return: None """ book_ref_id = self.select_book_combo_box.currentData() + if not book_ref_id: + # If there is no book selected, just exit early + return book = self.plugin.manager.get_book_by_id(self.bible.name, book_ref_id) self.chapter_count = self.plugin.manager.get_chapter_count(self.bible.name, book) verse_count = self.plugin.manager.get_verse_count_by_book_ref_id(self.bible.name, book_ref_id, 1) diff --git a/openlp/plugins/songs/lib/importers/presentationmanager.py b/openlp/plugins/songs/lib/importers/presentationmanager.py index cf40585af..9afa17889 100644 --- a/openlp/plugins/songs/lib/importers/presentationmanager.py +++ b/openlp/plugins/songs/lib/importers/presentationmanager.py @@ -80,6 +80,7 @@ class PresentationManagerImport(SongImport): except etree.XMLSyntaxError: # Try to detect encoding and use it self.process_xml(file_path, get_file_encoding(file_path)) + return file_str = etree.tostring(tree) if not file_str: diff --git a/tests/openlp_plugins/bibles/test_mediaitem.py b/tests/openlp_plugins/bibles/test_mediaitem.py index b1086dc9a..68ca701dc 100644 --- a/tests/openlp_plugins/bibles/test_mediaitem.py +++ b/tests/openlp_plugins/bibles/test_mediaitem.py @@ -933,6 +933,20 @@ def test_on_advanced_book_combo_box(media_item): assert mocked_critical_error_message_box.called is True +def test_on_advanced_book_combo_box_no_selection(media_item): + """ + Test on_advanced_book_combo_box when there is nothing selected + """ + # GIVEN: An instance of :class:`MediaManagerItem` and a mocked manager + media_item.select_book_combo_box = MagicMock(**{'currentData.return_value': None}) + + # WHEN: Calling on_advanced_book_combo_box + media_item.on_advanced_book_combo_box() + + # THEN: The method should exit early, and no query made + assert media_item.plugin.manager.get_book_by_id.call_count == 0 + + def test_on_advanced_book_combo_box_set_up_comboboxes(media_item): """ Test on_advanced_book_combo_box when the book returns 6 for the verse count.