From 4cea5e8b43756c593111a057d0640288f2b4b15f Mon Sep 17 00:00:00 2001 From: Tomas Groth Date: Sat, 12 Mar 2016 22:22:21 +0100 Subject: [PATCH 1/5] Fix traceback in the bug-report dialog. Fixes bug 1554428. Fixes: https://launchpad.net/bugs/1554428 --- openlp/core/ui/exceptionform.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/openlp/core/ui/exceptionform.py b/openlp/core/ui/exceptionform.py index e985829ba..2e4661579 100644 --- a/openlp/core/ui/exceptionform.py +++ b/openlp/core/ui/exceptionform.py @@ -180,11 +180,13 @@ class ExceptionForm(QtWidgets.QDialog, Ui_ExceptionDialog, RegistryProperties): if ':' in line: exception = line.split('\n')[-1].split(':')[0] subject = 'Bug report: %s in %s' % (exception, source) - mail_to_url = QtCore.QUrlQuery('mailto:bugs@openlp.org') - mail_to_url.addQueryItem('subject', subject) - mail_to_url.addQueryItem('body', self.report_text % content) + mail_urlquery = QtCore.QUrlQuery() + mail_urlquery.addQueryItem('subject', subject) + mail_urlquery.addQueryItem('body', self.report_text % content) if self.file_attachment: - mail_to_url.addQueryItem('attach', self.file_attachment) + mail_urlquery.addQueryItem('attach', self.file_attachment) + mail_to_url = QtCore.QUrl('mailto:bugs@openlp.org') + mail_to_url.setQuery(mail_urlquery) QtGui.QDesktopServices.openUrl(mail_to_url) def on_description_updated(self): From 4b57a2bae63b5483461141ed7eef8d7a673624a7 Mon Sep 17 00:00:00 2001 From: Tomas Groth Date: Sat, 12 Mar 2016 22:23:06 +0100 Subject: [PATCH 2/5] Fix weird test bug. --- .../openlp_core_lib/test_pluginmanager.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tests/interfaces/openlp_core_lib/test_pluginmanager.py b/tests/interfaces/openlp_core_lib/test_pluginmanager.py index 914bc7fb0..5efb1e3c7 100644 --- a/tests/interfaces/openlp_core_lib/test_pluginmanager.py +++ b/tests/interfaces/openlp_core_lib/test_pluginmanager.py @@ -32,7 +32,7 @@ from PyQt5 import QtWidgets from openlp.core.common import Registry, Settings from openlp.core.lib.pluginmanager import PluginManager -from tests.interfaces import MagicMock +from tests.interfaces import MagicMock, patch from tests.helpers.testmixin import TestMixin @@ -45,13 +45,12 @@ class TestPluginManager(TestCase, TestMixin): """ Some pre-test setup required. """ - Settings.setDefaultFormat(Settings.IniFormat) + self.setup_application() self.build_settings() self.temp_dir = mkdtemp('openlp') Settings().setValue('advanced/data path', self.temp_dir) Registry.create() Registry().register('service_list', MagicMock()) - self.setup_application() self.main_window = QtWidgets.QMainWindow() Registry().register('main_window', self.main_window) @@ -64,7 +63,13 @@ class TestPluginManager(TestCase, TestMixin): gc.collect() shutil.rmtree(self.temp_dir) - def find_plugins_test(self): + @patch('openlp.plugins.songusage.lib.db.init_schema') + @patch('openlp.plugins.songs.lib.db.init_schema') + @patch('openlp.plugins.images.lib.db.init_schema') + @patch('openlp.plugins.custom.lib.db.init_schema') + @patch('openlp.plugins.alerts.lib.db.init_schema') + @patch('openlp.plugins.bibles.lib.db.init_schema') + def find_plugins_test(self, mocked_is1, mocked_is2, mocked_is3, mocked_is4, mocked_is5, mocked_is6): """ Test the find_plugins() method to ensure it imports the correct plugins """ From 1dfad12edca5650edc62539eff7344a58b765905 Mon Sep 17 00:00:00 2001 From: Tomas Groth Date: Sat, 12 Mar 2016 22:25:39 +0100 Subject: [PATCH 3/5] Fix EasyWorship import issues with missing verses and traceback on unknown chars. Fixes: https://launchpad.net/bugs/1553922, https://launchpad.net/bugs/1547234 --- .../songs/lib/importers/easyworship.py | 72 ++++++++++--------- 1 file changed, 40 insertions(+), 32 deletions(-) diff --git a/openlp/plugins/songs/lib/importers/easyworship.py b/openlp/plugins/songs/lib/importers/easyworship.py index 5760e419d..25bbc37ff 100644 --- a/openlp/plugins/songs/lib/importers/easyworship.py +++ b/openlp/plugins/songs/lib/importers/easyworship.py @@ -289,40 +289,45 @@ class EasyWorshipSongImport(SongImport): for i in range(rec_count): if self.stop_import_flag: break - raw_record = db_file.read(record_size) - self.fields = self.record_structure.unpack(raw_record) - self.set_defaults() - self.title = self.get_field(fi_title).decode(self.encoding) - # Get remaining fields. - copy = self.get_field(fi_copy) - admin = self.get_field(fi_admin) - ccli = self.get_field(fi_ccli) - authors = self.get_field(fi_author) - words = self.get_field(fi_words) - if copy: - self.copyright = copy.decode(self.encoding) - if admin: + try: + raw_record = db_file.read(record_size) + self.fields = self.record_structure.unpack(raw_record) + self.set_defaults() + self.title = self.get_field(fi_title).decode(self.encoding) + # Get remaining fields. + copy = self.get_field(fi_copy) + admin = self.get_field(fi_admin) + ccli = self.get_field(fi_ccli) + authors = self.get_field(fi_author) + words = self.get_field(fi_words) if copy: - self.copyright += ', ' - self.copyright += translate('SongsPlugin.EasyWorshipSongImport', - 'Administered by %s') % admin.decode(self.encoding) - if ccli: - self.ccli_number = ccli.decode(self.encoding) - if authors: - authors = authors.decode(self.encoding) - else: - authors = '' - # Set the SongImport object members. - self.set_song_import_object(authors, words) - if self.stop_import_flag: - break - if self.entry_error_log: + self.copyright = copy.decode(self.encoding) + if admin: + if copy: + self.copyright += ', ' + self.copyright += translate('SongsPlugin.EasyWorshipSongImport', + 'Administered by %s') % admin.decode(self.encoding) + if ccli: + self.ccli_number = ccli.decode(self.encoding) + if authors: + authors = authors.decode(self.encoding) + else: + authors = '' + # Set the SongImport object members. + self.set_song_import_object(authors, words) + if self.stop_import_flag: + break + if self.entry_error_log: + self.log_error(self.import_source, + translate('SongsPlugin.EasyWorshipSongImport', '"%s" could not be imported. %s') + % (self.title, self.entry_error_log)) + self.entry_error_log = '' + elif not self.finish(): + self.log_error(self.import_source) + except Exception as e: self.log_error(self.import_source, translate('SongsPlugin.EasyWorshipSongImport', '"%s" could not be imported. %s') - % (self.title, self.entry_error_log)) - self.entry_error_log = '' - elif not self.finish(): - self.log_error(self.import_source) + % (self.title, e)) db_file.close() self.memo_file.close() @@ -368,7 +373,7 @@ class EasyWorshipSongImport(SongImport): first_line_is_tag = False # EW tags: verse, chorus, pre-chorus, bridge, tag, # intro, ending, slide - for tag in VerseType.tags + ['tag', 'slide']: + for tag in VerseType.names + ['tag', 'slide', 'end']: tag = tag.lower() ew_tag = verse_split[0].strip().lower() if ew_tag.startswith(tag): @@ -390,6 +395,9 @@ class EasyWorshipSongImport(SongImport): if not number_found: verse_type += '1' break + # If the verse only consist of the tag-line, add an empty line to create an empty slide + if first_line_is_tag and len(verse_split) == 1: + verse_split.append("") self.add_verse(verse_split[-1].strip() if first_line_is_tag else verse, verse_type) if len(self.comments) > 5: self.comments += str(translate('SongsPlugin.EasyWorshipSongImport', From faa434d937072b238d8d06d3f657d7f9fc6a58af Mon Sep 17 00:00:00 2001 From: Tomas Groth Date: Sun, 13 Mar 2016 19:37:08 +0100 Subject: [PATCH 4/5] pep8 fixes --- openlp/plugins/songs/lib/mediaitem.py | 4 ++-- tests/functional/openlp_plugins/songs/test_mediaitem.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/openlp/plugins/songs/lib/mediaitem.py b/openlp/plugins/songs/lib/mediaitem.py index 9dd4e29f8..8772f0771 100644 --- a/openlp/plugins/songs/lib/mediaitem.py +++ b/openlp/plugins/songs/lib/mediaitem.py @@ -295,7 +295,7 @@ class SongMediaItem(MediaManagerItem): :param search_keywords: A list of search keywords - book first, then number :return: None """ - + log.debug('display results Book') self.list_view.clear() @@ -700,7 +700,7 @@ class SongMediaItem(MediaManagerItem): :param s: A string value from the list we want to sort. """ return [int(text) if text.isdecimal() else text.lower() - for text in re.split('(\d+)', s)] + for text in re.split('(\d+)', s)] def search(self, string, show_error): """ diff --git a/tests/functional/openlp_plugins/songs/test_mediaitem.py b/tests/functional/openlp_plugins/songs/test_mediaitem.py index d09f5b76e..4ae15909b 100644 --- a/tests/functional/openlp_plugins/songs/test_mediaitem.py +++ b/tests/functional/openlp_plugins/songs/test_mediaitem.py @@ -422,10 +422,10 @@ class TestMediaItem(TestCase, TestMixin): """ # GIVEN: A string to be converted into a sort key string_sort_key = 'A1B12C' - + # WHEN: We attempt to create a sort key sort_key_result = self.media_item._natural_sort_key(string_sort_key) - + # THEN: We should get back a tuple split on integers self.assertEqual(sort_key_result, ['a', 1, 'b', 12, 'c']) From e908799240565564937372fdbce900ad6dbcb1c1 Mon Sep 17 00:00:00 2001 From: Tomas Groth Date: Sun, 13 Mar 2016 22:55:47 +0100 Subject: [PATCH 5/5] Fix slide order change when splitting custom slides. Fixes bug 1554748. Fixes: https://launchpad.net/bugs/1554748 --- openlp/plugins/custom/forms/editcustomform.py | 1 + .../custom/forms/test_customform.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/openlp/plugins/custom/forms/editcustomform.py b/openlp/plugins/custom/forms/editcustomform.py index 3aaee5290..b639c2692 100644 --- a/openlp/plugins/custom/forms/editcustomform.py +++ b/openlp/plugins/custom/forms/editcustomform.py @@ -198,6 +198,7 @@ class EditCustomForm(QtWidgets.QDialog, Ui_CustomEditDialog): # Insert all slides to make the old_slides list complete. for slide in slides: old_slides.insert(old_row, slide) + old_row += 1 self.slide_list_view.addItems(old_slides) self.slide_list_view.repaint() diff --git a/tests/interfaces/openlp_plugins/custom/forms/test_customform.py b/tests/interfaces/openlp_plugins/custom/forms/test_customform.py index b19f17fe7..333f03896 100644 --- a/tests/interfaces/openlp_plugins/custom/forms/test_customform.py +++ b/tests/interfaces/openlp_plugins/custom/forms/test_customform.py @@ -128,3 +128,19 @@ class TestEditCustomForm(TestCase, TestMixin): # THEN: The validate method should have returned False. assert not result, 'The _validate() method should have retured False' mocked_critical_error_message_box.assert_called_with(message='You need to add at least one slide.') + + def update_slide_list_test(self): + """ + Test the update_slide_list() method + """ + # GIVEN: Mocked slide_list_view with a slide with 3 lines + self.form.slide_list_view = MagicMock() + self.form.slide_list_view.count.return_value = 1 + self.form.slide_list_view.currentRow.return_value = 0 + self.form.slide_list_view.item.return_value = MagicMock(return_value='1st Slide\n2nd Slide\n3rd Slide') + + # WHEN: updating the slide by splitting the lines into slides + self.form.update_slide_list(['1st Slide', '2nd Slide', '3rd Slide']) + + # THEN: The slides should be created in correct order + self.form.slide_list_view.addItems.assert_called_with(['1st Slide', '2nd Slide', '3rd Slide'])