forked from openlp/openlp
Added another OPS Pro import test
This commit is contained in:
parent
e9e5976d22
commit
302fcb221b
@ -130,7 +130,7 @@ class OpsProImport(SongImport):
|
|||||||
tag = tag_match.group(1).lower()
|
tag = tag_match.group(1).lower()
|
||||||
tag = tag.split(' ')[0]
|
tag = tag.split(' ')[0]
|
||||||
verse_text = tag_match.group(2)
|
verse_text = tag_match.group(2)
|
||||||
if 'refrein' in tag:
|
if 'refrein' in tag or 'chorus' in tag:
|
||||||
verse_def = 'c'
|
verse_def = 'c'
|
||||||
elif 'bridge' in tag:
|
elif 'bridge' in tag:
|
||||||
verse_def = 'b'
|
verse_def = 'b'
|
||||||
|
@ -77,21 +77,8 @@ class TestOpsProSongImport(TestCase):
|
|||||||
# GIVEN: A mocked out SongImport class, a mocked out "manager" and a mocked song and lyrics entry
|
# GIVEN: A mocked out SongImport class, a mocked out "manager" and a mocked song and lyrics entry
|
||||||
mocked_manager = MagicMock()
|
mocked_manager = MagicMock()
|
||||||
importer = OpsProImport(mocked_manager, filenames=[])
|
importer = OpsProImport(mocked_manager, filenames=[])
|
||||||
song = MagicMock()
|
|
||||||
song.ID = 100
|
|
||||||
song.SongNumber = 123
|
|
||||||
song.SongBookName = 'The Song Book'
|
|
||||||
song.Title = 'Song Title'
|
|
||||||
song.CopyrightText = 'Music and text by me'
|
|
||||||
song.Version = '1'
|
|
||||||
song.Origin = '...'
|
|
||||||
lyrics = MagicMock()
|
|
||||||
test_file = open(os.path.join(TEST_PATH, 'you are so faithfull.txt'), 'rb')
|
|
||||||
lyrics.Lyrics = test_file.read().decode()
|
|
||||||
lyrics.Type = 1
|
|
||||||
lyrics.IsDualLanguage = True
|
|
||||||
importer.finish = MagicMock()
|
importer.finish = MagicMock()
|
||||||
|
song, lyrics = self._build_test_data('you are so faithfull.txt')
|
||||||
# WHEN: An importer object is created
|
# WHEN: An importer object is created
|
||||||
importer.process_song(song, lyrics, [])
|
importer.process_song(song, lyrics, [])
|
||||||
|
|
||||||
@ -101,7 +88,42 @@ class TestOpsProSongImport(TestCase):
|
|||||||
self.assertListEqual(importer.verses, self._get_data(result_data, 'verses'))
|
self.assertListEqual(importer.verses, self._get_data(result_data, 'verses'))
|
||||||
self.assertListEqual(importer.verse_order_list_generated, self._get_data(result_data, 'verse_order_list'))
|
self.assertListEqual(importer.verse_order_list_generated, self._get_data(result_data, 'verse_order_list'))
|
||||||
|
|
||||||
|
@patch('openlp.plugins.songs.lib.importers.opspro.SongImport')
|
||||||
|
def join_and_split_test(self, mocked_songimport):
|
||||||
|
"""
|
||||||
|
Test importing lyrics with a split and join tags works in OPS Pro
|
||||||
|
"""
|
||||||
|
# GIVEN: A mocked out SongImport class, a mocked out "manager" and a mocked song and lyrics entry
|
||||||
|
mocked_manager = MagicMock()
|
||||||
|
importer = OpsProImport(mocked_manager, filenames=[])
|
||||||
|
importer.finish = MagicMock()
|
||||||
|
song, lyrics = self._build_test_data('amazing grace.txt')
|
||||||
|
# WHEN: An importer object is created
|
||||||
|
importer.process_song(song, lyrics, [])
|
||||||
|
|
||||||
|
# THEN: The imported data should look like expected
|
||||||
|
result_file = open(os.path.join(TEST_PATH, 'Amazing Grace.json'), 'rb')
|
||||||
|
result_data = json.loads(result_file.read().decode())
|
||||||
|
self.assertListEqual(importer.verses, self._get_data(result_data, 'verses'))
|
||||||
|
self.assertListEqual(importer.verse_order_list_generated, self._get_data(result_data, 'verse_order_list'))
|
||||||
|
|
||||||
def _get_data(self, data, key):
|
def _get_data(self, data, key):
|
||||||
if key in data:
|
if key in data:
|
||||||
return data[key]
|
return data[key]
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
|
def _build_test_data(self, test_file):
|
||||||
|
song = MagicMock()
|
||||||
|
song.ID = 100
|
||||||
|
song.SongNumber = 123
|
||||||
|
song.SongBookName = 'The Song Book'
|
||||||
|
song.Title = 'Song Title'
|
||||||
|
song.CopyrightText = 'Music and text by me'
|
||||||
|
song.Version = '1'
|
||||||
|
song.Origin = '...'
|
||||||
|
lyrics = MagicMock()
|
||||||
|
test_file = open(os.path.join(TEST_PATH, test_file), 'rb')
|
||||||
|
lyrics.Lyrics = test_file.read().decode()
|
||||||
|
lyrics.Type = 1
|
||||||
|
lyrics.IsDualLanguage = True
|
||||||
|
return song, lyrics
|
||||||
|
21
tests/resources/opsprosongs/Amazing Grace.json
Normal file
21
tests/resources/opsprosongs/Amazing Grace.json
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"title": "Amazing Grace",
|
||||||
|
"verse_order_list": ["v1", "v2", "v3"],
|
||||||
|
"verses": [
|
||||||
|
[
|
||||||
|
"v1",
|
||||||
|
"Amazing grace! How sweet the sound!\r\nThat saved a wretch like me!\r\nI once was lost, but now am found;\r\nWas blind, but now I see.\r\n\r\n'Twas grace that taught my heart to fear,\r\nAnd grace my fears relieved.\r\nHow precious did that grace appear,\r\nThe hour I first believed.",
|
||||||
|
null
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"v2",
|
||||||
|
"The Lord has promised good to me,\r\nHis Word my hope secures.\r\nHe will my shield and portion be\r\nAs long as life endures.",
|
||||||
|
null
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"v3",
|
||||||
|
"Thro' many dangers, toils and snares\r\nI have already come.\r\n'Tis grace that brought me safe thus far,\r\nAnd grace will lead me home.\r\n\r\n[---]\r\nWhen we've been there ten thousand years,\r\nBright shining as the sun,\r\nWe've no less days to sing God's praise,\r\nThan when we first begun.",
|
||||||
|
null
|
||||||
|
]
|
||||||
|
]
|
||||||
|
}
|
24
tests/resources/opsprosongs/amazing grace.txt
Normal file
24
tests/resources/opsprosongs/amazing grace.txt
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
Amazing grace! How sweet the sound!
|
||||||
|
That saved a wretch like me!
|
||||||
|
I once was lost, but now am found;
|
||||||
|
Was blind, but now I see.
|
||||||
|
[join]
|
||||||
|
'Twas grace that taught my heart to fear,
|
||||||
|
And grace my fears relieved.
|
||||||
|
How precious did that grace appear,
|
||||||
|
The hour I first believed.
|
||||||
|
|
||||||
|
The Lord has promised good to me,
|
||||||
|
His Word my hope secures.
|
||||||
|
He will my shield and portion be
|
||||||
|
As long as life endures.
|
||||||
|
|
||||||
|
Thro' many dangers, toils and snares
|
||||||
|
I have already come.
|
||||||
|
'Tis grace that brought me safe thus far,
|
||||||
|
And grace will lead me home.
|
||||||
|
[split]
|
||||||
|
When we've been there ten thousand years,
|
||||||
|
Bright shining as the sun,
|
||||||
|
We've no less days to sing God's praise,
|
||||||
|
Than when we first begun.
|
Loading…
Reference in New Issue
Block a user