forked from openlp/openlp
Migrated songselect and songbeamer tests to the SongImportTestHelper based structure.
This commit is contained in:
parent
037d3f4f7d
commit
2a4205c0a1
@ -250,10 +250,10 @@ class SongFormat(object):
|
|||||||
},
|
},
|
||||||
Lyrix: {
|
Lyrix: {
|
||||||
'class': LyrixImport,
|
'class': LyrixImport,
|
||||||
'name': 'Lyrix',
|
'name': 'LyriX',
|
||||||
'prefix': 'lyrix',
|
'prefix': 'lyrix',
|
||||||
'filter': '%s (*.txt)' % translate('SongsPlugin.ImportWizardForm', 'Lyrix Files'),
|
'filter': '%s (*.txt)' % translate('SongsPlugin.ImportWizardForm', 'LyriX Files'),
|
||||||
'comboBoxText': translate('SongsPlugin.ImportWizardForm', 'Lyrix (exported txt-files)')
|
'comboBoxText': translate('SongsPlugin.ImportWizardForm', 'LyriX (Exported TXT-files)')
|
||||||
},
|
},
|
||||||
MediaShout: {
|
MediaShout: {
|
||||||
'name': 'MediaShout',
|
'name': 'MediaShout',
|
||||||
|
@ -48,7 +48,7 @@ class CCLIFileImport(SongImport):
|
|||||||
:param manager: The song manager for the running OpenLP installation.
|
:param manager: The song manager for the running OpenLP installation.
|
||||||
:param kwargs: The files to be imported.
|
:param kwargs: The files to be imported.
|
||||||
"""
|
"""
|
||||||
SongImport.__init__(self, manager, **kwargs)
|
super(CCLIFileImport, self).__init__(manager, **kwargs)
|
||||||
|
|
||||||
def do_import(self):
|
def do_import(self):
|
||||||
"""
|
"""
|
||||||
@ -161,7 +161,7 @@ class CCLIFileImport(SongImport):
|
|||||||
elif line.startswith('Author='):
|
elif line.startswith('Author='):
|
||||||
song_author = line[7:].strip()
|
song_author = line[7:].strip()
|
||||||
elif line.startswith('Copyright='):
|
elif line.startswith('Copyright='):
|
||||||
self.copyright = line[10:].strip()
|
self.add_copyright(line[10:].strip())
|
||||||
elif line.startswith('Themes='):
|
elif line.startswith('Themes='):
|
||||||
song_topics = line[7:].strip().replace(' | ', '/t')
|
song_topics = line[7:].strip().replace(' | ', '/t')
|
||||||
elif line.startswith('Fields='):
|
elif line.startswith('Fields='):
|
||||||
@ -318,14 +318,14 @@ class CCLIFileImport(SongImport):
|
|||||||
if line_number == 2:
|
if line_number == 2:
|
||||||
line_number += 1
|
line_number += 1
|
||||||
if clean_line.startswith('©'):
|
if clean_line.startswith('©'):
|
||||||
self.copyright = clean_line
|
self.add_copyright(clean_line)
|
||||||
else:
|
else:
|
||||||
song_author = clean_line
|
song_author = clean_line
|
||||||
# n=3, authors
|
# n=3, authors
|
||||||
elif line_number == 3:
|
elif line_number == 3:
|
||||||
line_number += 1
|
line_number += 1
|
||||||
if song_author:
|
if song_author:
|
||||||
self.copyright = clean_line
|
self.add_copyright(clean_line)
|
||||||
else:
|
else:
|
||||||
song_author = clean_line
|
song_author = clean_line
|
||||||
# line_number=4, comments lines before last line
|
# line_number=4, comments lines before last line
|
||||||
|
@ -26,27 +26,28 @@ This module contains tests for the Songbeamer song importer.
|
|||||||
import os
|
import os
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
|
|
||||||
|
from tests.helpers.songfileimport import SongImportTestHelper
|
||||||
from tests.functional import MagicMock, patch
|
from tests.functional import MagicMock, patch
|
||||||
from openlp.plugins.songs.lib.importers.songbeamer import SongBeamerImport
|
from openlp.plugins.songs.lib.importers.songbeamer import SongBeamerImport
|
||||||
from openlp.plugins.songs.lib import VerseType
|
|
||||||
from openlp.core.common import Registry
|
from openlp.core.common import Registry
|
||||||
|
|
||||||
TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__),
|
TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__),
|
||||||
'..', '..', '..', 'resources', 'songbeamersongs'))
|
'..', '..', '..', 'resources', 'songbeamersongs'))
|
||||||
SONG_TEST_DATA = {
|
|
||||||
'Lobsinget dem Herrn.sng': {
|
|
||||||
'title': 'GL 1 - Lobsinget dem Herrn',
|
class TestSongBeamerFileImport(SongImportTestHelper):
|
||||||
'verses': [
|
|
||||||
('1. Lobsinget dem Herrn,\no preiset Ihn gern!\nAnbetung und Lob Ihm gebühret.\n', 'v'),
|
def __init__(self, *args, **kwargs):
|
||||||
('2. Lobsingt Seiner Lieb´,\ndie einzig ihn trieb,\nzu sterben für unsere Sünden!\n', 'v'),
|
self.importer_class_name = 'SongBeamerImport'
|
||||||
('3. Lobsingt Seiner Macht!\nSein Werk ist vollbracht:\nEr sitzet zur Rechten des Vaters.\n', 'v'),
|
self.importer_module_name = 'songbeamer'
|
||||||
('4. Lobsingt seiner Treu´,\ndie immerdar neu,\nbis Er uns zur Herrlichket führet!\n\n', 'v')
|
super(TestSongBeamerFileImport, self).__init__(*args, **kwargs)
|
||||||
],
|
|
||||||
'song_book_name': 'Glaubenslieder I',
|
def test_song_import(self):
|
||||||
'song_number': "1",
|
"""
|
||||||
'authors': ['Carl Brockhaus', 'Johann Jakob Vetter']
|
Test that loading an OpenSong file works correctly on various files
|
||||||
}
|
"""
|
||||||
}
|
self.file_import([os.path.join(TEST_PATH, 'Lobsinget dem Herrn.sng')],
|
||||||
|
self.load_external_result_data(os.path.join(TEST_PATH, 'Lobsinget dem Herrn.json')))
|
||||||
|
|
||||||
|
|
||||||
class TestSongBeamerImport(TestCase):
|
class TestSongBeamerImport(TestCase):
|
||||||
@ -115,51 +116,6 @@ class TestSongBeamerImport(TestCase):
|
|||||||
'do_import should return None when import_source is a list and stop_import_flag is True')
|
'do_import 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))
|
mocked_import_wizard.progress_bar.setMaximum.assert_called_with(len(importer.import_source))
|
||||||
|
|
||||||
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('openlp.plugins.songs.lib.importers.songbeamer.SongImport'):
|
|
||||||
for song_file in SONG_TEST_DATA:
|
|
||||||
mocked_manager = MagicMock()
|
|
||||||
mocked_import_wizard = MagicMock()
|
|
||||||
mocked_add_verse = MagicMock()
|
|
||||||
mocked_finish = MagicMock()
|
|
||||||
mocked_finish.return_value = True
|
|
||||||
importer = SongBeamerImport(mocked_manager, filenames=[])
|
|
||||||
importer.import_wizard = mocked_import_wizard
|
|
||||||
importer.stop_import_flag = False
|
|
||||||
importer.add_verse = mocked_add_verse
|
|
||||||
importer.finish = mocked_finish
|
|
||||||
|
|
||||||
# WHEN: Importing each file
|
|
||||||
importer.import_source = [os.path.join(TEST_PATH, song_file)]
|
|
||||||
title = SONG_TEST_DATA[song_file]['title']
|
|
||||||
add_verse_calls = SONG_TEST_DATA[song_file]['verses']
|
|
||||||
song_book_name = SONG_TEST_DATA[song_file]['song_book_name']
|
|
||||||
song_number = SONG_TEST_DATA[song_file]['song_number']
|
|
||||||
song_authors = SONG_TEST_DATA[song_file]['authors']
|
|
||||||
|
|
||||||
# THEN: do_import should return none, the song data should be as expected, and finish should have been
|
|
||||||
# called.
|
|
||||||
self.assertIsNone(importer.do_import(), 'do_import should return None when it has completed')
|
|
||||||
self.assertEqual(importer.title, title, 'title for %s should be "%s"' % (song_file, title))
|
|
||||||
for verse_text, verse_tag in add_verse_calls:
|
|
||||||
mocked_add_verse.assert_any_call(verse_text, verse_tag)
|
|
||||||
if song_book_name:
|
|
||||||
self.assertEqual(importer.song_book_name, song_book_name,
|
|
||||||
'song_book_name for %s should be "%s"' % (song_file, song_book_name))
|
|
||||||
if song_number:
|
|
||||||
self.assertEqual(importer.song_number, song_number,
|
|
||||||
'song_number for %s should be %s' % (song_file, song_number))
|
|
||||||
if song_authors:
|
|
||||||
for author in importer.authors:
|
|
||||||
self.assertIn(author, song_authors)
|
|
||||||
mocked_finish.assert_called_with()
|
|
||||||
|
|
||||||
def check_verse_marks_test(self):
|
def check_verse_marks_test(self):
|
||||||
"""
|
"""
|
||||||
Tests different lines to see if a verse mark is detected or not
|
Tests different lines to see if a verse mark is detected or not
|
||||||
|
@ -28,6 +28,7 @@ from urllib.error import URLError
|
|||||||
|
|
||||||
from PyQt4 import QtGui
|
from PyQt4 import QtGui
|
||||||
|
|
||||||
|
from tests.helpers.songfileimport import SongImportTestHelper
|
||||||
from openlp.core import Registry
|
from openlp.core import Registry
|
||||||
from openlp.plugins.songs.forms.songselectform import SongSelectForm, SearchWorker
|
from openlp.plugins.songs.forms.songselectform import SongSelectForm, SearchWorker
|
||||||
from openlp.plugins.songs.lib import Song
|
from openlp.plugins.songs.lib import Song
|
||||||
@ -37,6 +38,9 @@ from openlp.plugins.songs.lib.importers.cclifile import CCLIFileImport
|
|||||||
from tests.functional import MagicMock, patch, call
|
from tests.functional import MagicMock, patch, call
|
||||||
from tests.helpers.testmixin import TestMixin
|
from tests.helpers.testmixin import TestMixin
|
||||||
|
|
||||||
|
TEST_PATH = os.path.abspath(
|
||||||
|
os.path.join(os.path.dirname(__file__), '..', '..', '..', 'resources', 'songselect'))
|
||||||
|
|
||||||
|
|
||||||
class TestSongSelectImport(TestCase, TestMixin):
|
class TestSongSelectImport(TestCase, TestMixin):
|
||||||
"""
|
"""
|
||||||
@ -645,68 +649,21 @@ class TestSongSelectForm(TestCase, TestMixin):
|
|||||||
mocked_view_button.setEnabled.assert_called_with(True)
|
mocked_view_button.setEnabled.assert_called_with(True)
|
||||||
|
|
||||||
|
|
||||||
class TestSongSelectFileImport(TestCase, TestMixin):
|
class TestSongSelectFileImport(SongImportTestHelper):
|
||||||
"""
|
|
||||||
Test SongSelect file import
|
|
||||||
"""
|
|
||||||
def setUp(self):
|
|
||||||
"""
|
|
||||||
Initial setups
|
|
||||||
"""
|
|
||||||
Registry.create()
|
|
||||||
test_song_name = 'TestSong'
|
|
||||||
self.file_name = os.path.join('tests', 'resources', 'songselect', test_song_name)
|
|
||||||
self.title = 'Test Song'
|
|
||||||
self.ccli_number = '0000000'
|
|
||||||
self.authors = ['Author One', 'Author Two']
|
|
||||||
self.topics = ['Adoration', 'Praise']
|
|
||||||
|
|
||||||
def songselect_import_bin_file_test(self):
|
def __init__(self, *args, **kwargs):
|
||||||
"""
|
self.importer_class_name = 'CCLIFileImport'
|
||||||
Verify import SongSelect BIN file parses file properly
|
self.importer_module_name = 'cclifile'
|
||||||
"""
|
super(TestSongSelectFileImport, self).__init__(*args, **kwargs)
|
||||||
# GIVEN: Text file to import and mocks
|
|
||||||
copyright_bin = '2011 OpenLP Programmer One (Admin. by OpenLP One) | ' \
|
|
||||||
'Openlp Programmer Two (Admin. by OpenLP Two)'
|
|
||||||
verses_bin = [
|
|
||||||
['v1', 'Line One Verse One\nLine Two Verse One\nLine Three Verse One\nLine Four Verse One', None],
|
|
||||||
['v2', 'Line One Verse Two\nLine Two Verse Two\nLine Three Verse Two\nLine Four Verse Two', None]
|
|
||||||
]
|
|
||||||
song_import = CCLIFileImport(manager=None, filename=['{}.bin'.format(self.file_name)])
|
|
||||||
|
|
||||||
with patch.object(song_import, 'import_wizard'), patch.object(song_import, 'finish'):
|
def test_song_import(self):
|
||||||
# WHEN: We call the song importer
|
|
||||||
song_import.do_import()
|
|
||||||
# THEN: Song values should be equal to test values in setUp
|
|
||||||
self.assertEquals(song_import.title, self.title, 'Song title should match')
|
|
||||||
self.assertEquals(song_import.ccli_number, self.ccli_number, 'CCLI Song Number should match')
|
|
||||||
self.assertEquals(song_import.authors, self.authors, 'Author(s) should match')
|
|
||||||
self.assertEquals(song_import.copyright, copyright_bin, 'Copyright should match')
|
|
||||||
self.assertEquals(song_import.topics, self.topics, 'Theme(s) should match')
|
|
||||||
self.assertEquals(song_import.verses, verses_bin, 'Verses should match with test verses')
|
|
||||||
|
|
||||||
def songselect_import_text_file_test(self):
|
|
||||||
"""
|
"""
|
||||||
Verify import SongSelect TEXT file parses file properly
|
Test that loading an OpenSong file works correctly on various files
|
||||||
"""
|
"""
|
||||||
# GIVEN: Text file to import and mocks
|
self.file_import([os.path.join(TEST_PATH, 'TestSong.bin')],
|
||||||
copyright_txt = '© 2011 OpenLP Programmer One (Admin. by OpenLP One)'
|
self.load_external_result_data(os.path.join(TEST_PATH, 'TestSong-bin.json')))
|
||||||
verses_txt = [
|
self.file_import([os.path.join(TEST_PATH, 'TestSong.txt')],
|
||||||
['v1', 'Line One Verse One\r\nLine Two Verse One\r\nLine Three Verse One\r\nLine Four Verse One', None],
|
self.load_external_result_data(os.path.join(TEST_PATH, 'TestSong-txt.json')))
|
||||||
['v2', 'Line One Verse Two\r\nLine Two Verse Two\r\nLine Three Verse Two\r\nLine Four Verse Two', None]
|
|
||||||
]
|
|
||||||
song_import = CCLIFileImport(manager=None, filename=['{}.txt'.format(self.file_name)])
|
|
||||||
|
|
||||||
with patch.object(song_import, 'import_wizard'), patch.object(song_import, 'finish'):
|
|
||||||
# WHEN: We call the song importer
|
|
||||||
song_import.do_import()
|
|
||||||
|
|
||||||
# THEN: Song values should be equal to test values in setUp
|
|
||||||
self.assertEquals(song_import.title, self.title, 'Song title should match')
|
|
||||||
self.assertEquals(song_import.ccli_number, self.ccli_number, 'CCLI Song Number should match')
|
|
||||||
self.assertEquals(song_import.authors, self.authors, 'Author(s) should match')
|
|
||||||
self.assertEquals(song_import.copyright, copyright_txt, 'Copyright should match')
|
|
||||||
self.assertEquals(song_import.verses, verses_txt, 'Verses should match with test verses')
|
|
||||||
|
|
||||||
|
|
||||||
class TestSearchWorker(TestCase, TestMixin):
|
class TestSearchWorker(TestCase, TestMixin):
|
||||||
|
12
tests/resources/songbeamersongs/Lobsinget dem Herrn.json
Normal file
12
tests/resources/songbeamersongs/Lobsinget dem Herrn.json
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"title": "GL 1 - Lobsinget dem Herrn",
|
||||||
|
"verses": [
|
||||||
|
["1. Lobsinget dem Herrn,\no preiset Ihn gern!\nAnbetung und Lob Ihm gebühret.\n", "v"],
|
||||||
|
["2. Lobsingt Seiner Lieb´,\ndie einzig ihn trieb,\nzu sterben für unsere Sünden!\n", "v"],
|
||||||
|
["3. Lobsingt Seiner Macht!\nSein Werk ist vollbracht:\nEr sitzet zur Rechten des Vaters.\n", "v"],
|
||||||
|
["4. Lobsingt seiner Treu´,\ndie immerdar neu,\nbis Er uns zur Herrlichket führet!\n\n", "v"]
|
||||||
|
],
|
||||||
|
"song_book_name": "Glaubenslieder I",
|
||||||
|
"song_number": "1",
|
||||||
|
"authors": ["Carl Brockhaus", "Johann Jakob Vetter"]
|
||||||
|
}
|
25
tests/resources/songselect/TestSong-bin.json
Normal file
25
tests/resources/songselect/TestSong-bin.json
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
{
|
||||||
|
"authors": [
|
||||||
|
"Author One",
|
||||||
|
"Author Two"
|
||||||
|
],
|
||||||
|
"ccli_number": "0000000",
|
||||||
|
"song_number": 0,
|
||||||
|
"title": "Test Song",
|
||||||
|
"topics": [
|
||||||
|
"Adoration",
|
||||||
|
"Praise"
|
||||||
|
],
|
||||||
|
"copyright": "2011 OpenLP Programmer One (Admin. by OpenLP One) | Openlp Programmer Two (Admin. by OpenLP Two)",
|
||||||
|
"verse_order_list": [],
|
||||||
|
"verses": [
|
||||||
|
[
|
||||||
|
"Line One Verse One\nLine Two Verse One\nLine Three Verse One\nLine Four Verse One\n",
|
||||||
|
"v"
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"Line One Verse Two\nLine Two Verse Two\nLine Three Verse Two\nLine Four Verse Two\n",
|
||||||
|
"v"
|
||||||
|
]
|
||||||
|
]
|
||||||
|
}
|
21
tests/resources/songselect/TestSong-txt.json
Normal file
21
tests/resources/songselect/TestSong-txt.json
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"authors": [
|
||||||
|
"Author One",
|
||||||
|
"Author Two"
|
||||||
|
],
|
||||||
|
"ccli_number": "0000000",
|
||||||
|
"song_number": 0,
|
||||||
|
"title": "Test Song",
|
||||||
|
"copyright": "© 2011 OpenLP Programmer One (Admin. by OpenLP One)",
|
||||||
|
"verse_order_list": [],
|
||||||
|
"verses": [
|
||||||
|
[
|
||||||
|
"Line One Verse One\nLine Two Verse One\nLine Three Verse One\nLine Four Verse One\n",
|
||||||
|
"v"
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"Line One Verse Two\nLine Two Verse Two\nLine Three Verse Two\nLine Four Verse Two\n",
|
||||||
|
"v"
|
||||||
|
]
|
||||||
|
]
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user