From 7c635ce79b72c455e643a4ea036f68577faeb62d Mon Sep 17 00:00:00 2001 From: phill-ridout Date: Tue, 19 Feb 2013 19:03:50 +0000 Subject: [PATCH 01/40] Fixes #1114457 by counting the records --- openlp/plugins/songs/lib/ewimport.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/openlp/plugins/songs/lib/ewimport.py b/openlp/plugins/songs/lib/ewimport.py index 8a344c189..06f062e90 100644 --- a/openlp/plugins/songs/lib/ewimport.py +++ b/openlp/plugins/songs/lib/ewimport.py @@ -107,10 +107,6 @@ class EasyWorshipSongImport(SongImport): self.encoding = retrieve_windows_encoding(self.encoding) if not self.encoding: return - # There does not appear to be a _reliable_ way of getting the number - # of songs/records, so let's use file blocks for measuring progress. - total_blocks = (db_size - header_size) / (block_size * 1024) - self.importWizard.progressBar.setMaximum(total_blocks) # Read the field description information db_file.seek(120) field_info = db_file.read(num_fields * 2) @@ -134,12 +130,22 @@ class EasyWorshipSongImport(SongImport): except IndexError: # This is the wrong table success = False - # Loop through each block of the file + # There does not appear to be a _reliable_ way of getting the number of songs/records, so loop through the file + # blocks and total the number of records. Store the information in a list so we dont have to do all this again. cur_block = first_block + total_count = 0 + block_list = [] while cur_block != 0 and success: - db_file.seek(header_size + ((cur_block - 1) * 1024 * block_size)) + cur_block_pos = header_size + ((cur_block - 1) * 1024 * block_size) + db_file.seek(cur_block_pos) cur_block, rec_count = struct.unpack(' Date: Tue, 19 Feb 2013 21:56:23 +0000 Subject: [PATCH 02/40] Unindented set progress max --- 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 06f062e90..6947da17b 100644 --- a/openlp/plugins/songs/lib/ewimport.py +++ b/openlp/plugins/songs/lib/ewimport.py @@ -142,7 +142,7 @@ class EasyWorshipSongImport(SongImport): rec_count = (rec_count + record_size) / record_size block_list.append((cur_block_pos, rec_count)) total_count += rec_count - self.importWizard.progressBar.setMaximum(total_count) + self.importWizard.progressBar.setMaximum(total_count) for block in block_list: cur_block_pos, rec_count = block db_file.seek(cur_block_pos + 6) From b61cfce03f57c81303213359c0f19761e5c168fb Mon Sep 17 00:00:00 2001 From: phill-ridout Date: Thu, 28 Feb 2013 20:45:57 +0000 Subject: [PATCH 03/40] Started on test --- openlp/plugins/songs/forms/songimportform.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/openlp/plugins/songs/forms/songimportform.py b/openlp/plugins/songs/forms/songimportform.py index b635b309b..8e812f00e 100644 --- a/openlp/plugins/songs/forms/songimportform.py +++ b/openlp/plugins/songs/forms/songimportform.py @@ -35,7 +35,7 @@ import os from PyQt4 import QtCore, QtGui -from openlp.core.lib import Settings, UiStrings, translate +from openlp.core.lib import Registry, Settings, UiStrings, translate from openlp.core.lib.ui import critical_error_message_box from openlp.core.ui.wizard import OpenLPWizard, WizardStrings from openlp.plugins.songs.lib.importer import SongFormat, SongFormatSelect @@ -489,6 +489,16 @@ class SongImportForm(OpenLPWizard): self.formatWidgets[this_format][u'importWidget'] = importWidget return importWidget + def _get_main_window(self): + """ + Adds the main window to the class dynamically + """ + if not hasattr(self, u'_main_window'): + self._main_window = Registry().get(u'main_window') + return self._main_window + + main_window = property(_get_main_window) + class SongImportSourcePage(QtGui.QWizardPage): """ From 03db7ff2a3bd39364450c3df3b219d18609a9c08 Mon Sep 17 00:00:00 2001 From: phill-ridout Date: Fri, 29 Mar 2013 21:13:55 +0000 Subject: [PATCH 04/40] Started EasyWorship import test --- .../openlp_plugins_songs_lib/test_ewimport.py | 162 ++++++++++++++++++ 1 file changed, 162 insertions(+) create mode 100644 tests/functional/openlp_plugins_songs_lib/test_ewimport.py diff --git a/tests/functional/openlp_plugins_songs_lib/test_ewimport.py b/tests/functional/openlp_plugins_songs_lib/test_ewimport.py new file mode 100644 index 000000000..afe4dd1c9 --- /dev/null +++ b/tests/functional/openlp_plugins_songs_lib/test_ewimport.py @@ -0,0 +1,162 @@ +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 + +""" +This module contains tests for the EasyWorship song importer. +""" + +import os +from unittest import TestCase +from mock import call, patch, MagicMock + +from openlp.plugins.songs.lib import VerseType +from openlp.plugins.songs.lib.ewimport import EasyWorshipSongImport, FieldDescEntry + +TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), u'../../../resources')) + +class TestFieldDesc: + def __init__(self, name, type, size): + self.name = name + self.type = type + self.size = size + +TEST_DATA_ENCODING = u'cp1252' +TEST_FIELD_DESCS = [TestFieldDesc(u'Title', 1, 50), + TestFieldDesc(u'Text Percentage Bottom', 3, 2), + TestFieldDesc(u'RecID', 4, 4), + TestFieldDesc(u'Default Background', 9, 1), + TestFieldDesc(u'Words', 12, 250), + TestFieldDesc(u'BK Bitmap', 13, 10), + TestFieldDesc(u'Last Modified', 21, 10)] +TEST_FIELDS = ['A Heart Like Thine\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0', 32868, 2147483750, + 129, '{\\rtf1\\ansi\\deff0\\deftab254{\\fonttbl{\\f0\\fnil\\fcharset0 Arial;}{\\f1\\fnil\\fcharset0 Verdana;}}' + '{\\colortbl\\red0\\green0\\blue0;\\red255\\green0\\blue0;\\red0\\green128\\blue0;\\red0\\green0\\blue255;' + '\\red255\\green255\\blue0;\\red255\\green0\\blue255;\\red128\\g��\7\0f\r\0\0\1\0', '\0\0\0\0\0\0\0\0\0\0', 0] +#22 + +class TestEasyWorshipSongImport(TestCase): + """ + Test the functions in the :mod:`ewimport` module. + """ + def create_field_desc_entry_test(self): + """ + Test creating an instance of the :class`FieldDescEntry` class. + """ + # GIVEN: Set arguments + name = u'Title' + type = 1 + size = 50 + + # WHEN: A FieldDescEntry object is created. + field_desc_entry = FieldDescEntry(name, type, size) + + # THEN: + self.assertIsNotNone(field_desc_entry, u'Import should not be none') + self.assertEquals(field_desc_entry.name, name, u'FieldDescEntry.name should be the same as the name argument') + self.assertEquals(field_desc_entry.type, type, u'FieldDescEntry.type should be the same as the type argument') + self.assertEquals(field_desc_entry.size, size, u'FieldDescEntry.size should be the same as the size argument') + + def create_importer_test(self): + """ + Test creating an instance of the EasyWorship file importer + """ + # GIVEN: A mocked out SongImport class, and a mocked out "manager" + with patch(u'openlp.plugins.songs.lib.ewimport.SongImport'): + mocked_manager = MagicMock() + + # WHEN: An importer object is created + importer = EasyWorshipSongImport(mocked_manager) + + # THEN: The importer object should not be None + self.assertIsNotNone(importer, u'Import should not be none') + + def find_field_test(self): + """ + Test finding a field in a given list using the :mod:`findField` + """ + # GIVEN: A mocked out SongImport class, a mocked out "manager" and a list of field descriptions + with patch(u'openlp.plugins.songs.lib.ewimport.SongImport'): + mocked_manager = MagicMock() + importer = EasyWorshipSongImport(mocked_manager) + importer.fieldDescs = TEST_FIELD_DESCS + + # WHEN: Given a field name that exists + existing_fields = [u'Title', u'Text Percentage Bottom', u'RecID', u'Default Background', u'Words', + u'BK Bitmap', u'Last Modified'] + + # THEN: The item corresponding the index returned should have the same name attribute + for field_name in existing_fields: + self.assertEquals(importer.fieldDescs[importer.findField(field_name)].name, field_name) + + # GIVEN: A mocked out SongImport class, a mocked out "manager" and a list of field descriptions + with patch(u'openlp.plugins.songs.lib.ewimport.SongImport'): + mocked_manager = MagicMock() + importer = EasyWorshipSongImport(mocked_manager) + importer.fieldDescs = TEST_FIELD_DESCS + + # WHEN: Given a field name that does not exist + non_existing_fields = [u'BK Gradient Shading', u'BK Gradient Variant', u'Favorite', u'Copyright'] + + # THEN: The importer object should not be None + for field_name in non_existing_fields: + self.assertRaises(IndexError, importer.findField, field_name) + + def set_record_struct_test(self): + """ + Test the :mod:`setRecordStruct` module + """ + # GIVEN: A mocked out SongImport class, a mocked out struct class, and a mocked out "manager" + with patch(u'openlp.plugins.songs.lib.ewimport.SongImport'), \ + patch(u'openlp.plugins.songs.lib.ewimport.struct') as mocked_struct: + mocked_manager = MagicMock() + importer = EasyWorshipSongImport(mocked_manager) + + # WHEN: Called with a list of field descriptions + + # THEN: setRecordStruct should return None and structStruct should be called with a value representing + # the list of field descriptions + self.assertIsNone(importer.setRecordStruct(TEST_FIELD_DESCS), u'setRecordStruct should return None') + mocked_struct.Struct.assert_called_with('>50sHIB250s10sQ') + + def get_field_test(self): + + + # GIVEN: A mocked out SongImport class, a mocked out "manager" + with patch(u'openlp.plugins.songs.lib.ewimport.SongImport'): + mocked_manager = MagicMock() + importer = EasyWorshipSongImport(mocked_manager) + importer.encoding = TEST_DATA_ENCODING + + # WHEN: Supplied with string with just NULL bytes, or an int with the value 0 + importer.fields = TEST_FIELDS + importer.fieldDescs = TEST_FIELD_DESCS + field_results = [(0, 'A Heart Like Thine'), (1, 100), (2, 102L), (3, True), (5, None), (6, None)] + + # THEN: getField should return None + for field_index, result in field_results: + self.assertEquals(importer.getField(field_index), result, + u'getField should return "%s" when called with "%s"' % (result, TEST_FIELDS[field_index])) + + # GIVEN: A mocked out SongImport class, a mocked out "manager" + with patch(u'openlp.plugins.songs.lib.ewimport.SongImport'), \ + patch(u'openlp.plugins.songs.lib.ewimport.SongImport'): + mocked_manager = MagicMock() + mocked + importer = EasyWorshipSongImport(mocked_manager) + importer.encoding = TEST_DATA_ENCODING + + # WHEN: Supplied with string with just NULL bytes, or an int with the value 0 + importer.fields = TEST_FIELDS + importer.fieldDescs = TEST_FIELD_DESCS + field_results = [(4, u'I dunno')] + + # THEN: getField should return None + for field_index, result in field_results: + self.assertEquals(importer.getField(field_index), result) + + # u'getField should return "%s" when called with "%s"' % (result, TEST_FIELDS[field_index])) + + +# TODO: Write doImport Tests + +# TODO: Write getField Tests \ No newline at end of file From dcf2cae3a1516f454fa39fb17e01bf7ea58608f0 Mon Sep 17 00:00:00 2001 From: phill-ridout Date: Fri, 29 Mar 2013 21:27:43 +0000 Subject: [PATCH 05/40] minor changes --- openlp/plugins/songs/lib/ewimport.py | 4 ++-- tests/functional/openlp_plugins_songs_lib/test_ewimport.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/openlp/plugins/songs/lib/ewimport.py b/openlp/plugins/songs/lib/ewimport.py index 6947da17b..3c7234203 100644 --- a/openlp/plugins/songs/lib/ewimport.py +++ b/openlp/plugins/songs/lib/ewimport.py @@ -48,9 +48,9 @@ NOTE_REGEX = re.compile(r'\(.*?\)') class FieldDescEntry: - def __init__(self, name, type, size): + def __init__(self, name, field_type, size): self.name = name - self.type = type + self.type = field_type self.size = size diff --git a/tests/functional/openlp_plugins_songs_lib/test_ewimport.py b/tests/functional/openlp_plugins_songs_lib/test_ewimport.py index afe4dd1c9..8fed5d855 100644 --- a/tests/functional/openlp_plugins_songs_lib/test_ewimport.py +++ b/tests/functional/openlp_plugins_songs_lib/test_ewimport.py @@ -15,9 +15,9 @@ from openlp.plugins.songs.lib.ewimport import EasyWorshipSongImport, FieldDescEn TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), u'../../../resources')) class TestFieldDesc: - def __init__(self, name, type, size): + def __init__(self, name, field_type, size): self.name = name - self.type = type + self.type = field_type self.size = size TEST_DATA_ENCODING = u'cp1252' @@ -70,7 +70,7 @@ class TestEasyWorshipSongImport(TestCase): # THEN: The importer object should not be None self.assertIsNotNone(importer, u'Import should not be none') - def find_field_test(self): + def find_field_exists_test(self): """ Test finding a field in a given list using the :mod:`findField` """ From 047f567ed8e730c3c173b699535be1ee94d4a161 Mon Sep 17 00:00:00 2001 From: phill-ridout Date: Sat, 6 Apr 2013 11:54:36 +0100 Subject: [PATCH 06/40] added some tests --- openlp/plugins/songs/lib/ewimport.py | 2 +- .../openlp_plugins_songs_lib/test_ewimport.py | 77 +++++++++++++------ 2 files changed, 53 insertions(+), 26 deletions(-) diff --git a/openlp/plugins/songs/lib/ewimport.py b/openlp/plugins/songs/lib/ewimport.py index 7747a7fdf..949955350 100644 --- a/openlp/plugins/songs/lib/ewimport.py +++ b/openlp/plugins/songs/lib/ewimport.py @@ -142,7 +142,7 @@ class EasyWorshipSongImport(SongImport): rec_count = (rec_count + record_size) / record_size block_list.append((cur_block_pos, rec_count)) total_count += rec_count - self.importWizard.progressBar.setMaximum(total_count) + self.import_wizard.progress_bar.setMaximum(total_count) for block in block_list: cur_block_pos, rec_count = block db_file.seek(cur_block_pos + 6) diff --git a/tests/functional/openlp_plugins_songs_lib/test_ewimport.py b/tests/functional/openlp_plugins_songs_lib/test_ewimport.py index 8fed5d855..8b60df2a7 100644 --- a/tests/functional/openlp_plugins_songs_lib/test_ewimport.py +++ b/tests/functional/openlp_plugins_songs_lib/test_ewimport.py @@ -26,13 +26,29 @@ TEST_FIELD_DESCS = [TestFieldDesc(u'Title', 1, 50), TestFieldDesc(u'RecID', 4, 4), TestFieldDesc(u'Default Background', 9, 1), TestFieldDesc(u'Words', 12, 250), + TestFieldDesc(u'Words', 12, 250), TestFieldDesc(u'BK Bitmap', 13, 10), TestFieldDesc(u'Last Modified', 21, 10)] TEST_FIELDS = ['A Heart Like Thine\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0', 32868, 2147483750, 129, '{\\rtf1\\ansi\\deff0\\deftab254{\\fonttbl{\\f0\\fnil\\fcharset0 Arial;}{\\f1\\fnil\\fcharset0 Verdana;}}' '{\\colortbl\\red0\\green0\\blue0;\\red255\\green0\\blue0;\\red0\\green128\\blue0;\\red0\\green0\\blue255;' - '\\red255\\green255\\blue0;\\red255\\green0\\blue255;\\red128\\g��\7\0f\r\0\0\1\0', '\0\0\0\0\0\0\0\0\0\0', 0] -#22 + '\\red255\\green255\\blue0;\\red255\\green0\\blue255;\\red128\\g��\7\0f\r\0\0\1\0', + '{\\rtf1\\ansi\\deff0\\deftab254{\\fonttbl{\\f0\\fnil\\fcharset0 Arial;}{\\f1\\fnil\\fcharset0 Verdana;}}' + '{\\colortbl\\red0\\green0\\blue0;\\red255\\green0\\blue0;\\red0\\green128\\blue0;\\red0\\green0\\blue255;\\red255' + '\\green255\\blue0;\\red255\\green0\\blue255;\\red128\\g>�\6\0�\6\0\0\1\0', '\0\0\0\0\0\0\0\0\0\0', 0] +GET_MEMO_FIELD_TEST_RESULTS = [ + (4, u'\2', {u'return': u'\2', + u'read': (1, 3430), + u'seek': (507136, (8, os.SEEK_CUR))}), + (4, u'\3', {u'return': u'', + u'read': (1, ), + u'seek': (507136, )}), + (5, u'\3', {u'return': u'\3', + u'read': (1, 1725), + u'seek': (3220111360L, (41L, os.SEEK_CUR), 3220111408L)}), + (5, u'\4', {u'return': u'', + u'read': (), + u'seek': ()})] class TestEasyWorshipSongImport(TestCase): """ @@ -72,7 +88,7 @@ class TestEasyWorshipSongImport(TestCase): def find_field_exists_test(self): """ - Test finding a field in a given list using the :mod:`findField` + Test finding an existing field in a given list using the :mod:`findField` """ # GIVEN: A mocked out SongImport class, a mocked out "manager" and a list of field descriptions with patch(u'openlp.plugins.songs.lib.ewimport.SongImport'): @@ -88,6 +104,10 @@ class TestEasyWorshipSongImport(TestCase): for field_name in existing_fields: self.assertEquals(importer.fieldDescs[importer.findField(field_name)].name, field_name) + def find_field_non_exists_test(self): + """ + Test finding an non-existing field in a given list using the :mod:`findField` + """ # GIVEN: A mocked out SongImport class, a mocked out "manager" and a list of field descriptions with patch(u'openlp.plugins.songs.lib.ewimport.SongImport'): mocked_manager = MagicMock() @@ -116,7 +136,7 @@ class TestEasyWorshipSongImport(TestCase): # THEN: setRecordStruct should return None and structStruct should be called with a value representing # the list of field descriptions self.assertIsNone(importer.setRecordStruct(TEST_FIELD_DESCS), u'setRecordStruct should return None') - mocked_struct.Struct.assert_called_with('>50sHIB250s10sQ') + mocked_struct.Struct.assert_called_with('>50sHIB250s250s10sQ') def get_field_test(self): @@ -130,33 +150,40 @@ class TestEasyWorshipSongImport(TestCase): # WHEN: Supplied with string with just NULL bytes, or an int with the value 0 importer.fields = TEST_FIELDS importer.fieldDescs = TEST_FIELD_DESCS - field_results = [(0, 'A Heart Like Thine'), (1, 100), (2, 102L), (3, True), (5, None), (6, None)] + field_results = [(0, 'A Heart Like Thine'), (1, 100), (2, 102L), (3, True), (6, None), (7, None)] # THEN: getField should return None for field_index, result in field_results: self.assertEquals(importer.getField(field_index), result, u'getField should return "%s" when called with "%s"' % (result, TEST_FIELDS[field_index])) - # GIVEN: A mocked out SongImport class, a mocked out "manager" - with patch(u'openlp.plugins.songs.lib.ewimport.SongImport'), \ - patch(u'openlp.plugins.songs.lib.ewimport.SongImport'): - mocked_manager = MagicMock() - mocked - importer = EasyWorshipSongImport(mocked_manager) - importer.encoding = TEST_DATA_ENCODING + def get_memo_field_test(self): + for test_results in GET_MEMO_FIELD_TEST_RESULTS: + # GIVEN: A mocked out SongImport class, a mocked out "manager" + with patch(u'openlp.plugins.songs.lib.ewimport.SongImport'): + mocked_manager = MagicMock() + mocked_memo_file = MagicMock() + importer = EasyWorshipSongImport(mocked_manager) + importer.encoding = TEST_DATA_ENCODING + importer.memoFile = mocked_memo_file - # WHEN: Supplied with string with just NULL bytes, or an int with the value 0 - importer.fields = TEST_FIELDS - importer.fieldDescs = TEST_FIELD_DESCS - field_results = [(4, u'I dunno')] + # WHEN: Supplied with string with just NULL bytes, or an int with the value 0 + importer.fields = TEST_FIELDS + importer.fieldDescs = TEST_FIELD_DESCS + field_index = test_results[0] + mocked_memo_file.read.return_value = test_results[1] + get_field_result = test_results[2][u'return'] + get_field_read_calls = test_results[2][u'read'] + get_field_seek_calls = test_results[2][u'seek'] - # THEN: getField should return None - for field_index, result in field_results: - self.assertEquals(importer.getField(field_index), result) + # THEN: getField should return None + self.assertEquals(importer.getField(field_index), get_field_result) + for call in get_field_read_calls: + mocked_memo_file.read.assert_any_call(call) + for call in get_field_seek_calls: + if isinstance(call, (int, long)): + mocked_memo_file.seek.assert_any_call(call) + else: + mocked_memo_file.seek.assert_any_call(call[0], call[1]) - # u'getField should return "%s" when called with "%s"' % (result, TEST_FIELDS[field_index])) - - -# TODO: Write doImport Tests - -# TODO: Write getField Tests \ No newline at end of file +# TODO: Write doImport Tests \ No newline at end of file From a307824d8569677d79eb34b227abb8aa6dedf54f Mon Sep 17 00:00:00 2001 From: phill-ridout Date: Wed, 10 Apr 2013 17:24:53 +0100 Subject: [PATCH 07/40] Moved some directories about. Added test files --- openlp/plugins/songs/lib/ewimport.py | 4 +- .../openlp_plugins/songs/test_ewimport.py | 333 ++++++++++++++++++ .../openlp_plugins_songs_lib/test_ewimport.py | 189 ---------- tests/resources/easyworshipsongs/Songs.DB | Bin 0 -> 6144 bytes tests/resources/easyworshipsongs/Songs.MB | Bin 0 -> 12288 bytes 5 files changed, 334 insertions(+), 192 deletions(-) create mode 100644 tests/functional/openlp_plugins/songs/test_ewimport.py delete mode 100644 tests/functional/openlp_plugins_songs_lib/test_ewimport.py create mode 100644 tests/resources/easyworshipsongs/Songs.DB create mode 100644 tests/resources/easyworshipsongs/Songs.MB diff --git a/openlp/plugins/songs/lib/ewimport.py b/openlp/plugins/songs/lib/ewimport.py index 949955350..4f8d7d970 100644 --- a/openlp/plugins/songs/lib/ewimport.py +++ b/openlp/plugins/songs/lib/ewimport.py @@ -65,9 +65,7 @@ class EasyWorshipSongImport(SongImport): def doImport(self): # Open the DB and MB files if they exist import_source_mb = self.import_source.replace('.DB', '.MB') - if not os.path.isfile(self.import_source): - return - if not os.path.isfile(import_source_mb): + if not (os.path.isfile(self.import_source) or os.path.isfile(import_source_mb)): return db_size = os.path.getsize(self.import_source) if db_size < 0x800: diff --git a/tests/functional/openlp_plugins/songs/test_ewimport.py b/tests/functional/openlp_plugins/songs/test_ewimport.py new file mode 100644 index 000000000..644a898db --- /dev/null +++ b/tests/functional/openlp_plugins/songs/test_ewimport.py @@ -0,0 +1,333 @@ +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 + +""" +This module contains tests for the EasyWorship song importer. +""" + +import os +from unittest import TestCase +from mock import call, patch, MagicMock + +from openlp.plugins.songs.lib import VerseType +from openlp.plugins.songs.lib.ewimport import EasyWorshipSongImport, FieldDescEntry + +TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), u'../../../resources/easyworshipsongs')) +SONG_TEST_DATA = [{u'title': u'Amazing Grace (Demonstration)', + u'authors': [u'John Newton', u'Edwin Excell', u'John P. Rees'], + u'copyright': u'Public Domain ', + u'ccli_number': 22025, + u'verses': + [(u'Amazing grace! How sweet the sound!\r\nThat saved a wretch like me!\r\n' + u'I once was lost, but now am found;\r\nWas blind, but now I see.', u'v1'), + (u'\'Twas grace that taught my heart to fear,\r\nAnd grace my fears relieved.\r\n' + u'How precious did that grace appear,\r\nThe hour I first believed.', u'v2'), + (u'The Lord has promised good to me,\r\nHis Word my hope secures.\r\n' + u'He will my shield and portion be\r\nAs long as life endures.', u'v3'), + (u'Thro\' many dangers, toils and snares\r\nI have already come.\r\n' + u'\'Tis grace that brought me safe thus far,\r\nAnd grace will lead me home.', u'v4'), + (u'When we\'ve been there ten thousand years,\r\nBright shining as the sun,\r\n' + u'We\'ve no less days to sing God\'s praise,\r\nThan when we first begun.', u'v5')], + u'topics': [u'Assurance', u'Grace', u'Praise', u'Salvation'], + u'comments': u'\n\n\n', + u'song_book_name': u'Demonstration Songs', + u'song_number': 0, + u'verse_order_list': []}, + {u'title': u'Beautiful Garden Of Prayer (Demonstration)', + u'authors': [u'Eleanor Allen Schroll', u'James H. Fillmore'], + u'copyright': u'Public Domain ', + u'ccli_number': 60252, + u'verses': + [(u'There\'s a garden where Jesus is waiting,\r\nThere\'s a place that is wondrously fair.\r\n' + u'For it glows with the light of His presence,\r\n\'Tis the beautiful garden of prayer.', u'v1'), + (u'There\'s a garden where Jesus is waiting,\r\nAnd I go with my burden and care.\r\n' + u'Just to learn from His lips, words of comfort,\r\nIn the beautiful garden of prayer.', u'v2'), + (u'There\'s a garden where Jesus is waiting,\r\nAnd He bids you to come meet Him there,\r\n' + u'Just to bow and receive a new blessing,\r\nIn the beautiful garden of prayer.', u'v3'), + (u'O the beautiful garden, the garden of prayer,\r\nO the beautiful garden of prayer.\r\n' + u'There my Savior awaits, and He opens the gates\r\nTo the beautiful garden of prayer.', u'c1')], + u'topics': [u'Devotion', u'Prayer'], + u'comments': u'', + u'song_book_name': u'', + u'song_number': 0, + u'verse_order_list': []}] + + +class TestFieldDesc: + def __init__(self, name, field_type, size): + self.name = name + self.type = field_type + self.size = size + +TEST_DATA_ENCODING = u'cp1252' +TEST_FIELD_DESCS = [TestFieldDesc(u'Title', 1, 50), TestFieldDesc(u'Text Percentage Bottom', 3, 2), + TestFieldDesc(u'RecID', 4, 4), TestFieldDesc(u'Default Background', 9, 1), TestFieldDesc(u'Words', 12, 250), + TestFieldDesc(u'Words', 12, 250), TestFieldDesc(u'BK Bitmap', 13, 10), TestFieldDesc(u'Last Modified', 21, 10)] +TEST_FIELDS = ['A Heart Like Thine\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0', 32868, 2147483750, + 129, '{\\rtf1\\ansi\\deff0\\deftab254{\\fonttbl{\\f0\\fnil\\fcharset0 Arial;}{\\f1\\fnil\\fcharset0 Verdana;}}' + '{\\colortbl\\red0\\green0\\blue0;\\red255\\green0\\blue0;\\red0\\green128\\blue0;\\red0\\green0\\blue255;' + '\\red255\\green255\\blue0;\\red255\\green0\\blue255;\\red128\\g��\7\0f\r\0\0\1\0', + '{\\rtf1\\ansi\\deff0\\deftab254{\\fonttbl{\\f0\\fnil\\fcharset0 Arial;}{\\f1\\fnil\\fcharset0 Verdana;}}' + '{\\colortbl\\red0\\green0\\blue0;\\red255\\green0\\blue0;\\red0\\green128\\blue0;\\red0\\green0\\blue255;\\red255' + '\\green255\\blue0;\\red255\\green0\\blue255;\\red128\\g>�\6\0�\6\0\0\1\0', '\0\0\0\0\0\0\0\0\0\0', 0] +GET_MEMO_FIELD_TEST_RESULTS = [ + (4, u'\2', {u'return': u'\2',u'read': (1, 3430), u'seek': (507136, (8, os.SEEK_CUR))}), + (4, u'\3', {u'return': u'', u'read': (1, ), u'seek': (507136, )}), + (5, u'\3', {u'return': u'\3', u'read': (1, 1725), u'seek': (3220111360L, (41L, os.SEEK_CUR), 3220111408L)}), + (5, u'\4', {u'return': u'', u'read': (), u'seek': ()})] + +class TestEasyWorshipSongImport(TestCase): + """ + Test the functions in the :mod:`ewimport` module. + """ + def create_field_desc_entry_test(self): + """ + Test creating an instance of the :class`FieldDescEntry` class. + """ + # GIVEN: Set arguments + name = u'Title' + field_type = 1 + size = 50 + + # WHEN: A FieldDescEntry object is created. + field_desc_entry = FieldDescEntry(name, field_type, size) + + # THEN: + self.assertIsNotNone(field_desc_entry, u'Import should not be none') + self.assertEquals(field_desc_entry.name, name, u'FieldDescEntry.name should be the same as the name argument') + self.assertEquals(field_desc_entry.type, field_type, + u'FieldDescEntry.type should be the same as the typeargument') + self.assertEquals(field_desc_entry.size, size, u'FieldDescEntry.size should be the same as the size argument') + + def create_importer_test(self): + """ + Test creating an instance of the EasyWorship file importer + """ + # GIVEN: A mocked out SongImport class, and a mocked out "manager" + with patch(u'openlp.plugins.songs.lib.ewimport.SongImport'): + mocked_manager = MagicMock() + + # WHEN: An importer object is created + importer = EasyWorshipSongImport(mocked_manager) + + # THEN: The importer object should not be None + self.assertIsNotNone(importer, u'Import should not be none') + + def find_field_exists_test(self): + """ + Test finding an existing field in a given list using the :mod:`findField` + """ + # GIVEN: A mocked out SongImport class, a mocked out "manager" and a list of field descriptions + with patch(u'openlp.plugins.songs.lib.ewimport.SongImport'): + mocked_manager = MagicMock() + importer = EasyWorshipSongImport(mocked_manager) + importer.fieldDescs = TEST_FIELD_DESCS + + # WHEN: Given a field name that exists + existing_fields = [u'Title', u'Text Percentage Bottom', u'RecID', u'Default Background', u'Words', + u'BK Bitmap', u'Last Modified'] + + # THEN: The item corresponding the index returned should have the same name attribute + for field_name in existing_fields: + self.assertEquals(importer.fieldDescs[importer.findField(field_name)].name, field_name) + + def find_field_non_exists_test(self): + """ + Test finding an non-existing field in a given list using the :mod:`findField` + """ + # GIVEN: A mocked out SongImport class, a mocked out "manager" and a list of field descriptions + with patch(u'openlp.plugins.songs.lib.ewimport.SongImport'): + mocked_manager = MagicMock() + importer = EasyWorshipSongImport(mocked_manager) + importer.fieldDescs = TEST_FIELD_DESCS + + # WHEN: Given a field name that does not exist + non_existing_fields = [u'BK Gradient Shading', u'BK Gradient Variant', u'Favorite', u'Copyright'] + + # THEN: The importer object should not be None + for field_name in non_existing_fields: + self.assertRaises(IndexError, importer.findField, field_name) + + def set_record_struct_test(self): + """ + Test the :mod:`setRecordStruct` module + """ + # GIVEN: A mocked out SongImport class, a mocked out struct class, and a mocked out "manager" + with patch(u'openlp.plugins.songs.lib.ewimport.SongImport'), \ + patch(u'openlp.plugins.songs.lib.ewimport.struct') as mocked_struct: + mocked_manager = MagicMock() + importer = EasyWorshipSongImport(mocked_manager) + + # WHEN: Called with a list of field descriptions + + # THEN: setRecordStruct should return None and structStruct should be called with a value representing + # the list of field descriptions + self.assertIsNone(importer.setRecordStruct(TEST_FIELD_DESCS), u'setRecordStruct should return None') + mocked_struct.Struct.assert_called_with('>50sHIB250s250s10sQ') + + def get_field_test(self): + """ + Test the :mod:`getField` module + """ + # GIVEN: A mocked out SongImport class, a mocked out "manager" and an encoding + with patch(u'openlp.plugins.songs.lib.ewimport.SongImport'): + mocked_manager = MagicMock() + importer = EasyWorshipSongImport(mocked_manager) + importer.encoding = TEST_DATA_ENCODING + + # WHEN: Supplied with string with just NULL bytes, or an int with the value 0 + importer.fields = TEST_FIELDS + importer.fieldDescs = TEST_FIELD_DESCS + field_results = [(0, 'A Heart Like Thine'), (1, 100), (2, 102L), (3, True), (6, None), (7, None)] + + # THEN: getField should return None + for field_index, result in field_results: + self.assertEquals(importer.getField(field_index), result, + u'getField should return "%s" when called with "%s"' % (result, TEST_FIELDS[field_index])) + + def get_memo_field_test(self): + """ + Test the :mod:`getField` module + """ + for test_results in GET_MEMO_FIELD_TEST_RESULTS: + # GIVEN: A mocked out SongImport class, a mocked out "manager", a mocked out memo_file and an encoding + with patch(u'openlp.plugins.songs.lib.ewimport.SongImport'): + mocked_manager = MagicMock() + mocked_memo_file = MagicMock() + importer = EasyWorshipSongImport(mocked_manager) + importer.memoFile = mocked_memo_file + importer.encoding = TEST_DATA_ENCODING + + # WHEN: Supplied with test fields and test field descriptions + importer.fields = TEST_FIELDS + importer.fieldDescs = TEST_FIELD_DESCS + field_index = test_results[0] + mocked_memo_file.read.return_value = test_results[1] + get_field_result = test_results[2][u'return'] + get_field_read_calls = test_results[2][u'read'] + get_field_seek_calls = test_results[2][u'seek'] + + # THEN: getField should return the appropriate value with the appropriate mocked objects being called + self.assertEquals(importer.getField(field_index), get_field_result) + for call in get_field_read_calls: + mocked_memo_file.read.assert_any_call(call) + for call in get_field_seek_calls: + if isinstance(call, (int, long)): + mocked_memo_file.seek.assert_any_call(call) + else: + mocked_memo_file.seek.assert_any_call(call[0], call[1]) + + def do_import_source_test(self): + """ + Test the :mod:`doImport` module + """ + # GIVEN: A mocked out SongImport class, a mocked out "manager" + with patch(u'openlp.plugins.songs.lib.ewimport.SongImport'), \ + patch(u'openlp.plugins.songs.lib.ewimport.os.path') as mocked_os_path: + mocked_manager = MagicMock() + importer = EasyWorshipSongImport(mocked_manager) + mocked_os_path.isfile.return_value = False + + # WHEN: Supplied with an import source + importer.import_source = u'Songs.DB' + + # THEN: doImport should return None having called os.path.isfile + self.assertIsNone(importer.doImport(), u'doImport should return None') + mocked_os_path.isfile.assert_any_call(u'Songs.DB') + mocked_os_path.isfile.assert_any_call(u'Songs.MB') + + def do_import_source_validity_test(self): + """ + Test the :mod:`doImport` module + """ + # GIVEN: A mocked out SongImport class, a mocked out "manager" + with patch(u'openlp.plugins.songs.lib.ewimport.SongImport'), \ + patch(u'openlp.plugins.songs.lib.ewimport.os.path') as mocked_os_path, \ + patch(u'__builtin__.open') as mocked_open: + mocked_manager = MagicMock() + importer = EasyWorshipSongImport(mocked_manager) + mocked_os_path.isfile.return_value = True + importer.import_source = u'Songs.DB' + + # WHEN: DB file size is less than 0x800 + mocked_os_path.getsize.return_value = 0x7FF + + # THEN: doImport should return None having called os.path.isfile + self.assertIsNone(importer.doImport(), u'doImport should return None when db_size is less than 0x800') + mocked_os_path.getsize.assert_any_call(u'Songs.DB') + + + def file_import_test(self): + """ + Test the actual import of real song files and check that the imported data is correct. + """ + + # 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(u'openlp.plugins.songs.lib.songshowplusimport.SongImport'): + mocked_manager = MagicMock() + mocked_import_wizard = MagicMock() + mocked_parse_author = MagicMock() + mocked_add_copyright = MagicMock() + mocked_add_verse = MagicMock() + mocked_finish = MagicMock() + mocked_finish.return_value = True + importer = EasyWorshipSongImport(mocked_manager) + importer.import_wizard = mocked_import_wizard + importer.stop_import_flag = False + importer.parse_author = mocked_parse_author + importer.addCopyright = mocked_add_copyright + importer.addVerse = mocked_add_verse + importer.finish = mocked_finish + importer.topics = [] + + # WHEN: Importing each file + importer.import_source = [os.path.join(TEST_PATH, u'Songs.DB')] + title = SONG_TEST_DATA[song_file][u'title'] + author_calls = SONG_TEST_DATA[song_file][u'authors'] + song_copyright = SONG_TEST_DATA[song_file][u'copyright'] + ccli_number = SONG_TEST_DATA[song_file][u'ccli_number'] + add_verse_calls = SONG_TEST_DATA[song_file][u'verses'] + topics = SONG_TEST_DATA[song_file][u'topics'] + comments = SONG_TEST_DATA[song_file][u'comments'] + song_book_name = SONG_TEST_DATA[song_file][u'song_book_name'] + song_number = SONG_TEST_DATA[song_file][u'song_number'] + verse_order_list = SONG_TEST_DATA[song_file][u'verse_order_list'] + + # THEN: doImport should return none, the song data should be as expected, and finish should have been + # called. + self.assertIsNone(importer.doImport(), u'doImport should return None when it has completed') + self.assertEquals(importer.title, title, u'title for %s should be "%s"' % (song_file, title)) + for author in author_calls: + mocked_parse_author.assert_any_call(author) + if song_copyright: + mocked_add_copyright.assert_called_with(song_copyright) + if ccli_number: + self.assertEquals(importer.ccliNumber, ccli_number, u'ccliNumber for %s should be %s' + % (song_file, ccli_number)) + for verse_text, verse_tag in add_verse_calls: + mocked_add_verse.assert_any_call(verse_text, verse_tag) + if topics: + self.assertEquals(importer.topics, topics, u'topics for %s should be %s' % (song_file, topics)) + if comments: + self.assertEquals(importer.comments, comments, u'comments for %s should be "%s"' + % (song_file, comments)) + if song_book_name: + self.assertEquals(importer.songBookName, song_book_name, u'songBookName for %s should be "%s"' + % (song_file, song_book_name)) + if song_number: + self.assertEquals(importer.songNumber, song_number, u'songNumber for %s should be %s' + % (song_file, song_number)) + if verse_order_list: + self.assertEquals(importer.verseOrderList, [], u'verseOrderList for %s should be %s' + % (song_file, verse_order_list)) + mocked_finish.assert_called_with() + + # Open the DB and MB files if they exist + # import_source_mb = self.import_source.replace('.DB', '.MB') + # if not (os.path.isfile(self.import_source) or os.path.isfile(import_source_mb)): + # return + # db_size = os.path.getsize(self.import_source) + # if db_size < 0x800: + # return + # TODO: Write doImport Tests \ No newline at end of file diff --git a/tests/functional/openlp_plugins_songs_lib/test_ewimport.py b/tests/functional/openlp_plugins_songs_lib/test_ewimport.py deleted file mode 100644 index 8b60df2a7..000000000 --- a/tests/functional/openlp_plugins_songs_lib/test_ewimport.py +++ /dev/null @@ -1,189 +0,0 @@ -# -*- coding: utf-8 -*- -# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 - -""" -This module contains tests for the EasyWorship song importer. -""" - -import os -from unittest import TestCase -from mock import call, patch, MagicMock - -from openlp.plugins.songs.lib import VerseType -from openlp.plugins.songs.lib.ewimport import EasyWorshipSongImport, FieldDescEntry - -TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), u'../../../resources')) - -class TestFieldDesc: - def __init__(self, name, field_type, size): - self.name = name - self.type = field_type - self.size = size - -TEST_DATA_ENCODING = u'cp1252' -TEST_FIELD_DESCS = [TestFieldDesc(u'Title', 1, 50), - TestFieldDesc(u'Text Percentage Bottom', 3, 2), - TestFieldDesc(u'RecID', 4, 4), - TestFieldDesc(u'Default Background', 9, 1), - TestFieldDesc(u'Words', 12, 250), - TestFieldDesc(u'Words', 12, 250), - TestFieldDesc(u'BK Bitmap', 13, 10), - TestFieldDesc(u'Last Modified', 21, 10)] -TEST_FIELDS = ['A Heart Like Thine\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0', 32868, 2147483750, - 129, '{\\rtf1\\ansi\\deff0\\deftab254{\\fonttbl{\\f0\\fnil\\fcharset0 Arial;}{\\f1\\fnil\\fcharset0 Verdana;}}' - '{\\colortbl\\red0\\green0\\blue0;\\red255\\green0\\blue0;\\red0\\green128\\blue0;\\red0\\green0\\blue255;' - '\\red255\\green255\\blue0;\\red255\\green0\\blue255;\\red128\\g��\7\0f\r\0\0\1\0', - '{\\rtf1\\ansi\\deff0\\deftab254{\\fonttbl{\\f0\\fnil\\fcharset0 Arial;}{\\f1\\fnil\\fcharset0 Verdana;}}' - '{\\colortbl\\red0\\green0\\blue0;\\red255\\green0\\blue0;\\red0\\green128\\blue0;\\red0\\green0\\blue255;\\red255' - '\\green255\\blue0;\\red255\\green0\\blue255;\\red128\\g>�\6\0�\6\0\0\1\0', '\0\0\0\0\0\0\0\0\0\0', 0] -GET_MEMO_FIELD_TEST_RESULTS = [ - (4, u'\2', {u'return': u'\2', - u'read': (1, 3430), - u'seek': (507136, (8, os.SEEK_CUR))}), - (4, u'\3', {u'return': u'', - u'read': (1, ), - u'seek': (507136, )}), - (5, u'\3', {u'return': u'\3', - u'read': (1, 1725), - u'seek': (3220111360L, (41L, os.SEEK_CUR), 3220111408L)}), - (5, u'\4', {u'return': u'', - u'read': (), - u'seek': ()})] - -class TestEasyWorshipSongImport(TestCase): - """ - Test the functions in the :mod:`ewimport` module. - """ - def create_field_desc_entry_test(self): - """ - Test creating an instance of the :class`FieldDescEntry` class. - """ - # GIVEN: Set arguments - name = u'Title' - type = 1 - size = 50 - - # WHEN: A FieldDescEntry object is created. - field_desc_entry = FieldDescEntry(name, type, size) - - # THEN: - self.assertIsNotNone(field_desc_entry, u'Import should not be none') - self.assertEquals(field_desc_entry.name, name, u'FieldDescEntry.name should be the same as the name argument') - self.assertEquals(field_desc_entry.type, type, u'FieldDescEntry.type should be the same as the type argument') - self.assertEquals(field_desc_entry.size, size, u'FieldDescEntry.size should be the same as the size argument') - - def create_importer_test(self): - """ - Test creating an instance of the EasyWorship file importer - """ - # GIVEN: A mocked out SongImport class, and a mocked out "manager" - with patch(u'openlp.plugins.songs.lib.ewimport.SongImport'): - mocked_manager = MagicMock() - - # WHEN: An importer object is created - importer = EasyWorshipSongImport(mocked_manager) - - # THEN: The importer object should not be None - self.assertIsNotNone(importer, u'Import should not be none') - - def find_field_exists_test(self): - """ - Test finding an existing field in a given list using the :mod:`findField` - """ - # GIVEN: A mocked out SongImport class, a mocked out "manager" and a list of field descriptions - with patch(u'openlp.plugins.songs.lib.ewimport.SongImport'): - mocked_manager = MagicMock() - importer = EasyWorshipSongImport(mocked_manager) - importer.fieldDescs = TEST_FIELD_DESCS - - # WHEN: Given a field name that exists - existing_fields = [u'Title', u'Text Percentage Bottom', u'RecID', u'Default Background', u'Words', - u'BK Bitmap', u'Last Modified'] - - # THEN: The item corresponding the index returned should have the same name attribute - for field_name in existing_fields: - self.assertEquals(importer.fieldDescs[importer.findField(field_name)].name, field_name) - - def find_field_non_exists_test(self): - """ - Test finding an non-existing field in a given list using the :mod:`findField` - """ - # GIVEN: A mocked out SongImport class, a mocked out "manager" and a list of field descriptions - with patch(u'openlp.plugins.songs.lib.ewimport.SongImport'): - mocked_manager = MagicMock() - importer = EasyWorshipSongImport(mocked_manager) - importer.fieldDescs = TEST_FIELD_DESCS - - # WHEN: Given a field name that does not exist - non_existing_fields = [u'BK Gradient Shading', u'BK Gradient Variant', u'Favorite', u'Copyright'] - - # THEN: The importer object should not be None - for field_name in non_existing_fields: - self.assertRaises(IndexError, importer.findField, field_name) - - def set_record_struct_test(self): - """ - Test the :mod:`setRecordStruct` module - """ - # GIVEN: A mocked out SongImport class, a mocked out struct class, and a mocked out "manager" - with patch(u'openlp.plugins.songs.lib.ewimport.SongImport'), \ - patch(u'openlp.plugins.songs.lib.ewimport.struct') as mocked_struct: - mocked_manager = MagicMock() - importer = EasyWorshipSongImport(mocked_manager) - - # WHEN: Called with a list of field descriptions - - # THEN: setRecordStruct should return None and structStruct should be called with a value representing - # the list of field descriptions - self.assertIsNone(importer.setRecordStruct(TEST_FIELD_DESCS), u'setRecordStruct should return None') - mocked_struct.Struct.assert_called_with('>50sHIB250s250s10sQ') - - def get_field_test(self): - - - # GIVEN: A mocked out SongImport class, a mocked out "manager" - with patch(u'openlp.plugins.songs.lib.ewimport.SongImport'): - mocked_manager = MagicMock() - importer = EasyWorshipSongImport(mocked_manager) - importer.encoding = TEST_DATA_ENCODING - - # WHEN: Supplied with string with just NULL bytes, or an int with the value 0 - importer.fields = TEST_FIELDS - importer.fieldDescs = TEST_FIELD_DESCS - field_results = [(0, 'A Heart Like Thine'), (1, 100), (2, 102L), (3, True), (6, None), (7, None)] - - # THEN: getField should return None - for field_index, result in field_results: - self.assertEquals(importer.getField(field_index), result, - u'getField should return "%s" when called with "%s"' % (result, TEST_FIELDS[field_index])) - - def get_memo_field_test(self): - for test_results in GET_MEMO_FIELD_TEST_RESULTS: - # GIVEN: A mocked out SongImport class, a mocked out "manager" - with patch(u'openlp.plugins.songs.lib.ewimport.SongImport'): - mocked_manager = MagicMock() - mocked_memo_file = MagicMock() - importer = EasyWorshipSongImport(mocked_manager) - importer.encoding = TEST_DATA_ENCODING - importer.memoFile = mocked_memo_file - - # WHEN: Supplied with string with just NULL bytes, or an int with the value 0 - importer.fields = TEST_FIELDS - importer.fieldDescs = TEST_FIELD_DESCS - field_index = test_results[0] - mocked_memo_file.read.return_value = test_results[1] - get_field_result = test_results[2][u'return'] - get_field_read_calls = test_results[2][u'read'] - get_field_seek_calls = test_results[2][u'seek'] - - # THEN: getField should return None - self.assertEquals(importer.getField(field_index), get_field_result) - for call in get_field_read_calls: - mocked_memo_file.read.assert_any_call(call) - for call in get_field_seek_calls: - if isinstance(call, (int, long)): - mocked_memo_file.seek.assert_any_call(call) - else: - mocked_memo_file.seek.assert_any_call(call[0], call[1]) - -# TODO: Write doImport Tests \ No newline at end of file diff --git a/tests/resources/easyworshipsongs/Songs.DB b/tests/resources/easyworshipsongs/Songs.DB new file mode 100644 index 0000000000000000000000000000000000000000..8c9679b86a8bacecdd559011139959ccbd0c155a GIT binary patch literal 6144 zcmeH~O>7%Q6vyAj8>sU^%SWJmX39q?6e7nE2`Qn)Zkm1&l8}UOv5>~Qv-ZflJJx#K zkd_Ju39gk87bFlj=%FVN;);X>Ck~w90QiK&3Bdt`Wd5^uVml!y5|>KZ8U1$Oy!U2y z_U-fAwPVvEvImIB>huxFGr#^^nYq@iKzy2DY@wr_x=ugLG%Ifb8nK`lKWx-}?ae_9 z8O*T*{Wj&kJVD>sM4wxhb!^aF$uui#WoXm9}hqi?(n3XzZrj_IuAaEAO9bRz3nBgB##0@GbZr`~-dne}lo(&B{@5 z5}XDr;586{b?^?j20jFzfX~2};5+aO_!A7j(5#Gs6W|$e9=rl7U<14j-UT0k>);FU zHTV(y0n)iQuCB`}qGjP+n59+mx@JovazvrJ4OC9hkTi`*@(D>wPRpIDmuBD|71GR1MRnlTz`!W7+I ztC)4S{o_Gi`EDFQx}do)owgibKj+I*7~m<Pkd)vJhlQZ+e)4LLB zRaJNCmg9_C6QQdjhUBwQ{ZeGpAl*W@qEe=5h=yr|M(H*>Oh@Q;x`XbdyJ(E=rhDip z-Anh;{qz7mNDt9C%HT12m>!`==`lJ^kJAZyf}W(4^c1QpuQ^g4#GiO_&o^5H96J~A z%P4H79y(%Q+q zxWe-?=BRlwJN4|9f`{6wi#~)*!3(8d@SHM_YC>mN4z=H(z6#UiP7`XC%R@eW6;{W* zZ?Hrm5^knYii8L=g`!^1LfhSKab93zk|(h&~-Q z-+Y^REJ@ot0*!4`SK3w~sW%($X3zK_ikppAs}<)_d}s`Gda98^bmERo%L`uD(yROI z9FJTPvPF+AMSKIFHhZ+QzThEV!#UrF`-)SJl<%{P_;{(Y^Al`N`hKABxz%kAqBoKf zbCZ-9MsytiC6f}<&Ch?AkhPuGm9{iECnbjPmfBB==?PjQCJ{&?kVGJfKoWr@0{;<# Fe*n9TVl@B& literal 0 HcmV?d00001 diff --git a/tests/resources/easyworshipsongs/Songs.MB b/tests/resources/easyworshipsongs/Songs.MB new file mode 100644 index 0000000000000000000000000000000000000000..b46323005db269bea5b7531b572cd2244009c19f GIT binary patch literal 12288 zcmeHM!EWO=6jX95wq2l~@J>y)2m;$px>@AXv_Kp0rH2O1MHfnvf1WO=DkU>m+U2f+x_H4l6>jEzfY3Sk_}&P_BTw% zsmMTNATkgchzvvqA_I|u$UtNuG7uSv3`7P#1qSx_lDD5H@BnU79|Q`*Dx+pQy{bJ>W_N__YUFo1O=@Sne+F z+T;>4ENDbhb=Dg_QBybNA8!%L=?4Jd6S z6RJOs?8qNiPO%AV9pN~#oUnJ9dH!q{fb$9aOQ?z}!*Wiw?#OnWJ90HAt6NnZ?v8y~ zGe?$P^MV+4hP%8bDSqcP;b*&}j!7$o+A&K~TX#qqcu)wOO{nw{?+$$h%uFKvZ$Zao zIX{8`TM6EJ!~aT%V`Nu=%LC8FTtMe3cdV^yN0TYl948w&O(g~aN}j7?u>e3lmL;cLYG1VZ9(>8?Uv)m%}>4?uQ?y3n7e28{G0YH}69L|ddJn*vmm_4q&Q;=m$ZnXr8Kpz$XGwA^yD%+0D* zM<}djpF(>PV~h+$20mg2(Eoq+MeP5*2NC=K*#Dz7-EM5$@7iPkziI((?AmYLqz~2q z|5$5-B0InU_@yr!GY&UFl&z!+P6SuzInY4O$D~VN_f2_72f2BfTj-;Zn$nlnXiR@) z*Fqa&9TN^+ldrKaIO&F~d2L)V#{&xPOTCe*m1lT-n;<~wOW%Q@gl9`xQHF!J*W6+Q zp^x*dq0kTL9&T5FT?LD#Z|6O-Rs~u^E8!h5VFIN73Gxb91X6c^6|U|Tk$oeCU3!7V zU?^A)gDBuR`nJ~Z|MjeRQmI26p+}e68$x5M^jrkwUe@|!qtCe<9z}r0uUoh^=sMBs z8%3qjlU`RT8sv1RO<}zZa4t&x^Cdv#ao?1GSdD|6qQ_2WuQATgOn~vJZoMYnFM|I9 zfA~U7eD0Z$JX Date: Mon, 15 Apr 2013 21:30:32 +0100 Subject: [PATCH 08/40] some more tests --- .../openlp_plugins/songs/test_ewimport.py | 193 +++++++++--------- 1 file changed, 102 insertions(+), 91 deletions(-) diff --git a/tests/functional/openlp_plugins/songs/test_ewimport.py b/tests/functional/openlp_plugins/songs/test_ewimport.py index 644a898db..2155d63e9 100644 --- a/tests/functional/openlp_plugins/songs/test_ewimport.py +++ b/tests/functional/openlp_plugins/songs/test_ewimport.py @@ -7,49 +7,55 @@ This module contains tests for the EasyWorship song importer. import os from unittest import TestCase -from mock import call, patch, MagicMock +from mock import patch, MagicMock -from openlp.plugins.songs.lib import VerseType from openlp.plugins.songs.lib.ewimport import EasyWorshipSongImport, FieldDescEntry +class EasyWorshipSongImportLogger(EasyWorshipSongImport): + """ + This class logs changes in the title instance variable + """ + _title_assignment_list = [] + + def __init__(self, manager): + EasyWorshipSongImport.__init__(self, manager) + + @property + def title(self): + return self._title_assignment_list[-1] + + @title.setter + def title(self, title): + self._title_assignment_list.append(title) + TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), u'../../../resources/easyworshipsongs')) -SONG_TEST_DATA = [{u'title': u'Amazing Grace (Demonstration)', - u'authors': [u'John Newton', u'Edwin Excell', u'John P. Rees'], - u'copyright': u'Public Domain ', - u'ccli_number': 22025, +SONG_TEST_DATA = [{u'title': u'Amazing Grace', + u'authors': [u'John Newton'], + u'copyright': u'Public Domain', + u'ccli_number': 0, u'verses': - [(u'Amazing grace! How sweet the sound!\r\nThat saved a wretch like me!\r\n' - u'I once was lost, but now am found;\r\nWas blind, but now I see.', u'v1'), - (u'\'Twas grace that taught my heart to fear,\r\nAnd grace my fears relieved.\r\n' - u'How precious did that grace appear,\r\nThe hour I first believed.', u'v2'), - (u'The Lord has promised good to me,\r\nHis Word my hope secures.\r\n' - u'He will my shield and portion be\r\nAs long as life endures.', u'v3'), - (u'Thro\' many dangers, toils and snares\r\nI have already come.\r\n' - u'\'Tis grace that brought me safe thus far,\r\nAnd grace will lead me home.', u'v4'), - (u'When we\'ve been there ten thousand years,\r\nBright shining as the sun,\r\n' - u'We\'ve no less days to sing God\'s praise,\r\nThan when we first begun.', u'v5')], - u'topics': [u'Assurance', u'Grace', u'Praise', u'Salvation'], - u'comments': u'\n\n\n', - u'song_book_name': u'Demonstration Songs', - u'song_number': 0, + [(u'Amazing grace how sweet the sound,\nThat saved a wretch like me;\n' + u'I once was lost, but now am found\nWas blind, but now I see.', u'v1'), + (u'T\'was grace that taught my heart to fear,\nAnd grace my fears relieved;\n' + u'How precious did that grace appear\nThe hour I first believed.', u'v2'), + (u'Through many dangers, toil and snares,\nI have already come;\n' + u'\'Tis grace has brought me safe thus far,\nAnd grace will lead me home.', u'v3'), + (u'When we\'ve been there ten thousand years\nBright shining as the sun,\n' + u'We\'ve no less days to sing God\'s praise\nThan when we\'ve first begun.', u'v4')], u'verse_order_list': []}, - {u'title': u'Beautiful Garden Of Prayer (Demonstration)', - u'authors': [u'Eleanor Allen Schroll', u'James H. Fillmore'], - u'copyright': u'Public Domain ', - u'ccli_number': 60252, + {u'title': u'Beautiful Garden Of Prayer', + u'authors': [u'Eleanor Allen Schroll James H. Fillmore'], + u'copyright': u'Public Domain', + u'ccli_number': 0, u'verses': - [(u'There\'s a garden where Jesus is waiting,\r\nThere\'s a place that is wondrously fair.\r\n' - u'For it glows with the light of His presence,\r\n\'Tis the beautiful garden of prayer.', u'v1'), - (u'There\'s a garden where Jesus is waiting,\r\nAnd I go with my burden and care.\r\n' - u'Just to learn from His lips, words of comfort,\r\nIn the beautiful garden of prayer.', u'v2'), - (u'There\'s a garden where Jesus is waiting,\r\nAnd He bids you to come meet Him there,\r\n' - u'Just to bow and receive a new blessing,\r\nIn the beautiful garden of prayer.', u'v3'), - (u'O the beautiful garden, the garden of prayer,\r\nO the beautiful garden of prayer.\r\n' - u'There my Savior awaits, and He opens the gates\r\nTo the beautiful garden of prayer.', u'c1')], - u'topics': [u'Devotion', u'Prayer'], - u'comments': u'', - u'song_book_name': u'', - u'song_number': 0, + [(u'O the beautiful garden, the garden of prayer,\nO the beautiful garden of prayer.\n' + u'There my Savior awaits, and He opens the gates\nTo the beautiful garden of prayer.', u'c1'), + (u'There\'s a garden where Jesus is waiting,\nThere\'s a place that is wondrously fair.\n' + u'For it glows with the light of His presence,\n\'Tis the beautiful garden of prayer.', u'v1'), + (u'There\'s a garden where Jesus is waiting,\nAnd I go with my burden and care.\n' + u'Just to learn from His lips, words of comfort,\nIn the beautiful garden of prayer.', u'v2'), + (u'There\'s a garden where Jesus is waiting,\nAnd He bids you to come meet Him there,\n' + u'Just to bow and receive a new blessing,\nIn the beautiful garden of prayer.', u'v3')], u'verse_order_list': []}] @@ -236,14 +242,13 @@ class TestEasyWorshipSongImport(TestCase): mocked_os_path.isfile.assert_any_call(u'Songs.DB') mocked_os_path.isfile.assert_any_call(u'Songs.MB') - def do_import_source_validity_test(self): + def do_import_database_validity_test(self): """ - Test the :mod:`doImport` module + Test the :mod:`doImport` module handles invalid database files correctly """ # GIVEN: A mocked out SongImport class, a mocked out "manager" with patch(u'openlp.plugins.songs.lib.ewimport.SongImport'), \ - patch(u'openlp.plugins.songs.lib.ewimport.os.path') as mocked_os_path, \ - patch(u'__builtin__.open') as mocked_open: + patch(u'openlp.plugins.songs.lib.ewimport.os.path') as mocked_os_path: mocked_manager = MagicMock() importer = EasyWorshipSongImport(mocked_manager) mocked_os_path.isfile.return_value = True @@ -256,6 +261,32 @@ class TestEasyWorshipSongImport(TestCase): self.assertIsNone(importer.doImport(), u'doImport should return None when db_size is less than 0x800') mocked_os_path.getsize.assert_any_call(u'Songs.DB') + def do_import_memo_validty_test(self): + """ + Test the :mod:`doImport` module handles invalid memo files correctly + """ + # GIVEN: A mocked out SongImport class, a mocked out "manager" + with patch(u'openlp.plugins.songs.lib.ewimport.SongImport'), \ + patch(u'openlp.plugins.songs.lib.ewimport.os.path') as mocked_os_path, \ + patch(u'__builtin__.open') as mocked_open, \ + patch(u'openlp.plugins.songs.lib.ewimport.struct') as mocked_struct: + mocked_manager = MagicMock() + importer = EasyWorshipSongImport(mocked_manager) + mocked_os_path.isfile.return_value = True + mocked_os_path.getsize.return_value = 0x800 + importer.import_source = u'Songs.DB' + + # WHEN: Unpacking first 35 bytes of Memo file + struct_unpack_return_values = [(0, 0x700, 2, 0, 0), (0, 0x800, 0, 0, 0), (0, 0x800, 5, 0, 0)] + mocked_struct.unpack.side_effect = struct_unpack_return_values + + # THEN: doImport should return None having called closed the open files db and memo files. + for effect in struct_unpack_return_values: + self.assertIsNone(importer.doImport(), u'doImport should return None when db_size is less than 0x800') + self.assertEqual(mocked_open().close.call_count, 2, + u'The open db and memo files should have been closed') + mocked_open().close.reset_mock() + self.assertIs(mocked_open().seek.called, False, u'db_file.seek should not have been called.') def file_import_test(self): """ @@ -264,70 +295,50 @@ class TestEasyWorshipSongImport(TestCase): # 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(u'openlp.plugins.songs.lib.songshowplusimport.SongImport'): + with patch(u'openlp.plugins.songs.lib.ewimport.SongImport'), \ + patch(u'openlp.plugins.songs.lib.ewimport.retrieve_windows_encoding') as mocked_retrieve_windows_encoding: + mocked_retrieve_windows_encoding.return_value = u'cp1252' mocked_manager = MagicMock() mocked_import_wizard = MagicMock() - mocked_parse_author = MagicMock() - mocked_add_copyright = MagicMock() + mocked_add_author = MagicMock() mocked_add_verse = MagicMock() mocked_finish = MagicMock() + mocked_title = MagicMock() mocked_finish.return_value = True - importer = EasyWorshipSongImport(mocked_manager) + importer = EasyWorshipSongImportLogger(mocked_manager) importer.import_wizard = mocked_import_wizard importer.stop_import_flag = False - importer.parse_author = mocked_parse_author - importer.addCopyright = mocked_add_copyright + importer.addAuthor = mocked_add_author importer.addVerse = mocked_add_verse + importer.title = mocked_title importer.finish = mocked_finish importer.topics = [] # WHEN: Importing each file - importer.import_source = [os.path.join(TEST_PATH, u'Songs.DB')] - title = SONG_TEST_DATA[song_file][u'title'] - author_calls = SONG_TEST_DATA[song_file][u'authors'] - song_copyright = SONG_TEST_DATA[song_file][u'copyright'] - ccli_number = SONG_TEST_DATA[song_file][u'ccli_number'] - add_verse_calls = SONG_TEST_DATA[song_file][u'verses'] - topics = SONG_TEST_DATA[song_file][u'topics'] - comments = SONG_TEST_DATA[song_file][u'comments'] - song_book_name = SONG_TEST_DATA[song_file][u'song_book_name'] - song_number = SONG_TEST_DATA[song_file][u'song_number'] - verse_order_list = SONG_TEST_DATA[song_file][u'verse_order_list'] + importer.import_source = os.path.join(TEST_PATH, u'Songs.DB') # THEN: doImport should return none, the song data should be as expected, and finish should have been # called. self.assertIsNone(importer.doImport(), u'doImport should return None when it has completed') - self.assertEquals(importer.title, title, u'title for %s should be "%s"' % (song_file, title)) - for author in author_calls: - mocked_parse_author.assert_any_call(author) - if song_copyright: - mocked_add_copyright.assert_called_with(song_copyright) - if ccli_number: - self.assertEquals(importer.ccliNumber, ccli_number, u'ccliNumber for %s should be %s' - % (song_file, ccli_number)) - for verse_text, verse_tag in add_verse_calls: - mocked_add_verse.assert_any_call(verse_text, verse_tag) - if topics: - self.assertEquals(importer.topics, topics, u'topics for %s should be %s' % (song_file, topics)) - if comments: - self.assertEquals(importer.comments, comments, u'comments for %s should be "%s"' - % (song_file, comments)) - if song_book_name: - self.assertEquals(importer.songBookName, song_book_name, u'songBookName for %s should be "%s"' - % (song_file, song_book_name)) - if song_number: - self.assertEquals(importer.songNumber, song_number, u'songNumber for %s should be %s' - % (song_file, song_number)) - if verse_order_list: - self.assertEquals(importer.verseOrderList, [], u'verseOrderList for %s should be %s' - % (song_file, verse_order_list)) - mocked_finish.assert_called_with() - - # Open the DB and MB files if they exist - # import_source_mb = self.import_source.replace('.DB', '.MB') - # if not (os.path.isfile(self.import_source) or os.path.isfile(import_source_mb)): - # return - # db_size = os.path.getsize(self.import_source) - # if db_size < 0x800: - # return - # TODO: Write doImport Tests \ No newline at end of file + for song_data in SONG_TEST_DATA: + print mocked_title.mocked_calls() + title = song_data[u'title'] + author_calls = song_data[u'authors'] + song_copyright = song_data[u'copyright'] + ccli_number = song_data[u'ccli_number'] + add_verse_calls = song_data[u'verses'] + verse_order_list = song_data[u'verse_order_list'] + self.assertIn(title, importer._title_assignment_list, u'title for %s should be "%s"' % (title, title)) + for author in author_calls: + mocked_add_author.assert_any_call(author) + if song_copyright: + self.assertEqual(importer.copyright, song_copyright) + if ccli_number: + self.assertEquals(importer.ccliNumber, ccli_number, u'ccliNumber for %s should be %s' + % (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.assertEquals(importer.verseOrderList, verse_order_list, u'verseOrderList for %s should be %s' + % (title, verse_order_list)) + mocked_finish.assert_called_with() From cc1d3b3c5b3cf0353eead2fc09e8c8f5136553e1 Mon Sep 17 00:00:00 2001 From: phill-ridout Date: Tue, 16 Apr 2013 18:06:42 +0100 Subject: [PATCH 09/40] finished tests --- .../openlp_plugins/songs/test_ewimport.py | 51 ++++++++++++++----- 1 file changed, 38 insertions(+), 13 deletions(-) diff --git a/tests/functional/openlp_plugins/songs/test_ewimport.py b/tests/functional/openlp_plugins/songs/test_ewimport.py index 2155d63e9..ab72230ff 100644 --- a/tests/functional/openlp_plugins/songs/test_ewimport.py +++ b/tests/functional/openlp_plugins/songs/test_ewimport.py @@ -28,6 +28,12 @@ class EasyWorshipSongImportLogger(EasyWorshipSongImport): def title(self, title): self._title_assignment_list.append(title) +class TestFieldDesc: + def __init__(self, name, field_type, size): + self.name = name + self.type = field_type + self.size = size + TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), u'../../../resources/easyworshipsongs')) SONG_TEST_DATA = [{u'title': u'Amazing Grace', u'authors': [u'John Newton'], @@ -57,15 +63,9 @@ SONG_TEST_DATA = [{u'title': u'Amazing Grace', (u'There\'s a garden where Jesus is waiting,\nAnd He bids you to come meet Him there,\n' u'Just to bow and receive a new blessing,\nIn the beautiful garden of prayer.', u'v3')], u'verse_order_list': []}] - - -class TestFieldDesc: - def __init__(self, name, field_type, size): - self.name = name - self.type = field_type - self.size = size - TEST_DATA_ENCODING = u'cp1252' +CODE_PAGE_MAPPINGS = [(852, u'cp1250'), (737, u'cp1253'), (775, u'cp1257'), (855, u'cp1251'), (857, u'cp1254'), + (866, u'cp1251'), (869, u'cp1253'), (862, u'cp1255'), (874, u'cp874')] TEST_FIELD_DESCS = [TestFieldDesc(u'Title', 1, 50), TestFieldDesc(u'Text Percentage Bottom', 3, 2), TestFieldDesc(u'RecID', 4, 4), TestFieldDesc(u'Default Background', 9, 1), TestFieldDesc(u'Words', 12, 250), TestFieldDesc(u'Words', 12, 250), TestFieldDesc(u'BK Bitmap', 13, 10), TestFieldDesc(u'Last Modified', 21, 10)] @@ -137,7 +137,7 @@ class TestEasyWorshipSongImport(TestCase): for field_name in existing_fields: self.assertEquals(importer.fieldDescs[importer.findField(field_name)].name, field_name) - def find_field_non_exists_test(self): + def find_non_existing_field_test(self): """ Test finding an non-existing field in a given list using the :mod:`findField` """ @@ -181,12 +181,12 @@ class TestEasyWorshipSongImport(TestCase): importer = EasyWorshipSongImport(mocked_manager) importer.encoding = TEST_DATA_ENCODING - # WHEN: Supplied with string with just NULL bytes, or an int with the value 0 + # WHEN: Supplied with some test data and known results importer.fields = TEST_FIELDS importer.fieldDescs = TEST_FIELD_DESCS field_results = [(0, 'A Heart Like Thine'), (1, 100), (2, 102L), (3, True), (6, None), (7, None)] - # THEN: getField should return None + # THEN: getField should return the known results for field_index, result in field_results: self.assertEquals(importer.getField(field_index), result, u'getField should return "%s" when called with "%s"' % (result, TEST_FIELDS[field_index])) @@ -225,7 +225,7 @@ class TestEasyWorshipSongImport(TestCase): def do_import_source_test(self): """ - Test the :mod:`doImport` module + Test the :mod:`doImport` module opens the correct files """ # GIVEN: A mocked out SongImport class, a mocked out "manager" with patch(u'openlp.plugins.songs.lib.ewimport.SongImport'), \ @@ -246,7 +246,7 @@ class TestEasyWorshipSongImport(TestCase): """ Test the :mod:`doImport` module handles invalid database files correctly """ - # GIVEN: A mocked out SongImport class, a mocked out "manager" + # GIVEN: A mocked out SongImport class, os.path and a mocked out "manager" with patch(u'openlp.plugins.songs.lib.ewimport.SongImport'), \ patch(u'openlp.plugins.songs.lib.ewimport.os.path') as mocked_os_path: mocked_manager = MagicMock() @@ -288,6 +288,31 @@ class TestEasyWorshipSongImport(TestCase): mocked_open().close.reset_mock() self.assertIs(mocked_open().seek.called, False, u'db_file.seek should not have been called.') + def code_page_to_encoding_test(self): + """ + Test the :mod:`doImport` converts the code page to the encoding correctly + """ + # GIVEN: A mocked out SongImport class, a mocked out "manager" + with patch(u'openlp.plugins.songs.lib.ewimport.SongImport'), \ + patch(u'openlp.plugins.songs.lib.ewimport.os.path') as mocked_os_path, \ + patch(u'__builtin__.open'), patch(u'openlp.plugins.songs.lib.ewimport.struct') as mocked_struct, \ + patch(u'openlp.plugins.songs.lib.ewimport.retrieve_windows_encoding') as mocked_retrieve_windows_encoding: + mocked_manager = MagicMock() + importer = EasyWorshipSongImport(mocked_manager) + mocked_os_path.isfile.return_value = True + mocked_os_path.getsize.return_value = 0x800 + importer.import_source = u'Songs.DB' + + # WHEN: Unpacking the code page + for code_page, encoding in CODE_PAGE_MAPPINGS: + struct_unpack_return_values = [(0, 0x800, 2, 0, 0), (code_page, )] + mocked_struct.unpack.side_effect = struct_unpack_return_values + mocked_retrieve_windows_encoding.return_value = False + + # THEN: doImport should return None having called retrieve_windows_encoding with the correct encoding. + self.assertIsNone(importer.doImport(), u'doImport should return None when db_size is less than 0x800') + mocked_retrieve_windows_encoding.assert_call(encoding) + def file_import_test(self): """ Test the actual import of real song files and check that the imported data is correct. From 09955c0ca2814e941eff285d220739232c3ae949 Mon Sep 17 00:00:00 2001 From: phill-ridout Date: Wed, 17 Apr 2013 22:10:19 +0100 Subject: [PATCH 10/40] Moved constants. --- .../openlp_plugins/songs/test_ewimport.py | 47 ++++++++++--------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/tests/functional/openlp_plugins/songs/test_ewimport.py b/tests/functional/openlp_plugins/songs/test_ewimport.py index ab72230ff..3c91e3d7a 100644 --- a/tests/functional/openlp_plugins/songs/test_ewimport.py +++ b/tests/functional/openlp_plugins/songs/test_ewimport.py @@ -11,29 +11,6 @@ from mock import patch, MagicMock from openlp.plugins.songs.lib.ewimport import EasyWorshipSongImport, FieldDescEntry -class EasyWorshipSongImportLogger(EasyWorshipSongImport): - """ - This class logs changes in the title instance variable - """ - _title_assignment_list = [] - - def __init__(self, manager): - EasyWorshipSongImport.__init__(self, manager) - - @property - def title(self): - return self._title_assignment_list[-1] - - @title.setter - def title(self, title): - self._title_assignment_list.append(title) - -class TestFieldDesc: - def __init__(self, name, field_type, size): - self.name = name - self.type = field_type - self.size = size - TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), u'../../../resources/easyworshipsongs')) SONG_TEST_DATA = [{u'title': u'Amazing Grace', u'authors': [u'John Newton'], @@ -63,6 +40,30 @@ SONG_TEST_DATA = [{u'title': u'Amazing Grace', (u'There\'s a garden where Jesus is waiting,\nAnd He bids you to come meet Him there,\n' u'Just to bow and receive a new blessing,\nIn the beautiful garden of prayer.', u'v3')], u'verse_order_list': []}] + +class EasyWorshipSongImportLogger(EasyWorshipSongImport): + """ + This class logs changes in the title instance variable + """ + _title_assignment_list = [] + + def __init__(self, manager): + EasyWorshipSongImport.__init__(self, manager) + + @property + def title(self): + return self._title_assignment_list[-1] + + @title.setter + def title(self, title): + self._title_assignment_list.append(title) + +class TestFieldDesc: + def __init__(self, name, field_type, size): + self.name = name + self.type = field_type + self.size = size + TEST_DATA_ENCODING = u'cp1252' CODE_PAGE_MAPPINGS = [(852, u'cp1250'), (737, u'cp1253'), (775, u'cp1257'), (855, u'cp1251'), (857, u'cp1254'), (866, u'cp1251'), (869, u'cp1253'), (862, u'cp1255'), (874, u'cp874')] From 774cf24bfddb7726c4801627c93d69b9e4f774f5 Mon Sep 17 00:00:00 2001 From: phill-ridout Date: Sun, 21 Apr 2013 20:15:49 +0100 Subject: [PATCH 11/40] renamed type attribute --- openlp/plugins/songs/lib/ewimport.py | 26 +++++++++---------- .../openlp_plugins/songs/test_ewimport.py | 4 +-- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/openlp/plugins/songs/lib/ewimport.py b/openlp/plugins/songs/lib/ewimport.py index 4f8d7d970..287310cb3 100644 --- a/openlp/plugins/songs/lib/ewimport.py +++ b/openlp/plugins/songs/lib/ewimport.py @@ -50,7 +50,7 @@ NOTE_REGEX = re.compile(r'\(.*?\)') class FieldDescEntry: def __init__(self, name, field_type, size): self.name = name - self.type = field_type + self.field_type = field_type self.size = size @@ -231,25 +231,25 @@ class EasyWorshipSongImport(SongImport): # Begin with empty field struct list fsl = ['>'] for field_desc in field_descs: - if field_desc.type == 1: + if field_desc.field_type == 1: # string fsl.append('%ds' % field_desc.size) - elif field_desc.type == 3: + elif field_desc.field_type == 3: # 16-bit int fsl.append('H') - elif field_desc.type == 4: + elif field_desc.field_type == 4: # 32-bit int fsl.append('I') - elif field_desc.type == 9: + elif field_desc.field_type == 9: # Logical fsl.append('B') - elif field_desc.type == 0x0c: + elif field_desc.field_type == 0x0c: # Memo fsl.append('%ds' % field_desc.size) - elif field_desc.type == 0x0d: + elif field_desc.field_type == 0x0d: # Blob fsl.append('%ds' % field_desc.size) - elif field_desc.type == 0x15: + elif field_desc.field_type == 0x15: # Timestamp fsl.append('Q') else: @@ -267,19 +267,19 @@ class EasyWorshipSongImport(SongImport): elif field == 0: return None # Format the field depending on the field type - if field_desc.type == 1: + if field_desc.field_type == 1: # string return field.rstrip('\0').decode(self.encoding) - elif field_desc.type == 3: + elif field_desc.field_type == 3: # 16-bit int return field ^ 0x8000 - elif field_desc.type == 4: + elif field_desc.field_type == 4: # 32-bit int return field ^ 0x80000000 - elif field_desc.type == 9: + elif field_desc.field_type == 9: # Logical return (field ^ 0x80 == 1) - elif field_desc.type == 0x0c or field_desc.type == 0x0d: + elif field_desc.field_type == 0x0c or field_desc.field_type == 0x0d: # Memo or Blob block_start, blob_size = struct.unpack_from(' Date: Sun, 23 Jun 2013 07:14:03 +0100 Subject: [PATCH 12/40] HEAD --- .../openlp_plugins/songs/test_ewimport.py | 35 ++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/tests/functional/openlp_plugins/songs/test_ewimport.py b/tests/functional/openlp_plugins/songs/test_ewimport.py index 48caa7574..fc134e008 100644 --- a/tests/functional/openlp_plugins/songs/test_ewimport.py +++ b/tests/functional/openlp_plugins/songs/test_ewimport.py @@ -124,18 +124,18 @@ class TestEasyWorshipSongImport(TestCase): """ Test finding an existing field in a given list using the :mod:`findField` """ - # GIVEN: A mocked out SongImport class, a mocked out "manager" and a list of field descriptions + # GIVEN: A mocked out SongImport class, a mocked out "manager" and a list of field descriptions. with patch(u'openlp.plugins.songs.lib.ewimport.SongImport'): mocked_manager = MagicMock() importer = EasyWorshipSongImport(mocked_manager) importer.fieldDescs = TEST_FIELD_DESCS - # WHEN: Given a field name that exists + # WHEN: Called with a field name that exists existing_fields = [u'Title', u'Text Percentage Bottom', u'RecID', u'Default Background', u'Words', u'BK Bitmap', u'Last Modified'] - - # THEN: The item corresponding the index returned should have the same name attribute for field_name in existing_fields: + + # THEN: The item corresponding the index returned should have the same name attribute self.assertEquals(importer.fieldDescs[importer.findField(field_name)].name, field_name) def find_non_existing_field_test(self): @@ -148,48 +148,51 @@ class TestEasyWorshipSongImport(TestCase): importer = EasyWorshipSongImport(mocked_manager) importer.fieldDescs = TEST_FIELD_DESCS - # WHEN: Given a field name that does not exist + # WHEN: Called with a field name that does not exist non_existing_fields = [u'BK Gradient Shading', u'BK Gradient Variant', u'Favorite', u'Copyright'] - - # THEN: The importer object should not be None for field_name in non_existing_fields: + + # THEN: The importer object should not be None self.assertRaises(IndexError, importer.findField, field_name) def set_record_struct_test(self): """ Test the :mod:`setRecordStruct` module """ - # GIVEN: A mocked out SongImport class, a mocked out struct class, and a mocked out "manager" + # GIVEN: A mocked out SongImport class, a mocked out struct class, and a mocked out "manager" and a list of + # field descriptions with patch(u'openlp.plugins.songs.lib.ewimport.SongImport'), \ patch(u'openlp.plugins.songs.lib.ewimport.struct') as mocked_struct: mocked_manager = MagicMock() importer = EasyWorshipSongImport(mocked_manager) - # WHEN: Called with a list of field descriptions + # WHEN: setRecordStruct is called with a list of field descriptions + return_value = importer.setRecordStruct(TEST_FIELD_DESCS) - # THEN: setRecordStruct should return None and structStruct should be called with a value representing + # THEN: setRecordStruct should return None and Struct should be called with a value representing # the list of field descriptions - self.assertIsNone(importer.setRecordStruct(TEST_FIELD_DESCS), u'setRecordStruct should return None') + self.assertIsNone(return_value, u'setRecordStruct should return None') mocked_struct.Struct.assert_called_with('>50sHIB250s250s10sQ') def get_field_test(self): """ Test the :mod:`getField` module """ - # GIVEN: A mocked out SongImport class, a mocked out "manager" and an encoding + # GIVEN: A mocked out SongImport class, a mocked out "manager", an encoding and some test data and known results with patch(u'openlp.plugins.songs.lib.ewimport.SongImport'): mocked_manager = MagicMock() importer = EasyWorshipSongImport(mocked_manager) importer.encoding = TEST_DATA_ENCODING - - # WHEN: Supplied with some test data and known results importer.fields = TEST_FIELDS importer.fieldDescs = TEST_FIELD_DESCS field_results = [(0, 'A Heart Like Thine'), (1, 100), (2, 102L), (3, True), (6, None), (7, None)] - # THEN: getField should return the known results + # WHEN: Called with test data for field_index, result in field_results: - self.assertEquals(importer.getField(field_index), result, + return_value = importer.getField(field_index) + + # THEN: getField should return the known results + self.assertEquals(return_value, result, u'getField should return "%s" when called with "%s"' % (result, TEST_FIELDS[field_index])) def get_memo_field_test(self): From 6fabfef7d8dba10ed9888465c249144231da0135 Mon Sep 17 00:00:00 2001 From: phill-ridout Date: Thu, 27 Jun 2013 09:36:00 +0100 Subject: [PATCH 13/40] Made changes as suggested in previous merger comments --- .../openlp_plugins/songs/test_ewimport.py | 57 ++++++++++--------- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/tests/functional/openlp_plugins/songs/test_ewimport.py b/tests/functional/openlp_plugins/songs/test_ewimport.py index fc134e008..b0669e560 100644 --- a/tests/functional/openlp_plugins/songs/test_ewimport.py +++ b/tests/functional/openlp_plugins/songs/test_ewimport.py @@ -12,34 +12,35 @@ from mock import patch, MagicMock from openlp.plugins.songs.lib.ewimport import EasyWorshipSongImport, FieldDescEntry TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), u'../../../resources/easyworshipsongs')) -SONG_TEST_DATA = [{u'title': u'Amazing Grace', - u'authors': [u'John Newton'], - u'copyright': u'Public Domain', - u'ccli_number': 0, - u'verses': - [(u'Amazing grace how sweet the sound,\nThat saved a wretch like me;\n' - u'I once was lost, but now am found\nWas blind, but now I see.', u'v1'), - (u'T\'was grace that taught my heart to fear,\nAnd grace my fears relieved;\n' - u'How precious did that grace appear\nThe hour I first believed.', u'v2'), - (u'Through many dangers, toil and snares,\nI have already come;\n' - u'\'Tis grace has brought me safe thus far,\nAnd grace will lead me home.', u'v3'), - (u'When we\'ve been there ten thousand years\nBright shining as the sun,\n' - u'We\'ve no less days to sing God\'s praise\nThan when we\'ve first begun.', u'v4')], - u'verse_order_list': []}, - {u'title': u'Beautiful Garden Of Prayer', - u'authors': [u'Eleanor Allen Schroll James H. Fillmore'], - u'copyright': u'Public Domain', - u'ccli_number': 0, - u'verses': - [(u'O the beautiful garden, the garden of prayer,\nO the beautiful garden of prayer.\n' - u'There my Savior awaits, and He opens the gates\nTo the beautiful garden of prayer.', u'c1'), - (u'There\'s a garden where Jesus is waiting,\nThere\'s a place that is wondrously fair.\n' - u'For it glows with the light of His presence,\n\'Tis the beautiful garden of prayer.', u'v1'), - (u'There\'s a garden where Jesus is waiting,\nAnd I go with my burden and care.\n' - u'Just to learn from His lips, words of comfort,\nIn the beautiful garden of prayer.', u'v2'), - (u'There\'s a garden where Jesus is waiting,\nAnd He bids you to come meet Him there,\n' - u'Just to bow and receive a new blessing,\nIn the beautiful garden of prayer.', u'v3')], - u'verse_order_list': []}] +SONG_TEST_DATA = [ + {u'title': u'Amazing Grace', + u'authors': [u'John Newton'], + u'copyright': u'Public Domain', + u'ccli_number': 0, + u'verses': + [(u'Amazing grace how sweet the sound,\nThat saved a wretch like me;\n' + u'I once was lost, but now am found\nWas blind, but now I see.', u'v1'), + (u'T\'was grace that taught my heart to fear,\nAnd grace my fears relieved;\n' + u'How precious did that grace appear\nThe hour I first believed.', u'v2'), + (u'Through many dangers, toil and snares,\nI have already come;\n' + u'\'Tis grace has brought me safe thus far,\nAnd grace will lead me home.', u'v3'), + (u'When we\'ve been there ten thousand years\nBright shining as the sun,\n' + u'We\'ve no less days to sing God\'s praise\nThan when we\'ve first begun.', u'v4')], + u'verse_order_list': []}, + {u'title': u'Beautiful Garden Of Prayer', + u'authors': [u'Eleanor Allen Schroll James H. Fillmore'], + u'copyright': u'Public Domain', + u'ccli_number': 0, + u'verses': + [(u'O the beautiful garden, the garden of prayer,\nO the beautiful garden of prayer.\n' + u'There my Savior awaits, and He opens the gates\nTo the beautiful garden of prayer.', u'c1'), + (u'There\'s a garden where Jesus is waiting,\nThere\'s a place that is wondrously fair.\n' + u'For it glows with the light of His presence,\n\'Tis the beautiful garden of prayer.', u'v1'), + (u'There\'s a garden where Jesus is waiting,\nAnd I go with my burden and care.\n' + u'Just to learn from His lips, words of comfort,\nIn the beautiful garden of prayer.', u'v2'), + (u'There\'s a garden where Jesus is waiting,\nAnd He bids you to come meet Him there,\n' + u'Just to bow and receive a new blessing,\nIn the beautiful garden of prayer.', u'v3')], + u'verse_order_list': []}] class EasyWorshipSongImportLogger(EasyWorshipSongImport): """ From e9c56b6cc53cf60f0552d2cf2cef27b59471bdad Mon Sep 17 00:00:00 2001 From: phill-ridout Date: Fri, 28 Jun 2013 22:16:44 +0100 Subject: [PATCH 14/40] Corrected if statment and added enumeration class. --- openlp/plugins/songs/lib/ewimport.py | 51 ++++++++++--------- .../openlp_plugins/songs/test_ewimport.py | 12 +++-- 2 files changed, 33 insertions(+), 30 deletions(-) diff --git a/openlp/plugins/songs/lib/ewimport.py b/openlp/plugins/songs/lib/ewimport.py index 287310cb3..2f7681b7e 100644 --- a/openlp/plugins/songs/lib/ewimport.py +++ b/openlp/plugins/songs/lib/ewimport.py @@ -54,6 +54,19 @@ class FieldDescEntry: self.size = size +class FieldType(object): + """ + An enumeration class for different field types that can be expected in an EasyWorship song file. + """ + String = 1 + Int16 = 3 + Int32 = 4 + Logical = 9 + Memo = 0x0c + Blob = 0x0d + Timestamp = 0x15 + + class EasyWorshipSongImport(SongImport): """ The :class:`EasyWorshipSongImport` class provides OpenLP with the @@ -65,7 +78,7 @@ class EasyWorshipSongImport(SongImport): def doImport(self): # Open the DB and MB files if they exist import_source_mb = self.import_source.replace('.DB', '.MB') - if not (os.path.isfile(self.import_source) or os.path.isfile(import_source_mb)): + if not (os.path.isfile(self.import_source) or not os.path.isfile(import_source_mb)): return db_size = os.path.getsize(self.import_source) if db_size < 0x800: @@ -231,26 +244,19 @@ class EasyWorshipSongImport(SongImport): # Begin with empty field struct list fsl = ['>'] for field_desc in field_descs: - if field_desc.field_type == 1: - # string + if field_desc.field_type == FieldType.String: fsl.append('%ds' % field_desc.size) - elif field_desc.field_type == 3: - # 16-bit int + elif field_desc.field_type == FieldType.Int16: fsl.append('H') - elif field_desc.field_type == 4: - # 32-bit int + elif field_desc.field_type == FieldType.Int32: fsl.append('I') - elif field_desc.field_type == 9: - # Logical + elif field_desc.field_type == FieldType.Logical: fsl.append('B') - elif field_desc.field_type == 0x0c: - # Memo + elif field_desc.field_type == FieldType.Memo: fsl.append('%ds' % field_desc.size) - elif field_desc.field_type == 0x0d: - # Blob + elif field_desc.field_type == FieldType.Blob: fsl.append('%ds' % field_desc.size) - elif field_desc.field_type == 0x15: - # Timestamp + elif field_desc.field_type == FieldType.Timestamp: fsl.append('Q') else: fsl.append('%ds' % field_desc.size) @@ -267,20 +273,15 @@ class EasyWorshipSongImport(SongImport): elif field == 0: return None # Format the field depending on the field type - if field_desc.field_type == 1: - # string + if field_desc.field_type == FieldType.String: return field.rstrip('\0').decode(self.encoding) - elif field_desc.field_type == 3: - # 16-bit int + elif field_desc.field_type == FieldType.Int16: return field ^ 0x8000 - elif field_desc.field_type == 4: - # 32-bit int + elif field_desc.field_type == FieldType.Int32: return field ^ 0x80000000 - elif field_desc.field_type == 9: - # Logical + elif field_desc.field_type == FieldType.Logical: return (field ^ 0x80 == 1) - elif field_desc.field_type == 0x0c or field_desc.field_type == 0x0d: - # Memo or Blob + elif field_desc.field_type == FieldType.Memo or field_desc.field_type == FieldType.Blob: block_start, blob_size = struct.unpack_from(' Date: Tue, 2 Jul 2013 22:10:28 +0100 Subject: [PATCH 15/40] changed test path to be "more" compatable with other os's --- tests/functional/openlp_plugins/songs/test_ewimport.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/functional/openlp_plugins/songs/test_ewimport.py b/tests/functional/openlp_plugins/songs/test_ewimport.py index 34a4b21b4..2190a7cfd 100644 --- a/tests/functional/openlp_plugins/songs/test_ewimport.py +++ b/tests/functional/openlp_plugins/songs/test_ewimport.py @@ -11,7 +11,8 @@ from mock import patch, MagicMock from openlp.plugins.songs.lib.ewimport import EasyWorshipSongImport, FieldDescEntry, FieldType -TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), u'../../../resources/easyworshipsongs')) +TEST_PATH = os.path.abspath( + os.path.join(os.path.dirname(__file__), u'..', u'..', u'..', u'resources', u'easyworshipsongs')) SONG_TEST_DATA = [ {u'title': u'Amazing Grace', u'authors': [u'John Newton'], From d1b2cd67c98046bb08c3f46fe0feed345e0ef9b9 Mon Sep 17 00:00:00 2001 From: phill-ridout Date: Sat, 6 Jul 2013 15:40:49 +0100 Subject: [PATCH 16/40] Fixed if statment logic. Fixed test --- openlp/plugins/songs/lib/ewimport.py | 2 +- tests/functional/openlp_plugins/songs/test_ewimport.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/openlp/plugins/songs/lib/ewimport.py b/openlp/plugins/songs/lib/ewimport.py index 2f7681b7e..b548b32e2 100644 --- a/openlp/plugins/songs/lib/ewimport.py +++ b/openlp/plugins/songs/lib/ewimport.py @@ -78,7 +78,7 @@ class EasyWorshipSongImport(SongImport): def doImport(self): # Open the DB and MB files if they exist import_source_mb = self.import_source.replace('.DB', '.MB') - if not (os.path.isfile(self.import_source) or not os.path.isfile(import_source_mb)): + if not os.path.isfile(self.import_source) or not os.path.isfile(import_source_mb): return db_size = os.path.getsize(self.import_source) if db_size < 0x800: diff --git a/tests/functional/openlp_plugins/songs/test_ewimport.py b/tests/functional/openlp_plugins/songs/test_ewimport.py index 2190a7cfd..0e6956461 100644 --- a/tests/functional/openlp_plugins/songs/test_ewimport.py +++ b/tests/functional/openlp_plugins/songs/test_ewimport.py @@ -240,7 +240,7 @@ class TestEasyWorshipSongImport(TestCase): patch(u'openlp.plugins.songs.lib.ewimport.os.path') as mocked_os_path: mocked_manager = MagicMock() importer = EasyWorshipSongImport(mocked_manager) - mocked_os_path.isfile.return_value = False + mocked_os_path.isfile.side_effect = [True, False] # WHEN: Supplied with an import source importer.import_source = u'Songs.DB' From 51ab25b716d87058dc4223a4bb182dcb7d5d0b84 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Thu, 11 Jul 2013 21:54:30 +0100 Subject: [PATCH 17/40] Fix the constraints to be > 1 Fixes: https://launchpad.net/bugs/1196926 --- openlp/core/ui/generaltab.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openlp/core/ui/generaltab.py b/openlp/core/ui/generaltab.py index 49497a10e..7fe7beaca 100644 --- a/openlp/core/ui/generaltab.py +++ b/openlp/core/ui/generaltab.py @@ -93,14 +93,14 @@ class GeneralTab(SettingsTab): self.monitor_layout.addWidget(self.custom_width_label, 3, 3) self.custom_width_value_edit = QtGui.QSpinBox(self.monitor_group_box) self.custom_width_value_edit.setObjectName(u'custom_width_value_edit') - self.custom_width_value_edit.setMaximum(9999) + self.custom_width_value_edit.setRange(1, 9999) self.monitor_layout.addWidget(self.custom_width_value_edit, 4, 3) self.custom_height_label = QtGui.QLabel(self.monitor_group_box) self.custom_height_label.setObjectName(u'custom_height_label') self.monitor_layout.addWidget(self.custom_height_label, 3, 4) self.custom_height_value_edit = QtGui.QSpinBox(self.monitor_group_box) self.custom_height_value_edit.setObjectName(u'custom_height_value_edit') - self.custom_height_value_edit.setMaximum(9999) + self.custom_height_value_edit.setRange(1, 9999) self.monitor_layout.addWidget(self.custom_height_value_edit, 4, 4) self.display_on_monitor_check = QtGui.QCheckBox(self.monitor_group_box) self.display_on_monitor_check.setObjectName(u'monitor_combo_box') From 6062605622aa44b6b4a5261ad44fc40e892e8bef Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Thu, 11 Jul 2013 21:58:15 +0100 Subject: [PATCH 18/40] make sure we have the image file for theme backgrounds Fixes: https://launchpad.net/bugs/1197376 --- openlp/core/ui/themeform.py | 4 ++-- openlp/core/utils/__init__.py | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/openlp/core/ui/themeform.py b/openlp/core/ui/themeform.py index 68d8cc216..007932f6e 100644 --- a/openlp/core/ui/themeform.py +++ b/openlp/core/ui/themeform.py @@ -38,7 +38,7 @@ from openlp.core.lib import UiStrings, Registry, translate from openlp.core.lib.theme import BackgroundType, BackgroundGradientType from openlp.core.lib.ui import critical_error_message_box from openlp.core.ui import ThemeLayoutForm -from openlp.core.utils import get_images_filter +from openlp.core.utils import get_images_filter, is_not_image_file from themewizard import Ui_ThemeWizard log = logging.getLogger(__name__) @@ -178,7 +178,7 @@ class ThemeForm(QtGui.QWizard, Ui_ThemeWizard): """ background_image = BackgroundType.to_string(BackgroundType.Image) if self.page(self.currentId()) == self.backgroundPage and \ - self.theme.background_type == background_image and not self.imageFileEdit.text(): + self.theme.background_type == background_image and is_not_image_file(self.imageFileEdit.text()): QtGui.QMessageBox.critical(self, translate('OpenLP.ThemeWizard', 'Background Image Empty'), translate('OpenLP.ThemeWizard', 'You have not selected a ' 'background image. Please select one before continuing.')) diff --git a/openlp/core/utils/__init__.py b/openlp/core/utils/__init__.py index bfd0b0740..fb06332f3 100644 --- a/openlp/core/utils/__init__.py +++ b/openlp/core/utils/__init__.py @@ -246,6 +246,23 @@ def get_images_filter(): return IMAGES_FILTER +def is_not_image_file(file_name): + """ + Validate that the file is not an image file. + + ``file_name`` + File name to be checked. + """ + if file_name.isEmpty(): + return True + else: + formats = [fmt.lower() for fmt in QtGui.QImageReader.supportedImageFormats()] + file_part, file_extension = os.path.splitext(unicode(file_name)) + if file_extension[1:].lower() in formats and os.path.exists(file_name): + return False + return True + + def split_filename(path): """ Return a list of the parts in a given path. From 6e7700d8fd262f2126ca6ca66f396d2ed2909de5 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Fri, 12 Jul 2013 19:13:06 +0100 Subject: [PATCH 19/40] rename url from live to main --- .../remotes/html/{live.css => main.css} | 0 .../remotes/html/{live.html => main.html} | 4 +- .../plugins/remotes/html/{live.js => main.js} | 4 +- openlp/plugins/remotes/lib/httpserver.py | 40 +++++++++---------- 4 files changed, 24 insertions(+), 24 deletions(-) rename openlp/plugins/remotes/html/{live.css => main.css} (100%) rename openlp/plugins/remotes/html/{live.html => main.html} (94%) rename openlp/plugins/remotes/html/{live.js => main.js} (98%) diff --git a/openlp/plugins/remotes/html/live.css b/openlp/plugins/remotes/html/main.css similarity index 100% rename from openlp/plugins/remotes/html/live.css rename to openlp/plugins/remotes/html/main.css diff --git a/openlp/plugins/remotes/html/live.html b/openlp/plugins/remotes/html/main.html similarity index 94% rename from openlp/plugins/remotes/html/live.html rename to openlp/plugins/remotes/html/main.html index f9a2c874c..3fbd42447 100644 --- a/openlp/plugins/remotes/html/live.html +++ b/openlp/plugins/remotes/html/main.html @@ -30,10 +30,10 @@ ${live_title} - + - + diff --git a/openlp/plugins/remotes/html/live.js b/openlp/plugins/remotes/html/main.js similarity index 98% rename from openlp/plugins/remotes/html/live.js rename to openlp/plugins/remotes/html/main.js index d55072c16..4f4f36351 100644 --- a/openlp/plugins/remotes/html/live.js +++ b/openlp/plugins/remotes/html/main.js @@ -26,7 +26,7 @@ window.OpenLP = { loadSlide: function (event) { $.getJSON( - "/live/image", + "/main/image", function (data, status) { var img = document.getElementById('image'); img.src = data.results.slide_image; @@ -36,7 +36,7 @@ window.OpenLP = { }, pollServer: function () { $.getJSON( - "/live/poll", + "/main/poll", function (data, status) { if (OpenLP.slideCount != data.results.slide_count) { OpenLP.slideCount = data.results.slide_count; diff --git a/openlp/plugins/remotes/lib/httpserver.py b/openlp/plugins/remotes/lib/httpserver.py index a2abbb41e..ac68c2e24 100644 --- a/openlp/plugins/remotes/lib/httpserver.py +++ b/openlp/plugins/remotes/lib/httpserver.py @@ -177,11 +177,11 @@ class HttpServer(object): self.root = self.Public() self.root.files = self.Files() self.root.stage = self.Stage() - self.root.live = self.Live() + self.root.main = self.Main() self.root.router = self.router self.root.files.router = self.router self.root.stage.router = self.router - self.root.live.router = self.router + self.root.main.router = self.router cherrypy.tree.mount(self.root, '/', config=self.define_config()) # Turn off the flood of access messages cause by poll cherrypy.log.access_log.propagate = False @@ -218,7 +218,7 @@ class HttpServer(object): u'/stage': {u'tools.staticdir.on': True, u'tools.staticdir.dir': self.router.html_dir, u'tools.basic_auth.on': False}, - u'/live': {u'tools.staticdir.on': True, + u'/main': {u'tools.staticdir.on': True, u'tools.staticdir.dir': self.router.html_dir, u'tools.basic_auth.on': False}} return directory_config @@ -253,9 +253,9 @@ class HttpServer(object): url = urlparse.urlparse(cherrypy.url()) return self.router.process_http_request(url.path, *args) - class Live(object): + class Main(object): """ - Live view is read only so security is not relevant and would reduce it's usability + Main view is read only so security is not relevant and would reduce it's usability """ @cherrypy.expose def default(self, *args, **kwargs): @@ -281,12 +281,12 @@ class HttpRouter(object): self.routes = [ (u'^/$', self.serve_file), (u'^/(stage)$', self.serve_file), - (u'^/(live)$', self.serve_file), + (u'^/(main)$', self.serve_file), (r'^/files/(.*)$', self.serve_file), (r'^/api/poll$', self.poll), (r'^/stage/poll$', self.poll), - (r'^/live/poll$', self.live_poll), - (r'^/live/image$', self.live_image), + (r'^/main/poll$', self.main_poll), + (r'^/main/image$', self.main_image), (r'^/api/controller/(live|preview)/(.*)$', self.controller), (r'^/stage/controller/(live|preview)/(.*)$', self.controller), (r'^/api/service/(.*)$', self.service), @@ -378,7 +378,7 @@ class HttpRouter(object): 'slides': translate('RemotePlugin.Mobile', 'Slides') } - def serve_file(self, filename=None): + def serve_file(self, file_name=None): """ Send a file to the socket. For now, just a subset of file types and must be top level inside the html folder. If subfolders requested return 404, easier for security for the present. @@ -386,17 +386,17 @@ class HttpRouter(object): Ultimately for i18n, this could first look for xx/file.html before falling back to file.html. where xx is the language, e.g. 'en' """ - log.debug(u'serve file request %s' % filename) - if not filename: - filename = u'index.html' - elif filename == u'stage': - filename = u'stage.html' - elif filename == u'live': - filename = u'live.html' - path = os.path.normpath(os.path.join(self.html_dir, filename)) + log.debug(u'serve file request %s' % file_name) + if not file_name: + file_name = u'index.html' + elif file_name == u'stage': + file_name = u'stage.html' + elif file_name == u'main': + file_name = u'main.html' + path = os.path.normpath(os.path.join(self.html_dir, file_name)) if not path.startswith(self.html_dir): return self._http_not_found() - ext = os.path.splitext(filename)[1] + ext = os.path.splitext(file_name)[1] html = None if ext == u'.html': mimetype = u'text/html' @@ -447,7 +447,7 @@ class HttpRouter(object): cherrypy.response.headers['Content-Type'] = u'application/json' return json.dumps({u'results': result}) - def live_poll(self): + def main_poll(self): """ Poll OpenLP to determine the current slide count. """ @@ -457,7 +457,7 @@ class HttpRouter(object): cherrypy.response.headers['Content-Type'] = u'application/json' return json.dumps({u'results': result}) - def live_image(self): + def main_image(self): """ Return the latest display image as a byte stream. """ From 94e8b90c5d3679fed4aacf44b7dad6c7e7eacfed Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Sat, 13 Jul 2013 17:33:32 +0100 Subject: [PATCH 20/40] Added first test --- openlp/core/utils/__init__.py | 4 +-- .../interfaces/openlp_core_utils/__init__.py | 0 .../openlp_core_utils/test_utils.py | 29 +++++++++++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 tests/interfaces/openlp_core_utils/__init__.py create mode 100644 tests/interfaces/openlp_core_utils/test_utils.py diff --git a/openlp/core/utils/__init__.py b/openlp/core/utils/__init__.py index fb06332f3..843849f63 100644 --- a/openlp/core/utils/__init__.py +++ b/openlp/core/utils/__init__.py @@ -253,10 +253,10 @@ def is_not_image_file(file_name): ``file_name`` File name to be checked. """ - if file_name.isEmpty(): + if not file_name: return True else: - formats = [fmt.lower() for fmt in QtGui.QImageReader.supportedImageFormats()] + formats = [unicode(fmt).lower() for fmt in QtGui.QImageReader.supportedImageFormats()] file_part, file_extension = os.path.splitext(unicode(file_name)) if file_extension[1:].lower() in formats and os.path.exists(file_name): return False diff --git a/tests/interfaces/openlp_core_utils/__init__.py b/tests/interfaces/openlp_core_utils/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/interfaces/openlp_core_utils/test_utils.py b/tests/interfaces/openlp_core_utils/test_utils.py new file mode 100644 index 000000000..b4b4c2bc9 --- /dev/null +++ b/tests/interfaces/openlp_core_utils/test_utils.py @@ -0,0 +1,29 @@ +""" +Functional tests to test the AppLocation class and related methods. +""" +from unittest import TestCase + +from mock import patch +from PyQt4 import QtCore + + +from openlp.core.utils import is_not_image_file +from tests.utils.constants import TEST_RESOURCES_PATH + + +class TestUtils(TestCase): + """ + A test suite to test out various methods around the Utils functions. + """ + def is_not_image_empty_test(self): + """ + Test the method handles an empty string + """ + # Given and empty string + file_name = "" + + # WHEN testing for it + result = is_not_image_file(file_name) + + # THEN the result is false + assert result is True, u'The missing file test should return True' From 3f1d2c1c2108f8bd7745423e048e5c66aa287c66 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Sun, 14 Jul 2013 06:56:11 +0100 Subject: [PATCH 21/40] Fix up tests --- .../openlp_core_utils/test_utils.py | 31 ++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/tests/interfaces/openlp_core_utils/test_utils.py b/tests/interfaces/openlp_core_utils/test_utils.py index b4b4c2bc9..fe5d33560 100644 --- a/tests/interfaces/openlp_core_utils/test_utils.py +++ b/tests/interfaces/openlp_core_utils/test_utils.py @@ -1,12 +1,9 @@ """ Functional tests to test the AppLocation class and related methods. """ +import os from unittest import TestCase -from mock import patch -from PyQt4 import QtCore - - from openlp.core.utils import is_not_image_file from tests.utils.constants import TEST_RESOURCES_PATH @@ -27,3 +24,29 @@ class TestUtils(TestCase): # THEN the result is false assert result is True, u'The missing file test should return True' + + def is_not_image_with_image_file_test(self): + """ + Test the method handles an image file + """ + # Given and empty string + file_name = os.path.join(TEST_RESOURCES_PATH, u'church.jpg') + + # WHEN testing for it + result = is_not_image_file(file_name) + + # THEN the result is false + assert result is False, u'The file is present so the test should return False' + + def is_not_image_with_none_image_file_test(self): + """ + Test the method handles a non image file + """ + # Given and empty string + file_name = os.path.join(TEST_RESOURCES_PATH, u'serviceitem_custom_1.osj') + + # WHEN testing for it + result = is_not_image_file(file_name) + + # THEN the result is false + assert result is True, u'The file is not an image file so the test should return True' \ No newline at end of file From fc81c69ee9a190468e35a83fb13198bcd0b425e2 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Tue, 16 Jul 2013 22:00:18 +0200 Subject: [PATCH 22/40] removed migrate from check_dependencies --- scripts/check_dependencies.py | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/check_dependencies.py b/scripts/check_dependencies.py index bd7786b01..40377bb5b 100755 --- a/scripts/check_dependencies.py +++ b/scripts/check_dependencies.py @@ -83,7 +83,6 @@ MODULES = [ 'bs4', 'mako', 'cherrypy', - 'migrate', 'uno', 'icu', 'bs4', From 63bfacf0d13d3445b6f418cf2862ac8adddb982d Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Wed, 17 Jul 2013 14:37:42 +0200 Subject: [PATCH 23/40] fixed presentations --- openlp/plugins/presentations/lib/mediaitem.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/openlp/plugins/presentations/lib/mediaitem.py b/openlp/plugins/presentations/lib/mediaitem.py index cef30a498..6e5f20646 100644 --- a/openlp/plugins/presentations/lib/mediaitem.py +++ b/openlp/plugins/presentations/lib/mediaitem.py @@ -80,15 +80,15 @@ class PresentationMediaItem(MediaManagerItem): """ Build the list of file extensions to be used in the Open file dialog. """ - file_type_list = u'' + file_type_string = u'' for controller in self.controllers: if self.controllers[controller].enabled(): file_types = self.controllers[controller].supports + self.controllers[controller].also_supports for file_type in file_types: - if file_type.find(file_type) == -1: - file_type_list += u'*.%s ' % file_type + if file_type not in file_type_string: + file_type_string += u'*.%s ' % file_type self.service_manager.supported_suffixes(file_type) - self.on_new_file_masks = translate('PresentationPlugin.MediaItem', 'Presentations (%s)') % file_type_list + self.on_new_file_masks = translate('PresentationPlugin.MediaItem', 'Presentations (%s)') % file_type_string def required_icons(self): """ From 4fee73fc37f9d06b70c4310ac50a27ca71755edf Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Wed, 17 Jul 2013 15:59:35 +0200 Subject: [PATCH 24/40] added test --- openlp/plugins/presentations/lib/mediaitem.py | 2 +- .../presentations/test_mediaitem.py | 71 +++++++++++++++++++ .../openlp_plugins/songs/test_mediaitem.py | 2 +- 3 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 tests/functional/openlp_plugins/presentations/test_mediaitem.py diff --git a/openlp/plugins/presentations/lib/mediaitem.py b/openlp/plugins/presentations/lib/mediaitem.py index 6e5f20646..c9f11a5d8 100644 --- a/openlp/plugins/presentations/lib/mediaitem.py +++ b/openlp/plugins/presentations/lib/mediaitem.py @@ -66,7 +66,7 @@ class PresentationMediaItem(MediaManagerItem): Registry().register_function(u'mediaitem_presentation_rebuild', self.populate_display_types) Registry().register_function(u'mediaitem_suffixes', self.build_file_mask_string) # Allow DnD from the desktop - self.list_view.activateDnD() + # self.list_view.activateDnD() def retranslateUi(self): """ diff --git a/tests/functional/openlp_plugins/presentations/test_mediaitem.py b/tests/functional/openlp_plugins/presentations/test_mediaitem.py new file mode 100644 index 000000000..488e76608 --- /dev/null +++ b/tests/functional/openlp_plugins/presentations/test_mediaitem.py @@ -0,0 +1,71 @@ +""" +This module contains tests for the lib submodule of the Presentations plugin. +""" +import os +from tempfile import mkstemp +from unittest import TestCase + +from mock import patch, MagicMock + +from PyQt4 import QtGui + +from openlp.core.lib import Registry + +from openlp.plugins.presentations.lib.mediaitem import PresentationMediaItem + + +class TestMediaItem(TestCase): + """ + Test the mediaitem methods. + """ + def setUp(self): + """ + Set up the components need for all tests. + """ + Registry.create() + Registry().register(u'service_manager', MagicMock()) + Registry().register(u'main_window', MagicMock()) + + with patch('openlp.core.lib.mediamanageritem.MediaManagerItem.__init__'), \ + patch('openlp.core.lib.mediamanageritem.ListWidgetWithDnD'): + self.media_item = PresentationMediaItem(MagicMock(), MagicMock(), MagicMock(), MagicMock()) + + self.application = QtGui.QApplication.instance() + + def tearDown(self): + """ + Delete all the C++ objects at the end so that we don't have a segfault + """ + del self.application + + def build_file_mask_string_test(self): + """ + Test the build_file_mask_string() method + """ + # GIVEN: Different controllers. + impress_controller = MagicMock() + impress_controller.enabled.return_value = True + impress_controller.supports = [u'odp'] + impress_controller.also_supports = [u'ppt'] + presentation_controller = MagicMock() + presentation_controller.enabled.return_value = True + presentation_controller.supports = [u'ppt'] + presentation_controller.also_supports = [] + presentation_viewer_controller = MagicMock() + presentation_viewer_controller.enabled.return_value = False + # Mock the controllers. + self.media_item.controllers = { + u'Impress': impress_controller, + u'Powerpoint': presentation_controller, + u'Powerpoint Viewer': presentation_viewer_controller + } + + # WHEN: Build the file mask. + with patch('openlp.plugins.presentations.lib.mediaitem.translate') as mocked_translate: + mocked_translate.side_effect = lambda module, string_to_translate: string_to_translate + self.media_item.build_file_mask_string() + + # THEN: The file mask should be generated. + assert self.media_item.on_new_file_masks == u'Presentations (*.odp *.ppt )' + + diff --git a/tests/functional/openlp_plugins/songs/test_mediaitem.py b/tests/functional/openlp_plugins/songs/test_mediaitem.py index 21616e959..c55a45693 100644 --- a/tests/functional/openlp_plugins/songs/test_mediaitem.py +++ b/tests/functional/openlp_plugins/songs/test_mediaitem.py @@ -26,7 +26,7 @@ class TestMediaItem(TestCase): Registry().register(u'service_list', MagicMock()) Registry().register(u'main_window', MagicMock()) with patch('openlp.core.lib.mediamanageritem.MediaManagerItem.__init__'), \ - patch('openlp.plugins.songs.forms.editsongform.EditSongForm.__init__'): + patch('openlp.plugins.songs.forms.editsongform.EditSongForm.__init__'): self.media_item = SongMediaItem(MagicMock(), MagicMock()) fd, self.ini_file = mkstemp(u'.ini') From 6e66cdefcff29ab9949e81a5e152ac99de731c8e Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Wed, 17 Jul 2013 16:19:21 +0200 Subject: [PATCH 25/40] clean ups --- openlp/plugins/presentations/lib/mediaitem.py | 2 +- .../openlp_plugins/presentations/__init__.py | 0 .../openlp_plugins/custom/forms/test_customform.py | 12 +++--------- 3 files changed, 4 insertions(+), 10 deletions(-) create mode 100644 tests/functional/openlp_plugins/presentations/__init__.py diff --git a/openlp/plugins/presentations/lib/mediaitem.py b/openlp/plugins/presentations/lib/mediaitem.py index c9f11a5d8..6e5f20646 100644 --- a/openlp/plugins/presentations/lib/mediaitem.py +++ b/openlp/plugins/presentations/lib/mediaitem.py @@ -66,7 +66,7 @@ class PresentationMediaItem(MediaManagerItem): Registry().register_function(u'mediaitem_presentation_rebuild', self.populate_display_types) Registry().register_function(u'mediaitem_suffixes', self.build_file_mask_string) # Allow DnD from the desktop - # self.list_view.activateDnD() + self.list_view.activateDnD() def retranslateUi(self): """ diff --git a/tests/functional/openlp_plugins/presentations/__init__.py b/tests/functional/openlp_plugins/presentations/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/interfaces/openlp_plugins/custom/forms/test_customform.py b/tests/interfaces/openlp_plugins/custom/forms/test_customform.py index 41671403b..fbf613661 100644 --- a/tests/interfaces/openlp_plugins/custom/forms/test_customform.py +++ b/tests/interfaces/openlp_plugins/custom/forms/test_customform.py @@ -80,9 +80,7 @@ class TestEditCustomForm(TestCase): # GIVEN: Mocked methods. with patch(u'openlp.plugins.custom.forms.editcustomform.critical_error_message_box') as \ mocked_critical_error_message_box: - mocked_displayText = MagicMock() - mocked_displayText.return_value = u'' - self.form.title_edit.displayText = mocked_displayText + self.form.title_edit.displayText = MagicMock(return_value=u'') mocked_setFocus = MagicMock() self.form.title_edit.setFocus = mocked_setFocus @@ -101,12 +99,8 @@ class TestEditCustomForm(TestCase): # GIVEN: Mocked methods. with patch(u'openlp.plugins.custom.forms.editcustomform.critical_error_message_box') as \ mocked_critical_error_message_box: - mocked_displayText = MagicMock() - mocked_displayText.return_value = u'something' - self.form.title_edit.displayText = mocked_displayText - mocked_count = MagicMock() - mocked_count.return_value = 0 - self.form.slide_list_view.count = mocked_count + self.form.title_edit.displayText = MagicMock(return_value=u'something') + self.form.slide_list_view.count = MagicMock(return_value=0) # WHEN: Call the method. result = self.form._validate() From b1290100592b95dcad74728ad2de35d5e5a1a25e Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Wed, 17 Jul 2013 16:28:22 +0200 Subject: [PATCH 26/40] added assertion message --- .../functional/openlp_plugins/presentations/test_mediaitem.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/functional/openlp_plugins/presentations/test_mediaitem.py b/tests/functional/openlp_plugins/presentations/test_mediaitem.py index 488e76608..b8abb2e51 100644 --- a/tests/functional/openlp_plugins/presentations/test_mediaitem.py +++ b/tests/functional/openlp_plugins/presentations/test_mediaitem.py @@ -66,6 +66,7 @@ class TestMediaItem(TestCase): self.media_item.build_file_mask_string() # THEN: The file mask should be generated. - assert self.media_item.on_new_file_masks == u'Presentations (*.odp *.ppt )' + assert self.media_item.on_new_file_masks == u'Presentations (*.odp *.ppt )', \ + u'The file mask should contain the odp and ppt extensions' From cec9689dce537454c8e36d46445871c5916fcf21 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Wed, 17 Jul 2013 23:07:52 +0200 Subject: [PATCH 27/40] Fix up the build_file_mask_string test. - Fix up the build_file_mask_string test by mocking out the __init__() method of the PresentationMediaItem class - Change the way of calling the parent __init__() method to something slightly better (though it has nothing to do with the test) --- openlp/plugins/presentations/lib/mediaitem.py | 2 +- .../openlp_plugins/presentations/test_mediaitem.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/openlp/plugins/presentations/lib/mediaitem.py b/openlp/plugins/presentations/lib/mediaitem.py index 6e5f20646..62e2cd78b 100644 --- a/openlp/plugins/presentations/lib/mediaitem.py +++ b/openlp/plugins/presentations/lib/mediaitem.py @@ -59,7 +59,7 @@ class PresentationMediaItem(MediaManagerItem): self.controllers = controllers self.icon_path = u'presentations/presentation' self.Automatic = u'' - MediaManagerItem.__init__(self, parent, plugin) + super(PresentationMediaItem, self).__init__(parent, plugin) self.message_listener = MessageListener(self) self.has_search = True self.single_service_item = False diff --git a/tests/functional/openlp_plugins/presentations/test_mediaitem.py b/tests/functional/openlp_plugins/presentations/test_mediaitem.py index b8abb2e51..294e21779 100644 --- a/tests/functional/openlp_plugins/presentations/test_mediaitem.py +++ b/tests/functional/openlp_plugins/presentations/test_mediaitem.py @@ -26,9 +26,9 @@ class TestMediaItem(TestCase): Registry().register(u'service_manager', MagicMock()) Registry().register(u'main_window', MagicMock()) - with patch('openlp.core.lib.mediamanageritem.MediaManagerItem.__init__'), \ - patch('openlp.core.lib.mediamanageritem.ListWidgetWithDnD'): - self.media_item = PresentationMediaItem(MagicMock(), MagicMock(), MagicMock(), MagicMock()) + with patch('openlp.plugins.presentations.lib.mediaitem.PresentationMediaItem.__init__') as mocked_init: + mocked_init.return_value = None + self.media_item = PresentationMediaItem(MagicMock(), MagicMock, MagicMock(), MagicMock()) self.application = QtGui.QApplication.instance() From 11597d7252441be0550b6439303cb624a8527abe Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Thu, 18 Jul 2013 06:53:20 +0200 Subject: [PATCH 28/40] missing empty line --- tests/functional/openlp_plugins/presentations/test_mediaitem.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/functional/openlp_plugins/presentations/test_mediaitem.py b/tests/functional/openlp_plugins/presentations/test_mediaitem.py index b8abb2e51..13b2c320f 100644 --- a/tests/functional/openlp_plugins/presentations/test_mediaitem.py +++ b/tests/functional/openlp_plugins/presentations/test_mediaitem.py @@ -69,4 +69,3 @@ class TestMediaItem(TestCase): assert self.media_item.on_new_file_masks == u'Presentations (*.odp *.ppt )', \ u'The file mask should contain the odp and ppt extensions' - From 7f541327cab1ef6042ba3c1568d9fe1b19c4d5f5 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Thu, 18 Jul 2013 21:28:35 +0200 Subject: [PATCH 29/40] changed to 120 chars --- openlp.py | 2 +- openlp/__init__.py | 2 +- openlp/core/ui/media/vendor/__init__.py | 2 +- openlp/plugins/alerts/lib/db.py | 2 +- openlp/plugins/bibles/__init__.py | 2 +- openlp/plugins/bibles/forms/languageform.py | 2 +- openlp/plugins/media/__init__.py | 2 +- openlp/plugins/media/lib/__init__.py | 2 +- openlp/plugins/presentations/lib/pptviewlib/ppttest.py | 2 +- openlp/plugins/remotes/__init__.py | 2 +- openlp/plugins/songs/lib/test/test_import_file.py | 2 +- openlp/plugins/songs/lib/test/test_importing_lots.py | 2 +- resources/__init__.py | 2 +- resources/pyinstaller/hook-openlp.core.ui.media.py | 2 +- .../hook-openlp.plugins.presentations.presentationplugin.py | 2 +- resources/pyinstaller/hook-openlp.py | 2 +- scripts/check_dependencies.py | 2 +- scripts/translation_utils.py | 2 +- setup.py | 2 +- 19 files changed, 19 insertions(+), 19 deletions(-) diff --git a/openlp.py b/openlp.py index 0732fb066..bbbcf5320 100755 --- a/openlp.py +++ b/openlp.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 ############################################################################### # OpenLP - Open Source Lyrics Projection # diff --git a/openlp/__init__.py b/openlp/__init__.py index 606d4ef9d..797203f05 100644 --- a/openlp/__init__.py +++ b/openlp/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 ############################################################################### # OpenLP - Open Source Lyrics Projection # diff --git a/openlp/core/ui/media/vendor/__init__.py b/openlp/core/ui/media/vendor/__init__.py index 317fb9f81..43c8a3394 100644 --- a/openlp/core/ui/media/vendor/__init__.py +++ b/openlp/core/ui/media/vendor/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 ############################################################################### # OpenLP - Open Source Lyrics Projection # diff --git a/openlp/plugins/alerts/lib/db.py b/openlp/plugins/alerts/lib/db.py index 499e63906..f930d9b24 100644 --- a/openlp/plugins/alerts/lib/db.py +++ b/openlp/plugins/alerts/lib/db.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 ############################################################################### # OpenLP - Open Source Lyrics Projection # diff --git a/openlp/plugins/bibles/__init__.py b/openlp/plugins/bibles/__init__.py index 62e6c5f90..91cfc2923 100644 --- a/openlp/plugins/bibles/__init__.py +++ b/openlp/plugins/bibles/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 ############################################################################### # OpenLP - Open Source Lyrics Projection # diff --git a/openlp/plugins/bibles/forms/languageform.py b/openlp/plugins/bibles/forms/languageform.py index 2bba3d7a4..dfa18a67f 100644 --- a/openlp/plugins/bibles/forms/languageform.py +++ b/openlp/plugins/bibles/forms/languageform.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 ############################################################################### # OpenLP - Open Source Lyrics Projection # diff --git a/openlp/plugins/media/__init__.py b/openlp/plugins/media/__init__.py index 2a2e9f5aa..0074b09d1 100644 --- a/openlp/plugins/media/__init__.py +++ b/openlp/plugins/media/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 ############################################################################### # OpenLP - Open Source Lyrics Projection # diff --git a/openlp/plugins/media/lib/__init__.py b/openlp/plugins/media/lib/__init__.py index c5fda0130..2604447a1 100644 --- a/openlp/plugins/media/lib/__init__.py +++ b/openlp/plugins/media/lib/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 ############################################################################### # OpenLP - Open Source Lyrics Projection # diff --git a/openlp/plugins/presentations/lib/pptviewlib/ppttest.py b/openlp/plugins/presentations/lib/pptviewlib/ppttest.py index f07468bb8..2e1406e18 100644 --- a/openlp/plugins/presentations/lib/pptviewlib/ppttest.py +++ b/openlp/plugins/presentations/lib/pptviewlib/ppttest.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 ############################################################################### # OpenLP - Open Source Lyrics Projection # diff --git a/openlp/plugins/remotes/__init__.py b/openlp/plugins/remotes/__init__.py index e16d47f67..dd2fb6433 100644 --- a/openlp/plugins/remotes/__init__.py +++ b/openlp/plugins/remotes/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 ############################################################################### # OpenLP - Open Source Lyrics Projection # diff --git a/openlp/plugins/songs/lib/test/test_import_file.py b/openlp/plugins/songs/lib/test/test_import_file.py index 06d1af38f..0f675e079 100644 --- a/openlp/plugins/songs/lib/test/test_import_file.py +++ b/openlp/plugins/songs/lib/test/test_import_file.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 ############################################################################### # OpenLP - Open Source Lyrics Projection # diff --git a/openlp/plugins/songs/lib/test/test_importing_lots.py b/openlp/plugins/songs/lib/test/test_importing_lots.py index f6bac243b..605809ae2 100644 --- a/openlp/plugins/songs/lib/test/test_importing_lots.py +++ b/openlp/plugins/songs/lib/test/test_importing_lots.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 ############################################################################### # OpenLP - Open Source Lyrics Projection # diff --git a/resources/__init__.py b/resources/__init__.py index 898553165..abcc392d9 100644 --- a/resources/__init__.py +++ b/resources/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 ############################################################################### # OpenLP - Open Source Lyrics Projection # diff --git a/resources/pyinstaller/hook-openlp.core.ui.media.py b/resources/pyinstaller/hook-openlp.core.ui.media.py index 36d98abb0..28bf44a32 100644 --- a/resources/pyinstaller/hook-openlp.core.ui.media.py +++ b/resources/pyinstaller/hook-openlp.core.ui.media.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 ############################################################################### # OpenLP - Open Source Lyrics Projection # diff --git a/resources/pyinstaller/hook-openlp.plugins.presentations.presentationplugin.py b/resources/pyinstaller/hook-openlp.plugins.presentations.presentationplugin.py index 4948a641f..4b35f0235 100644 --- a/resources/pyinstaller/hook-openlp.plugins.presentations.presentationplugin.py +++ b/resources/pyinstaller/hook-openlp.plugins.presentations.presentationplugin.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 ############################################################################### # OpenLP - Open Source Lyrics Projection # diff --git a/resources/pyinstaller/hook-openlp.py b/resources/pyinstaller/hook-openlp.py index 4a78d932f..b83a63113 100644 --- a/resources/pyinstaller/hook-openlp.py +++ b/resources/pyinstaller/hook-openlp.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 ############################################################################### # OpenLP - Open Source Lyrics Projection # diff --git a/scripts/check_dependencies.py b/scripts/check_dependencies.py index 40377bb5b..9dead4a36 100755 --- a/scripts/check_dependencies.py +++ b/scripts/check_dependencies.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 ############################################################################### # OpenLP - Open Source Lyrics Projection # diff --git a/scripts/translation_utils.py b/scripts/translation_utils.py index 40000946d..1ceb4cd82 100755 --- a/scripts/translation_utils.py +++ b/scripts/translation_utils.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 ############################################################################### # OpenLP - Open Source Lyrics Projection # diff --git a/setup.py b/setup.py index 94720dd1c..e0c35ea47 100755 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 ############################################################################### # OpenLP - Open Source Lyrics Projection # From a0f35e0d5eac8d05e011385eefa5337aaa2df052 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Fri, 19 Jul 2013 15:57:19 +0200 Subject: [PATCH 30/40] fixed bug 1183078 Fixes: https://launchpad.net/bugs/1183078 --- openlp/core/lib/plugin.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/openlp/core/lib/plugin.py b/openlp/core/lib/plugin.py index a79ba850a..1950477ed 100644 --- a/openlp/core/lib/plugin.py +++ b/openlp/core/lib/plugin.py @@ -308,12 +308,12 @@ class Plugin(QtCore.QObject): Perform tasks on application startup """ # FIXME: Remove after 2.2 release. - # This is needed to load the list of images/media/presentation from the config saved - # before the settings rewrite. + # This is needed to load the list of media/presentation from the config saved before the settings rewrite. if self.media_item_class is not None and self.name != u'images': loaded_list = Settings().get_files_from_config(self) # Now save the list to the config using our Settings class. - Settings().setValue(u'%s/%s files' % (self.settings_section, self.name), loaded_list) + if loaded_list: + Settings().setValue(u'%s/%s files' % (self.settings_section, self.name), loaded_list) def uses_theme(self, theme): """ From dc7cb85574810717888f97ca6e6cfa864b9cf18e Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Fri, 19 Jul 2013 16:51:47 +0100 Subject: [PATCH 31/40] Uneeded import --- openlp/core/ui/formattingtagform.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openlp/core/ui/formattingtagform.py b/openlp/core/ui/formattingtagform.py index d2390c2f9..30ab0902d 100644 --- a/openlp/core/ui/formattingtagform.py +++ b/openlp/core/ui/formattingtagform.py @@ -31,7 +31,7 @@ The :mod:`formattingtagform` provides an Tag Edit facility. The Base set are pro Custom tags can be defined and saved. The Custom Tag arrays are saved in a pickle so QSettings works on them. Base Tags cannot be changed. """ -from PyQt4 import QtCore, QtGui +from PyQt4 import QtGui from openlp.core.lib import FormattingTags, translate from openlp.core.lib.ui import critical_error_message_box From 50f3b2b563b938a0665b94240636a991c4d974cf Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Fri, 19 Jul 2013 21:56:31 +0100 Subject: [PATCH 32/40] Fix uno import noise in python 3 --- openlp/core/__init__.py | 2 +- openlp/core/ui/exceptionform.py | 48 +++++++++++++++++++++------------ 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/openlp/core/__init__.py b/openlp/core/__init__.py index 23986ffc4..16987df5d 100644 --- a/openlp/core/__init__.py +++ b/openlp/core/__init__.py @@ -185,7 +185,7 @@ class OpenLP(QtGui.QApplication): """ log.exception(''.join(format_exception(exctype, value, traceback))) if not hasattr(self, u'exception_form'): - self.exception_form = ExceptionForm(self.main_window) + self.exception_form = ExceptionForm() self.exception_form.exception_text_edit.setPlainText(''.join(format_exception(exctype, value, traceback))) self.set_normal_cursor() self.exception_form.exec_() diff --git a/openlp/core/ui/exceptionform.py b/openlp/core/ui/exceptionform.py index 49d6b0bef..bbd76446b 100644 --- a/openlp/core/ui/exceptionform.py +++ b/openlp/core/ui/exceptionform.py @@ -37,6 +37,8 @@ import platform import bs4 import sqlalchemy from lxml import etree + +from openlp.core.lib import Registry from PyQt4 import Qt, QtCore, QtGui, QtWebKit try: @@ -77,19 +79,7 @@ try: CHERRYPY_VERSION = cherrypy.__version__ except ImportError: CHERRYPY_VERSION = u'-' -try: - import uno - arg = uno.createUnoStruct(u'com.sun.star.beans.PropertyValue') - arg.Name = u'nodepath' - arg.Value = u'/org.openoffice.Setup/Product' - context = uno.getComponentContext() - provider = context.ServiceManager.createInstance(u'com.sun.star.configuration.ConfigurationProvider') - node = provider.createInstanceWithArguments(u'com.sun.star.configuration.ConfigurationAccess', (arg,)) - UNO_VERSION = node.getByName(u'ooSetupVersion') -except ImportError: - UNO_VERSION = u'-' -except: - UNO_VERSION = u'- (Possible non-standard UNO installation)' + try: WEBKIT_VERSION = QtWebKit.qWebKitVersion() except AttributeError: @@ -100,7 +90,6 @@ try: except ImportError: VLC_VERSION = u'-' - from openlp.core.lib import UiStrings, Settings, translate from openlp.core.utils import get_application_version @@ -113,11 +102,11 @@ class ExceptionForm(QtGui.QDialog, Ui_ExceptionDialog): """ The exception dialog """ - def __init__(self, parent): + def __init__(self): """ Constructor. """ - QtGui.QDialog.__init__(self, parent) + QtGui.QDialog.__init__(self, self.main_window) self.setupUi(self) self.settings_section = u'crashreport' @@ -152,7 +141,7 @@ class ExceptionForm(QtGui.QDialog, Ui_ExceptionDialog): u'Mako: %s\n' % MAKO_VERSION + \ u'CherryPy: %s\n' % CHERRYPY_VERSION + \ u'pyICU: %s\n' % ICU_VERSION + \ - u'pyUNO bridge: %s\n' % UNO_VERSION + \ + u'pyUNO bridge: %s\n' % self._pyuno_import() + \ u'VLC: %s\n' % VLC_VERSION if platform.system() == u'Linux': if os.environ.get(u'KDE_FULL_SESSION') == u'true': @@ -256,3 +245,28 @@ class ExceptionForm(QtGui.QDialog, Ui_ExceptionDialog): """ self.save_report_button.setEnabled(state) self.send_report_button.setEnabled(state) + + def _pyuno_import(self): + try: + import uno + arg = uno.createUnoStruct(u'com.sun.star.beans.PropertyValue') + arg.Name = u'nodepath' + arg.Value = u'/org.openoffice.Setup/Product' + context = uno.getComponentContext() + provider = context.ServiceManager.createInstance(u'com.sun.star.configuration.ConfigurationProvider') + node = provider.createInstanceWithArguments(u'com.sun.star.configuration.ConfigurationAccess', (arg,)) + return node.getByName(u'ooSetupVersion') + except ImportError: + return u'-' + except: + return u'- (Possible non-standard UNO installation)' + + def _get_main_window(self): + """ + Adds the main window to the class dynamically + """ + if not hasattr(self, u'_main_window'): + self._main_window = Registry().get(u'main_window') + return self._main_window + + main_window = property(_get_main_window) \ No newline at end of file From 790c9ae4f6440a6830156d2d42118593cc5a94a6 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Sun, 21 Jul 2013 15:10:21 +0100 Subject: [PATCH 33/40] Add doc string --- openlp/core/ui/exceptionform.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/openlp/core/ui/exceptionform.py b/openlp/core/ui/exceptionform.py index bbd76446b..62f8fae71 100644 --- a/openlp/core/ui/exceptionform.py +++ b/openlp/core/ui/exceptionform.py @@ -247,6 +247,12 @@ class ExceptionForm(QtGui.QDialog, Ui_ExceptionDialog): self.send_report_button.setEnabled(state) def _pyuno_import(self): + """ + Added here to define only when the form is actioned. The uno interface spits out lots of exception messages + if the import is at a file level. If uno import is changed this could be reverted. + This happens in other classes but there it is localised here it is across the whole system and hides real + errors. + """ try: import uno arg = uno.createUnoStruct(u'com.sun.star.beans.PropertyValue') From 72c83d444bff9f2ef76e38a6d52047979fcf25a8 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Sun, 21 Jul 2013 15:13:44 +0100 Subject: [PATCH 34/40] missing blank line --- openlp/core/ui/exceptionform.py | 1 + 1 file changed, 1 insertion(+) diff --git a/openlp/core/ui/exceptionform.py b/openlp/core/ui/exceptionform.py index 62f8fae71..d89a9fef9 100644 --- a/openlp/core/ui/exceptionform.py +++ b/openlp/core/ui/exceptionform.py @@ -39,6 +39,7 @@ import sqlalchemy from lxml import etree from openlp.core.lib import Registry + from PyQt4 import Qt, QtCore, QtGui, QtWebKit try: From ad3d1b5e94df6d6de7971d9e4575213cf3c50e9c Mon Sep 17 00:00:00 2001 From: Philip Ridout Date: Tue, 23 Jul 2013 19:19:26 +0100 Subject: [PATCH 35/40] fixes #171891 tests added --- .../plugins/songs/lib/foilpresenterimport.py | 37 ++++++++++++------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/openlp/plugins/songs/lib/foilpresenterimport.py b/openlp/plugins/songs/lib/foilpresenterimport.py index cc91562c5..586b6ca3c 100644 --- a/openlp/plugins/songs/lib/foilpresenterimport.py +++ b/openlp/plugins/songs/lib/foilpresenterimport.py @@ -96,6 +96,7 @@ import os from lxml import etree, objectify +from openlp.core.lib import translate from openlp.core.ui.wizard import WizardStrings from openlp.plugins.songs.lib import clean_song, VerseType from openlp.plugins.songs.lib.songimport import SongImport @@ -115,7 +116,7 @@ class FoilPresenterImport(SongImport): """ log.debug(u'initialise FoilPresenterImport') SongImport.__init__(self, manager, **kwargs) - self.FoilPresenter = FoilPresenter(self.manager) + self.FoilPresenter = FoilPresenter(self.manager, self) def doImport(self): """ @@ -202,8 +203,9 @@ class FoilPresenter(object): tag. """ - def __init__(self, manager): + def __init__(self, manager, importer): self.manager = manager + self.importer = importer def xml_to_song(self, xml): """ @@ -222,22 +224,23 @@ class FoilPresenter(object): song.search_lyrics = u'' song.verse_order = u'' song.search_title = u'' - # Because "text" seems to be an reserverd word, we have to recompile it. + self.skip_song = False + # Because "text" seems to be an reserved word, we have to recompile it. xml = re.compile(u'').sub(u'', xml) xml = re.compile(u'').sub(u'', xml) song_xml = objectify.fromstring(xml) - foilpresenterfolie = song_xml - self._process_copyright(foilpresenterfolie, song) - self._process_cclinumber(foilpresenterfolie, song) - self._process_titles(foilpresenterfolie, song) + self._process_copyright(song_xml, song) + self._process_cclinumber(song_xml, song) + self._process_titles(song_xml, song) # The verse order is processed with the lyrics! - self._process_lyrics(foilpresenterfolie, song) - self._process_comments(foilpresenterfolie, song) - self._process_authors(foilpresenterfolie, song) - self._process_songbooks(foilpresenterfolie, song) - self._process_topics(foilpresenterfolie, song) - clean_song(self.manager, song) - self.manager.save_object(song) + self._process_lyrics(song_xml, song) + self._process_comments(song_xml, song) + self._process_authors(song_xml, song) + self._process_songbooks(song_xml, song) + self._process_topics(song_xml, song) + if not self.skip_song: + clean_song(self.manager, song) + self.manager.save_object(song) def _child(self, element): """ @@ -420,6 +423,12 @@ class FoilPresenter(object): VerseType.tags[VerseType.Intro]: 1, VerseType.tags[VerseType.PreChorus]: 1 } + if not hasattr(foilpresenterfolie.strophen, u'strophe'): + self.importer.logError(self._child(foilpresenterfolie.titel), + unicode(translate('SongsPlugin.FoilPresenterSongImport', + 'Invalid Foilpresenter song file. No verses found.'))) + self.skip_song = True + return for strophe in foilpresenterfolie.strophen.strophe: text = self._child(strophe.text_) if hasattr(strophe, u'text_') else u'' verse_name = self._child(strophe.key) From 47ffa7c9e35b0e39b0b48f7c145252503ee96725 Mon Sep 17 00:00:00 2001 From: Philip Ridout Date: Tue, 23 Jul 2013 19:23:45 +0100 Subject: [PATCH 36/40] actually add test file --- .../songs/test_foilpresenterimport.py | 195 ++++++++++++++++++ 1 file changed, 195 insertions(+) create mode 100644 tests/functional/openlp_plugins/songs/test_foilpresenterimport.py diff --git a/tests/functional/openlp_plugins/songs/test_foilpresenterimport.py b/tests/functional/openlp_plugins/songs/test_foilpresenterimport.py new file mode 100644 index 000000000..e8ca03c7e --- /dev/null +++ b/tests/functional/openlp_plugins/songs/test_foilpresenterimport.py @@ -0,0 +1,195 @@ +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 + +############################################################################### +# OpenLP - Open Source Lyrics Projection # +# --------------------------------------------------------------------------- # +# Copyright (c) 2008-2013 Raoul Snyman # +# Portions copyright (c) 2008-2013 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 SongShow Plus song importer. +""" + +import os +from unittest import TestCase +from mock import patch, MagicMock + +from openlp.plugins.songs.lib import VerseType +from openlp.plugins.songs.lib.foilpresenterimport import FoilPresenter + +TEST_PATH = os.path.abspath( + os.path.join(os.path.dirname(__file__), u'..', u'..', u'..', u'/resources/foilpresentersongs')) + + +class TestFoilPresenter(TestCase): + """ + Test the functions in the :mod:`foilpresenterimport` module. + """ + #TODO: The following modules still need tests written for + # xml_to_song + # _child + # _process_authors + # _process_cclinumber + # _process_comments + # _process_copyright + # _process_lyrics + # _process_songbooks + # _process_titles + # _process_topics + + def setUp(self): + self.child_patcher = patch(u'openlp.plugins.songs.lib.foilpresenterimport.FoilPresenter._child') + self.clean_song_patcher = patch(u'openlp.plugins.songs.lib.foilpresenterimport.clean_song') + self.objectify_patcher = patch(u'openlp.plugins.songs.lib.foilpresenterimport.objectify') + self.process_authors_patcher = \ + patch(u'openlp.plugins.songs.lib.foilpresenterimport.FoilPresenter._process_authors') + self.process_cclinumber_patcher = \ + patch(u'openlp.plugins.songs.lib.foilpresenterimport.FoilPresenter._process_cclinumber') + self.process_comments_patcher = \ + patch(u'openlp.plugins.songs.lib.foilpresenterimport.FoilPresenter._process_comments') + self.process_lyrics_patcher = \ + patch(u'openlp.plugins.songs.lib.foilpresenterimport.FoilPresenter._process_lyrics') + self.process_songbooks_patcher = \ + patch(u'openlp.plugins.songs.lib.foilpresenterimport.FoilPresenter._process_songbooks') + self.process_titles_patcher = \ + patch(u'openlp.plugins.songs.lib.foilpresenterimport.FoilPresenter._process_titles') + self.process_topics_patcher = \ + patch(u'openlp.plugins.songs.lib.foilpresenterimport.FoilPresenter._process_topics') + self.re_patcher = patch(u'openlp.plugins.songs.lib.foilpresenterimport.re') + self.song_patcher = patch(u'openlp.plugins.songs.lib.foilpresenterimport.Song') + self.song_xml_patcher = patch(u'openlp.plugins.songs.lib.foilpresenterimport.SongXML') + self.translate_patcher = patch(u'openlp.plugins.songs.lib.foilpresenterimport.translate') + + self.mocked_child = self.child_patcher.start() + self.mocked_clean_song = self.clean_song_patcher.start() + self.mocked_objectify = self.objectify_patcher.start() + self.mocked_process_authors = self.process_authors_patcher.start() + self.mocked_process_cclinumber = self.process_cclinumber_patcher.start() + self.mocked_process_comments = self.process_comments_patcher.start() + self.mocked_process_lyrics = self.process_lyrics_patcher.start() + self.mocked_process_songbooks = self.process_songbooks_patcher.start() + self.mocked_process_titles = self.process_titles_patcher.start() + self.mocked_process_topics = self.process_topics_patcher.start() + self.mocked_re = self.re_patcher.start() + self.mocked_song = self.song_patcher.start() + self.mocked_song_xml = self.song_xml_patcher.start() + self.mocked_translate = self.translate_patcher.start() + self.mocked_child.return_value = u'Element Text' + self.mocked_translate.return_value = u'Translated String' + self.mocked_manager = MagicMock() + self.mocked_song_import = MagicMock() + + def tearDown(self): + self.child_patcher.stop() + self.clean_song_patcher.stop() + self.objectify_patcher.stop() + self.process_authors_patcher.stop() + self.process_cclinumber_patcher.stop() + self.process_comments_patcher.stop() + self.process_lyrics_patcher.stop() + self.process_songbooks_patcher.stop() + self.process_titles_patcher.stop() + self.process_topics_patcher.stop() + self.re_patcher.stop() + self.song_patcher.stop() + self.song_xml_patcher.stop() + self.translate_patcher.stop() + + def create_foil_presenter_test(self): + """ + Test creating an instance of the FoilPresenter class + """ + # GIVEN: A mocked out "manager" and "SongImport" instance + mocked_manager = MagicMock() + mocked_song_import = MagicMock() + + # WHEN: An FoilPresenter instance is created + foil_presenter_instance = FoilPresenter(mocked_manager, mocked_song_import) + + # THEN: The instance should not be None + self.assertIsNotNone(foil_presenter_instance, u'FoilPresenter instance should not be none') + + def no_xml_test(self): + """ + Test calling xml_to_song with out the xml argument + """ + # GIVEN: A mocked out "manager" and "SongImport" as well as an foil_presenter instance + mocked_manager = MagicMock() + mocked_song_import = MagicMock() + foil_presenter_instance = FoilPresenter(mocked_manager, mocked_song_import) + + # WHEN: xml_to_song is called without valid an argument + for arg in [None, False, 0, u'']: + result = foil_presenter_instance.xml_to_song(arg) + + # Then: xml_to_song should return False + self.assertEqual(result, None, u'xml_to_song should return None when called with %s' % arg) + + def encoding_declaration_removal_test(self): + """ + Test that the encoding declaration is removed + """ + # GIVEN: A reset mocked out re and an instance of foil_presenter + self.mocked_re.reset() + foil_presenter_instance = FoilPresenter(self.mocked_manager, self.mocked_song_import) + + # WHEN: xml_to_song is called with a string with an xml encoding declaration + foil_presenter_instance.xml_to_song(u'\n') + + # THEN: the xml encoding declaration should have been stripped + self.mocked_re.compile.sub.called_with(u'\n') + + def no_encoding_declaration_test(self): + """ + Check that the xml sting is left intact when no encoding declaration is made + """ + # GIVEN: A reset mocked out re and an instance of foil_presenter + self.mocked_re.reset() + foil_presenter_instance = FoilPresenter(self.mocked_manager, self.mocked_song_import) + + # WHEN: xml_to_song is called with a string without an xml encoding declaration + foil_presenter_instance.xml_to_song(u'') + + # THEN: the string shiuld have been left intact + self.mocked_re.compile.sub.called_with(u'') + + def process_lyrics_no_verses_test(self): + """ + Test that _process_lyrics handles song files that have no verses. + """ + # GIVEN: A mocked foilpresenterfolie with no attribute strophe, a mocked song and a + # foil presenter instance + self.process_lyrics_patcher.stop() + self.mocked_song_xml.reset() + mock_foilpresenterfolie = MagicMock() + del mock_foilpresenterfolie.strophen.strophe + mocked_song = MagicMock() + foil_presenter_instance = FoilPresenter(self.mocked_manager, self.mocked_song_import) + + # WHEN: _process_lyrics is called + result = foil_presenter_instance._process_lyrics(mock_foilpresenterfolie, mocked_song) + + # THEN: _process_lyrics should return None and the song_import logError method should have been called once + self.assertIsNone(result) + self.mocked_song_import.logError.assert_called_once_with(u'Element Text', u'Translated String') + self.process_lyrics_patcher.start() \ No newline at end of file From f8808164340bd84ccc1bfb21b86f75830d306986 Mon Sep 17 00:00:00 2001 From: Philip Ridout Date: Wed, 24 Jul 2013 19:43:56 +0100 Subject: [PATCH 37/40] change skip_song to save_song --- openlp/plugins/songs/lib/foilpresenterimport.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/openlp/plugins/songs/lib/foilpresenterimport.py b/openlp/plugins/songs/lib/foilpresenterimport.py index 586b6ca3c..253cddb57 100644 --- a/openlp/plugins/songs/lib/foilpresenterimport.py +++ b/openlp/plugins/songs/lib/foilpresenterimport.py @@ -224,7 +224,7 @@ class FoilPresenter(object): song.search_lyrics = u'' song.verse_order = u'' song.search_title = u'' - self.skip_song = False + self.save_song = False # Because "text" seems to be an reserved word, we have to recompile it. xml = re.compile(u'').sub(u'', xml) xml = re.compile(u'').sub(u'', xml) @@ -238,7 +238,7 @@ class FoilPresenter(object): self._process_authors(song_xml, song) self._process_songbooks(song_xml, song) self._process_topics(song_xml, song) - if not self.skip_song: + if not self.save_song: clean_song(self.manager, song) self.manager.save_object(song) @@ -427,7 +427,7 @@ class FoilPresenter(object): self.importer.logError(self._child(foilpresenterfolie.titel), unicode(translate('SongsPlugin.FoilPresenterSongImport', 'Invalid Foilpresenter song file. No verses found.'))) - self.skip_song = True + self.save_song = True return for strophe in foilpresenterfolie.strophen.strophe: text = self._child(strophe.text_) if hasattr(strophe, u'text_') else u'' From 1cde5f146d3e5afc79da3c28ac04ba9582c99ff3 Mon Sep 17 00:00:00 2001 From: Philip Ridout Date: Wed, 24 Jul 2013 21:04:49 +0100 Subject: [PATCH 38/40] change logic round due to name change --- openlp/plugins/songs/lib/foilpresenterimport.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/openlp/plugins/songs/lib/foilpresenterimport.py b/openlp/plugins/songs/lib/foilpresenterimport.py index 253cddb57..a8b252ced 100644 --- a/openlp/plugins/songs/lib/foilpresenterimport.py +++ b/openlp/plugins/songs/lib/foilpresenterimport.py @@ -224,7 +224,7 @@ class FoilPresenter(object): song.search_lyrics = u'' song.verse_order = u'' song.search_title = u'' - self.save_song = False + self.save_song = True # Because "text" seems to be an reserved word, we have to recompile it. xml = re.compile(u'').sub(u'', xml) xml = re.compile(u'').sub(u'', xml) @@ -238,7 +238,7 @@ class FoilPresenter(object): self._process_authors(song_xml, song) self._process_songbooks(song_xml, song) self._process_topics(song_xml, song) - if not self.save_song: + if self.save_song: clean_song(self.manager, song) self.manager.save_object(song) @@ -427,7 +427,7 @@ class FoilPresenter(object): self.importer.logError(self._child(foilpresenterfolie.titel), unicode(translate('SongsPlugin.FoilPresenterSongImport', 'Invalid Foilpresenter song file. No verses found.'))) - self.save_song = True + self.save_song = False return for strophe in foilpresenterfolie.strophen.strophe: text = self._child(strophe.text_) if hasattr(strophe, u'text_') else u'' From 3236af354c1da802bcf80ece1199d19316ea095a Mon Sep 17 00:00:00 2001 From: Philip Ridout Date: Thu, 25 Jul 2013 21:11:57 +0100 Subject: [PATCH 39/40] fixed #1204629 and made the validation more robust by checking the open dialog --- openlp/core/ui/themeform.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/openlp/core/ui/themeform.py b/openlp/core/ui/themeform.py index 007932f6e..edb8f26b6 100644 --- a/openlp/core/ui/themeform.py +++ b/openlp/core/ui/themeform.py @@ -71,6 +71,7 @@ class ThemeForm(QtGui.QWizard, Ui_ThemeWizard): self.gradientStartButton.clicked.connect(self.onGradientStartButtonClicked) self.gradientEndButton.clicked.connect(self.onGradientEndButtonClicked) self.imageBrowseButton.clicked.connect(self.onImageBrowseButtonClicked) + self.imageFileEdit.editingFinished.connect(self.onImageFileEditEditingFinished) self.mainColorButton.clicked.connect(self.onMainColorButtonClicked) self.outlineColorButton.clicked.connect(self.onOutlineColorButtonClicked) self.shadowColorButton.clicked.connect(self.onShadowColorButtonClicked) @@ -441,6 +442,12 @@ class ThemeForm(QtGui.QWizard, Ui_ThemeWizard): self.theme.background_filename = unicode(filename) self.setBackgroundPageValues() + def onImageFileEditEditingFinished(self): + """ + Background image path edited + """ + self.theme.background_filename = unicode(self.imageFileEdit.text()) + def onMainColorButtonClicked(self): """ Set the main colour value From 57cf6d5445002ececdf2015b1a71d6669b7a4586 Mon Sep 17 00:00:00 2001 From: Philip Ridout Date: Fri, 26 Jul 2013 21:17:51 +0100 Subject: [PATCH 40/40] actually changed validation this time --- openlp/core/ui/themeform.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openlp/core/ui/themeform.py b/openlp/core/ui/themeform.py index edb8f26b6..9a38b1f5f 100644 --- a/openlp/core/ui/themeform.py +++ b/openlp/core/ui/themeform.py @@ -179,7 +179,7 @@ class ThemeForm(QtGui.QWizard, Ui_ThemeWizard): """ background_image = BackgroundType.to_string(BackgroundType.Image) if self.page(self.currentId()) == self.backgroundPage and \ - self.theme.background_type == background_image and is_not_image_file(self.imageFileEdit.text()): + self.theme.background_type == background_image and is_not_image_file(self.theme.background_filename): QtGui.QMessageBox.critical(self, translate('OpenLP.ThemeWizard', 'Background Image Empty'), translate('OpenLP.ThemeWizard', 'You have not selected a ' 'background image. Please select one before continuing.'))