forked from openlp/openlp
Added an extra test song, and cleaned up the test some what
This commit is contained in:
parent
86fb343759
commit
c3492d6aed
@ -1,5 +1,5 @@
|
|||||||
"""
|
"""
|
||||||
This module contains tests for the OpenLP song importer.
|
This module contains tests for the SongShow Plus song importer.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
@ -10,10 +10,51 @@ from openlp.plugins.songs.lib import VerseType
|
|||||||
from openlp.plugins.songs.lib.songshowplusimport import SongShowPlusImport
|
from openlp.plugins.songs.lib.songshowplusimport import SongShowPlusImport
|
||||||
|
|
||||||
TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), u'../../../resources'))
|
TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), u'../../../resources'))
|
||||||
|
SONG_TEST_DATA = {u'Amazing Grace.sbsong':
|
||||||
|
{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'Beautiful Garden Of Prayer.sbsong':
|
||||||
|
{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 TestSongShowPlusFileImport(TestCase):
|
|
||||||
|
class TestSongShowPlusImport(TestCase):
|
||||||
"""
|
"""
|
||||||
Test the functions in the :mod:`lib` module.
|
Test the functions in the :mod:`songshowplusimport` module.
|
||||||
"""
|
"""
|
||||||
def create_importer_test(self):
|
def create_importer_test(self):
|
||||||
"""
|
"""
|
||||||
@ -29,6 +70,43 @@ class TestSongShowPlusFileImport(TestCase):
|
|||||||
# THEN: The importer object should not be None
|
# THEN: The importer object should not be None
|
||||||
self.assertIsNotNone(importer, u'Import should not be none')
|
self.assertIsNotNone(importer, u'Import should not be none')
|
||||||
|
|
||||||
|
def import_source_test(self):
|
||||||
|
"""
|
||||||
|
Test SongShowPlusImport.doImport handles different import_source values
|
||||||
|
"""
|
||||||
|
# GIVEN: A mocked out SongImport class, and a mocked out "manager"
|
||||||
|
with patch(u'openlp.plugins.songs.lib.songshowplusimport.SongImport'):
|
||||||
|
mocked_manager = MagicMock()
|
||||||
|
mocked_import_wizard = MagicMock()
|
||||||
|
importer = SongShowPlusImport(mocked_manager)
|
||||||
|
importer.import_wizard = mocked_import_wizard
|
||||||
|
importer.stop_import_flag = True
|
||||||
|
|
||||||
|
# WHEN: Import source is a string
|
||||||
|
importer.import_source = u'not a list'
|
||||||
|
|
||||||
|
# THEN: doImport should return none and the progress bar maximum should not be set.
|
||||||
|
self.assertIsNone(importer.doImport(), u'doImport should return None when import_source is not a list')
|
||||||
|
self.assertEquals(mocked_import_wizard.progress_bar.setMaximum.called, False,
|
||||||
|
u'setMaxium on import_wizard.progress_bar should not have been called')
|
||||||
|
|
||||||
|
# WHEN: Import source is an int
|
||||||
|
importer.import_source = 0
|
||||||
|
|
||||||
|
# THEN: doImport should return none and the progress bar maximum should not be set.
|
||||||
|
self.assertIsNone(importer.doImport(), u'doImport should return None when import_source is not a list')
|
||||||
|
self.assertEquals(mocked_import_wizard.progress_bar.setMaximum.called, False,
|
||||||
|
u'setMaxium on import_wizard.progress_bar should not have been called')
|
||||||
|
|
||||||
|
# WHEN: Import source is a list
|
||||||
|
importer.import_source = [u'List', u'of', u'files']
|
||||||
|
|
||||||
|
# THEN: doImport should return none and the progress bar setMaximum should be called with the length of
|
||||||
|
# import_source.
|
||||||
|
self.assertIsNone(importer.doImport(),
|
||||||
|
u'doImport should return None when import_source is a list and stop_import_flag is True')
|
||||||
|
mocked_import_wizard.progress_bar.setMaximum.assert_called_with(len(importer.import_source))
|
||||||
|
|
||||||
def toOpenLPVerseTag_test(self):
|
def toOpenLPVerseTag_test(self):
|
||||||
"""
|
"""
|
||||||
Test toOpenLPVerseTag method
|
Test toOpenLPVerseTag method
|
||||||
@ -75,95 +153,69 @@ class TestSongShowPlusFileImport(TestCase):
|
|||||||
u'SongShowPlusImport.toOpenLPVerseTag should return "%s" when called with "%s"'
|
u'SongShowPlusImport.toOpenLPVerseTag should return "%s" when called with "%s"'
|
||||||
% (openlp_tag, original_tag))
|
% (openlp_tag, original_tag))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def import_source_test(self):
|
|
||||||
"""
|
|
||||||
Test creating an instance of the SongShow Plus file importer
|
|
||||||
"""
|
|
||||||
# GIVEN: A mocked out SongImport class, and a mocked out "manager"
|
|
||||||
with patch(u'openlp.plugins.songs.lib.songshowplusimport.SongImport'):
|
|
||||||
mocked_manager = MagicMock()
|
|
||||||
mocked_import_wizard = MagicMock()
|
|
||||||
importer = SongShowPlusImport(mocked_manager)
|
|
||||||
importer.import_wizard = mocked_import_wizard
|
|
||||||
importer.stop_import_flag = True
|
|
||||||
|
|
||||||
# WHEN: Import source is a string
|
|
||||||
importer.import_source = u'not a list'
|
|
||||||
|
|
||||||
# THEN: doImport should return none and the progress bar maximum should not be set.
|
|
||||||
self.assertIsNone(importer.doImport(), u'doImport should return None when import_source is not a list')
|
|
||||||
self.assertEquals(mocked_import_wizard.progress_bar.setMaximum.called, False,
|
|
||||||
u'setMaxium on import_wizard.progress_bar should not have been called')
|
|
||||||
|
|
||||||
# WHEN: Import source is an int
|
|
||||||
importer.import_source = 0
|
|
||||||
|
|
||||||
# THEN: doImport should return none and the progress bar maximum should not be set.
|
|
||||||
self.assertIsNone(importer.doImport(), u'doImport should return None when import_source is not a list')
|
|
||||||
self.assertEquals(mocked_import_wizard.progress_bar.setMaximum.called, False,
|
|
||||||
u'setMaxium on import_wizard.progress_bar should not have been called')
|
|
||||||
|
|
||||||
# WHEN: Import source is a list
|
|
||||||
importer.import_source = [u'List', u'of', u'files']
|
|
||||||
|
|
||||||
# THEN: doImport should return none and the progress bar maximum should be set.
|
|
||||||
self.assertIsNone(importer.doImport(),
|
|
||||||
u'doImport should return None when import_source is a list and stop_import_flag is True')
|
|
||||||
mocked_import_wizard.progress_bar.setMaximum.assert_called_with(
|
|
||||||
len(importer.import_source))
|
|
||||||
|
|
||||||
def file_import_test(self):
|
def file_import_test(self):
|
||||||
"""
|
"""
|
||||||
Test creating an instance of the SongShow Plus file importer
|
Test the actual import of real song files and check that the imported data is correct.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# GIVEN: A mocked out SongImport class, and a mocked out "manager"
|
# 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.songshowplusimport.SongImport'):
|
||||||
mocked_manager = MagicMock()
|
for song_file in SONG_TEST_DATA:
|
||||||
mocked_import_wizard = MagicMock()
|
mocked_manager = MagicMock()
|
||||||
mocked_parse_author = MagicMock()
|
mocked_import_wizard = MagicMock()
|
||||||
mocked_add_copyright = MagicMock()
|
mocked_parse_author = MagicMock()
|
||||||
mocked_add_verse = MagicMock()
|
mocked_add_copyright = MagicMock()
|
||||||
mocked_finish = MagicMock()
|
mocked_add_verse = MagicMock()
|
||||||
mocked_finish.return_value = True
|
mocked_finish = MagicMock()
|
||||||
importer = SongShowPlusImport(mocked_manager)
|
mocked_finish.return_value = True
|
||||||
importer.import_wizard = mocked_import_wizard
|
importer = SongShowPlusImport(mocked_manager)
|
||||||
importer.stop_import_flag = False
|
importer.import_wizard = mocked_import_wizard
|
||||||
importer.parse_author = mocked_parse_author
|
importer.stop_import_flag = False
|
||||||
importer.addCopyright = mocked_add_copyright
|
importer.parse_author = mocked_parse_author
|
||||||
importer.addVerse = mocked_add_verse
|
importer.addCopyright = mocked_add_copyright
|
||||||
importer.finish = mocked_finish
|
importer.addVerse = mocked_add_verse
|
||||||
importer.topics = []
|
importer.finish = mocked_finish
|
||||||
|
importer.topics = []
|
||||||
|
|
||||||
# WHEN: Import source is a string
|
# WHEN: Importing each file
|
||||||
importer.import_source = [os.path.join(TEST_PATH, u'Amazing Grace.sbsong')]
|
importer.import_source = [os.path.join(TEST_PATH, song_file)]
|
||||||
|
title = SONG_TEST_DATA[song_file][u'title']
|
||||||
|
parse_author_calls = [call(author) for author in 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 = \
|
||||||
|
[call(verse_text, verse_tag) for verse_text, verse_tag in 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))
|
||||||
|
mocked_parse_author.assert_has_calls(parse_author_calls)
|
||||||
|
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))
|
||||||
|
mocked_add_verse.assert_has_calls(add_verse_calls)
|
||||||
|
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()
|
||||||
|
|
||||||
# THEN: doImport should return none and the progress bar maximum should not be set.
|
|
||||||
self.assertIsNone(importer.doImport(), u'doImport should return None when import_source is not a list')
|
|
||||||
self.assertEquals(importer.title, u'Amazing Grace (Demonstration)',
|
|
||||||
u'Title for Amazing Grace.sbsong should be "Amazing Grace (Demonstration)"')
|
|
||||||
calls = [call(u'John Newton'), call(u'Edwin Excell'), call(u'John P. Rees')]
|
|
||||||
mocked_parse_author.assert_has_calls(calls)
|
|
||||||
mocked_add_copyright.assert_called_with(u'Public Domain ')
|
|
||||||
self.assertEquals(importer.ccliNumber, 22025, u'ccliNumber should be set as 22025 for Amazing Grace.sbsong')
|
|
||||||
calls = [call(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'),
|
|
||||||
call(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'),
|
|
||||||
call(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'),
|
|
||||||
call(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'),
|
|
||||||
call(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')]
|
|
||||||
mocked_add_verse.assert_has_calls(calls)
|
|
||||||
self.assertEquals(importer.topics, [u'Assurance', u'Grace', u'Praise', u'Salvation'])
|
|
||||||
self.assertEquals(importer.comments, u'\n\n\n', u'comments should be "\\n\\n\\n" Amazing Grace.sbsong')
|
|
||||||
self.assertEquals(importer.songBookName, u'Demonstration Songs', u'songBookName should be '
|
|
||||||
u'"Demonstration Songs"')
|
|
||||||
self.assertEquals(importer.songNumber, 0, u'songNumber should be 0')
|
|
||||||
self.assertEquals(importer.verseOrderList, [], u'verseOrderList should be empty')
|
|
||||||
mocked_finish.assert_called_with()
|
|
BIN
tests/resources/Beautiful Garden Of Prayer.sbsong
Normal file
BIN
tests/resources/Beautiful Garden Of Prayer.sbsong
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user