2013-09-19 21:02:28 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
# OpenLP - Open Source Lyrics Projection #
|
|
|
|
# --------------------------------------------------------------------------- #
|
2013-12-24 08:56:50 +00:00
|
|
|
# Copyright (c) 2008-2014 Raoul Snyman #
|
|
|
|
# Portions copyright (c) 2008-2014 Tim Bentley, Gerald Britton, Jonathan #
|
2013-09-19 21:02:28 +00:00
|
|
|
# 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 #
|
|
|
|
###############################################################################
|
2013-03-24 11:32:03 +00:00
|
|
|
"""
|
2013-03-24 13:25:31 +00:00
|
|
|
This module contains tests for the SongShow Plus song importer.
|
2013-03-24 11:32:03 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
import os
|
|
|
|
from unittest import TestCase
|
|
|
|
|
2013-10-10 19:58:52 +00:00
|
|
|
from tests.helpers.songfileimport import SongImportTestHelper
|
2013-03-24 11:32:03 +00:00
|
|
|
from openlp.plugins.songs.lib import VerseType
|
|
|
|
from openlp.plugins.songs.lib.songshowplusimport import SongShowPlusImport
|
2013-09-19 21:02:28 +00:00
|
|
|
from tests.functional import patch, MagicMock
|
2013-03-24 11:32:03 +00:00
|
|
|
|
2013-08-29 21:04:23 +00:00
|
|
|
TEST_PATH = os.path.abspath(
|
2013-09-07 16:55:09 +00:00
|
|
|
os.path.join(os.path.dirname(__file__), '..', '..', '..', 'resources', 'songshowplussongs'))
|
2013-08-29 21:04:23 +00:00
|
|
|
|
|
|
|
class TestSongShowPlusFileImport(SongImportTestHelper):
|
|
|
|
def __init__(self, *args, **kwargs):
|
2013-09-07 16:55:09 +00:00
|
|
|
self.importer_class_name = 'SongShowPlusImport'
|
|
|
|
self.importer_module_name = 'songshowplusimport'
|
2013-09-17 20:31:19 +00:00
|
|
|
super(TestSongShowPlusFileImport, self).__init__(*args, **kwargs)
|
2013-08-29 21:04:23 +00:00
|
|
|
|
|
|
|
def test_song_import(self):
|
2013-09-07 16:55:09 +00:00
|
|
|
test_import = self.file_import(os.path.join(TEST_PATH, 'Amazing Grace.sbsong'),
|
|
|
|
self.load_external_result_data(os.path.join(TEST_PATH, 'Amazing Grace.json')))
|
|
|
|
test_import = self.file_import(os.path.join(TEST_PATH, 'Beautiful Garden Of Prayer.sbsong'),
|
|
|
|
self.load_external_result_data(os.path.join(TEST_PATH, 'Beautiful Garden Of Prayer.json')))
|
2013-03-24 13:25:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestSongShowPlusImport(TestCase):
|
2013-03-24 11:32:03 +00:00
|
|
|
"""
|
2013-03-24 13:25:31 +00:00
|
|
|
Test the functions in the :mod:`songshowplusimport` module.
|
2013-03-24 11:32:03 +00:00
|
|
|
"""
|
|
|
|
def create_importer_test(self):
|
|
|
|
"""
|
|
|
|
Test creating an instance of the SongShow Plus file importer
|
|
|
|
"""
|
|
|
|
# GIVEN: A mocked out SongImport class, and a mocked out "manager"
|
2013-08-31 18:17:38 +00:00
|
|
|
with patch('openlp.plugins.songs.lib.songshowplusimport.SongImport'):
|
2013-03-24 11:32:03 +00:00
|
|
|
mocked_manager = MagicMock()
|
|
|
|
|
|
|
|
# WHEN: An importer object is created
|
|
|
|
importer = SongShowPlusImport(mocked_manager)
|
|
|
|
|
|
|
|
# THEN: The importer object should not be None
|
2013-08-31 18:17:38 +00:00
|
|
|
self.assertIsNotNone(importer, 'Import should not be none')
|
2013-03-24 11:32:03 +00:00
|
|
|
|
2013-03-31 10:55:58 +00:00
|
|
|
def invalid_import_source_test(self):
|
2013-03-24 13:25:31 +00:00
|
|
|
"""
|
2013-03-31 10:55:58 +00:00
|
|
|
Test SongShowPlusImport.doImport handles different invalid import_source values
|
2013-03-24 13:25:31 +00:00
|
|
|
"""
|
|
|
|
# GIVEN: A mocked out SongImport class, and a mocked out "manager"
|
2013-08-31 18:17:38 +00:00
|
|
|
with patch('openlp.plugins.songs.lib.songshowplusimport.SongImport'):
|
2013-03-24 13:25:31 +00:00
|
|
|
mocked_manager = MagicMock()
|
|
|
|
mocked_import_wizard = MagicMock()
|
|
|
|
importer = SongShowPlusImport(mocked_manager)
|
|
|
|
importer.import_wizard = mocked_import_wizard
|
|
|
|
importer.stop_import_flag = True
|
|
|
|
|
2013-03-31 10:55:58 +00:00
|
|
|
# WHEN: Import source is not a list
|
2013-08-31 18:17:38 +00:00
|
|
|
for source in ['not a list', 0]:
|
2013-03-31 10:55:58 +00:00
|
|
|
importer.import_source = source
|
2013-03-24 13:25:31 +00:00
|
|
|
|
2013-03-31 10:55:58 +00:00
|
|
|
# THEN: doImport should return none and the progress bar maximum should not be set.
|
2013-08-31 18:17:38 +00:00
|
|
|
self.assertIsNone(importer.doImport(), 'doImport should return None when import_source is not a list')
|
2013-03-31 10:55:58 +00:00
|
|
|
self.assertEquals(mocked_import_wizard.progress_bar.setMaximum.called, False,
|
2013-09-14 21:43:46 +00:00
|
|
|
'setMaximum on import_wizard.progress_bar should not have been called')
|
2013-03-28 19:50:06 +00:00
|
|
|
|
2013-03-31 10:55:58 +00:00
|
|
|
def valid_import_source_test(self):
|
|
|
|
"""
|
|
|
|
Test SongShowPlusImport.doImport handles different invalid import_source values
|
|
|
|
"""
|
2013-03-28 19:56:50 +00:00
|
|
|
# GIVEN: A mocked out SongImport class, and a mocked out "manager"
|
2013-08-31 18:17:38 +00:00
|
|
|
with patch('openlp.plugins.songs.lib.songshowplusimport.SongImport'):
|
2013-03-28 19:50:06 +00:00
|
|
|
mocked_manager = MagicMock()
|
|
|
|
mocked_import_wizard = MagicMock()
|
|
|
|
importer = SongShowPlusImport(mocked_manager)
|
|
|
|
importer.import_wizard = mocked_import_wizard
|
|
|
|
importer.stop_import_flag = True
|
2013-03-24 13:25:31 +00:00
|
|
|
|
|
|
|
# WHEN: Import source is a list
|
2013-08-31 18:17:38 +00:00
|
|
|
importer.import_source = ['List', 'of', 'files']
|
2013-03-24 13:25:31 +00:00
|
|
|
|
|
|
|
# THEN: doImport should return none and the progress bar setMaximum should be called with the length of
|
|
|
|
# import_source.
|
|
|
|
self.assertIsNone(importer.doImport(),
|
2013-08-31 18:17:38 +00:00
|
|
|
'doImport should return None when import_source is a list and stop_import_flag is True')
|
2013-03-24 13:25:31 +00:00
|
|
|
mocked_import_wizard.progress_bar.setMaximum.assert_called_with(len(importer.import_source))
|
|
|
|
|
2013-03-28 19:50:06 +00:00
|
|
|
def to_openlp_verse_tag_test(self):
|
2013-03-24 11:32:03 +00:00
|
|
|
"""
|
2013-03-31 10:47:31 +00:00
|
|
|
Test to_openlp_verse_tag method by simulating adding a verse
|
2013-03-24 11:32:03 +00:00
|
|
|
"""
|
|
|
|
# GIVEN: A mocked out SongImport class, and a mocked out "manager"
|
2013-08-31 18:17:38 +00:00
|
|
|
with patch('openlp.plugins.songs.lib.songshowplusimport.SongImport'):
|
2013-03-24 11:32:03 +00:00
|
|
|
mocked_manager = MagicMock()
|
|
|
|
importer = SongShowPlusImport(mocked_manager)
|
|
|
|
|
|
|
|
# WHEN: Supplied with the following arguments replicating verses being added
|
2013-08-31 18:17:38 +00:00
|
|
|
test_values = [('Verse 1', VerseType.tags[VerseType.Verse] + '1'),
|
|
|
|
('Verse 2', VerseType.tags[VerseType.Verse] + '2'),
|
|
|
|
('verse1', VerseType.tags[VerseType.Verse] + '1'),
|
|
|
|
('Verse', VerseType.tags[VerseType.Verse] + '1'),
|
|
|
|
('Verse1', VerseType.tags[VerseType.Verse] + '1'),
|
|
|
|
('chorus 1', VerseType.tags[VerseType.Chorus] + '1'),
|
|
|
|
('bridge 1', VerseType.tags[VerseType.Bridge] + '1'),
|
|
|
|
('pre-chorus 1', VerseType.tags[VerseType.PreChorus] + '1'),
|
|
|
|
('different 1', VerseType.tags[VerseType.Other] + '1'),
|
|
|
|
('random 1', VerseType.tags[VerseType.Other] + '2')]
|
2013-03-24 11:32:03 +00:00
|
|
|
|
|
|
|
# THEN: The returned value should should correlate with the input arguments
|
|
|
|
for original_tag, openlp_tag in test_values:
|
2013-03-24 14:56:22 +00:00
|
|
|
self.assertEquals(importer.to_openlp_verse_tag(original_tag), openlp_tag,
|
2013-08-31 18:17:38 +00:00
|
|
|
'SongShowPlusImport.to_openlp_verse_tag should return "%s" when called with "%s"'
|
2013-03-24 11:32:03 +00:00
|
|
|
% (openlp_tag, original_tag))
|
|
|
|
|
2013-03-31 10:47:31 +00:00
|
|
|
def to_openlp_verse_tag_verse_order_test(self):
|
|
|
|
"""
|
|
|
|
Test to_openlp_verse_tag method by simulating adding a verse to the verse order
|
|
|
|
"""
|
2013-03-28 19:50:06 +00:00
|
|
|
# GIVEN: A mocked out SongImport class, and a mocked out "manager"
|
2013-08-31 18:17:38 +00:00
|
|
|
with patch('openlp.plugins.songs.lib.songshowplusimport.SongImport'):
|
2013-03-28 19:50:06 +00:00
|
|
|
mocked_manager = MagicMock()
|
|
|
|
importer = SongShowPlusImport(mocked_manager)
|
|
|
|
|
2013-03-24 11:32:03 +00:00
|
|
|
# WHEN: Supplied with the following arguments replicating a verse order being added
|
2013-08-31 18:17:38 +00:00
|
|
|
test_values = [('Verse 1', VerseType.tags[VerseType.Verse] + '1'),
|
|
|
|
('Verse 2', VerseType.tags[VerseType.Verse] + '2'),
|
|
|
|
('verse1', VerseType.tags[VerseType.Verse] + '1'),
|
|
|
|
('Verse', VerseType.tags[VerseType.Verse] + '1'),
|
|
|
|
('Verse1', VerseType.tags[VerseType.Verse] + '1'),
|
|
|
|
('chorus 1', VerseType.tags[VerseType.Chorus] + '1'),
|
|
|
|
('bridge 1', VerseType.tags[VerseType.Bridge] + '1'),
|
|
|
|
('pre-chorus 1', VerseType.tags[VerseType.PreChorus] + '1'),
|
|
|
|
('different 1', VerseType.tags[VerseType.Other] + '1'),
|
|
|
|
('random 1', VerseType.tags[VerseType.Other] + '2'),
|
|
|
|
('unused 2', None)]
|
2013-03-24 11:32:03 +00:00
|
|
|
|
|
|
|
# THEN: The returned value should should correlate with the input arguments
|
|
|
|
for original_tag, openlp_tag in test_values:
|
2013-03-24 14:56:22 +00:00
|
|
|
self.assertEquals(importer.to_openlp_verse_tag(original_tag, ignore_unique=True), openlp_tag,
|
2013-08-31 18:17:38 +00:00
|
|
|
'SongShowPlusImport.to_openlp_verse_tag should return "%s" when called with "%s"'
|
2013-03-24 11:32:03 +00:00
|
|
|
% (openlp_tag, original_tag))
|