forked from openlp/openlp
Improve the worshipcenter pro importer and updated test.
This commit is contained in:
parent
d65fa351c3
commit
fc5f2e1018
@ -24,7 +24,7 @@ The :mod:`worshipcenterpro` module provides the functionality for importing
|
|||||||
a WorshipCenter Pro database into the OpenLP database.
|
a WorshipCenter Pro database into the OpenLP database.
|
||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
|
import re
|
||||||
import pyodbc
|
import pyodbc
|
||||||
|
|
||||||
from openlp.core.common import translate
|
from openlp.core.common import translate
|
||||||
@ -71,8 +71,41 @@ class WorshipCenterProImport(SongImport):
|
|||||||
break
|
break
|
||||||
self.set_defaults()
|
self.set_defaults()
|
||||||
self.title = songs[song]['TITLE']
|
self.title = songs[song]['TITLE']
|
||||||
|
if 'AUTHOR' in songs[song]:
|
||||||
|
self.parse_author(songs[song]['AUTHOR'])
|
||||||
|
if 'CCLISONGID' in songs[song]:
|
||||||
|
self.ccli_number = songs[song]['CCLISONGID']
|
||||||
|
if 'COMMENTS' in songs[song]:
|
||||||
|
self.add_comment(songs[song]['COMMENTS'])
|
||||||
|
if 'COPY' in songs[song]:
|
||||||
|
self.add_copyright(songs[song]['COPY'])
|
||||||
|
if 'SUBJECT' in songs[song]:
|
||||||
|
self.topics.append(songs[song]['SUBJECT'])
|
||||||
lyrics = songs[song]['LYRICS'].strip('&crlf;&crlf;')
|
lyrics = songs[song]['LYRICS'].strip('&crlf;&crlf;')
|
||||||
for verse in lyrics.split('&crlf;&crlf;'):
|
for verse in lyrics.split('&crlf;&crlf;'):
|
||||||
verse = verse.replace('&crlf;', '\n')
|
verse = verse.replace('&crlf;', '\n')
|
||||||
self.add_verse(verse)
|
marker_type = 'v'
|
||||||
|
# Find verse markers if any
|
||||||
|
marker_start = verse.find('<')
|
||||||
|
if marker_start > -1:
|
||||||
|
marker_end = verse.find('>')
|
||||||
|
marker = verse[marker_start + 1:marker_end]
|
||||||
|
# Identify the marker type
|
||||||
|
if 'REFRAIN' in marker or 'CHORUS' in marker:
|
||||||
|
marker_type = 'c'
|
||||||
|
elif 'BRIDGE' in marker:
|
||||||
|
marker_type = 'b'
|
||||||
|
elif 'PRECHORUS' in marker:
|
||||||
|
marker_type = 'p'
|
||||||
|
elif 'END' in marker:
|
||||||
|
marker_type = 'e'
|
||||||
|
elif 'INTRO' in marker:
|
||||||
|
marker_type = 'i'
|
||||||
|
elif 'TAG' in marker:
|
||||||
|
marker_type = 'o'
|
||||||
|
else:
|
||||||
|
marker_type = 'v'
|
||||||
|
# Strip tags from text
|
||||||
|
verse = re.sub('<[^<]+?>', '', verse)
|
||||||
|
self.add_verse(verse, marker_type)
|
||||||
self.finish()
|
self.finish()
|
||||||
|
@ -25,9 +25,6 @@ This module contains tests for the WorshipCenter Pro song importer.
|
|||||||
import os
|
import os
|
||||||
from unittest import TestCase, SkipTest
|
from unittest import TestCase, SkipTest
|
||||||
|
|
||||||
if os.name != 'nt':
|
|
||||||
raise SkipTest('Not Windows, skipping test')
|
|
||||||
|
|
||||||
import pyodbc
|
import pyodbc
|
||||||
from tests.functional import patch, MagicMock
|
from tests.functional import patch, MagicMock
|
||||||
|
|
||||||
@ -67,6 +64,10 @@ class WorshipCenterProImportLogger(WorshipCenterProImport):
|
|||||||
|
|
||||||
|
|
||||||
RECORDSET_TEST_DATA = [TestRecord(1, 'TITLE', 'Amazing Grace'),
|
RECORDSET_TEST_DATA = [TestRecord(1, 'TITLE', 'Amazing Grace'),
|
||||||
|
TestRecord(1, 'AUTHOR', 'John Newton'),
|
||||||
|
TestRecord(1, 'CCLISONGID', '12345'),
|
||||||
|
TestRecord(1, 'COMMENTS', 'The original version'),
|
||||||
|
TestRecord(1, 'COPY', 'Public Domain'),
|
||||||
TestRecord(
|
TestRecord(
|
||||||
1, 'LYRICS',
|
1, 'LYRICS',
|
||||||
'Amazing grace! How&crlf;sweet the sound&crlf;That saved a wretch like me!&crlf;'
|
'Amazing grace! How&crlf;sweet the sound&crlf;That saved a wretch like me!&crlf;'
|
||||||
@ -97,7 +98,9 @@ RECORDSET_TEST_DATA = [TestRecord(1, 'TITLE', 'Amazing Grace'),
|
|||||||
'Just to learn from His&crlf;lips words of comfort&crlf;In the beautiful&crlf;'
|
'Just to learn from His&crlf;lips words of comfort&crlf;In the beautiful&crlf;'
|
||||||
'garden of prayer.&crlf;&crlf;There\'s a garden where&crlf;Jesus is waiting,&crlf;'
|
'garden of prayer.&crlf;&crlf;There\'s a garden where&crlf;Jesus is waiting,&crlf;'
|
||||||
'And He bids you to come,&crlf;meet Him there;&crlf;Just to bow and&crlf;'
|
'And He bids you to come,&crlf;meet Him there;&crlf;Just to bow and&crlf;'
|
||||||
'receive a new blessing&crlf;In the beautiful&crlf;garden of prayer.&crlf;&crlf;')]
|
'receive a new blessing&crlf;In the beautiful&crlf;garden of prayer.&crlf;&crlf;'),
|
||||||
|
|
||||||
|
]
|
||||||
SONG_TEST_DATA = [{'title': 'Amazing Grace',
|
SONG_TEST_DATA = [{'title': 'Amazing Grace',
|
||||||
'verses': [
|
'verses': [
|
||||||
('Amazing grace! How\nsweet the sound\nThat saved a wretch like me!\nI once was lost,\n'
|
('Amazing grace! How\nsweet the sound\nThat saved a wretch like me!\nI once was lost,\n'
|
||||||
@ -113,7 +116,10 @@ SONG_TEST_DATA = [{'title': 'Amazing Grace',
|
|||||||
('The earth shall soon\ndissolve like snow,\nThe sun forbear to shine;\nBut God, Who called\n'
|
('The earth shall soon\ndissolve like snow,\nThe sun forbear to shine;\nBut God, Who called\n'
|
||||||
'me here below,\nShall be forever mine.'),
|
'me here below,\nShall be forever mine.'),
|
||||||
('When we\'ve been there\nten thousand years,\nBright shining as the sun,\n'
|
('When we\'ve been there\nten thousand years,\nBright shining as the sun,\n'
|
||||||
'We\'ve no less days to\nsing God\'s praise\nThan when we\'d first begun.')]},
|
'We\'ve no less days to\nsing God\'s praise\nThan when we\'d first begun.')],
|
||||||
|
'author': 'John Newton',
|
||||||
|
'comments': 'The original version',
|
||||||
|
'copyright': 'Public Domain'},
|
||||||
{'title': 'Beautiful Garden Of Prayer, The',
|
{'title': 'Beautiful Garden Of Prayer, The',
|
||||||
'verses': [
|
'verses': [
|
||||||
('There\'s a garden where\nJesus is waiting,\nThere\'s a place that\nis wondrously fair,\n'
|
('There\'s a garden where\nJesus is waiting,\nThere\'s a place that\nis wondrously fair,\n'
|
||||||
@ -191,6 +197,9 @@ class TestWorshipCenterProSongImport(TestCase):
|
|||||||
mocked_manager = MagicMock()
|
mocked_manager = MagicMock()
|
||||||
mocked_import_wizard = MagicMock()
|
mocked_import_wizard = MagicMock()
|
||||||
mocked_add_verse = MagicMock()
|
mocked_add_verse = MagicMock()
|
||||||
|
mocked_parse_author= MagicMock()
|
||||||
|
mocked_add_comment = MagicMock()
|
||||||
|
mocked_add_copyright = MagicMock()
|
||||||
mocked_finish = MagicMock()
|
mocked_finish = MagicMock()
|
||||||
mocked_pyodbc.connect().cursor().fetchall.return_value = RECORDSET_TEST_DATA
|
mocked_pyodbc.connect().cursor().fetchall.return_value = RECORDSET_TEST_DATA
|
||||||
mocked_translate.return_value = 'Translated Text'
|
mocked_translate.return_value = 'Translated Text'
|
||||||
@ -198,6 +207,9 @@ class TestWorshipCenterProSongImport(TestCase):
|
|||||||
importer.import_source = 'import_source'
|
importer.import_source = 'import_source'
|
||||||
importer.import_wizard = mocked_import_wizard
|
importer.import_wizard = mocked_import_wizard
|
||||||
importer.add_verse = mocked_add_verse
|
importer.add_verse = mocked_add_verse
|
||||||
|
importer.parse_author = mocked_parse_author
|
||||||
|
importer.add_comment = mocked_add_comment
|
||||||
|
importer.add_copyright = mocked_add_copyright
|
||||||
importer.stop_import_flag = False
|
importer.stop_import_flag = False
|
||||||
importer.finish = mocked_finish
|
importer.finish = mocked_finish
|
||||||
|
|
||||||
@ -220,6 +232,12 @@ class TestWorshipCenterProSongImport(TestCase):
|
|||||||
verse_calls = song_data['verses']
|
verse_calls = song_data['verses']
|
||||||
add_verse_call_count += len(verse_calls)
|
add_verse_call_count += len(verse_calls)
|
||||||
for call in verse_calls:
|
for call in verse_calls:
|
||||||
mocked_add_verse.assert_any_call(call)
|
mocked_add_verse.assert_any_call(call, 'v')
|
||||||
|
if 'author' in song_data:
|
||||||
|
mocked_parse_author.assert_any_call(song_data['author'])
|
||||||
|
if 'comments' in song_data:
|
||||||
|
mocked_add_comment.assert_any_call(song_data['comments'])
|
||||||
|
if 'copyright' in song_data:
|
||||||
|
mocked_add_copyright.assert_any_call(song_data['copyright'])
|
||||||
self.assertEqual(mocked_add_verse.call_count, add_verse_call_count,
|
self.assertEqual(mocked_add_verse.call_count, add_verse_call_count,
|
||||||
'Incorrect number of calls made to add_verse')
|
'Incorrect number of calls made to add_verse')
|
||||||
|
Loading…
Reference in New Issue
Block a user