From 721bcc20e2ee5dc1dfaab0f1e722cd411c140e35 Mon Sep 17 00:00:00 2001 From: Jonathan Springer Date: Tue, 15 Apr 2014 16:51:55 -0400 Subject: [PATCH 01/42] Reorder imports --- tests/functional/openlp_core_ui/test_firsttimeform.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/functional/openlp_core_ui/test_firsttimeform.py b/tests/functional/openlp_core_ui/test_firsttimeform.py index 9fc6f5137..2e26c286a 100644 --- a/tests/functional/openlp_core_ui/test_firsttimeform.py +++ b/tests/functional/openlp_core_ui/test_firsttimeform.py @@ -31,12 +31,12 @@ Package to test the openlp.core.ui.firsttimeform package. """ from unittest import TestCase -from tests.functional import MagicMock - -from tests.helpers.testmixin import TestMixin from openlp.core.common import Registry from openlp.core.ui.firsttimeform import FirstTimeForm +from tests.functional import MagicMock +from tests.helpers.testmixin import TestMixin + class TestFirstTimeForm(TestCase, TestMixin): From aa6b75695610d3b959ef563863c18d8f08343f24 Mon Sep 17 00:00:00 2001 From: Jonathan Springer Date: Wed, 16 Apr 2014 16:26:49 -0400 Subject: [PATCH 02/42] Change how we define which menu items are included in the main menu on Mac OS X --- openlp/core/ui/mainwindow.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index 81e822c16..4e1d28ef8 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -320,14 +320,14 @@ class Ui_MainWindow(object): # i18n add Language Actions add_actions(self.settings_language_menu, (self.auto_language_item, None)) add_actions(self.settings_language_menu, self.language_group.actions()) - # Order things differently in OS X so that Preferences menu item in the - # app menu is correct (this gets picked up automatically by Qt). + # Qt on OS X look for keywords in the menu items title to determine which menu items get added to the main menu. + # If we are running on Mac OS X the menu items whose title contains those keywords but don't belong in the main + # menu need to be marked as such with QAction.NoRole. if sys.platform == 'darwin': - add_actions(self.settings_menu, (self.settings_plugin_list_item, self.settings_language_menu.menuAction(), - None, self.settings_configure_item, self.settings_shortcuts_item, self.formatting_tag_item)) - else: - add_actions(self.settings_menu, (self.settings_plugin_list_item, self.settings_language_menu.menuAction(), - None, self.formatting_tag_item, self.settings_shortcuts_item, self.settings_configure_item)) + self.settings_shortcuts_item.setMenuRole(QtGui.QAction.NoRole) + self.formatting_tag_item.setMenuRole(QtGui.QAction.NoRole) + add_actions(self.settings_menu, (self.settings_plugin_list_item, self.settings_language_menu.menuAction(), + None, self.formatting_tag_item, self.settings_shortcuts_item, self.settings_configure_item)) add_actions(self.tools_menu, (self.tools_add_tool_item, None)) add_actions(self.tools_menu, (self.tools_open_data_folder, None)) add_actions(self.tools_menu, (self.tools_first_time_wizard, None)) From b6e0aa6c2eb4a49d36e4623f70ae667888b77a44 Mon Sep 17 00:00:00 2001 From: Jonathan Springer Date: Wed, 16 Apr 2014 16:44:22 -0400 Subject: [PATCH 03/42] PEP8 clean up in tests --- tests/functional/openlp_core_common/test_common.py | 5 +++-- tests/functional/openlp_core_lib/test_image_manager.py | 2 +- tests/functional/openlp_core_lib/test_ui.py | 2 +- tests/functional/openlp_core_ui/test_maindisplay.py | 2 +- tests/functional/openlp_plugins/songs/test_ewimport.py | 10 +++++----- tests/functional/openlp_plugins/songs/test_lib.py | 1 - .../openlp_plugins/songs/test_songbeamerimport.py | 6 +++--- .../openlp_plugins/songs/test_songshowplusimport.py | 10 +++++----- tests/helpers/songfileimport.py | 10 +++++----- .../openlp_plugins/bibles/test_lib_parse_reference.py | 2 +- 10 files changed, 25 insertions(+), 25 deletions(-) diff --git a/tests/functional/openlp_core_common/test_common.py b/tests/functional/openlp_core_common/test_common.py index 90b7d0520..993a4cede 100644 --- a/tests/functional/openlp_core_common/test_common.py +++ b/tests/functional/openlp_core_common/test_common.py @@ -40,6 +40,7 @@ class TestCommonFunctions(TestCase): """ A test suite to test out various functions in the openlp.core.common module. """ + def de_hump_conversion_test(self): """ Test the de_hump function with a class name @@ -79,5 +80,5 @@ class TestCommonFunctions(TestCase): trace_error_handler(mocked_logger) # THEN: The mocked_logger.error() method should have been called with the correct parameters - mocked_logger.error.assert_called_with('OpenLP Error trace\n File openlp.fake at line 56 \n\t called trace_error_handler_test') - + mocked_logger.error.assert_called_with( + 'OpenLP Error trace\n File openlp.fake at line 56 \n\t called trace_error_handler_test') diff --git a/tests/functional/openlp_core_lib/test_image_manager.py b/tests/functional/openlp_core_lib/test_image_manager.py index 37b6d6fdd..072978993 100644 --- a/tests/functional/openlp_core_lib/test_image_manager.py +++ b/tests/functional/openlp_core_lib/test_image_manager.py @@ -171,4 +171,4 @@ class TestImageManager(TestCase, TestMixin): self.lock.release() # The sleep time is adjusted in the test case. time.sleep(self.sleep_time) - return '' \ No newline at end of file + return '' diff --git a/tests/functional/openlp_core_lib/test_ui.py b/tests/functional/openlp_core_lib/test_ui.py index 91d59ab5a..025b1a638 100644 --- a/tests/functional/openlp_core_lib/test_ui.py +++ b/tests/functional/openlp_core_lib/test_ui.py @@ -162,7 +162,7 @@ class TestUi(TestCase): # WHEN: We create an action with some properties action = create_action(dialog, 'my_action', text='my text', icon=':/wizards/wizard_firsttime.bmp', - tooltip='my tooltip', statustip='my statustip') + tooltip='my tooltip', statustip='my statustip') # THEN: These properties should be set self.assertIsInstance(action, QtGui.QAction) diff --git a/tests/functional/openlp_core_ui/test_maindisplay.py b/tests/functional/openlp_core_ui/test_maindisplay.py index b1a4dc7f7..6d67a3b67 100644 --- a/tests/functional/openlp_core_ui/test_maindisplay.py +++ b/tests/functional/openlp_core_ui/test_maindisplay.py @@ -106,4 +106,4 @@ class TestMainDisplay(TestCase): self.assertEqual('QGraphicsView {}', main_display.styleSheet(), 'MainDisplay instance should not be transparent') self.assertFalse(main_display.testAttribute(QtCore.Qt.WA_TranslucentBackground), - 'MainDisplay hasnt translucent background') + 'MainDisplay hasnt translucent background') diff --git a/tests/functional/openlp_plugins/songs/test_ewimport.py b/tests/functional/openlp_plugins/songs/test_ewimport.py index c1b9db52d..984c87028 100644 --- a/tests/functional/openlp_plugins/songs/test_ewimport.py +++ b/tests/functional/openlp_plugins/songs/test_ewimport.py @@ -141,7 +141,7 @@ class TestEasyWorshipSongImport(TestCase): self.assertIsNotNone(field_desc_entry, 'Import should not be none') self.assertEqual(field_desc_entry.name, name, 'FieldDescEntry.name should be the same as the name argument') self.assertEqual(field_desc_entry.field_type, field_type, - 'FieldDescEntry.type should be the same as the type argument') + 'FieldDescEntry.type should be the same as the type argument') self.assertEqual(field_desc_entry.size, size, 'FieldDescEntry.size should be the same as the size argument') def create_importer_test(self): @@ -231,8 +231,8 @@ class TestEasyWorshipSongImport(TestCase): # THEN: get_field should return the known results self.assertEqual(return_value, result, - 'get_field should return "%s" when called with "%s"' % - (result, TEST_FIELDS[field_index])) + 'get_field should return "%s" when called with "%s"' % + (result, TEST_FIELDS[field_index])) def get_memo_field_test(self): """ @@ -404,10 +404,10 @@ class TestEasyWorshipSongImport(TestCase): self.assertEqual(importer.copyright, song_copyright) if ccli_number: self.assertEqual(importer.ccli_number, ccli_number, 'ccli_number for %s should be %s' - % (title, ccli_number)) + % (title, ccli_number)) for verse_text, verse_tag in add_verse_calls: mocked_add_verse.assert_any_call(verse_text, verse_tag) if verse_order_list: self.assertEqual(importer.verse_order_list, verse_order_list, - 'verse_order_list for %s should be %s' % (title, verse_order_list)) + 'verse_order_list for %s should be %s' % (title, verse_order_list)) mocked_finish.assert_called_with() diff --git a/tests/functional/openlp_plugins/songs/test_lib.py b/tests/functional/openlp_plugins/songs/test_lib.py index 2ab808bc9..b67c1a4be 100644 --- a/tests/functional/openlp_plugins/songs/test_lib.py +++ b/tests/functional/openlp_plugins/songs/test_lib.py @@ -129,7 +129,6 @@ class TestLib(TestCase): # THEN: The result should be a tuple of songs.. assert result == (self.song1, self.song2), 'The result should be the tuble of songs' - def songs_probably_equal_different_song_test(self): """ Test the songs_probably_equal function with two different songs. diff --git a/tests/functional/openlp_plugins/songs/test_songbeamerimport.py b/tests/functional/openlp_plugins/songs/test_songbeamerimport.py index f08cedec5..d95d49d80 100644 --- a/tests/functional/openlp_plugins/songs/test_songbeamerimport.py +++ b/tests/functional/openlp_plugins/songs/test_songbeamerimport.py @@ -91,7 +91,7 @@ class TestSongBeamerImport(TestCase): # THEN: do_import should return none and the progress bar maximum should not be set. self.assertIsNone(importer.do_import(), 'do_import should return None when import_source is not a list') self.assertEqual(mocked_import_wizard.progress_bar.setMaximum.called, False, - 'setMaxium on import_wizard.progress_bar should not have been called') + 'setMaxium on import_wizard.progress_bar should not have been called') def valid_import_source_test(self): """ @@ -149,10 +149,10 @@ class TestSongBeamerImport(TestCase): mocked_add_verse.assert_any_call(verse_text, verse_tag) if song_book_name: self.assertEqual(importer.song_book_name, song_book_name, 'song_book_name for %s should be "%s"' % - (song_file, song_book_name)) + (song_file, song_book_name)) if song_number: self.assertEqual(importer.song_number, song_number, 'song_number for %s should be %s' % - (song_file, song_number)) + (song_file, song_number)) mocked_finish.assert_called_with() def check_verse_marks_test(self): diff --git a/tests/functional/openlp_plugins/songs/test_songshowplusimport.py b/tests/functional/openlp_plugins/songs/test_songshowplusimport.py index f2839c332..63e5beb8a 100644 --- a/tests/functional/openlp_plugins/songs/test_songshowplusimport.py +++ b/tests/functional/openlp_plugins/songs/test_songshowplusimport.py @@ -96,7 +96,7 @@ class TestSongShowPlusImport(TestCase): # THEN: do_import should return none and the progress bar maximum should not be set. self.assertIsNone(importer.do_import(), 'do_import should return None when import_source is not a list') self.assertEqual(mocked_import_wizard.progress_bar.setMaximum.called, False, - 'setMaximum on import_wizard.progress_bar should not have been called') + 'setMaximum on import_wizard.progress_bar should not have been called') def valid_import_source_test(self): """ @@ -144,8 +144,8 @@ class TestSongShowPlusImport(TestCase): # THEN: The returned value should should correlate with the input arguments for original_tag, openlp_tag in test_values: self.assertEqual(importer.to_openlp_verse_tag(original_tag), openlp_tag, - 'SongShowPlusImport.to_openlp_verse_tag should return "%s" when called with "%s"' % - (openlp_tag, original_tag)) + 'SongShowPlusImport.to_openlp_verse_tag should return "%s" when called with "%s"' % + (openlp_tag, original_tag)) def to_openlp_verse_tag_verse_order_test(self): """ @@ -173,5 +173,5 @@ class TestSongShowPlusImport(TestCase): # THEN: The returned value should should correlate with the input arguments for original_tag, openlp_tag in test_values: self.assertEqual(importer.to_openlp_verse_tag(original_tag, ignore_unique=True), openlp_tag, - 'SongShowPlusImport.to_openlp_verse_tag should return "%s" when called with "%s"' % - (openlp_tag, original_tag)) + 'SongShowPlusImport.to_openlp_verse_tag should return "%s" when called with "%s"' % + (openlp_tag, original_tag)) diff --git a/tests/helpers/songfileimport.py b/tests/helpers/songfileimport.py index 49a09528c..b961b7d64 100644 --- a/tests/helpers/songfileimport.py +++ b/tests/helpers/songfileimport.py @@ -117,23 +117,23 @@ class SongImportTestHelper(TestCase): self.mocked_add_copyright.assert_called_with(song_copyright) if ccli_number: self.assertEqual(importer.ccli_number, ccli_number, 'ccli_number for %s should be %s' % - (source_file_name, ccli_number)) + (source_file_name, ccli_number)) for verse_text, verse_tag in add_verse_calls: self.mocked_add_verse.assert_any_call(verse_text, verse_tag) if topics: self.assertEqual(importer.topics, topics, 'topics for %s should be %s' % (source_file_name, topics)) if comments: self.assertEqual(importer.comments, comments, 'comments for %s should be "%s"' % - (source_file_name, comments)) + (source_file_name, comments)) if song_book_name: self.assertEqual(importer.song_book_name, song_book_name, 'song_book_name for %s should be "%s"' % - (source_file_name, song_book_name)) + (source_file_name, song_book_name)) if song_number: self.assertEqual(importer.song_number, song_number, 'song_number for %s should be %s' % - (source_file_name, song_number)) + (source_file_name, song_number)) if verse_order_list: self.assertEqual(importer.verse_order_list, [], 'verse_order_list for %s should be %s' % - (source_file_name, verse_order_list)) + (source_file_name, verse_order_list)) self.mocked_finish.assert_called_with() def _get_data(self, data, key): diff --git a/tests/interfaces/openlp_plugins/bibles/test_lib_parse_reference.py b/tests/interfaces/openlp_plugins/bibles/test_lib_parse_reference.py index 84f80e7ed..b005992ff 100644 --- a/tests/interfaces/openlp_plugins/bibles/test_lib_parse_reference.py +++ b/tests/interfaces/openlp_plugins/bibles/test_lib_parse_reference.py @@ -104,4 +104,4 @@ class TestBibleManager(TestCase, TestMixin): results = parse_reference('1 Timothy 1:1-2:1', self.manager.db_cache['tests'], MagicMock(), 54) # THEN a verse array should be returned self.assertEqual([(54, 1, 1, -1), (54, 2, 1, 1)], results, "The bible verses should matches the expected " - "results") + "results") From 85fc53954d905488c5bec91680ebf80ef2c7cb0e Mon Sep 17 00:00:00 2001 From: Jonathan Springer Date: Wed, 16 Apr 2014 16:49:24 -0400 Subject: [PATCH 04/42] More PEP8 fixes --- openlp/core/ui/mainwindow.py | 2 +- openlp/plugins/songs/lib/songbeamerimport.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index 4e1d28ef8..dca7bf815 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -320,7 +320,7 @@ class Ui_MainWindow(object): # i18n add Language Actions add_actions(self.settings_language_menu, (self.auto_language_item, None)) add_actions(self.settings_language_menu, self.language_group.actions()) - # Qt on OS X look for keywords in the menu items title to determine which menu items get added to the main menu. + # Qt on OS X look for keywords in the menu items title to determine which menu items get added to the main menu. # If we are running on Mac OS X the menu items whose title contains those keywords but don't belong in the main # menu need to be marked as such with QAction.NoRole. if sys.platform == 'darwin': diff --git a/openlp/plugins/songs/lib/songbeamerimport.py b/openlp/plugins/songs/lib/songbeamerimport.py index 5b86591e8..a0b166ded 100644 --- a/openlp/plugins/songs/lib/songbeamerimport.py +++ b/openlp/plugins/songs/lib/songbeamerimport.py @@ -137,7 +137,7 @@ class SongBeamerImport(SongImport): if line.startswith('#') and not read_verses: self.parseTags(line) elif line.startswith('--'): - # --- and -- allowed for page-breaks (difference in Songbeamer only in printout) + # --- and -- allowed for page-breaks (difference in Songbeamer only in printout) if self.current_verse: self.replace_html_tags() self.add_verse(self.current_verse, self.current_verse_type) From ef5b1cf4ac08062f80758bb539bdee3491b35c38 Mon Sep 17 00:00:00 2001 From: Jonathan Springer Date: Wed, 16 Apr 2014 17:19:22 -0400 Subject: [PATCH 05/42] Revert PEP8 clean ups as they were already done in a different branch --- openlp/core/ui/mainwindow.py | 2 +- openlp/plugins/songs/lib/songbeamerimport.py | 2 +- tests/functional/openlp_core_common/test_common.py | 5 ++--- tests/functional/openlp_core_lib/test_image_manager.py | 2 +- tests/functional/openlp_core_lib/test_ui.py | 2 +- tests/functional/openlp_core_ui/test_maindisplay.py | 2 +- tests/functional/openlp_plugins/songs/test_ewimport.py | 10 +++++----- tests/functional/openlp_plugins/songs/test_lib.py | 1 + .../openlp_plugins/songs/test_songbeamerimport.py | 6 +++--- .../openlp_plugins/songs/test_songshowplusimport.py | 10 +++++----- tests/helpers/songfileimport.py | 10 +++++----- .../openlp_plugins/bibles/test_lib_parse_reference.py | 2 +- 12 files changed, 27 insertions(+), 27 deletions(-) diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index dca7bf815..4e1d28ef8 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -320,7 +320,7 @@ class Ui_MainWindow(object): # i18n add Language Actions add_actions(self.settings_language_menu, (self.auto_language_item, None)) add_actions(self.settings_language_menu, self.language_group.actions()) - # Qt on OS X look for keywords in the menu items title to determine which menu items get added to the main menu. + # Qt on OS X look for keywords in the menu items title to determine which menu items get added to the main menu. # If we are running on Mac OS X the menu items whose title contains those keywords but don't belong in the main # menu need to be marked as such with QAction.NoRole. if sys.platform == 'darwin': diff --git a/openlp/plugins/songs/lib/songbeamerimport.py b/openlp/plugins/songs/lib/songbeamerimport.py index a0b166ded..5b86591e8 100644 --- a/openlp/plugins/songs/lib/songbeamerimport.py +++ b/openlp/plugins/songs/lib/songbeamerimport.py @@ -137,7 +137,7 @@ class SongBeamerImport(SongImport): if line.startswith('#') and not read_verses: self.parseTags(line) elif line.startswith('--'): - # --- and -- allowed for page-breaks (difference in Songbeamer only in printout) + # --- and -- allowed for page-breaks (difference in Songbeamer only in printout) if self.current_verse: self.replace_html_tags() self.add_verse(self.current_verse, self.current_verse_type) diff --git a/tests/functional/openlp_core_common/test_common.py b/tests/functional/openlp_core_common/test_common.py index 993a4cede..90b7d0520 100644 --- a/tests/functional/openlp_core_common/test_common.py +++ b/tests/functional/openlp_core_common/test_common.py @@ -40,7 +40,6 @@ class TestCommonFunctions(TestCase): """ A test suite to test out various functions in the openlp.core.common module. """ - def de_hump_conversion_test(self): """ Test the de_hump function with a class name @@ -80,5 +79,5 @@ class TestCommonFunctions(TestCase): trace_error_handler(mocked_logger) # THEN: The mocked_logger.error() method should have been called with the correct parameters - mocked_logger.error.assert_called_with( - 'OpenLP Error trace\n File openlp.fake at line 56 \n\t called trace_error_handler_test') + mocked_logger.error.assert_called_with('OpenLP Error trace\n File openlp.fake at line 56 \n\t called trace_error_handler_test') + diff --git a/tests/functional/openlp_core_lib/test_image_manager.py b/tests/functional/openlp_core_lib/test_image_manager.py index 072978993..37b6d6fdd 100644 --- a/tests/functional/openlp_core_lib/test_image_manager.py +++ b/tests/functional/openlp_core_lib/test_image_manager.py @@ -171,4 +171,4 @@ class TestImageManager(TestCase, TestMixin): self.lock.release() # The sleep time is adjusted in the test case. time.sleep(self.sleep_time) - return '' + return '' \ No newline at end of file diff --git a/tests/functional/openlp_core_lib/test_ui.py b/tests/functional/openlp_core_lib/test_ui.py index 025b1a638..91d59ab5a 100644 --- a/tests/functional/openlp_core_lib/test_ui.py +++ b/tests/functional/openlp_core_lib/test_ui.py @@ -162,7 +162,7 @@ class TestUi(TestCase): # WHEN: We create an action with some properties action = create_action(dialog, 'my_action', text='my text', icon=':/wizards/wizard_firsttime.bmp', - tooltip='my tooltip', statustip='my statustip') + tooltip='my tooltip', statustip='my statustip') # THEN: These properties should be set self.assertIsInstance(action, QtGui.QAction) diff --git a/tests/functional/openlp_core_ui/test_maindisplay.py b/tests/functional/openlp_core_ui/test_maindisplay.py index 6d67a3b67..b1a4dc7f7 100644 --- a/tests/functional/openlp_core_ui/test_maindisplay.py +++ b/tests/functional/openlp_core_ui/test_maindisplay.py @@ -106,4 +106,4 @@ class TestMainDisplay(TestCase): self.assertEqual('QGraphicsView {}', main_display.styleSheet(), 'MainDisplay instance should not be transparent') self.assertFalse(main_display.testAttribute(QtCore.Qt.WA_TranslucentBackground), - 'MainDisplay hasnt translucent background') + 'MainDisplay hasnt translucent background') diff --git a/tests/functional/openlp_plugins/songs/test_ewimport.py b/tests/functional/openlp_plugins/songs/test_ewimport.py index 984c87028..c1b9db52d 100644 --- a/tests/functional/openlp_plugins/songs/test_ewimport.py +++ b/tests/functional/openlp_plugins/songs/test_ewimport.py @@ -141,7 +141,7 @@ class TestEasyWorshipSongImport(TestCase): self.assertIsNotNone(field_desc_entry, 'Import should not be none') self.assertEqual(field_desc_entry.name, name, 'FieldDescEntry.name should be the same as the name argument') self.assertEqual(field_desc_entry.field_type, field_type, - 'FieldDescEntry.type should be the same as the type argument') + 'FieldDescEntry.type should be the same as the type argument') self.assertEqual(field_desc_entry.size, size, 'FieldDescEntry.size should be the same as the size argument') def create_importer_test(self): @@ -231,8 +231,8 @@ class TestEasyWorshipSongImport(TestCase): # THEN: get_field should return the known results self.assertEqual(return_value, result, - 'get_field should return "%s" when called with "%s"' % - (result, TEST_FIELDS[field_index])) + 'get_field should return "%s" when called with "%s"' % + (result, TEST_FIELDS[field_index])) def get_memo_field_test(self): """ @@ -404,10 +404,10 @@ class TestEasyWorshipSongImport(TestCase): self.assertEqual(importer.copyright, song_copyright) if ccli_number: self.assertEqual(importer.ccli_number, ccli_number, 'ccli_number for %s should be %s' - % (title, ccli_number)) + % (title, ccli_number)) for verse_text, verse_tag in add_verse_calls: mocked_add_verse.assert_any_call(verse_text, verse_tag) if verse_order_list: self.assertEqual(importer.verse_order_list, verse_order_list, - 'verse_order_list for %s should be %s' % (title, verse_order_list)) + 'verse_order_list for %s should be %s' % (title, verse_order_list)) mocked_finish.assert_called_with() diff --git a/tests/functional/openlp_plugins/songs/test_lib.py b/tests/functional/openlp_plugins/songs/test_lib.py index b67c1a4be..2ab808bc9 100644 --- a/tests/functional/openlp_plugins/songs/test_lib.py +++ b/tests/functional/openlp_plugins/songs/test_lib.py @@ -129,6 +129,7 @@ class TestLib(TestCase): # THEN: The result should be a tuple of songs.. assert result == (self.song1, self.song2), 'The result should be the tuble of songs' + def songs_probably_equal_different_song_test(self): """ Test the songs_probably_equal function with two different songs. diff --git a/tests/functional/openlp_plugins/songs/test_songbeamerimport.py b/tests/functional/openlp_plugins/songs/test_songbeamerimport.py index d95d49d80..f08cedec5 100644 --- a/tests/functional/openlp_plugins/songs/test_songbeamerimport.py +++ b/tests/functional/openlp_plugins/songs/test_songbeamerimport.py @@ -91,7 +91,7 @@ class TestSongBeamerImport(TestCase): # THEN: do_import should return none and the progress bar maximum should not be set. self.assertIsNone(importer.do_import(), 'do_import should return None when import_source is not a list') self.assertEqual(mocked_import_wizard.progress_bar.setMaximum.called, False, - 'setMaxium on import_wizard.progress_bar should not have been called') + 'setMaxium on import_wizard.progress_bar should not have been called') def valid_import_source_test(self): """ @@ -149,10 +149,10 @@ class TestSongBeamerImport(TestCase): mocked_add_verse.assert_any_call(verse_text, verse_tag) if song_book_name: self.assertEqual(importer.song_book_name, song_book_name, 'song_book_name for %s should be "%s"' % - (song_file, song_book_name)) + (song_file, song_book_name)) if song_number: self.assertEqual(importer.song_number, song_number, 'song_number for %s should be %s' % - (song_file, song_number)) + (song_file, song_number)) mocked_finish.assert_called_with() def check_verse_marks_test(self): diff --git a/tests/functional/openlp_plugins/songs/test_songshowplusimport.py b/tests/functional/openlp_plugins/songs/test_songshowplusimport.py index 63e5beb8a..f2839c332 100644 --- a/tests/functional/openlp_plugins/songs/test_songshowplusimport.py +++ b/tests/functional/openlp_plugins/songs/test_songshowplusimport.py @@ -96,7 +96,7 @@ class TestSongShowPlusImport(TestCase): # THEN: do_import should return none and the progress bar maximum should not be set. self.assertIsNone(importer.do_import(), 'do_import should return None when import_source is not a list') self.assertEqual(mocked_import_wizard.progress_bar.setMaximum.called, False, - 'setMaximum on import_wizard.progress_bar should not have been called') + 'setMaximum on import_wizard.progress_bar should not have been called') def valid_import_source_test(self): """ @@ -144,8 +144,8 @@ class TestSongShowPlusImport(TestCase): # THEN: The returned value should should correlate with the input arguments for original_tag, openlp_tag in test_values: self.assertEqual(importer.to_openlp_verse_tag(original_tag), openlp_tag, - 'SongShowPlusImport.to_openlp_verse_tag should return "%s" when called with "%s"' % - (openlp_tag, original_tag)) + 'SongShowPlusImport.to_openlp_verse_tag should return "%s" when called with "%s"' % + (openlp_tag, original_tag)) def to_openlp_verse_tag_verse_order_test(self): """ @@ -173,5 +173,5 @@ class TestSongShowPlusImport(TestCase): # THEN: The returned value should should correlate with the input arguments for original_tag, openlp_tag in test_values: self.assertEqual(importer.to_openlp_verse_tag(original_tag, ignore_unique=True), openlp_tag, - 'SongShowPlusImport.to_openlp_verse_tag should return "%s" when called with "%s"' % - (openlp_tag, original_tag)) + 'SongShowPlusImport.to_openlp_verse_tag should return "%s" when called with "%s"' % + (openlp_tag, original_tag)) diff --git a/tests/helpers/songfileimport.py b/tests/helpers/songfileimport.py index b961b7d64..49a09528c 100644 --- a/tests/helpers/songfileimport.py +++ b/tests/helpers/songfileimport.py @@ -117,23 +117,23 @@ class SongImportTestHelper(TestCase): self.mocked_add_copyright.assert_called_with(song_copyright) if ccli_number: self.assertEqual(importer.ccli_number, ccli_number, 'ccli_number for %s should be %s' % - (source_file_name, ccli_number)) + (source_file_name, ccli_number)) for verse_text, verse_tag in add_verse_calls: self.mocked_add_verse.assert_any_call(verse_text, verse_tag) if topics: self.assertEqual(importer.topics, topics, 'topics for %s should be %s' % (source_file_name, topics)) if comments: self.assertEqual(importer.comments, comments, 'comments for %s should be "%s"' % - (source_file_name, comments)) + (source_file_name, comments)) if song_book_name: self.assertEqual(importer.song_book_name, song_book_name, 'song_book_name for %s should be "%s"' % - (source_file_name, song_book_name)) + (source_file_name, song_book_name)) if song_number: self.assertEqual(importer.song_number, song_number, 'song_number for %s should be %s' % - (source_file_name, song_number)) + (source_file_name, song_number)) if verse_order_list: self.assertEqual(importer.verse_order_list, [], 'verse_order_list for %s should be %s' % - (source_file_name, verse_order_list)) + (source_file_name, verse_order_list)) self.mocked_finish.assert_called_with() def _get_data(self, data, key): diff --git a/tests/interfaces/openlp_plugins/bibles/test_lib_parse_reference.py b/tests/interfaces/openlp_plugins/bibles/test_lib_parse_reference.py index b005992ff..84f80e7ed 100644 --- a/tests/interfaces/openlp_plugins/bibles/test_lib_parse_reference.py +++ b/tests/interfaces/openlp_plugins/bibles/test_lib_parse_reference.py @@ -104,4 +104,4 @@ class TestBibleManager(TestCase, TestMixin): results = parse_reference('1 Timothy 1:1-2:1', self.manager.db_cache['tests'], MagicMock(), 54) # THEN a verse array should be returned self.assertEqual([(54, 1, 1, -1), (54, 2, 1, 1)], results, "The bible verses should matches the expected " - "results") + "results") From e86539888d2dfff0984e01e959cc01318659e692 Mon Sep 17 00:00:00 2001 From: Jonathan Springer Date: Thu, 17 Apr 2014 20:09:31 -0400 Subject: [PATCH 06/42] Fix typo --- openlp/core/ui/mainwindow.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index 4e1d28ef8..2b03c05cb 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -320,9 +320,9 @@ class Ui_MainWindow(object): # i18n add Language Actions add_actions(self.settings_language_menu, (self.auto_language_item, None)) add_actions(self.settings_language_menu, self.language_group.actions()) - # Qt on OS X look for keywords in the menu items title to determine which menu items get added to the main menu. - # If we are running on Mac OS X the menu items whose title contains those keywords but don't belong in the main - # menu need to be marked as such with QAction.NoRole. + # Qt on OS X looks for keywords in the menu items title to determine which menu items get added to the main + # menu. If we are running on Mac OS X the menu items whose title contains those keywords but don't belong in the + # main menu need to be marked as such with QAction.NoRole. if sys.platform == 'darwin': self.settings_shortcuts_item.setMenuRole(QtGui.QAction.NoRole) self.formatting_tag_item.setMenuRole(QtGui.QAction.NoRole) From 13fb4496f3114571c9f8ef35aca8e8c1f66a63ae Mon Sep 17 00:00:00 2001 From: Jonathan Springer Date: Wed, 23 Apr 2014 22:57:02 -0400 Subject: [PATCH 07/42] Change type to conform to expected type --- openlp/plugins/images/lib/mediaitem.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openlp/plugins/images/lib/mediaitem.py b/openlp/plugins/images/lib/mediaitem.py index c28f1e834..36df55dac 100644 --- a/openlp/plugins/images/lib/mediaitem.py +++ b/openlp/plugins/images/lib/mediaitem.py @@ -353,7 +353,7 @@ class ImageMediaItem(MediaManagerItem): icon = build_icon(thumb) else: icon = create_thumb(imageFile.filename, thumb) - item_name = QtGui.QTreeWidgetItem(filename) + item_name = QtGui.QTreeWidgetItem([filename]) item_name.setText(0, filename) item_name.setIcon(0, icon) item_name.setToolTip(0, imageFile.filename) From bdf3109aaa9e02897568244297a70bb0e4f63af5 Mon Sep 17 00:00:00 2001 From: Samuel Mehrbrodt Date: Thu, 1 May 2014 10:46:45 +0200 Subject: [PATCH 08/42] Fix SongShowPlus Import for certain cases Fixes: https://launchpad.net/bugs/1310623 --- .../plugins/songs/lib/songshowplusimport.py | 7 +++-- .../songs/test_songshowplusimport.py | 2 ++ .../a mighty fortress is our god.json | 29 ++++++++++++++++++ .../a mighty fortress is our god.sbsong | Bin 0 -> 1342 bytes 4 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 tests/resources/songshowplussongs/a mighty fortress is our god.json create mode 100644 tests/resources/songshowplussongs/a mighty fortress is our god.sbsong diff --git a/openlp/plugins/songs/lib/songshowplusimport.py b/openlp/plugins/songs/lib/songshowplusimport.py index 0a8dc4650..c1c6d04cb 100644 --- a/openlp/plugins/songs/lib/songshowplusimport.py +++ b/openlp/plugins/songs/lib/songshowplusimport.py @@ -121,7 +121,7 @@ class SongShowPlusImport(SongImport): null, verse_no, = struct.unpack("BB", song_data.read(2)) elif block_key == CUSTOM_VERSE: null, verse_name_length, = struct.unpack("BB", song_data.read(2)) - verse_name = song_data.read(verse_name_length) + verse_name = self.decode(song_data.read(verse_name_length)) length_descriptor_size, = struct.unpack("B", song_data.read(1)) log.debug(length_descriptor_size) # Detect if/how long the length descriptor is @@ -147,7 +147,10 @@ class SongShowPlusImport(SongImport): elif block_key == COPYRIGHT: self.add_copyright(self.decode(data)) elif block_key == CCLI_NO: - self.ccli_number = int(data) + try: + self.ccli_number = int(data) + except ValueError: + continue elif block_key == VERSE: self.add_verse(self.decode(data), "%s%s" % (VerseType.tags[VerseType.Verse], verse_no)) elif block_key == CHORUS: diff --git a/tests/functional/openlp_plugins/songs/test_songshowplusimport.py b/tests/functional/openlp_plugins/songs/test_songshowplusimport.py index 7292bb2b0..08400fdc5 100644 --- a/tests/functional/openlp_plugins/songs/test_songshowplusimport.py +++ b/tests/functional/openlp_plugins/songs/test_songshowplusimport.py @@ -57,6 +57,8 @@ class TestSongShowPlusFileImport(SongImportTestHelper): self.load_external_result_data(os.path.join(TEST_PATH, 'Amazing Grace.json'))) self.file_import(os.path.join(TEST_PATH, 'Beautiful Garden Of Prayer.sbsong'), self.load_external_result_data(os.path.join(TEST_PATH, 'Beautiful Garden Of Prayer.json'))) + self.file_import(os.path.join(TEST_PATH, 'a mighty fortress is our god.sbsong'), + self.load_external_result_data(os.path.join(TEST_PATH, 'a mighty fortress is our god.json'))) class TestSongShowPlusImport(TestCase): diff --git a/tests/resources/songshowplussongs/a mighty fortress is our god.json b/tests/resources/songshowplussongs/a mighty fortress is our god.json new file mode 100644 index 000000000..7e3d400b4 --- /dev/null +++ b/tests/resources/songshowplussongs/a mighty fortress is our god.json @@ -0,0 +1,29 @@ +{ + "authors": [ + "Martin Luther" + ], + "comments": "", + "copyright": "Public Domain", + "song_number": 0, + "title": "A Mighty Fortress is our God", + "topics": [], + "verse_order_list": [], + "verses": [ + [ + "A mighty fortress is our God, a bulwark never failing;\r\nOur helper He, amid the flood of mortal ills prevailing:\r\nFor still our ancient foe doth seek to work us woe;\r\nHis craft and power are great, and, armed with cruel hate,\r\nOn earth is not his equal.\r\n", + "v1" + ], + [ + "Did we in our own strength confide, our striving would be losing;\r\nWere not the right Man on our side, the Man of God’s own choosing:\r\nDost ask who that may be? Christ Jesus, it is He;\r\nLord Sabaoth, His Name, from age to age the same,\r\nAnd He must win the battle.\r\n", + "v2" + ], + [ + "And though this world, with devils filled, should threaten to undo us,\r\nWe will not fear, for God hath willed His truth to triumph through us:\r\nThe Prince of Darkness grim, we tremble not for him;\r\nHis rage we can endure, for lo, his doom is sure,\r\nOne little word shall fell him.\r\n", + "v3" + ], + [ + "That word above all earthly powers, no thanks to them, abideth;\r\nThe Spirit and the gifts are ours through Him Who with us sideth:\r\nLet goods and kindred go, this mortal life also;\r\nThe body they may kill: God’s truth abideth still,\r\nHis kingdom is forever.\r\n", + "v4" + ] + ] +} \ No newline at end of file diff --git a/tests/resources/songshowplussongs/a mighty fortress is our god.sbsong b/tests/resources/songshowplussongs/a mighty fortress is our god.sbsong new file mode 100644 index 0000000000000000000000000000000000000000..b66d52b2b73ef827e1427a90d8b54dfae1808508 GIT binary patch literal 1342 zcmZXU%We}f6o$j4Ekq3<=n5fp7F@cB5H01RvOrZM2&gTUTG6#9J~OuBv4ibNlpU|Z z>+vG+pP8tN#9}-iU(V(G&zTp!UT;&L+ppj6eYkAg%Eeze!JJ+-4nDw!{x%Go%V%ppMdqi~?Tls%%LsC>UZlU6oJkL2&sjRcU z`Z(x+NBD-_42xsN!P;s<;8eO0G=-9C*i(+IbBSh==iSZ2K_3t(WvsUdl%H7knaaSV zLpGF{r<4ON0=zZ}Z-%=uh)tp@GbyiW78dZUB2yJvWw`emL#$cT!otWTHtfi#%tM6g ziNV$gbssVry!mIN+^a!fh&)~+vcI#9uMv`2FhLDbDJ(n!j_fP39DHdtGL{{z+BtY2 z$i`_Zm|RF5pDRXm;!U7LK}@F#_BxZPH6dH=VkwpI=htsk1$<3RXsv+NC?sT@rnE2t zmQ_{;| zWGieWXN~L>!Y>&EY_51cTH|%Fvw^Qm(XPFqiZExAOKnlQWmnA*(YF%&DRPw=BXU)s zP_jX&lHkS6Mkp;EAQDx!%&F}H)FLjec#LgLS16ZO3p9|_S~g&G!kH>`C+@())OsDk zwnCn*gsX;iwv_NvSUD|%UW&VATY6K7b$DH^ohGXwyQT&rQ47{9-GKv4`F8-#OEjDO Nw;tl@?XG{w!aqH)mM#DQ literal 0 HcmV?d00001 From 41c950b819f05ce06eae4ace47e317f813dab97b Mon Sep 17 00:00:00 2001 From: Jonathan Springer Date: Thu, 1 May 2014 08:53:49 -0400 Subject: [PATCH 09/42] merge trunk From b993af2e90d84c98e05442f8b0f945fe4de797c8 Mon Sep 17 00:00:00 2001 From: Samuel Mehrbrodt Date: Fri, 2 May 2014 10:04:11 +0200 Subject: [PATCH 10/42] No newline at end of file... --- .../songshowplussongs/a mighty fortress is our god.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/resources/songshowplussongs/a mighty fortress is our god.json b/tests/resources/songshowplussongs/a mighty fortress is our god.json index 7e3d400b4..2ab95781d 100644 --- a/tests/resources/songshowplussongs/a mighty fortress is our god.json +++ b/tests/resources/songshowplussongs/a mighty fortress is our god.json @@ -26,4 +26,5 @@ "v4" ] ] -} \ No newline at end of file +} + From 5d63820b174157c8c7714c39dc0e250557810d9f Mon Sep 17 00:00:00 2001 From: Tomas Groth Date: Fri, 2 May 2014 23:07:56 +0200 Subject: [PATCH 11/42] Added support for importing EW songs even if RTF is not escaped as espected, also fixed importing og songs with unicode in metadata. Fixes: https://launchpad.net/bugs/1299837 --- openlp/plugins/songs/lib/ewimport.py | 25 +++++++++++++----- .../openlp_plugins/songs/test_ewimport.py | 24 ++++++++++++++++- tests/resources/easyworshipsongs/Songs.DB | Bin 6144 -> 6144 bytes tests/resources/easyworshipsongs/Songs.MB | Bin 12288 -> 20480 bytes 4 files changed, 42 insertions(+), 7 deletions(-) diff --git a/openlp/plugins/songs/lib/ewimport.py b/openlp/plugins/songs/lib/ewimport.py index faa4122c8..604a70d81 100644 --- a/openlp/plugins/songs/lib/ewimport.py +++ b/openlp/plugins/songs/lib/ewimport.py @@ -281,7 +281,7 @@ class EasyWorshipSongImport(SongImport): 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.title = self.get_field(fi_title).decode('unicode-escape') # Get remaining fields. copy = self.get_field(fi_copy) admin = self.get_field(fi_admin) @@ -289,16 +289,16 @@ class EasyWorshipSongImport(SongImport): authors = self.get_field(fi_author) words = self.get_field(fi_words) if copy: - self.copyright = copy.decode() + self.copyright = copy.decode('unicode-escape') if admin: if copy: self.copyright += ', ' self.copyright += translate('SongsPlugin.EasyWorshipSongImport', - 'Administered by %s') % admin.decode() + 'Administered by %s') % admin.decode('unicode-escape') if ccli: - self.ccli_number = ccli.decode() + self.ccli_number = ccli.decode('unicode-escape') if authors: - authors = authors.decode() + authors = authors.decode('unicode-escape') else: authors = '' # Set the SongImport object members. @@ -328,7 +328,20 @@ class EasyWorshipSongImport(SongImport): self.add_author(author_name.strip()) if words: # Format the lyrics - result = strip_rtf(words.decode(), self.encoding) + result = None + decoded_words = None + try: + decoded_words = words.decode() + except UnicodeDecodeError: + log.debug('The unicode chars in the rtf was not escaped in the expected manor, doing it manually.') + newbytes = bytearray() + for b in words: + if b > 127: + newbytes += bytearray(b'\\\'') + bytearray(str(hex(b))[-2:].encode()) + else: + newbytes.append(b) + decoded_words = newbytes.decode() + result = strip_rtf(decoded_words, self.encoding) if result is None: return words, self.encoding = result diff --git a/tests/functional/openlp_plugins/songs/test_ewimport.py b/tests/functional/openlp_plugins/songs/test_ewimport.py index 49bc367cd..e93ce9517 100644 --- a/tests/functional/openlp_plugins/songs/test_ewimport.py +++ b/tests/functional/openlp_plugins/songs/test_ewimport.py @@ -67,7 +67,21 @@ SONG_TEST_DATA = [ 'Just to learn from His lips, words of comfort,\nIn the beautiful garden of prayer.', 'v2'), ('There\'s a garden where Jesus is waiting,\nAnd He bids you to come meet Him there,\n' 'Just to bow and receive a new blessing,\nIn the beautiful garden of prayer.', 'v3')], - 'verse_order_list': []}] + 'verse_order_list': []}, + {'title': 'Vi pløjed og vi så\'de', + 'authors': ['Matthias Claudius'], + 'copyright': 'Public Domain', + 'ccli_number': 0, + 'verses': + [('Vi pløjed og vi så\'de\nvor sæd i sorten jord,\nså bad vi ham os hjælpe,\nsom højt i Himlen bor,\n' + 'og han lod snefald hegne\nmod frosten barsk og hård,\nhan lod det tø og regne\nog varme mildt i vår.', + 'v1'), + ('Alle gode gaver\nde kommer ovenned,\nså tak da Gud, ja, pris dog Gud\nfor al hans kærlighed!', 'c1'), + ('Han er jo den, hvis vilje\nopholder alle ting,\nhan klæder markens lilje\nog runder himlens ring,\n' + 'ham lyder vind og vove,\nham rører ravnes nød,\nhvi skulle ej hans småbørn\nda og få dagligt brød?', 'v2'), + ('Ja, tak, du kære Fader,\nså mild, så rig, så rund,\nfor korn i hæs og lader,\nfor godt i allen stund!\n' + 'Vi kan jo intet give,\nsom nogen ting er værd,\nmen tag vort stakkels hjerte,\nså ringe som det er!', 'v3')], + 'verse_order_list': []}] EWS_SONG_TEST_DATA =\ {'title': 'Vi pløjed og vi så\'de', @@ -139,6 +153,14 @@ class TestEasyWorshipSongImport(TestCase): """ Test the functions in the :mod:`ewimport` module. """ + def setUp(self): + self.songimport_patcher = patch('openlp.plugins.songs.lib.ewimport.EasyWorshipSongImport.__init__') + self.mocked_songimport = self.songimport_patcher.start() + self.mocked_songimport.return_value = None + + def tearDown(self): + self.songimport_patcher.stop() + def create_field_desc_entry_test(self): """ Test creating an instance of the :class`FieldDescEntry` class. diff --git a/tests/resources/easyworshipsongs/Songs.DB b/tests/resources/easyworshipsongs/Songs.DB index 8c9679b86a8bacecdd559011139959ccbd0c155a..b6a13abc5b28bd7fbf670ba370ad6517fc2e7cb9 100644 GIT binary patch delta 492 zcmXZYKS/zXg?^7pjlLZH2RANuvX#*#CoOYx>+ z=~6ie-PEo7(T)xdF6y95?b2|dE)Ip#p@Nb=P~V3i@54L3zUiB#r37>&;sCVUq}biP zrkb;UD%JvGK#SqzbI2by)yY9~v-BXjecD?tZ;Dsze}*G

>7rSg&Lpd1xwil%9v zDkSJFeWWc4X_t=ZJ6+H(x}kI-Qdu&{qQ|sIit4mMK_M!uFDzf_fPT<9{ibWui;=oV zgY<}=lBD%w6n@Ye@sSwfn7}v^NFvQ=w4oh$(1A{Lp&LEOpoCsz(T9h@LNb>rViYDU zjA0VCwnYN7SnzY^Ed0Qh_6QXKXUbuB(jg_Y=HQ{hqmj9nyCeWV^ npLGpt*}cQFflF%`{;a4Pvv$=}BK+Jvu7!#Ael7fz{HFZ_Ud61z delta 356 zcmXZYJ4gdj5Czb?n|*O(;@{Qy0Sg;Nl!(Y$tjVSmI}uw!R*UdRWg)2yf&r@-6+uv} z)D(8Funh?5M69(?rxL703qjCZIKzQEOf^%^lrw(hz=dN2u>L#69K65kpemYi5?ubW zS=lg5i5cTF%Y`Z{#UVC6KO}7Yw*iEuo*`ZO! z0wS>@+er#5gx*O~Rg0ZNIyBhZYag6{uRl1r@y%No&UYIhdWG0X+&nZ<|MUHYetG-wSn_jQLpD zX@4---I}eN(ql*72b-@bDhk})6%G^{4&wMGE zGqujPx?`V~+%v}~B4eCQt?t_$b$79?kfE3K%($tonuv}W_Svt4( zBlr@Tyt6M$Yv4RqaedBEXcUO=EjUmr#^D2}xfL$JkteJ~JTk7V;MqAFnxIhJJe7-y zS5oLSwqxQUb?{uko$zb^o+jQ@D#aA6CioI|e*{P3UE0-=?@FQBRBVFm6m=oxQwv6# z5vDsi^PJ+S`yGC^lA_#|5(P`az<-moYaK8>-Zchm1EL*5lAiWB-rVbh)t6?%HGj ze^Uaww`;#vlRj1d|4V5sitGRZ;Mb;XOa;^gnb(RHP$Gmz&w&PNHfAQLy6;?sbddMo z<{ElCq^6|O8jb01d?Jlye9EOq*F-h;v0!E_^sF{6xEBEh_o=y;svFPn;bnpVN1sv$ zf)buD+=?KLlmJ8?rIW*PFP`PPC)FXHKmOv z=7!KH0(|_YhFXKJ6TQCGEVrg={Ho*_F+DXlbL0jn7daMR0=#_EH07Vx$3aTbhYn}* zG4f|B!T7nU$tR>2L4Schd@L)9JsT2d3s0vc-r{DE0)-@XifJ*05DN_=EFmp-anu|h za32>SvLfdy!%};p1Nf`}gloyY(U<~z&?(2e_(XYSpKK!>)42b%aVK|vTwRWcE57AeQ9;2qs96$q7amy z8Pq&f?TL^Cdp$^gn~YOE)Twd|w#8zK23PXZC!6h|aRsz3`7!r12oz_LkZ z*o?DQpL~y%6;tN~IKk$p<{g1a9FWQ>ds|937MPY#v~Wz*-yu-}=Q1~{$t&V)Hi2D5 zsV8mjq`OZ;L>a;=CoDuXUkq Date: Fri, 2 May 2014 23:48:59 +0200 Subject: [PATCH 12/42] fixes for tests --- openlp/plugins/songs/lib/ewimport.py | 2 +- .../openlp_plugins/songs/test_ewimport.py | 37 +++++++++++++++++- tests/resources/easyworshipsongs/Songs.DB | Bin 6144 -> 10240 bytes tests/resources/easyworshipsongs/Songs.MB | Bin 20480 -> 32768 bytes 4 files changed, 37 insertions(+), 2 deletions(-) diff --git a/openlp/plugins/songs/lib/ewimport.py b/openlp/plugins/songs/lib/ewimport.py index 604a70d81..e12b7e181 100644 --- a/openlp/plugins/songs/lib/ewimport.py +++ b/openlp/plugins/songs/lib/ewimport.py @@ -333,7 +333,7 @@ class EasyWorshipSongImport(SongImport): try: decoded_words = words.decode() except UnicodeDecodeError: - log.debug('The unicode chars in the rtf was not escaped in the expected manor, doing it manually.') + # The unicode chars in the rtf was not escaped in the expected manor, doing it manually. newbytes = bytearray() for b in words: if b > 127: diff --git a/tests/functional/openlp_plugins/songs/test_ewimport.py b/tests/functional/openlp_plugins/songs/test_ewimport.py index e93ce9517..e6344e39b 100644 --- a/tests/functional/openlp_plugins/songs/test_ewimport.py +++ b/tests/functional/openlp_plugins/songs/test_ewimport.py @@ -153,13 +153,14 @@ class TestEasyWorshipSongImport(TestCase): """ Test the functions in the :mod:`ewimport` module. """ - def setUp(self): + """def setUp(self): self.songimport_patcher = patch('openlp.plugins.songs.lib.ewimport.EasyWorshipSongImport.__init__') self.mocked_songimport = self.songimport_patcher.start() self.mocked_songimport.return_value = None def tearDown(self): self.songimport_patcher.stop() + """ def create_field_desc_entry_test(self): """ @@ -489,3 +490,37 @@ class TestEasyWorshipSongImport(TestCase): for verse_text, verse_tag in EWS_SONG_TEST_DATA['verses']: mocked_add_verse.assert_any_call(verse_text, verse_tag) mocked_finish.assert_called_with() + + def import_rtf_unescaped_unicode_test(self): + """ + Test import of rtf without the expected escaping of unicode + """ + + # GIVEN: Test files with a mocked out SongImport class, a mocked out "manager", a mocked out "import_wizard", + # and mocked out "author", "add_copyright", "add_verse", "finish" methods. + with patch('openlp.plugins.songs.lib.ewimport.SongImport'), \ + patch('openlp.plugins.songs.lib.ewimport.strip_rtf') as mocked_strip_rtf, \ + patch('openlp.plugins.songs.lib.ewimport.retrieve_windows_encoding') \ + as mocked_retrieve_windows_encoding: + mocked_retrieve_windows_encoding.return_value = 'cp1252' + mocked_manager = MagicMock() + mocked_import_wizard = MagicMock() + mocked_add_author = MagicMock() + mocked_add_verse = MagicMock() + mocked_finish = MagicMock() + mocked_title = MagicMock() + mocked_finish.return_value = True + importer = EasyWorshipSongImportLogger(mocked_manager) + importer.import_wizard = mocked_import_wizard + importer.stop_import_flag = False + importer.add_author = mocked_add_author + importer.add_verse = mocked_add_verse + importer.title = mocked_title + importer.finish = mocked_finish + importer.topics = [] + + # WHEN: running set_song_import_object on a verse string without the needed escaping + importer.set_song_import_object('Test Author', b'Det som var fr\x86n begynnelsen') + + # THEN: The escaping shoud be added + mocked_strip_rtf.assert_called_with("Det som var fr\'86n begynnelsen", 'cp1252') diff --git a/tests/resources/easyworshipsongs/Songs.DB b/tests/resources/easyworshipsongs/Songs.DB index b6a13abc5b28bd7fbf670ba370ad6517fc2e7cb9..3476950578a9374493f8fc0c2d318652526ec414 100644 GIT binary patch delta 246 zcmZoLXb9j%8!klf8XU#5V8;V(DHl*R^zh6V z%#&<;1EYq?j9j9d?YR{hIT?V;fslb=b0*Ij7Kp)ou jiKl~+Re*tE6ZhtLzFelwnLKA$Hs?$HV&1H;dXWhL78Mjk diff --git a/tests/resources/easyworshipsongs/Songs.MB b/tests/resources/easyworshipsongs/Songs.MB index f5c7ad54cd12d287485e8e254e2ee1c1db26590e..949d7755c20d8efd6d91c96f791d26cb61069c44 100644 GIT binary patch delta 1089 zcmZXT&u$Yj5XN`Yw2D+DQd*U?gk%8GKT?HKK`TT!KsnHIq!Jf;ak}1(6R$V2ofWx- z69+Cx%LDKVG-sr~2QSfMFG$STi6C&vX6^BBzV93F_**z0m%cn*UT6hDDOjimLHK?D z$IVJP3@(;~AedCD*Ud_~6x3JUTkE=c(R#RAwjXS#xLmDIb{~HYi>sZL;&NxH__@`7 zaB78=40iCn2syV%#Q&YYISt$~SY&k;Gh?CKqg^@R8jF)h)T;ROe3vBNcqbyHE9f#6 z(Z(8yw0e{zU1aA%DXv}XdaM~DNwi^7&^E_ou3!#{u3yd^r%pY2&PhVzBFM3o_Ks^g z(~NW`$P(U4pGoODu3%2Sq19*G@u9IKa3eeKg0Zv^QGD^ChCjdt?@cwj3d;?tq$4q6 z=X7oyp-BeA!C(*YlomMy#iOa+`=nO`9`0*F5Ca1#`qr_!R5k~5qaN4V_35a+amv!o z6lX3XM)I3Zi<52Wx6dGPZ}`M{JL8)vkC=jpVJZggq$$&2P{$OZM%MNi#9o*iHFcu9 zbYShAE;v<8TkvKK8o{)YhqjC)ydN!TA_4}kVW_br!U{_Tb2R7jWV79zx^zQT$RvP! zk^L-H&ZxiNM4kFDa_G~OD&tjV?yzj_x>StHk zCF^r1^#XH|I9yB@&!ZDcf4wuZ%s`sq*Ml``#7bfCYq?l#y(*5Yx5E9&`|6#g;>FhO a85J!bO|I78hW{)sO~$p)|1X|w%EjL)3vt%~ delta 38 ucmZo@U}{*vIKg6L+#>#o32Gcnj0~H&85kHha|ry9-xQ!Kyjj)xHV**mn+vJ{ From e8c7547ab25a956f23a2ce071efc8d6c61f91f26 Mon Sep 17 00:00:00 2001 From: Samuel Mehrbrodt Date: Sat, 3 May 2014 10:47:31 +0200 Subject: [PATCH 13/42] Try to get ccli number even if there is text in the field --- openlp/plugins/songs/lib/songshowplusimport.py | 8 ++++---- .../songshowplussongs/a mighty fortress is our god.json | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/openlp/plugins/songs/lib/songshowplusimport.py b/openlp/plugins/songs/lib/songshowplusimport.py index c1c6d04cb..fe81b61a2 100644 --- a/openlp/plugins/songs/lib/songshowplusimport.py +++ b/openlp/plugins/songs/lib/songshowplusimport.py @@ -147,10 +147,10 @@ class SongShowPlusImport(SongImport): elif block_key == COPYRIGHT: self.add_copyright(self.decode(data)) elif block_key == CCLI_NO: - try: - self.ccli_number = int(data) - except ValueError: - continue + # Try to get the CCLI number even if the field contains additional text + match = re.search(r'\d+', self.decode(data)) + if match: + self.ccli_number = int(match.group()) elif block_key == VERSE: self.add_verse(self.decode(data), "%s%s" % (VerseType.tags[VerseType.Verse], verse_no)) elif block_key == CHORUS: diff --git a/tests/resources/songshowplussongs/a mighty fortress is our god.json b/tests/resources/songshowplussongs/a mighty fortress is our god.json index 2ab95781d..2788ad05c 100644 --- a/tests/resources/songshowplussongs/a mighty fortress is our god.json +++ b/tests/resources/songshowplussongs/a mighty fortress is our god.json @@ -2,6 +2,7 @@ "authors": [ "Martin Luther" ], + "ccli_number": 12456, "comments": "", "copyright": "Public Domain", "song_number": 0, From e0d813db3f6ed8ad8dc88b4c7c886561f1145e98 Mon Sep 17 00:00:00 2001 From: Samuel Mehrbrodt Date: Sat, 3 May 2014 12:03:50 +0200 Subject: [PATCH 14/42] Add an option to display the songbook in the footer --- openlp/plugins/songs/lib/mediaitem.py | 8 +++++--- openlp/plugins/songs/lib/songstab.py | 11 +++++++++++ openlp/plugins/songs/songsplugin.py | 1 + 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/openlp/plugins/songs/lib/mediaitem.py b/openlp/plugins/songs/lib/mediaitem.py index 32730ce3c..e2cb0f141 100644 --- a/openlp/plugins/songs/lib/mediaitem.py +++ b/openlp/plugins/songs/lib/mediaitem.py @@ -36,8 +36,8 @@ from PyQt4 import QtCore, QtGui from sqlalchemy.sql import or_ from openlp.core.common import Registry, AppLocation, Settings, check_directory_exists, UiStrings, translate -from openlp.core.lib import MediaManagerItem, ItemCapabilities, PluginStatus, ServiceItemContext, check_item_selected, \ - create_separated_list +from openlp.core.lib import MediaManagerItem, ItemCapabilities, PluginStatus, ServiceItem, ServiceItemContext, \ + check_item_selected, create_separated_list from openlp.core.lib.ui import create_widget_action from openlp.plugins.songs.forms.editsongform import EditSongForm from openlp.plugins.songs.forms.songmaintenanceform import SongMaintenanceForm @@ -460,7 +460,7 @@ class SongMediaItem(MediaManagerItem): service_item.background_audio = [m.file_name for m in song.media_files] return True - def generate_footer(self, item, song): + def generate_footer(self, item: ServiceItem, song: Song): """ Generates the song footer based on a song and adds details to a service item. @@ -506,6 +506,8 @@ class SongMediaItem(MediaManagerItem): item.raw_footer.append("%s: %s" % (AuthorType.Types[AuthorType.Translation], create_separated_list(authors_translation))) item.raw_footer.append(song.copyright) + if Settings().value('songs/display songbook') and song.book: + item.raw_footer.append("%s #%s" % (song.book.name, song.song_number)) if Settings().value('core/ccli number'): item.raw_footer.append(translate('SongsPlugin.MediaItem', 'CCLI License: ') + Settings().value('core/ccli number')) diff --git a/openlp/plugins/songs/lib/songstab.py b/openlp/plugins/songs/lib/songstab.py index bf74a4e7c..1cf06d047 100644 --- a/openlp/plugins/songs/lib/songstab.py +++ b/openlp/plugins/songs/lib/songstab.py @@ -59,6 +59,9 @@ class SongsTab(SettingsTab): self.add_from_service_check_box = QtGui.QCheckBox(self.mode_group_box) self.add_from_service_check_box.setObjectName('add_from_service_check_box') self.mode_layout.addWidget(self.add_from_service_check_box) + self.display_songbook_check_box = QtGui.QCheckBox(self.mode_group_box) + self.display_songbook_check_box.setObjectName('songbook_check_box') + self.mode_layout.addWidget(self.display_songbook_check_box) self.left_layout.addWidget(self.mode_group_box) self.left_layout.addStretch() self.right_layout.addStretch() @@ -66,6 +69,7 @@ class SongsTab(SettingsTab): self.tool_bar_active_check_box.stateChanged.connect(self.on_tool_bar_active_check_box_changed) self.update_on_edit_check_box.stateChanged.connect(self.on_update_on_edit_check_box_changed) self.add_from_service_check_box.stateChanged.connect(self.on_add_from_service_check_box_changed) + self.display_songbook_check_box.stateChanged.connect(self.on_songbook_check_box_changed) def retranslateUi(self): self.mode_group_box.setTitle(translate('SongsPlugin.SongsTab', 'Songs Mode')) @@ -75,6 +79,7 @@ class SongsTab(SettingsTab): self.update_on_edit_check_box.setText(translate('SongsPlugin.SongsTab', 'Update service from song edit')) self.add_from_service_check_box.setText(translate('SongsPlugin.SongsTab', 'Import missing songs from service files')) + self.display_songbook_check_box.setText(translate('SongsPlugin.SongsTab', 'Display songbook in footer')) def on_search_as_type_check_box_changed(self, check_state): self.song_search = (check_state == QtCore.Qt.Checked) @@ -88,6 +93,9 @@ class SongsTab(SettingsTab): def on_add_from_service_check_box_changed(self, check_state): self.update_load = (check_state == QtCore.Qt.Checked) + def on_songbook_check_box_changed(self, check_state): + self.display_songbook = (check_state == QtCore.Qt.Checked) + def load(self): settings = Settings() settings.beginGroup(self.settings_section) @@ -95,10 +103,12 @@ class SongsTab(SettingsTab): self.tool_bar = settings.value('display songbar') self.update_edit = settings.value('update service on edit') self.update_load = settings.value('add song from service') + self.display_songbook = settings.value('display songbook') self.search_as_type_check_box.setChecked(self.song_search) self.tool_bar_active_check_box.setChecked(self.tool_bar) self.update_on_edit_check_box.setChecked(self.update_edit) self.add_from_service_check_box.setChecked(self.update_load) + self.display_songbook_check_box.setChecked(self.display_songbook) settings.endGroup() def save(self): @@ -108,6 +118,7 @@ class SongsTab(SettingsTab): settings.setValue('display songbar', self.tool_bar) settings.setValue('update service on edit', self.update_edit) settings.setValue('add song from service', self.update_load) + settings.setValue('display songbook', self.display_songbook) settings.endGroup() if self.tab_visited: self.settings_form.register_post_process('songs_config_updated') diff --git a/openlp/plugins/songs/songsplugin.py b/openlp/plugins/songs/songsplugin.py index b1ddaf412..79fc282a6 100644 --- a/openlp/plugins/songs/songsplugin.py +++ b/openlp/plugins/songs/songsplugin.py @@ -63,6 +63,7 @@ __default_settings__ = { 'songs/search as type': False, 'songs/add song from service': True, 'songs/display songbar': True, + 'songs/display songbook': False, 'songs/last directory import': '', 'songs/last directory export': '', 'songs/songselect username': '', From a98ea19306d59217e802f8a1362167481b073735 Mon Sep 17 00:00:00 2001 From: Samuel Mehrbrodt Date: Sat, 3 May 2014 12:42:18 +0200 Subject: [PATCH 15/42] Add test for songbook display --- openlp/plugins/songs/lib/mediaitem.py | 5 ++-- .../openlp_plugins/songs/test_mediaitem.py | 29 +++++++++++++++++-- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/openlp/plugins/songs/lib/mediaitem.py b/openlp/plugins/songs/lib/mediaitem.py index e2cb0f141..413498af6 100644 --- a/openlp/plugins/songs/lib/mediaitem.py +++ b/openlp/plugins/songs/lib/mediaitem.py @@ -124,7 +124,8 @@ class SongMediaItem(MediaManagerItem): log.debug('config_updated') self.search_as_you_type = Settings().value(self.settings_section + '/search as type') self.update_service_on_edit = Settings().value(self.settings_section + '/update service on edit') - self.add_song_from_service = Settings().value(self.settings_section + '/add song from service',) + self.add_song_from_service = Settings().value(self.settings_section + '/add song from service') + self.display_songbook = Settings().value(self.settings_section + '/display songbook') def retranslateUi(self): self.search_text_label.setText('%s:' % UiStrings().Search) @@ -506,7 +507,7 @@ class SongMediaItem(MediaManagerItem): item.raw_footer.append("%s: %s" % (AuthorType.Types[AuthorType.Translation], create_separated_list(authors_translation))) item.raw_footer.append(song.copyright) - if Settings().value('songs/display songbook') and song.book: + if self.display_songbook and song.book: item.raw_footer.append("%s #%s" % (song.book.name, song.song_number)) if Settings().value('core/ccli number'): item.raw_footer.append(translate('SongsPlugin.MediaItem', diff --git a/tests/functional/openlp_plugins/songs/test_mediaitem.py b/tests/functional/openlp_plugins/songs/test_mediaitem.py index 308881c2e..824b57a20 100644 --- a/tests/functional/openlp_plugins/songs/test_mediaitem.py +++ b/tests/functional/openlp_plugins/songs/test_mediaitem.py @@ -1,8 +1,6 @@ """ This module contains tests for the lib submodule of the Songs plugin. """ -import os -from tempfile import mkstemp from unittest import TestCase from PyQt4 import QtCore, QtGui @@ -29,6 +27,7 @@ class TestMediaItem(TestCase, TestMixin): with patch('openlp.core.lib.mediamanageritem.MediaManagerItem._setup'), \ patch('openlp.plugins.songs.forms.editsongform.EditSongForm.__init__'): self.media_item = SongMediaItem(None, MagicMock()) + self.media_item.display_songbook = False self.get_application() self.build_settings() QtCore.QLocale.setDefault(QtCore.QLocale('en_GB')) @@ -128,3 +127,29 @@ class TestMediaItem(TestCase, TestMixin): # THEN: I would get an amended footer string self.assertEqual(service_item.raw_footer, ['My Song', 'My copyright', 'CCLI License: 4321'], 'The array should be returned correctly with a song, an author, copyright and amended ccli') + + def build_song_footer_base_songbook_test(self): + """ + Test build songs footer with basic song and a songbook + """ + # GIVEN: A Song and a Service Item and a configured CCLI license + mock_song = MagicMock() + mock_song.title = 'My Song' + mock_song.copyright = 'My copyright' + mock_song.book = MagicMock() + mock_song.book.name = "My songbook" + mock_song.song_number = 12 + service_item = ServiceItem(None) + + # WHEN: I generate the Footer with default settings + self.media_item.generate_footer(service_item, mock_song) + + # THEN: The songbook should not be in the footer + self.assertEqual(service_item.raw_footer, ['My Song', 'My copyright']) + + # WHEN: I activate the "display songbook" option + self.media_item.display_songbook = True + self.media_item.generate_footer(service_item, mock_song) + + # THEN: The songbook should be in the footer + self.assertEqual(service_item.raw_footer, ['My Song', 'My copyright', 'My songbook #12']) From 922bbc3b57219b1789a1e4b7da81d185c549e35a Mon Sep 17 00:00:00 2001 From: Samuel Mehrbrodt Date: Sat, 3 May 2014 12:53:51 +0200 Subject: [PATCH 16/42] Typo, remove annotations --- openlp/plugins/songs/lib/mediaitem.py | 2 +- tests/functional/openlp_plugins/songs/test_mediaitem.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/openlp/plugins/songs/lib/mediaitem.py b/openlp/plugins/songs/lib/mediaitem.py index 413498af6..699f812e3 100644 --- a/openlp/plugins/songs/lib/mediaitem.py +++ b/openlp/plugins/songs/lib/mediaitem.py @@ -461,7 +461,7 @@ class SongMediaItem(MediaManagerItem): service_item.background_audio = [m.file_name for m in song.media_files] return True - def generate_footer(self, item: ServiceItem, song: Song): + def generate_footer(self, item, song): """ Generates the song footer based on a song and adds details to a service item. diff --git a/tests/functional/openlp_plugins/songs/test_mediaitem.py b/tests/functional/openlp_plugins/songs/test_mediaitem.py index 824b57a20..22291c6a6 100644 --- a/tests/functional/openlp_plugins/songs/test_mediaitem.py +++ b/tests/functional/openlp_plugins/songs/test_mediaitem.py @@ -132,7 +132,7 @@ class TestMediaItem(TestCase, TestMixin): """ Test build songs footer with basic song and a songbook """ - # GIVEN: A Song and a Service Item and a configured CCLI license + # GIVEN: A Song and a Service Item mock_song = MagicMock() mock_song.title = 'My Song' mock_song.copyright = 'My copyright' From c7ce62bd43a79616e3b2cbd9e26ab0ca439f14ac Mon Sep 17 00:00:00 2001 From: Tomas Groth Date: Mon, 5 May 2014 19:29:57 +0200 Subject: [PATCH 17/42] Changed to ignore wrongly formatted songs. --- openlp/plugins/songs/lib/ewimport.py | 29 ++++++++++----- .../openlp_plugins/songs/test_ewimport.py | 37 ++++--------------- 2 files changed, 26 insertions(+), 40 deletions(-) diff --git a/openlp/plugins/songs/lib/ewimport.py b/openlp/plugins/songs/lib/ewimport.py index e12b7e181..b08193672 100644 --- a/openlp/plugins/songs/lib/ewimport.py +++ b/openlp/plugins/songs/lib/ewimport.py @@ -74,6 +74,7 @@ class EasyWorshipSongImport(SongImport): """ def __init__(self, manager, **kwargs): super(EasyWorshipSongImport, self).__init__(manager, **kwargs) + self.entry_error_log = '' def do_import(self): """ @@ -183,7 +184,12 @@ class EasyWorshipSongImport(SongImport): self.set_song_import_object(authors, inflated_content) if self.stop_import_flag: break - if not self.finish(): + 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) # Set file_pos for next entry file_pos += entry_length @@ -305,7 +311,12 @@ class EasyWorshipSongImport(SongImport): self.set_song_import_object(authors, words) if self.stop_import_flag: break - if not self.finish(): + 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) db_file.close() self.memo_file.close() @@ -333,16 +344,14 @@ class EasyWorshipSongImport(SongImport): try: decoded_words = words.decode() except UnicodeDecodeError: - # The unicode chars in the rtf was not escaped in the expected manor, doing it manually. - newbytes = bytearray() - for b in words: - if b > 127: - newbytes += bytearray(b'\\\'') + bytearray(str(hex(b))[-2:].encode()) - else: - newbytes.append(b) - decoded_words = newbytes.decode() + # The unicode chars in the rtf was not escaped in the expected manor + self.entry_error_log = translate('SongsPlugin.EasyWorshipSongImport', + 'Unexpected data formatting.') + return result = strip_rtf(decoded_words, self.encoding) if result is None: + self.entry_error_log = translate('SongsPlugin.EasyWorshipSongImport', + 'No song text found.') return words, self.encoding = result verse_type = VerseType.tags[VerseType.Verse] diff --git a/tests/functional/openlp_plugins/songs/test_ewimport.py b/tests/functional/openlp_plugins/songs/test_ewimport.py index e6344e39b..8d9302015 100644 --- a/tests/functional/openlp_plugins/songs/test_ewimport.py +++ b/tests/functional/openlp_plugins/songs/test_ewimport.py @@ -153,15 +153,7 @@ class TestEasyWorshipSongImport(TestCase): """ Test the functions in the :mod:`ewimport` module. """ - """def setUp(self): - self.songimport_patcher = patch('openlp.plugins.songs.lib.ewimport.EasyWorshipSongImport.__init__') - self.mocked_songimport = self.songimport_patcher.start() - self.mocked_songimport.return_value = None - - def tearDown(self): - self.songimport_patcher.stop() - """ - + def create_field_desc_entry_test(self): """ Test creating an instance of the :class`FieldDescEntry` class. @@ -495,32 +487,17 @@ class TestEasyWorshipSongImport(TestCase): """ Test import of rtf without the expected escaping of unicode """ - - # GIVEN: Test files with a mocked out SongImport class, a mocked out "manager", a mocked out "import_wizard", - # and mocked out "author", "add_copyright", "add_verse", "finish" methods. - with patch('openlp.plugins.songs.lib.ewimport.SongImport'), \ - patch('openlp.plugins.songs.lib.ewimport.strip_rtf') as mocked_strip_rtf, \ - patch('openlp.plugins.songs.lib.ewimport.retrieve_windows_encoding') \ - as mocked_retrieve_windows_encoding: - mocked_retrieve_windows_encoding.return_value = 'cp1252' + + # GIVEN: A mocked out SongImport class, a mocked out "manager" and mocked out "author" method. + with patch('openlp.plugins.songs.lib.ewimport.SongImport'): mocked_manager = MagicMock() - mocked_import_wizard = MagicMock() mocked_add_author = MagicMock() - mocked_add_verse = MagicMock() - mocked_finish = MagicMock() - mocked_title = MagicMock() - mocked_finish.return_value = True importer = EasyWorshipSongImportLogger(mocked_manager) - importer.import_wizard = mocked_import_wizard - importer.stop_import_flag = False importer.add_author = mocked_add_author - importer.add_verse = mocked_add_verse - importer.title = mocked_title - importer.finish = mocked_finish - importer.topics = [] + importer.encoding = 'cp1252' # WHEN: running set_song_import_object on a verse string without the needed escaping importer.set_song_import_object('Test Author', b'Det som var fr\x86n begynnelsen') - # THEN: The escaping shoud be added - mocked_strip_rtf.assert_called_with("Det som var fr\'86n begynnelsen", 'cp1252') + # THEN: The import should fail + self.assertEquals(importer.entry_error_log, 'Unexpected data formatting.', 'Import should fail') From 0fd815051f677f92ece5eb3c021ed0a1162af9af Mon Sep 17 00:00:00 2001 From: Tomas Groth Date: Mon, 5 May 2014 19:31:45 +0200 Subject: [PATCH 18/42] Fix for packaging --- MANIFEST.in | 2 ++ 1 file changed, 2 insertions(+) diff --git a/MANIFEST.in b/MANIFEST.in index 35e83e30f..be81efb23 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -5,6 +5,8 @@ recursive-include openlp *.html recursive-include openlp *.js recursive-include openlp *.css recursive-include openlp *.png +recursive-include openlp *.ps +recursive-include openlp *.json recursive-include documentation * recursive-include resources * recursive-include scripts * From 0d48c09180b0648ca476c9977ef3392a48b4211d Mon Sep 17 00:00:00 2001 From: Tomas Groth Date: Tue, 6 May 2014 21:53:08 +0200 Subject: [PATCH 19/42] Added support for import of Zefania XML bibles. --- openlp/core/ui/wizard.py | 1 + .../plugins/bibles/forms/bibleimportform.py | 45 ++++++- openlp/plugins/bibles/lib/manager.py | 5 + openlp/plugins/bibles/lib/opensong.py | 7 ++ openlp/plugins/bibles/lib/zefania.py | 110 ++++++++++++++++++ 5 files changed, 166 insertions(+), 2 deletions(-) create mode 100644 openlp/plugins/bibles/lib/zefania.py diff --git a/openlp/core/ui/wizard.py b/openlp/core/ui/wizard.py index 5996296b5..37070092b 100644 --- a/openlp/core/ui/wizard.py +++ b/openlp/core/ui/wizard.py @@ -51,6 +51,7 @@ class WizardStrings(object): CSV = 'CSV' OS = 'OpenSong' OSIS = 'OSIS' + ZEF = 'Zefania' # These strings should need a good reason to be retranslated elsewhere. FinishedImport = translate('OpenLP.Ui', 'Finished import.') FormatLabel = translate('OpenLP.Ui', 'Format:') diff --git a/openlp/plugins/bibles/forms/bibleimportform.py b/openlp/plugins/bibles/forms/bibleimportform.py index 79b0bc699..171994d18 100644 --- a/openlp/plugins/bibles/forms/bibleimportform.py +++ b/openlp/plugins/bibles/forms/bibleimportform.py @@ -110,6 +110,7 @@ class BibleImportForm(OpenLPWizard): self.csv_books_button.clicked.connect(self.on_csv_books_browse_button_clicked) self.csv_verses_button.clicked.connect(self.on_csv_verses_browse_button_clicked) self.open_song_browse_button.clicked.connect(self.on_open_song_browse_button_clicked) + self.zefania_browse_button.clicked.connect(self.on_zefania_browse_button_clicked) def add_custom_pages(self): """ @@ -125,7 +126,7 @@ class BibleImportForm(OpenLPWizard): self.format_label = QtGui.QLabel(self.select_page) self.format_label.setObjectName('FormatLabel') self.format_combo_box = QtGui.QComboBox(self.select_page) - self.format_combo_box.addItems(['', '', '', '']) + self.format_combo_box.addItems(['', '', '', '', '']) self.format_combo_box.setObjectName('FormatComboBox') self.format_layout.addRow(self.format_label, self.format_combo_box) self.spacer = QtGui.QSpacerItem(10, 0, QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Minimum) @@ -247,6 +248,25 @@ class BibleImportForm(OpenLPWizard): self.web_proxy_layout.setWidget(2, QtGui.QFormLayout.FieldRole, self.web_password_edit) self.web_tab_widget.addTab(self.web_proxy_tab, '') self.select_stack.addWidget(self.web_tab_widget) + self.zefania_widget = QtGui.QWidget(self.select_page) + self.zefania_widget.setObjectName('ZefaniaWidget') + self.zefania_layout = QtGui.QFormLayout(self.zefania_widget) + self.zefania_layout.setMargin(0) + self.zefania_layout.setObjectName('ZefaniaLayout') + self.zefania_file_label = QtGui.QLabel(self.zefania_widget) + self.zefania_file_label.setObjectName('ZefaniaFileLabel') + self.zefania_file_layout = QtGui.QHBoxLayout() + self.zefania_file_layout.setObjectName('ZefaniaFileLayout') + self.zefania_file_edit = QtGui.QLineEdit(self.zefania_widget) + self.zefania_file_edit.setObjectName('ZefaniaFileEdit') + self.zefania_file_layout.addWidget(self.zefania_file_edit) + self.zefania_browse_button = QtGui.QToolButton(self.zefania_widget) + self.zefania_browse_button.setIcon(self.open_icon) + self.zefania_browse_button.setObjectName('ZefaniaBrowseButton') + self.zefania_file_layout.addWidget(self.zefania_browse_button) + self.zefania_layout.addRow(self.zefania_file_label, self.zefania_file_layout) + self.zefania_layout.setItem(5, QtGui.QFormLayout.LabelRole, self.spacer) + self.select_stack.addWidget(self.zefania_widget) self.select_page_layout.addLayout(self.select_stack) self.addPage(self.select_page) # License Page @@ -294,11 +314,13 @@ class BibleImportForm(OpenLPWizard): self.format_combo_box.setItemText(BibleFormat.OpenSong, WizardStrings.OS) self.format_combo_box.setItemText(BibleFormat.WebDownload, translate('BiblesPlugin.ImportWizardForm', 'Web Download')) + self.format_combo_box.setItemText(BibleFormat.Zefania, WizardStrings.ZEF) self.osis_file_label.setText(translate('BiblesPlugin.ImportWizardForm', 'Bible file:')) self.csv_books_label.setText(translate('BiblesPlugin.ImportWizardForm', 'Books file:')) self.csv_verses_label.setText(translate('BiblesPlugin.ImportWizardForm', 'Verses file:')) self.open_song_file_label.setText(translate('BiblesPlugin.ImportWizardForm', 'Bible file:')) self.web_source_label.setText(translate('BiblesPlugin.ImportWizardForm', 'Location:')) + self.zefania_file_label.setText(translate('BiblesPlugin.ImportWizardForm', 'Bible file:')) self.web_source_combo_box.setItemText(WebDownload.Crosswalk, translate('BiblesPlugin.ImportWizardForm', 'Crosswalk')) self.web_source_combo_box.setItemText(WebDownload.BibleGateway, translate('BiblesPlugin.ImportWizardForm', @@ -331,7 +353,8 @@ class BibleImportForm(OpenLPWizard): self.osis_file_label.minimumSizeHint().width(), self.csv_books_label.minimumSizeHint().width(), self.csv_verses_label.minimumSizeHint().width(), - self.open_song_file_label.minimumSizeHint().width()) + self.open_song_file_label.minimumSizeHint().width(), + self.zefania_file_label.minimumSizeHint().width()) self.spacer.changeSize(label_width, 0, QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed) def validateCurrentPage(self): @@ -366,6 +389,11 @@ class BibleImportForm(OpenLPWizard): critical_error_message_box(UiStrings().NFSs, WizardStrings.YouSpecifyFile % WizardStrings.OS) self.open_song_file_edit.setFocus() return False + elif self.field('source_format') == BibleFormat.Zefania: + if not self.field('zefania_file'): + critical_error_message_box(UiStrings().NFSs, WizardStrings.YouSpecifyFile % WizardStrings.ZEF) + self.zefania_file_edit.setFocus() + return False elif self.field('source_format') == BibleFormat.WebDownload: self.version_name_edit.setText(self.web_translation_combo_box.currentText()) return True @@ -447,6 +475,13 @@ class BibleImportForm(OpenLPWizard): self.get_file_name(WizardStrings.OpenTypeFile % WizardStrings.OS, self.open_song_file_edit, 'last directory import') + def on_zefania_browse_button_clicked(self): + """ + Show the file open dialog for the Zefania file. + """ + self.get_file_name(WizardStrings.OpenTypeFile % WizardStrings.ZEF, self.zefania_file_edit, + 'last directory import') + def register_fields(self): """ Register the bible import wizard fields. @@ -456,6 +491,7 @@ class BibleImportForm(OpenLPWizard): self.select_page.registerField('csv_booksfile', self.csv_books_edit) self.select_page.registerField('csv_versefile', self.csv_verses_edit) self.select_page.registerField('opensong_file', self.open_song_file_edit) + self.select_page.registerField('zefania_file', self.zefania_file_edit) self.select_page.registerField('web_location', self.web_source_combo_box) self.select_page.registerField('web_biblename', self.web_translation_combo_box) self.select_page.registerField('proxy_server', self.web_server_edit) @@ -479,6 +515,7 @@ class BibleImportForm(OpenLPWizard): self.setField('csv_booksfile', '') self.setField('csv_versefile', '') self.setField('opensong_file', '') + self.setField('zefania_file', '') self.setField('web_location', WebDownload.Crosswalk) self.setField('web_biblename', self.web_translation_combo_box.currentIndex()) self.setField('proxy_server', settings.value('proxy address')) @@ -562,6 +599,10 @@ class BibleImportForm(OpenLPWizard): proxy_username=self.field('proxy_username'), proxy_password=self.field('proxy_password') ) + elif bible_type == BibleFormat.Zefania: + # Import an Zefania bible. + importer = self.manager.import_bible(BibleFormat.Zefania, name=license_version, + filename=self.field('zefania_file')) if importer.do_import(license_version): self.manager.save_meta_data(license_version, license_version, license_copyright, license_permissions) self.manager.reload_bibles() diff --git a/openlp/plugins/bibles/lib/manager.py b/openlp/plugins/bibles/lib/manager.py index c57fc117e..7dab8b3d7 100644 --- a/openlp/plugins/bibles/lib/manager.py +++ b/openlp/plugins/bibles/lib/manager.py @@ -38,6 +38,7 @@ from .csvbible import CSVBible from .http import HTTPBible from .opensong import OpenSongBible from .osis import OSISBible +from .zefania import ZefaniaBible log = logging.getLogger(__name__) @@ -52,6 +53,7 @@ class BibleFormat(object): CSV = 1 OpenSong = 2 WebDownload = 3 + Zefania = 4 @staticmethod def get_class(bible_format): @@ -68,6 +70,8 @@ class BibleFormat(object): return OpenSongBible elif bible_format == BibleFormat.WebDownload: return HTTPBible + elif bible_format == BibleFormat.Zefania: + return ZefaniaBible else: return None @@ -81,6 +85,7 @@ class BibleFormat(object): BibleFormat.CSV, BibleFormat.OpenSong, BibleFormat.WebDownload, + BibleFormar.Zefania, ] diff --git a/openlp/plugins/bibles/lib/opensong.py b/openlp/plugins/bibles/lib/opensong.py index c7bfa01a2..fa8323d7f 100644 --- a/openlp/plugins/bibles/lib/opensong.py +++ b/openlp/plugins/bibles/lib/opensong.py @@ -81,6 +81,13 @@ class OpenSongBible(BibleDB): import_file = open(self.filename, 'rb') opensong = objectify.parse(import_file) bible = opensong.getroot() + # Check that we're not trying to import a Zefania XML bible, it is sometimes refered to as 'OpenSong' + if bible.tag.upper() == 'XMLBIBLE': + critical_error_message_box( + message=translate('BiblesPlugin.OpenSongImport', + 'Incorrect Bible file type supplied. This looks like a Zefania XML bible, ' + 'please use the Zefania import option.')) + return False language_id = self.get_language(bible_name) if not language_id: log.error('Importing books from "%s" failed' % self.filename) diff --git a/openlp/plugins/bibles/lib/zefania.py b/openlp/plugins/bibles/lib/zefania.py new file mode 100644 index 000000000..16680efa3 --- /dev/null +++ b/openlp/plugins/bibles/lib/zefania.py @@ -0,0 +1,110 @@ +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 + +############################################################################### +# OpenLP - Open Source Lyrics Projection # +# --------------------------------------------------------------------------- # +# Copyright (c) 2008-2014 Raoul Snyman # +# Portions copyright (c) 2008-2014 Tim Bentley, Gerald Britton, Jonathan # +# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, # +# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. # +# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, # +# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, # +# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, # +# Frode Woldsund, Martin Zibricky, Patrick Zimmermann # +# --------------------------------------------------------------------------- # +# 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 # +############################################################################### + +import logging +from lxml import etree, objectify + +from openlp.core.common import translate +from openlp.core.lib.ui import critical_error_message_box +from openlp.plugins.bibles.lib.db import BibleDB, BiblesResourcesDB + + +log = logging.getLogger(__name__) + + +class ZefaniaBible(BibleDB): + """ + Zefania Bible format importer class. + """ + def __init__(self, parent, **kwargs): + """ + Constructor to create and set up an instance of the ZefaniaBible class. This class is used to import Bibles + from ZefaniaBible's XML format. + """ + log.debug(self.__class__.__name__) + BibleDB.__init__(self, parent, **kwargs) + self.filename = kwargs['filename'] + + def do_import(self, bible_name=None): + """ + Loads a Bible from file. + """ + log.debug('Starting Zefania import from "%s"' % self.filename) + if not isinstance(self.filename, str): + self.filename = str(self.filename, 'utf8') + import_file = None + success = True + try: + # NOTE: We don't need to do any of the normal encoding detection here, because lxml does it's own encoding + # detection, and the two mechanisms together interfere with each other. + import_file = open(self.filename, 'rb') + language_id = self.get_language(bible_name) + if not language_id: + log.error('Importing books from "%s" failed' % self.filename) + return False + zefania_bible_tree = etree.parse(import_file) + num_books = int(zefania_bible_tree.xpath("count(//BIBLEBOOK)")) + # Strip tags we don't use + etree.strip_tags(zefania_bible_tree, ('STYLE', 'GRAM', 'NOTE', 'SUP', 'XREF')) + xmlbible = zefania_bible_tree.getroot() + for BIBLEBOOK in xmlbible: + book_ref_id = self.get_book_ref_id_by_name(str(BIBLEBOOK.get('bname')), num_books) + if not book_ref_id: + book_ref_id = self.get_book_ref_id_by_localised_name(str(BIBLEBOOK.get('bname'))) + if not book_ref_id: + log.error('Importing books from "%s" failed' % self.filename) + return False + book_details = BiblesResourcesDB.get_book_by_id(book_ref_id) + db_book = self.create_book(book_details['name'], book_ref_id, book_details['testament_id']) + for CHAPTER in BIBLEBOOK: + if self.stop_import_flag: + break + chapter_number = CHAPTER.get("cnumber") + for VERS in CHAPTER: + verse_number = VERS.get("vnumber") + self.create_verse(db_book.id, chapter_number, verse_number, VERS.text.replace('
', '\n')) + self.wizard.increment_progress_bar( + translate('BiblesPlugin.Zefnia', 'Importing %(bookname)s %(chapter)s...' % + {'bookname': db_book.name, 'chapter': chapter_number})) + self.session.commit() + self.application.process_events() + except Exception as e: + critical_error_message_box( + message=translate('BiblesPlugin.ZefaniaImport', + 'Incorrect Bible file type supplied. Zefania Bibles may be ' + 'compressed. You must decompress them before import.')) + log.exception(str(e)) + success = False + finally: + if import_file: + import_file.close() + if self.stop_import_flag: + return False + else: + return success From ef2a03d5103698d7de40cee8a0d9a9b0be6fddec Mon Sep 17 00:00:00 2001 From: Samuel Mehrbrodt Date: Wed, 7 May 2014 11:51:59 +0200 Subject: [PATCH 20/42] Fix bug 1316979 by making the authors relation viewonly Fixes: https://launchpad.net/bugs/1316979 --- .../songs/forms/songmaintenanceform.py | 10 +++--- openlp/plugins/songs/lib/__init__.py | 4 +-- openlp/plugins/songs/lib/db.py | 32 +++++++++++++++++-- .../plugins/songs/lib/foilpresenterimport.py | 2 +- openlp/plugins/songs/lib/olpimport.py | 2 +- openlp/plugins/songs/lib/songimport.py | 2 +- openlp/plugins/songs/lib/songselect.py | 2 +- 7 files changed, 40 insertions(+), 14 deletions(-) diff --git a/openlp/plugins/songs/forms/songmaintenanceform.py b/openlp/plugins/songs/forms/songmaintenanceform.py index 4e9bdad93..bdbae41fb 100644 --- a/openlp/plugins/songs/forms/songmaintenanceform.py +++ b/openlp/plugins/songs/forms/songmaintenanceform.py @@ -400,7 +400,7 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog, RegistryPrope """ Merges two authors into one author. - :param old_author: The object, which was edited, that will be deleted + :param old_author: The object, which was edited, that will be deleted """ # Find the duplicate. existing_author = self.manager.get_object_filtered( @@ -415,11 +415,9 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog, RegistryPrope # Find the songs, which have the old_author as author. songs = self.manager.get_all_objects(Song, Song.authors.contains(old_author)) for song in songs: - # We check if the song has already existing_author as author. If - # that is not the case we add it. - if existing_author not in song.authors: - song.authors.append(existing_author) - song.authors.remove(old_author) + for author_song in song.authors_songs: + song.add_author(existing_author, author_song.author_type) + song.remove_author(old_author, author_song.author_type) self.manager.save_object(song) self.manager.delete_object(Author, old_author.id) diff --git a/openlp/plugins/songs/lib/__init__.py b/openlp/plugins/songs/lib/__init__.py index 95868ffa7..f6d43fb6e 100644 --- a/openlp/plugins/songs/lib/__init__.py +++ b/openlp/plugins/songs/lib/__init__.py @@ -390,12 +390,12 @@ def clean_song(manager, song): verses = SongXML().get_verses(song.lyrics) song.search_lyrics = ' '.join([clean_string(verse[1]) for verse in verses]) # The song does not have any author, add one. - if not song.authors and not song.authors_songs: # Need to check both relations + if not song.authors_songs: name = SongStrings.AuthorUnknown author = manager.get_object_filtered(Author, Author.display_name == name) if author is None: author = Author.populate(display_name=name, last_name='', first_name='') - song.authors.append(author) + song.add_author(author) if song.copyright: song.copyright = CONTROL_CHARS.sub('', song.copyright).strip() diff --git a/openlp/plugins/songs/lib/db.py b/openlp/plugins/songs/lib/db.py index 91649c951..e77d98bda 100644 --- a/openlp/plugins/songs/lib/db.py +++ b/openlp/plugins/songs/lib/db.py @@ -114,6 +114,33 @@ class Song(BaseModel): """ self.sort_key = get_natural_key(self.title) + def add_author(self, author, author_type=None, ignore_type=False): + """ + Add an author to the song if it not yet exists + + :return: True if the author has been added successfully. False if it was already there. + """ + for author_song in self.authors_songs: + if author_song.author == author and (ignore_type or author_song.author_type == author_type): + return False + new_author_song = AuthorSong() + new_author_song.author = author + new_author_song.author_type = author_type + self.authors_songs.append(new_author_song) + return True + + def remove_author(self, author, author_type=None, ignore_type=False): + """ + Remove an existing author from the song + + :return: True if the author has been removed successfully. False if it could not be found. + """ + for author_song in self.authors_songs: + if author_song.author == author and (ignore_type or author_song.author_type == author_type): + self.authors_songs.remove(author_song) + return True + return False + class Topic(BaseModel): """ @@ -283,9 +310,10 @@ def init_schema(url): mapper(Book, song_books_table) mapper(MediaFile, media_files_table) mapper(Song, songs_table, properties={ - # Use the authors_songs relation when you need access to the 'author_type' attribute. + # Use the authors_songs relation when you need access to the 'author_type' attribute + # or when creating new relations 'authors_songs': relation(AuthorSong, cascade="all, delete-orphan"), - 'authors': relation(Author, secondary=authors_songs_table), + 'authors': relation(Author, secondary=authors_songs_table, viewonly=True), 'book': relation(Book, backref='songs'), 'media_files': relation(MediaFile, backref='songs', order_by=media_files_table.c.weight), 'topics': relation(Topic, backref='songs', secondary=songs_topics_table) diff --git a/openlp/plugins/songs/lib/foilpresenterimport.py b/openlp/plugins/songs/lib/foilpresenterimport.py index 6f8bd6978..2b31718c2 100644 --- a/openlp/plugins/songs/lib/foilpresenterimport.py +++ b/openlp/plugins/songs/lib/foilpresenterimport.py @@ -343,7 +343,7 @@ class FoilPresenter(object): author = Author.populate(display_name=display_name, last_name=display_name.split(' ')[-1], first_name=' '.join(display_name.split(' ')[:-1])) self.manager.save_object(author) - song.authors.append(author) + song.add_author(author) def _process_cclinumber(self, foilpresenterfolie, song): """ diff --git a/openlp/plugins/songs/lib/olpimport.py b/openlp/plugins/songs/lib/olpimport.py index 335ba606a..d38c8c9d8 100644 --- a/openlp/plugins/songs/lib/olpimport.py +++ b/openlp/plugins/songs/lib/olpimport.py @@ -187,7 +187,7 @@ class OpenLPSongImport(SongImport): first_name=author.first_name, last_name=author.last_name, display_name=author.display_name) - new_song.authors.append(existing_author) + new_song.authors.add_author(existing_author) if song.book: existing_song_book = self.manager.get_object_filtered(Book, Book.name == song.book.name) if existing_song_book is None: diff --git a/openlp/plugins/songs/lib/songimport.py b/openlp/plugins/songs/lib/songimport.py index a5fbb99e0..c4fda6120 100644 --- a/openlp/plugins/songs/lib/songimport.py +++ b/openlp/plugins/songs/lib/songimport.py @@ -325,7 +325,7 @@ class SongImport(QtCore.QObject): author = Author.populate(display_name=author_text, last_name=author_text.split(' ')[-1], first_name=' '.join(author_text.split(' ')[:-1])) - song.authors.append(author) + song.authors.add_author(author) if self.song_book_name: song_book = self.manager.get_object_filtered(Book, Book.name == self.song_book_name) if song_book is None: diff --git a/openlp/plugins/songs/lib/songselect.py b/openlp/plugins/songs/lib/songselect.py index 232cdb9cf..b75caa654 100644 --- a/openlp/plugins/songs/lib/songselect.py +++ b/openlp/plugins/songs/lib/songselect.py @@ -203,6 +203,6 @@ class SongSelectImport(object): author = Author.populate(first_name=author_name.rsplit(' ', 1)[0], last_name=author_name.rsplit(' ', 1)[1], display_name=author_name) - db_song.authors.append(author) + db_song.authors.add_author(author) self.db_manager.save_object(db_song) return db_song From aaacbeac6934cf1ff40d93f79d562ac8a86fe656 Mon Sep 17 00:00:00 2001 From: Samuel Mehrbrodt Date: Wed, 7 May 2014 12:21:27 +0200 Subject: [PATCH 21/42] Fixes --- openlp/plugins/songs/lib/olpimport.py | 2 +- openlp/plugins/songs/lib/songimport.py | 2 +- openlp/plugins/songs/lib/songselect.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/openlp/plugins/songs/lib/olpimport.py b/openlp/plugins/songs/lib/olpimport.py index d38c8c9d8..f4b066ef0 100644 --- a/openlp/plugins/songs/lib/olpimport.py +++ b/openlp/plugins/songs/lib/olpimport.py @@ -187,7 +187,7 @@ class OpenLPSongImport(SongImport): first_name=author.first_name, last_name=author.last_name, display_name=author.display_name) - new_song.authors.add_author(existing_author) + new_song.add_author(existing_author) if song.book: existing_song_book = self.manager.get_object_filtered(Book, Book.name == song.book.name) if existing_song_book is None: diff --git a/openlp/plugins/songs/lib/songimport.py b/openlp/plugins/songs/lib/songimport.py index c4fda6120..754288546 100644 --- a/openlp/plugins/songs/lib/songimport.py +++ b/openlp/plugins/songs/lib/songimport.py @@ -325,7 +325,7 @@ class SongImport(QtCore.QObject): author = Author.populate(display_name=author_text, last_name=author_text.split(' ')[-1], first_name=' '.join(author_text.split(' ')[:-1])) - song.authors.add_author(author) + song.add_author(author) if self.song_book_name: song_book = self.manager.get_object_filtered(Book, Book.name == self.song_book_name) if song_book is None: diff --git a/openlp/plugins/songs/lib/songselect.py b/openlp/plugins/songs/lib/songselect.py index b75caa654..195f542aa 100644 --- a/openlp/plugins/songs/lib/songselect.py +++ b/openlp/plugins/songs/lib/songselect.py @@ -203,6 +203,6 @@ class SongSelectImport(object): author = Author.populate(first_name=author_name.rsplit(' ', 1)[0], last_name=author_name.rsplit(' ', 1)[1], display_name=author_name) - db_song.authors.add_author(author) + db_song.add_author(author) self.db_manager.save_object(db_song) return db_song From ee7a8b980418fab3431cb98b34bb7d8cf9002cd6 Mon Sep 17 00:00:00 2001 From: Samuel Mehrbrodt Date: Wed, 7 May 2014 12:25:36 +0200 Subject: [PATCH 22/42] Fixes --- openlp/plugins/songs/lib/songselect.py | 2 +- tests/functional/openlp_plugins/songs/test_songselect.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/openlp/plugins/songs/lib/songselect.py b/openlp/plugins/songs/lib/songselect.py index 195f542aa..6fd084a47 100644 --- a/openlp/plugins/songs/lib/songselect.py +++ b/openlp/plugins/songs/lib/songselect.py @@ -196,7 +196,7 @@ class SongSelectImport(object): db_song.lyrics = song_xml.extract_xml() clean_song(self.db_manager, db_song) self.db_manager.save_object(db_song) - db_song.authors = [] + db_song.authors_songs = [] for author_name in song['authors']: author = self.db_manager.get_object_filtered(Author, Author.display_name == author_name) if not author: diff --git a/tests/functional/openlp_plugins/songs/test_songselect.py b/tests/functional/openlp_plugins/songs/test_songselect.py index 8d1237190..0f9001342 100644 --- a/tests/functional/openlp_plugins/songs/test_songselect.py +++ b/tests/functional/openlp_plugins/songs/test_songselect.py @@ -344,7 +344,7 @@ class TestSongSelect(TestCase): mocked_db_manager.get_object_filtered.assert_called_with(MockedAuthor, False) MockedAuthor.populate.assert_called_with(first_name='Public', last_name='Domain', display_name='Public Domain') - self.assertEqual(1, len(result.authors), 'There should only be one author') + self.assertEqual(1, len(result.authors_songs), 'There should only be one author') def save_song_existing_author_test(self): """ @@ -379,4 +379,4 @@ class TestSongSelect(TestCase): 'The save_object() method should have been called twice') mocked_db_manager.get_object_filtered.assert_called_with(MockedAuthor, False) self.assertEqual(0, MockedAuthor.populate.call_count, 'A new author should not have been instantiated') - self.assertEqual(1, len(result.authors), 'There should only be one author') + self.assertEqual(1, len(result.authors_songs), 'There should only be one author') From a9e620c175ab4b422683e6948f1e63becaed620b Mon Sep 17 00:00:00 2001 From: Samuel Mehrbrodt Date: Wed, 7 May 2014 12:30:55 +0200 Subject: [PATCH 23/42] Remove direct usage of AuthorSong --- openlp/plugins/songs/forms/editsongform.py | 8 +++----- openlp/plugins/songs/lib/xml.py | 7 ++----- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/openlp/plugins/songs/forms/editsongform.py b/openlp/plugins/songs/forms/editsongform.py index 1814655ea..0ea014c73 100644 --- a/openlp/plugins/songs/forms/editsongform.py +++ b/openlp/plugins/songs/forms/editsongform.py @@ -42,7 +42,7 @@ from openlp.core.common import Registry, RegistryProperties, AppLocation, UiStri from openlp.core.lib import FileDialog, PluginStatus, MediaType, create_separated_list from openlp.core.lib.ui import set_case_insensitive_completer, critical_error_message_box, find_and_set_in_combo_box from openlp.plugins.songs.lib import VerseType, clean_song -from openlp.plugins.songs.lib.db import Book, Song, Author, AuthorSong, AuthorType, Topic, MediaFile +from openlp.plugins.songs.lib.db import Book, Song, Author, AuthorType, Topic, MediaFile from openlp.plugins.songs.lib.ui import SongStrings from openlp.plugins.songs.lib.xml import SongXML from openlp.plugins.songs.forms.editsongdialog import Ui_EditSongDialog @@ -916,10 +916,8 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog, RegistryProperties): self.song.authors_songs = [] for row in range(self.authors_list_view.count()): item = self.authors_list_view.item(row) - author_song = AuthorSong() - author_song.author_id = item.data(QtCore.Qt.UserRole)[0] - author_song.author_type = item.data(QtCore.Qt.UserRole)[1] - self.song.authors_songs.append(author_song) + self.song.add_author(self.manager.get_object(Author, item.data(QtCore.Qt.UserRole)[0]), + item.data(QtCore.Qt.UserRole)[1]) self.song.topics = [] for row in range(self.topics_list_view.count()): item = self.topics_list_view.item(row) diff --git a/openlp/plugins/songs/lib/xml.py b/openlp/plugins/songs/lib/xml.py index b856cb53f..f67a35201 100644 --- a/openlp/plugins/songs/lib/xml.py +++ b/openlp/plugins/songs/lib/xml.py @@ -71,7 +71,7 @@ from lxml import etree, objectify from openlp.core.common import translate from openlp.core.lib import FormattingTags from openlp.plugins.songs.lib import VerseType, clean_song -from openlp.plugins.songs.lib.db import Author, AuthorSong, AuthorType, Book, Song, Topic +from openlp.plugins.songs.lib.db import Author, AuthorType, Book, Song, Topic from openlp.core.utils import get_application_version log = logging.getLogger(__name__) @@ -519,10 +519,7 @@ class OpenLyrics(object): author = Author.populate(display_name=display_name, last_name=display_name.split(' ')[-1], first_name=' '.join(display_name.split(' ')[:-1])) - author_song = AuthorSong() - author_song.author = author - author_song.author_type = author_type - song.authors_songs.append(author_song) + song.add_author(author, author_type) def _process_cclinumber(self, properties, song): """ From 3d1cb3f3838330233169894f5f6cc1cef9a0661a Mon Sep 17 00:00:00 2001 From: Samuel Mehrbrodt Date: Wed, 7 May 2014 13:00:34 +0200 Subject: [PATCH 24/42] Add test --- openlp/core/lib/ui.py | 2 +- tests/functional/openlp_core_lib/test_ui.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/openlp/core/lib/ui.py b/openlp/core/lib/ui.py index 965adb053..a1e37abcf 100644 --- a/openlp/core/lib/ui.py +++ b/openlp/core/lib/ui.py @@ -295,7 +295,7 @@ def set_case_insensitive_completer(cache, widget): Sets a case insensitive text completer for a widget. :param cache: The list of items to use as suggestions. - :param widget: A widget to set the completer (QComboBox or QTextEdit instance) + :param widget: A widget to set the completer (QComboBox or QLineEdit instance) """ completer = QtGui.QCompleter(cache) completer.setCaseSensitivity(QtCore.Qt.CaseInsensitive) diff --git a/tests/functional/openlp_core_lib/test_ui.py b/tests/functional/openlp_core_lib/test_ui.py index 025b1a638..d48e5d694 100644 --- a/tests/functional/openlp_core_lib/test_ui.py +++ b/tests/functional/openlp_core_lib/test_ui.py @@ -170,3 +170,19 @@ class TestUi(TestCase): self.assertIsInstance(action.icon(), QtGui.QIcon) self.assertEqual('my tooltip', action.toolTip()) self.assertEqual('my statustip', action.statusTip()) + + def test_set_case_insensitive_completer(self): + """ + Test setting a case insensitive completer on a widget + """ + # GIVEN: A QComboBox and a list of completion items + line_edit = QtGui.QLineEdit() + suggestions = ['one', 'Two', 'THRee', 'FOUR'] + + # WHEN: We call the function + set_case_insensitive_completer(suggestions, line_edit) + + # THEN: The Combobox should have a completer which is case insensitive + completer = line_edit.completer() + self.assertIsInstance(completer, QtGui.QCompleter) + self.assertEqual(completer.caseSensitivity(), QtCore.Qt.CaseInsensitive) From 6440ac008f94dc3385f42a6ed9dcd0ef5a085440 Mon Sep 17 00:00:00 2001 From: Samuel Mehrbrodt Date: Wed, 7 May 2014 15:59:31 +0200 Subject: [PATCH 25/42] Remove unused code --- openlp/plugins/songs/lib/db.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/openlp/plugins/songs/lib/db.py b/openlp/plugins/songs/lib/db.py index e77d98bda..93c27d32e 100644 --- a/openlp/plugins/songs/lib/db.py +++ b/openlp/plugins/songs/lib/db.py @@ -114,32 +114,32 @@ class Song(BaseModel): """ self.sort_key = get_natural_key(self.title) - def add_author(self, author, author_type=None, ignore_type=False): + def add_author(self, author, author_type=None): """ Add an author to the song if it not yet exists - :return: True if the author has been added successfully. False if it was already there. + :param author: Author object + :param author_type: AuthorType constant or None """ for author_song in self.authors_songs: - if author_song.author == author and (ignore_type or author_song.author_type == author_type): - return False + if author_song.author == author and author_song.author_type == author_type: + return new_author_song = AuthorSong() new_author_song.author = author new_author_song.author_type = author_type self.authors_songs.append(new_author_song) - return True - def remove_author(self, author, author_type=None, ignore_type=False): + def remove_author(self, author, author_type=None): """ Remove an existing author from the song - :return: True if the author has been removed successfully. False if it could not be found. + :param author: Author object + :param author_type: AuthorType constant or None """ for author_song in self.authors_songs: - if author_song.author == author and (ignore_type or author_song.author_type == author_type): + if author_song.author == author and author_song.author_type == author_type: self.authors_songs.remove(author_song) - return True - return False + return class Topic(BaseModel): From 55c9e3e19678357a28f6c49b1a04f9205271f137 Mon Sep 17 00:00:00 2001 From: Samuel Mehrbrodt Date: Wed, 7 May 2014 21:17:47 +0200 Subject: [PATCH 26/42] Log warning when CCLI no can't be parsed --- openlp/plugins/songs/lib/songshowplusimport.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/openlp/plugins/songs/lib/songshowplusimport.py b/openlp/plugins/songs/lib/songshowplusimport.py index fe81b61a2..aebded029 100644 --- a/openlp/plugins/songs/lib/songshowplusimport.py +++ b/openlp/plugins/songs/lib/songshowplusimport.py @@ -151,6 +151,8 @@ class SongShowPlusImport(SongImport): match = re.search(r'\d+', self.decode(data)) if match: self.ccli_number = int(match.group()) + else: + log.warn("Can't parse CCLI Number from string: %s" % self.decode(data)) elif block_key == VERSE: self.add_verse(self.decode(data), "%s%s" % (VerseType.tags[VerseType.Verse], verse_no)) elif block_key == CHORUS: From 60fa4c2dcac032db960967c81c3bd32b756c12aa Mon Sep 17 00:00:00 2001 From: Jonathan Springer Date: Wed, 7 May 2014 18:52:06 -0400 Subject: [PATCH 27/42] Make vlcplayer stop call asynchronous to aviod a deadlock with the UI thread --- openlp/core/ui/media/vlcplayer.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/openlp/core/ui/media/vlcplayer.py b/openlp/core/ui/media/vlcplayer.py index c80bb6218..d02526b0e 100644 --- a/openlp/core/ui/media/vlcplayer.py +++ b/openlp/core/ui/media/vlcplayer.py @@ -34,6 +34,7 @@ from distutils.version import LooseVersion import logging import os import sys +import threading from PyQt4 import QtGui @@ -207,7 +208,7 @@ class VlcPlayer(MediaPlayer): start_time = 0 if self.state != MediaState.Paused and controller.media_info.start_time > 0: start_time = controller.media_info.start_time - display.vlc_media_player.play() + threading.Thread(target=display.vlc_media_player.play).start() if not self.media_state_wait(display, vlc.State.Playing): return False self.volume(display, controller.media_info.volume) @@ -233,7 +234,7 @@ class VlcPlayer(MediaPlayer): """ Stop the current item """ - display.vlc_media_player.stop() + threading.Thread(target=display.vlc_media_player.stop).start() self.state = MediaState.Stopped def volume(self, display, vol): From 6de740333b4521d46fc9c518e5260eb1b6424598 Mon Sep 17 00:00:00 2001 From: Jonathan Springer Date: Wed, 7 May 2014 18:54:14 -0400 Subject: [PATCH 28/42] merge trunk From 13b9a7de72b01147199e928a831931668be681eb Mon Sep 17 00:00:00 2001 From: Jonathan Springer Date: Thu, 8 May 2014 10:57:26 -0400 Subject: [PATCH 29/42] Add test for the main window function set_service_modified --- .../openlp_core_ui/test_mainwindow.py | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/tests/functional/openlp_core_ui/test_mainwindow.py b/tests/functional/openlp_core_ui/test_mainwindow.py index 0b17828b9..b348f8f80 100644 --- a/tests/functional/openlp_core_ui/test_mainwindow.py +++ b/tests/functional/openlp_core_ui/test_mainwindow.py @@ -34,6 +34,7 @@ import os from unittest import TestCase from openlp.core.ui.mainwindow import MainWindow +from openlp.core.lib.ui import UiStrings from openlp.core.common.registry import Registry from tests.utils.constants import TEST_RESOURCES_PATH from tests.helpers.testmixin import TestMixin @@ -95,3 +96,41 @@ class TestMainWindow(TestCase, TestMixin): # THEN the file should not be opened assert not mocked_load_path.called, 'load_path should not have been called' + + def main_window_title_test(self): + """ + Test that running a new instance of OpenLP set the window title correctly + """ + # GIVEN a newly opened OpenLP instance + + # WHEN no changes are made to the service + + # THEN the main window's title shoud be the same as the OLPV2x string in the UiStrings class + self.assertEqual(self.main_window.windowTitle(), UiStrings().OLPV2x, + 'The main window\'s title should be the same as the OLPV2x string in UiStrings class') + + def set_service_modifed_test(self): + """ + Test that when setting the service's title the main window's title is set correctly + """ + # GIVEN a newly opened OpenLP instance + + # WHEN set_service_modified is called with with the modified flag set true and a file name + self.main_window.set_service_modified(True, 'test.osz') + + # THEN the main window's title should be set to the + self.assertEqual(self.main_window.windowTitle(), '%s - %s*' % (UiStrings().OLPV2x, 'test.osz'), + 'The main window\'s title should be set to " - test.osz*"') + + def set_service_unmodified_test(self): + """ + Test that when setting the service's title the main window's title is set correctly + """ + # GIVEN a newly opened OpenLP instance + + # WHEN set_service_modified is called with with the modified flag set False and a file name + self.main_window.set_service_modified(False, 'test.osz') + + # THEN the main window's title should be set to the + self.assertEqual(self.main_window.windowTitle(), '%s - %s' % (UiStrings().OLPV2x, 'test.osz'), + 'The main window\'s title should be set to " - test.osz"') From 6eb2d4f49dfba79b1361dc14160c88d9e917cf2a Mon Sep 17 00:00:00 2001 From: Samuel Mehrbrodt Date: Tue, 13 May 2014 11:08:46 +0200 Subject: [PATCH 30/42] Write test for adding and removing authors --- .../openlp_plugins/songs/test_db.py | 121 ++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 tests/functional/openlp_plugins/songs/test_db.py diff --git a/tests/functional/openlp_plugins/songs/test_db.py b/tests/functional/openlp_plugins/songs/test_db.py new file mode 100644 index 000000000..f9afe8cd2 --- /dev/null +++ b/tests/functional/openlp_plugins/songs/test_db.py @@ -0,0 +1,121 @@ +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 + +############################################################################### +# OpenLP - Open Source Lyrics Projection # +# --------------------------------------------------------------------------- # +# Copyright (c) 2008-2014 Raoul Snyman # +# Portions copyright (c) 2008-2014 Tim Bentley, Gerald Britton, Jonathan # +# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, # +# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. # +# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, # +# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, # +# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, # +# Frode Woldsund, Martin Zibricky, Patrick Zimmermann # +# --------------------------------------------------------------------------- # +# 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 # +############################################################################### +""" +This module contains tests for the db submodule of the Songs plugin. +""" +from unittest import TestCase +from tests.functional import patch, MagicMock + +from openlp.plugins.songs.lib.db import Song, Author, AuthorType + + +class TestDB(TestCase): + """ + Test the functions in the :mod:`lib` module. + """ + def setUp(self): + pass + + def test_add_author(self): + """ + Test adding an author to a song + """ + # GIVEN: A song and an author + song = Song() + song.authors_songs = [] + author = Author() + author.first_name = "Max" + author.last_name = "Mustermann" + + # WHEN: We add an author to the song + song.add_author(author) + + # THEN: The author should have been added with author_type=None + self.assertEqual(1, len(song.authors_songs)) + self.assertEqual("Max", song.authors_songs[0].author.first_name) + self.assertEqual("Mustermann", song.authors_songs[0].author.last_name) + self.assertIsNone(song.authors_songs[0].author_type) + + def test_add_author_with_type(self): + """ + Test adding an author with a type specified to a song + """ + # GIVEN: A song and an author + song = Song() + song.authors_songs = [] + author = Author() + author.first_name = "Max" + author.last_name = "Mustermann" + + # WHEN: We add an author to the song + song.add_author(author, AuthorType.Words) + + # THEN: The author should have been added with author_type=None + self.assertEqual(1, len(song.authors_songs)) + self.assertEqual("Max", song.authors_songs[0].author.first_name) + self.assertEqual("Mustermann", song.authors_songs[0].author.last_name) + self.assertEqual(AuthorType.Words ,song.authors_songs[0].author_type) + + def test_remove_author(self): + """ + Test removing an author from a song + """ + # GIVEN: A song with an author + song = Song() + song.authors_songs = [] + author = Author() + author.first_name = "Max" + author.last_name = "Mustermann" + song.add_author(author) + + # WHEN: We remove the author + song.remove_author(author) + + # THEN: It should have been removed + self.assertEqual(0, len(song.authors_songs)) + + def test_remove_author_with_type(self): + """ + Test removing an author with a type specified from a song + """ + # GIVEN: A song with two authors + song = Song() + song.authors_songs = [] + author = Author() + author.first_name = "Max" + author.last_name = "Mustermann" + song.add_author(author) + song.add_author(author, AuthorType.Translation) + + # WHEN: We remove the author with a certain type + song.remove_author(author, AuthorType.Translation) + + # THEN: It should have been removed and the other author should still be there + self.assertEqual(1, len(song.authors_songs)) + self.assertEqual(None ,song.authors_songs[0].author_type) \ No newline at end of file From a1e2e921329986042b0f94d67a354a220acb725e Mon Sep 17 00:00:00 2001 From: Samuel Mehrbrodt Date: Tue, 13 May 2014 11:09:42 +0200 Subject: [PATCH 31/42] PEP8 --- tests/functional/openlp_plugins/songs/test_db.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/tests/functional/openlp_plugins/songs/test_db.py b/tests/functional/openlp_plugins/songs/test_db.py index f9afe8cd2..bb70cb588 100644 --- a/tests/functional/openlp_plugins/songs/test_db.py +++ b/tests/functional/openlp_plugins/songs/test_db.py @@ -80,7 +80,7 @@ class TestDB(TestCase): self.assertEqual(1, len(song.authors_songs)) self.assertEqual("Max", song.authors_songs[0].author.first_name) self.assertEqual("Mustermann", song.authors_songs[0].author.last_name) - self.assertEqual(AuthorType.Words ,song.authors_songs[0].author_type) + self.assertEqual(AuthorType.Words, song.authors_songs[0].author_type) def test_remove_author(self): """ @@ -90,8 +90,6 @@ class TestDB(TestCase): song = Song() song.authors_songs = [] author = Author() - author.first_name = "Max" - author.last_name = "Mustermann" song.add_author(author) # WHEN: We remove the author @@ -108,8 +106,6 @@ class TestDB(TestCase): song = Song() song.authors_songs = [] author = Author() - author.first_name = "Max" - author.last_name = "Mustermann" song.add_author(author) song.add_author(author, AuthorType.Translation) @@ -118,4 +114,4 @@ class TestDB(TestCase): # THEN: It should have been removed and the other author should still be there self.assertEqual(1, len(song.authors_songs)) - self.assertEqual(None ,song.authors_songs[0].author_type) \ No newline at end of file + self.assertEqual(None ,song.authors_songs[0].author_type) From b7b0176dece0d41c923fda32c8f39843335ab8c9 Mon Sep 17 00:00:00 2001 From: Samuel Mehrbrodt Date: Tue, 13 May 2014 11:12:07 +0200 Subject: [PATCH 32/42] Cleanups --- tests/functional/openlp_plugins/songs/test_db.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/tests/functional/openlp_plugins/songs/test_db.py b/tests/functional/openlp_plugins/songs/test_db.py index bb70cb588..3080db77e 100644 --- a/tests/functional/openlp_plugins/songs/test_db.py +++ b/tests/functional/openlp_plugins/songs/test_db.py @@ -30,17 +30,14 @@ This module contains tests for the db submodule of the Songs plugin. """ from unittest import TestCase -from tests.functional import patch, MagicMock from openlp.plugins.songs.lib.db import Song, Author, AuthorType class TestDB(TestCase): """ - Test the functions in the :mod:`lib` module. + Test the functions in the :mod:`db` module. """ - def setUp(self): - pass def test_add_author(self): """ @@ -114,4 +111,4 @@ class TestDB(TestCase): # THEN: It should have been removed and the other author should still be there self.assertEqual(1, len(song.authors_songs)) - self.assertEqual(None ,song.authors_songs[0].author_type) + self.assertEqual(None, song.authors_songs[0].author_type) From 37f04c51996b7e8d58b3bb0f8816581bf33bf5b5 Mon Sep 17 00:00:00 2001 From: Tomas Groth Date: Wed, 14 May 2014 22:53:43 +0200 Subject: [PATCH 33/42] Added simple tests. --- openlp/plugins/bibles/lib/zefania.py | 4 +- .../bibles/test_zefaniaimport.py | 116 ++++++++++++++++++ tests/resources/bibles/zefania-dk1933.xml | 45 +++++++ 3 files changed, 164 insertions(+), 1 deletion(-) create mode 100644 tests/functional/openlp_plugins/bibles/test_zefaniaimport.py create mode 100644 tests/resources/bibles/zefania-dk1933.xml diff --git a/openlp/plugins/bibles/lib/zefania.py b/openlp/plugins/bibles/lib/zefania.py index 16680efa3..c52b58eae 100644 --- a/openlp/plugins/bibles/lib/zefania.py +++ b/openlp/plugins/bibles/lib/zefania.py @@ -70,8 +70,10 @@ class ZefaniaBible(BibleDB): return False zefania_bible_tree = etree.parse(import_file) num_books = int(zefania_bible_tree.xpath("count(//BIBLEBOOK)")) - # Strip tags we don't use + # Strip tags we don't use - keep content etree.strip_tags(zefania_bible_tree, ('STYLE', 'GRAM', 'NOTE', 'SUP', 'XREF')) + # Strip tags we don't use - remove content + etree.strip_elements(zefania_bible_tree, ('PROLOG', 'REMARK', 'CAPTION', 'MEDIA'), with_tail=False) xmlbible = zefania_bible_tree.getroot() for BIBLEBOOK in xmlbible: book_ref_id = self.get_book_ref_id_by_name(str(BIBLEBOOK.get('bname')), num_books) diff --git a/tests/functional/openlp_plugins/bibles/test_zefaniaimport.py b/tests/functional/openlp_plugins/bibles/test_zefaniaimport.py new file mode 100644 index 000000000..64fa3251e --- /dev/null +++ b/tests/functional/openlp_plugins/bibles/test_zefaniaimport.py @@ -0,0 +1,116 @@ +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 + +############################################################################### +# OpenLP - Open Source Lyrics Projection # +# --------------------------------------------------------------------------- # +# Copyright (c) 2008-2014 Raoul Snyman # +# Portions copyright (c) 2008-2014 Tim Bentley, Gerald Britton, Jonathan # +# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, # +# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. # +# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, # +# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, # +# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, # +# Frode Woldsund, Martin Zibricky, Patrick Zimmermann # +# --------------------------------------------------------------------------- # +# 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 # +############################################################################### +""" +This module contains tests for the Zefania Bible importer. +""" + +import os +from unittest import TestCase + +from tests.functional import MagicMock, patch +from openlp.plugins.bibles.lib.zefania import ZefaniaBible +from openlp.plugins.bibles.lib.db import BibleDB + +TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), + '..', '..', '..', 'resources', 'bibles')) +ZEFANIA_TEST_DATA = { + 'zefania-dk1933.xml': { + 'book': 'Genesis', + 'chapter' : 1, + 'verses': [ + (1, 'I Begyndelsen skabte Gud Himmelen og Jorden.\n'), + (2, 'Og Jorden var øde og tom, og der var Mørke over Verdensdybet. ' + 'Men Guds Ånd svævede over Vandene.'), + (3, 'Og Gud sagde: "Der blive Lys!" Og der blev Lys.'), + (4, 'Og Gud så, at Lyset var godt, og Gud satte Skel mellem Lyset og Mørket,'), + (5, 'og Gud kaldte Lyset Dag, og Mørket kaldte han Nat. Og det blev Aften, ' + 'og det blev Morgen, første Dag.'), + (6, 'Derpå sagde Gud: "Der blive en Hvælving midt i Vandene til at skille Vandene ad!"'), + (7, 'Og således skete det: Gud gjorde Hvælvingen og skilte Vandet under Hvælvingen ' + 'fra Vandet over Hvælvingen;'), + (8, 'og Gud kaldte Hvælvingen Himmel. Og det blev Aften, og det blev Morgen, anden Dag.'), + (9, 'Derpå sagde Gud: "Vandet under Himmelen samle sig på eet Sted, så det faste Land kommer til Syne!" ' + 'Og således skete det;'), + (10, 'og Gud kaldte det faste Land Jord, og Stedet, hvor Vandet samlede sig, kaldte han Hav. Og Gud så, ' + 'at det var godt.') + ] + } +} + + +class TestZefaniaImport(TestCase): + """ + Test the functions in the :mod:`zefaniaimport` module. + """ + + def setUp(self): + self.construtor_patcher = patch('openlp.plugins.bibles.lib.zefania.BibleDB') + self.construtor_patcher.start() + + def tearDown(self): + self.construtor_patcher.stop() + + def create_importer_test(self): + """ + Test creating an instance of the Zefania file importer + """ + # GIVEN: A mocked out BibleDB class, and a mocked out "manager" + #with patch('openlp.plugins.bibles.lib.zefania.BibleDB'): + if True: + mocked_manager = MagicMock() + + # WHEN: An importer object is created + importer = ZefaniaBible(mocked_manager, filename='') + + # THEN: The importer should be an instance of SongImport + self.assertIsInstance(importer, BibleDB) + + def file_import_test(self): + """ + Test the actual import of real song files + """ + # GIVEN: Test files with a mocked out "manager" and a mocked out "import_wizard" + #with patch('openlp.plugins.bibles.lib.zefania.BibleDB'): + if True: + for bible_file in ZEFANIA_TEST_DATA: + mocked_manager = MagicMock() + mocked_import_wizard = MagicMock() + importer = ZefaniaBible(mocked_manager, filename='') + importer.import_wizard = mocked_import_wizard + importer.get_book_ref_id_by_name = MagicMock() + importer.get_book_ref_id_by_name.return_value = { 'id': 1, 'testament_id': 1, 'name': 'Genesis', + 'abbreviation': 'Gen', 'chapters': 1 } + importer.create_verse = MagicMock() + + # WHEN: Importing each file + importer.filename = os.path.join(TEST_PATH, bible_file) + importer.do_import() + + # THEN: The create_verse() method should have been called + self.assertTrue(importer.create_verse.called) diff --git a/tests/resources/bibles/zefania-dk1933.xml b/tests/resources/bibles/zefania-dk1933.xml new file mode 100644 index 000000000..f538edb99 --- /dev/null +++ b/tests/resources/bibles/zefania-dk1933.xml @@ -0,0 +1,45 @@ + + + + + + + + Danish Version + + + The Holy Bible + The electronic edition of this Bible comes from the Danish 1933 edition. The Old Testament is an update from the 1931 edition, and the New Testament is an update from the 1907 edition. + Free Bible Software Group + + The Unbound Bible + Biola University: Administrative Computing + 13800 Biola Ave. + La Mirada, CA 90639 + United States of America + 562-903-4722 + + 2009-01-20 + Zefania XML Bible Markup Language + DAN + ftp://unboundftp.biola.edu/pub/danish1933_utf8.zip + DAN + provide the bible to the world + + + + + + I skabte Gud Himmelen og Jorden. + Og Jorden var øde og tom, og der var Mørke over Verdensdybet. Men Guds Ånd svævede over Vandene. + Og Gud sagde: "Der blive Lys!" Og der blev Lys. + Og Gud så, at Lyset var godt, og Gud satte Skel mellem Lyset og Mørket, + og Gud kaldte Lyset Dag, og Mørket kaldte han Nat. Og det blev Aften, og det blev Morgen, første Dag. + Derpå sagde Gud: "Der blive en Hvælving midt i Vandene til at skille Vandene ad!" + Og således skete det: Gud gjorde Hvælvingen og skilte Vandet under Hvælvingen fra Vandet over Hvælvingen; + og Gud kaldte Hvælvingen Himmel. Og det blev Aften, og det blev Morgen, anden Dag. + Derpå sagde Gud: "Vandet under Himmelen samle sig på eet Sted, så det faste Land kommer til Syne!" Og således skete det; + og Gud kaldte det faste Land Jord, og Stedet, hvor Vandet samlede sig, kaldte han Hav. Og Gud så, at det var godt. + + + \ No newline at end of file From de8074b00a9e64244ee0ad082d4df899fe8a5384 Mon Sep 17 00:00:00 2001 From: Samuel Mehrbrodt Date: Mon, 19 May 2014 21:19:05 +0200 Subject: [PATCH 34/42] Improve single click behavior (remove flickering) --- openlp/core/lib/mediamanageritem.py | 5 +++-- openlp/core/ui/listpreviewwidget.py | 1 - 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/openlp/core/lib/mediamanageritem.py b/openlp/core/lib/mediamanageritem.py index 4d7676ad6..5893e8c38 100644 --- a/openlp/core/lib/mediamanageritem.py +++ b/openlp/core/lib/mediamanageritem.py @@ -495,8 +495,8 @@ s if service_item: service_item.from_plugin = True self.preview_controller.add_service_item(service_item) - if keep_focus: - self.list_view.setFocus() + if not keep_focus: + self.preview_controller.preview_widget.setFocus() def on_live_click(self): """ @@ -535,6 +535,7 @@ s if remote: service_item.will_auto_start = True self.live_controller.add_service_item(service_item) + self.live_controller.preview_widget.setFocus() def create_item_from_id(self, item_id): """ diff --git a/openlp/core/ui/listpreviewwidget.py b/openlp/core/ui/listpreviewwidget.py index 7dbcfc2bd..831eb182b 100644 --- a/openlp/core/ui/listpreviewwidget.py +++ b/openlp/core/ui/listpreviewwidget.py @@ -136,7 +136,6 @@ class ListPreviewWidget(QtGui.QTableWidget, RegistryProperties): if self.service_item.is_text(): self.resizeRowsToContents() self.setColumnWidth(0, self.viewport().width()) - self.setFocus() self.change_slide(slide_number) def change_slide(self, slide): From 58179f8d832ec661fbf55243db4db78654715220 Mon Sep 17 00:00:00 2001 From: Tomas Groth Date: Tue, 20 May 2014 20:41:07 +0200 Subject: [PATCH 35/42] Tests --- openlp/plugins/bibles/lib/zefania.py | 1 + .../bibles/test_zefaniaimport.py | 27 ++++++++++++++----- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/openlp/plugins/bibles/lib/zefania.py b/openlp/plugins/bibles/lib/zefania.py index c52b58eae..4e8373a93 100644 --- a/openlp/plugins/bibles/lib/zefania.py +++ b/openlp/plugins/bibles/lib/zefania.py @@ -97,6 +97,7 @@ class ZefaniaBible(BibleDB): self.session.commit() self.application.process_events() except Exception as e: + print(str(e)) critical_error_message_box( message=translate('BiblesPlugin.ZefaniaImport', 'Incorrect Bible file type supplied. Zefania Bibles may be ' diff --git a/tests/functional/openlp_plugins/bibles/test_zefaniaimport.py b/tests/functional/openlp_plugins/bibles/test_zefaniaimport.py index 64fa3251e..942834d7a 100644 --- a/tests/functional/openlp_plugins/bibles/test_zefaniaimport.py +++ b/tests/functional/openlp_plugins/bibles/test_zefaniaimport.py @@ -70,11 +70,20 @@ class TestZefaniaImport(TestCase): """ def setUp(self): - self.construtor_patcher = patch('openlp.plugins.bibles.lib.zefania.BibleDB') + self.construtor_patcher = patch('openlp.plugins.bibles.lib.db.Registry') self.construtor_patcher.start() + self.get_lang_patcher = patch('openlp.plugins.bibles.lib.db.Manager') + self.get_lang_patcher.start() + self.brdb = patch('openlp.plugins.bibles.lib.zefania.BiblesResourcesDB') + self.brdb.start() + self.qt_core = patch('openlp.plugins.bibles.lib.db.QtCore') + self.qt_core.start() def tearDown(self): self.construtor_patcher.stop() + self.get_lang_patcher.stop() + self.brdb.stop() + self.qt_core.stop() def create_importer_test(self): """ @@ -86,7 +95,7 @@ class TestZefaniaImport(TestCase): mocked_manager = MagicMock() # WHEN: An importer object is created - importer = ZefaniaBible(mocked_manager, filename='') + importer = ZefaniaBible(mocked_manager, path='.', name='.', filename='') # THEN: The importer should be an instance of SongImport self.assertIsInstance(importer, BibleDB) @@ -96,21 +105,27 @@ class TestZefaniaImport(TestCase): Test the actual import of real song files """ # GIVEN: Test files with a mocked out "manager" and a mocked out "import_wizard" - #with patch('openlp.plugins.bibles.lib.zefania.BibleDB'): + #with patch('openlp.plugins.bibles.lib.zefania.BiblesResourcesDB') as brdb: if True: for bible_file in ZEFANIA_TEST_DATA: mocked_manager = MagicMock() mocked_import_wizard = MagicMock() - importer = ZefaniaBible(mocked_manager, filename='') - importer.import_wizard = mocked_import_wizard + importer = ZefaniaBible(mocked_manager, path='.', name='.', filename='') + importer.wizard = mocked_import_wizard + #importer.wizard.increment_progress_bar = MagicMock() importer.get_book_ref_id_by_name = MagicMock() importer.get_book_ref_id_by_name.return_value = { 'id': 1, 'testament_id': 1, 'name': 'Genesis', 'abbreviation': 'Gen', 'chapters': 1 } importer.create_verse = MagicMock() + importer.create_book = MagicMock() + importer.session = MagicMock() + importer.get_language = MagicMock() + importer.get_language.return_value = 'Danish' + importer.application.process_events = MagicMock() # WHEN: Importing each file importer.filename = os.path.join(TEST_PATH, bible_file) - importer.do_import() + importer.do_import('Dansk Version') # THEN: The create_verse() method should have been called self.assertTrue(importer.create_verse.called) From 4039cf1103230fec05d8035153f6f2fbbccefb32 Mon Sep 17 00:00:00 2001 From: Tomas Groth Date: Tue, 20 May 2014 23:54:18 +0200 Subject: [PATCH 36/42] More tests --- .../bibles/test_zefaniaimport.py | 64 ++++++++----------- 1 file changed, 27 insertions(+), 37 deletions(-) diff --git a/tests/functional/openlp_plugins/bibles/test_zefaniaimport.py b/tests/functional/openlp_plugins/bibles/test_zefaniaimport.py index 942834d7a..63e6ae40d 100644 --- a/tests/functional/openlp_plugins/bibles/test_zefaniaimport.py +++ b/tests/functional/openlp_plugins/bibles/test_zefaniaimport.py @@ -44,20 +44,20 @@ ZEFANIA_TEST_DATA = { 'book': 'Genesis', 'chapter' : 1, 'verses': [ - (1, 'I Begyndelsen skabte Gud Himmelen og Jorden.\n'), - (2, 'Og Jorden var øde og tom, og der var Mørke over Verdensdybet. ' + ('1', 'I Begyndelsen skabte Gud Himmelen og Jorden.'), + ('2', 'Og Jorden var øde og tom, og der var Mørke over Verdensdybet. ' 'Men Guds Ånd svævede over Vandene.'), - (3, 'Og Gud sagde: "Der blive Lys!" Og der blev Lys.'), - (4, 'Og Gud så, at Lyset var godt, og Gud satte Skel mellem Lyset og Mørket,'), - (5, 'og Gud kaldte Lyset Dag, og Mørket kaldte han Nat. Og det blev Aften, ' + ('3', 'Og Gud sagde: "Der blive Lys!" Og der blev Lys.'), + ('4', 'Og Gud så, at Lyset var godt, og Gud satte Skel mellem Lyset og Mørket,'), + ('5', 'og Gud kaldte Lyset Dag, og Mørket kaldte han Nat. Og det blev Aften, ' 'og det blev Morgen, første Dag.'), - (6, 'Derpå sagde Gud: "Der blive en Hvælving midt i Vandene til at skille Vandene ad!"'), - (7, 'Og således skete det: Gud gjorde Hvælvingen og skilte Vandet under Hvælvingen ' + ('6', 'Derpå sagde Gud: "Der blive en Hvælving midt i Vandene til at skille Vandene ad!"'), + ('7', 'Og således skete det: Gud gjorde Hvælvingen og skilte Vandet under Hvælvingen ' 'fra Vandet over Hvælvingen;'), - (8, 'og Gud kaldte Hvælvingen Himmel. Og det blev Aften, og det blev Morgen, anden Dag.'), - (9, 'Derpå sagde Gud: "Vandet under Himmelen samle sig på eet Sted, så det faste Land kommer til Syne!" ' + ('8', 'og Gud kaldte Hvælvingen Himmel. Og det blev Aften, og det blev Morgen, anden Dag.'), + ('9', 'Derpå sagde Gud: "Vandet under Himmelen samle sig på eet Sted, så det faste Land kommer til Syne!" ' 'Og således skete det;'), - (10, 'og Gud kaldte det faste Land Jord, og Stedet, hvor Vandet samlede sig, kaldte han Hav. Og Gud så, ' + ('10', 'og Gud kaldte det faste Land Jord, og Stedet, hvor Vandet samlede sig, kaldte han Hav. Og Gud så, ' 'at det var godt.') ] } @@ -70,62 +70,52 @@ class TestZefaniaImport(TestCase): """ def setUp(self): - self.construtor_patcher = patch('openlp.plugins.bibles.lib.db.Registry') - self.construtor_patcher.start() - self.get_lang_patcher = patch('openlp.plugins.bibles.lib.db.Manager') - self.get_lang_patcher.start() - self.brdb = patch('openlp.plugins.bibles.lib.zefania.BiblesResourcesDB') - self.brdb.start() - self.qt_core = patch('openlp.plugins.bibles.lib.db.QtCore') - self.qt_core.start() + self.registry_patcher = patch('openlp.plugins.bibles.lib.db.Registry') + self.registry_patcher.start() + self.manager_patcher = patch('openlp.plugins.bibles.lib.db.Manager') + self.manager_patcher.start() def tearDown(self): - self.construtor_patcher.stop() - self.get_lang_patcher.stop() - self.brdb.stop() - self.qt_core.stop() + self.registry_patcher.stop() + self.manager_patcher.stop() def create_importer_test(self): """ Test creating an instance of the Zefania file importer """ # GIVEN: A mocked out BibleDB class, and a mocked out "manager" - #with patch('openlp.plugins.bibles.lib.zefania.BibleDB'): - if True: - mocked_manager = MagicMock() + mocked_manager = MagicMock() - # WHEN: An importer object is created - importer = ZefaniaBible(mocked_manager, path='.', name='.', filename='') + # WHEN: An importer object is created + importer = ZefaniaBible(mocked_manager, path='.', name='.', filename='') - # THEN: The importer should be an instance of SongImport - self.assertIsInstance(importer, BibleDB) + # THEN: The importer should be an instance of SongImport + self.assertIsInstance(importer, BibleDB) def file_import_test(self): """ Test the actual import of real song files """ # GIVEN: Test files with a mocked out "manager" and a mocked out "import_wizard" - #with patch('openlp.plugins.bibles.lib.zefania.BiblesResourcesDB') as brdb: - if True: + with patch('openlp.plugins.bibles.lib.zefania.ZefaniaBible.application') as brdb: for bible_file in ZEFANIA_TEST_DATA: mocked_manager = MagicMock() mocked_import_wizard = MagicMock() importer = ZefaniaBible(mocked_manager, path='.', name='.', filename='') importer.wizard = mocked_import_wizard - #importer.wizard.increment_progress_bar = MagicMock() importer.get_book_ref_id_by_name = MagicMock() - importer.get_book_ref_id_by_name.return_value = { 'id': 1, 'testament_id': 1, 'name': 'Genesis', - 'abbreviation': 'Gen', 'chapters': 1 } importer.create_verse = MagicMock() importer.create_book = MagicMock() importer.session = MagicMock() importer.get_language = MagicMock() importer.get_language.return_value = 'Danish' - importer.application.process_events = MagicMock() - # WHEN: Importing each file + # WHEN: Importing bible file importer.filename = os.path.join(TEST_PATH, bible_file) importer.do_import('Dansk Version') - # THEN: The create_verse() method should have been called + # THEN: The create_verse() method should have been called with each verse in the file. self.assertTrue(importer.create_verse.called) + for verse_tag, verse_text in ZEFANIA_TEST_DATA['zefania-dk1933.xml']['verses']: + importer.create_verse.assert_any_call(importer.create_book().id, '1', verse_tag, verse_text) + From c0b167ca781cd2a024ff3953573c5acc26ed7580 Mon Sep 17 00:00:00 2001 From: Tomas Groth Date: Wed, 21 May 2014 11:30:36 +0200 Subject: [PATCH 37/42] Added tests for import of OpenSong bible format --- .../bibles/test_opensongimport.py | 140 ++++++++++++++++++ .../bibles/test_zefaniaimport.py | 16 +- tests/resources/bibles/opensong-dk1933.xml | 46 ++++++ 3 files changed, 194 insertions(+), 8 deletions(-) create mode 100644 tests/functional/openlp_plugins/bibles/test_opensongimport.py create mode 100644 tests/resources/bibles/opensong-dk1933.xml diff --git a/tests/functional/openlp_plugins/bibles/test_opensongimport.py b/tests/functional/openlp_plugins/bibles/test_opensongimport.py new file mode 100644 index 000000000..542cf289d --- /dev/null +++ b/tests/functional/openlp_plugins/bibles/test_opensongimport.py @@ -0,0 +1,140 @@ +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 + +############################################################################### +# OpenLP - Open Source Lyrics Projection # +# --------------------------------------------------------------------------- # +# Copyright (c) 2008-2014 Raoul Snyman # +# Portions copyright (c) 2008-2014 Tim Bentley, Gerald Britton, Jonathan # +# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, # +# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. # +# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, # +# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, # +# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, # +# Frode Woldsund, Martin Zibricky, Patrick Zimmermann # +# --------------------------------------------------------------------------- # +# 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 # +############################################################################### +""" +This module contains tests for the OpenSong Bible importer. +""" + +import os +from unittest import TestCase + +from tests.functional import MagicMock, patch +from openlp.plugins.bibles.lib.opensong import OpenSongBible +from openlp.plugins.bibles.lib.db import BibleDB + +TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), + '..', '..', '..', 'resources', 'bibles')) +OPENSONG_TEST_DATA = { + 'opensong-dk1933.xml': { + 'book': 'Genesis', + 'chapter': 1, + 'verses': [ + (1, 'I Begyndelsen skabte Gud Himmelen og Jorden.'), + (2, 'Og Jorden var øde og tom, og der var Mørke over Verdensdybet. ' + 'Men Guds Ånd svævede over Vandene.'), + (3, 'Og Gud sagde: "Der blive Lys!" Og der blev Lys.'), + (4, 'Og Gud så, at Lyset var godt, og Gud satte Skel mellem Lyset og Mørket,'), + (5, 'og Gud kaldte Lyset Dag, og Mørket kaldte han Nat. Og det blev Aften, ' + 'og det blev Morgen, første Dag.'), + (6, 'Derpå sagde Gud: "Der blive en Hvælving midt i Vandene til at skille Vandene ad!"'), + (7, 'Og således skete det: Gud gjorde Hvælvingen og skilte Vandet under Hvælvingen ' + 'fra Vandet over Hvælvingen;'), + (8, 'og Gud kaldte Hvælvingen Himmel. Og det blev Aften, og det blev Morgen, anden Dag.'), + (9, 'Derpå sagde Gud: "Vandet under Himmelen samle sig på eet Sted, så det faste Land kommer til Syne!" ' + 'Og således skete det;'), + (10, 'og Gud kaldte det faste Land Jord, og Stedet, hvor Vandet samlede sig, kaldte han Hav. Og Gud så, ' + 'at det var godt.') + ] + } +} + + +class TestOpenSongImport(TestCase): + """ + Test the functions in the :mod:`opensongimport` module. + """ + + def setUp(self): + self.registry_patcher = patch('openlp.plugins.bibles.lib.db.Registry') + self.registry_patcher.start() + self.manager_patcher = patch('openlp.plugins.bibles.lib.db.Manager') + self.manager_patcher.start() + + def tearDown(self): + self.registry_patcher.stop() + self.manager_patcher.stop() + + def create_importer_test(self): + """ + Test creating an instance of the OpenSong file importer + """ + # GIVEN: A mocked out "manager" + mocked_manager = MagicMock() + + # WHEN: An importer object is created + importer = OpenSongBible(mocked_manager, path='.', name='.', filename='') + + # THEN: The importer should be an instance of BibleDB + self.assertIsInstance(importer, BibleDB) + + def file_import_test(self): + """ + Test the actual import of real song files + """ + # GIVEN: Test files with a mocked out "manager", "import_wizard", and mocked functions + # get_book_ref_id_by_name, create_verse, create_book, session and get_language. + with patch('openlp.plugins.bibles.lib.opensong.OpenSongBible.application'): + for bible_file in OPENSONG_TEST_DATA: + mocked_manager = MagicMock() + mocked_import_wizard = MagicMock() + importer = OpenSongBible(mocked_manager, path='.', name='.', filename='') + importer.wizard = mocked_import_wizard + importer.get_book_ref_id_by_name = MagicMock() + importer.create_verse = MagicMock() + importer.create_book = MagicMock() + importer.session = MagicMock() + importer.get_language = MagicMock() + importer.get_language.return_value = 'Danish' + + # WHEN: Importing bible file + importer.filename = os.path.join(TEST_PATH, bible_file) + importer.do_import() + + # THEN: The create_verse() method should have been called with each verse in the file. + self.assertTrue(importer.create_verse.called) + for verse_tag, verse_text in OPENSONG_TEST_DATA[bible_file]['verses']: + importer.create_verse.assert_any_call(importer.create_book().id, 1, verse_tag, verse_text) + + def zefania_import_error_test(self): + """ + Test that we give an error message if trying to import a zefania bible + """ + # GIVEN: A mocked out "manager" and mocked out critical_error_message_box and an import + with patch('openlp.plugins.bibles.lib.opensong.critical_error_message_box') as \ + mocked_critical_error_message_box: + mocked_manager = MagicMock() + importer = OpenSongBible(mocked_manager, path='.', name='.', filename='') + + # WHEN: An trying to import a zefania bible + importer.filename = os.path.join(TEST_PATH, 'zefania-dk1933.xml') + importer.do_import() + + # THEN: The importer should have "shown" an error message + mocked_critical_error_message_box.assert_called_with(message='Incorrect Bible file type supplied. ' + 'This looks like a Zefania XML bible, ' + 'please use the Zefania import option.') diff --git a/tests/functional/openlp_plugins/bibles/test_zefaniaimport.py b/tests/functional/openlp_plugins/bibles/test_zefaniaimport.py index 63e6ae40d..50307b401 100644 --- a/tests/functional/openlp_plugins/bibles/test_zefaniaimport.py +++ b/tests/functional/openlp_plugins/bibles/test_zefaniaimport.py @@ -42,7 +42,7 @@ TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), ZEFANIA_TEST_DATA = { 'zefania-dk1933.xml': { 'book': 'Genesis', - 'chapter' : 1, + 'chapter': 1, 'verses': [ ('1', 'I Begyndelsen skabte Gud Himmelen og Jorden.'), ('2', 'Og Jorden var øde og tom, og der var Mørke over Verdensdybet. ' @@ -83,21 +83,22 @@ class TestZefaniaImport(TestCase): """ Test creating an instance of the Zefania file importer """ - # GIVEN: A mocked out BibleDB class, and a mocked out "manager" + # GIVEN: A mocked out "manager" mocked_manager = MagicMock() # WHEN: An importer object is created importer = ZefaniaBible(mocked_manager, path='.', name='.', filename='') - # THEN: The importer should be an instance of SongImport + # THEN: The importer should be an instance of BibleDB self.assertIsInstance(importer, BibleDB) def file_import_test(self): """ Test the actual import of real song files """ - # GIVEN: Test files with a mocked out "manager" and a mocked out "import_wizard" - with patch('openlp.plugins.bibles.lib.zefania.ZefaniaBible.application') as brdb: + # GIVEN: Test files with a mocked out "manager", "import_wizard", and mocked functions + # get_book_ref_id_by_name, create_verse, create_book, session and get_language. + with patch('openlp.plugins.bibles.lib.zefania.ZefaniaBible.application'): for bible_file in ZEFANIA_TEST_DATA: mocked_manager = MagicMock() mocked_import_wizard = MagicMock() @@ -112,10 +113,9 @@ class TestZefaniaImport(TestCase): # WHEN: Importing bible file importer.filename = os.path.join(TEST_PATH, bible_file) - importer.do_import('Dansk Version') + importer.do_import() # THEN: The create_verse() method should have been called with each verse in the file. self.assertTrue(importer.create_verse.called) - for verse_tag, verse_text in ZEFANIA_TEST_DATA['zefania-dk1933.xml']['verses']: + for verse_tag, verse_text in ZEFANIA_TEST_DATA[bible_file]['verses']: importer.create_verse.assert_any_call(importer.create_book().id, '1', verse_tag, verse_text) - diff --git a/tests/resources/bibles/opensong-dk1933.xml b/tests/resources/bibles/opensong-dk1933.xml new file mode 100644 index 000000000..1aa1140f7 --- /dev/null +++ b/tests/resources/bibles/opensong-dk1933.xml @@ -0,0 +1,46 @@ + + + + + + + + + Danish Version + + + The Holy Bible + The electronic edition of this Bible comes from the Danish 1933 edition. The Old Testament is an update from the 1931 edition, and the New Testament is an update from the 1907 edition. + Free Bible Software Group + + The Unbound Bible + Biola University: Administrative Computing + 13800 Biola Ave. + La Mirada, CA 90639 + United States of America + 562-903-4722 + + 2009-01-20 + Zefania XML Bible Markup Language + DAN + ftp://unboundftp.biola.edu/pub/danish1933_utf8.zip + DAN + provide the bible to the world + + + + + + I Begyndelsen skabte Gud Himmelen og Jorden. + Og Jorden var øde og tom, og der var Mørke over Verdensdybet. Men Guds Ånd svævede over Vandene. + Og Gud sagde: "Der blive Lys!" Og der blev Lys. + Og Gud så, at Lyset var godt, og Gud satte Skel mellem Lyset og Mørket, + og Gud kaldte Lyset Dag, og Mørket kaldte han Nat. Og det blev Aften, og det blev Morgen, første Dag. + Derpå sagde Gud: "Der blive en Hvælving midt i Vandene til at skille Vandene ad!" + Og således skete det: Gud gjorde Hvælvingen og skilte Vandet under Hvælvingen fra Vandet over Hvælvingen; + og Gud kaldte Hvælvingen Himmel. Og det blev Aften, og det blev Morgen, anden Dag. + Derpå sagde Gud: "Vandet under Himmelen samle sig på eet Sted, så det faste Land kommer til Syne!" Og således skete det; + og Gud kaldte det faste Land Jord, og Stedet, hvor Vandet samlede sig, kaldte han Hav. Og Gud så, at det var godt. + + + From b352c05ff065aa3844fb7207d67d7c20e7e07e60 Mon Sep 17 00:00:00 2001 From: Tomas Groth Date: Wed, 21 May 2014 11:33:23 +0200 Subject: [PATCH 38/42] Fix spelling in a comment --- openlp/plugins/songs/lib/ewimport.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openlp/plugins/songs/lib/ewimport.py b/openlp/plugins/songs/lib/ewimport.py index b08193672..42f375e4b 100644 --- a/openlp/plugins/songs/lib/ewimport.py +++ b/openlp/plugins/songs/lib/ewimport.py @@ -344,7 +344,7 @@ class EasyWorshipSongImport(SongImport): try: decoded_words = words.decode() except UnicodeDecodeError: - # The unicode chars in the rtf was not escaped in the expected manor + # The unicode chars in the rtf was not escaped in the expected manner self.entry_error_log = translate('SongsPlugin.EasyWorshipSongImport', 'Unexpected data formatting.') return From d1814f05dea6eb728570514ef444102ac2dc843b Mon Sep 17 00:00:00 2001 From: Samuel Mehrbrodt Date: Wed, 21 May 2014 17:17:08 +0200 Subject: [PATCH 39/42] Add test --- tests/functional/openlp_core_lib/test_ui.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/functional/openlp_core_lib/test_ui.py b/tests/functional/openlp_core_lib/test_ui.py index f1b8ee17a..b017a60f0 100644 --- a/tests/functional/openlp_core_lib/test_ui.py +++ b/tests/functional/openlp_core_lib/test_ui.py @@ -197,3 +197,20 @@ class TestUi(TestCase): # THEN: The index should have changed self.assertEqual(2, combo.currentIndex()) + + def test_set_case_insensitive_completer(self): + """ + Test setting a case insensitive completer on a widget + """ + # GIVEN: A QComboBox and a list of completion items + line_edit = QtGui.QLineEdit() + suggestions = ['one', 'Two', 'THRee', 'FOUR'] + + # WHEN: We call the function + set_case_insensitive_completer(suggestions, line_edit) + + # THEN: The Combobox should have a completer which is case insensitive + completer = line_edit.completer() + self.assertIsInstance(completer, QtGui.QCompleter) + self.assertEqual(completer.caseSensitivity(), QtCore.Qt.CaseInsensitive) + From 2462fcf06e99efc9d9220a74e487e2891aba13d9 Mon Sep 17 00:00:00 2001 From: Samuel Mehrbrodt Date: Wed, 21 May 2014 17:18:04 +0200 Subject: [PATCH 40/42] Remove test --- tests/functional/openlp_core_lib/test_ui.py | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/tests/functional/openlp_core_lib/test_ui.py b/tests/functional/openlp_core_lib/test_ui.py index 87aaab701..f1b8ee17a 100644 --- a/tests/functional/openlp_core_lib/test_ui.py +++ b/tests/functional/openlp_core_lib/test_ui.py @@ -154,22 +154,6 @@ class TestUi(TestCase): self.assertEqual('my tooltip', action.toolTip()) self.assertEqual('my statustip', action.statusTip()) - def test_set_case_insensitive_completer(self): - """ - Test setting a case insensitive completer on a widget - """ - # GIVEN: A QComboBox and a list of completion items - line_edit = QtGui.QLineEdit() - suggestions = ['one', 'Two', 'THRee', 'FOUR'] - - # WHEN: We call the function - set_case_insensitive_completer(suggestions, line_edit) - - # THEN: The Combobox should have a completer which is case insensitive - completer = line_edit.completer() - self.assertIsInstance(completer, QtGui.QCompleter) - self.assertEqual(completer.caseSensitivity(), QtCore.Qt.CaseInsensitive) - def test_create_valign_selection_widgets(self): """ Test creating a combo box for valign selection From 4fadbef1964ff5a5ff753d7151345faa7e659724 Mon Sep 17 00:00:00 2001 From: Samuel Mehrbrodt Date: Wed, 21 May 2014 17:22:13 +0200 Subject: [PATCH 41/42] PEP8 --- tests/functional/openlp_core_lib/test_ui.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/functional/openlp_core_lib/test_ui.py b/tests/functional/openlp_core_lib/test_ui.py index b017a60f0..fa098ba84 100644 --- a/tests/functional/openlp_core_lib/test_ui.py +++ b/tests/functional/openlp_core_lib/test_ui.py @@ -197,7 +197,7 @@ class TestUi(TestCase): # THEN: The index should have changed self.assertEqual(2, combo.currentIndex()) - + def test_set_case_insensitive_completer(self): """ Test setting a case insensitive completer on a widget @@ -213,4 +213,3 @@ class TestUi(TestCase): completer = line_edit.completer() self.assertIsInstance(completer, QtGui.QCompleter) self.assertEqual(completer.caseSensitivity(), QtCore.Qt.CaseInsensitive) - From 5345f52cf41de9c86205c46b215707de461d2928 Mon Sep 17 00:00:00 2001 From: Samuel Mehrbrodt Date: Wed, 21 May 2014 17:22:49 +0200 Subject: [PATCH 42/42] chmod +x jenkins_script.py --- scripts/jenkins_script.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 scripts/jenkins_script.py diff --git a/scripts/jenkins_script.py b/scripts/jenkins_script.py old mode 100644 new mode 100755