diff --git a/openlp/core/ui/slidecontroller.py b/openlp/core/ui/slidecontroller.py index 456399869..75616960b 100644 --- a/openlp/core/ui/slidecontroller.py +++ b/openlp/core/ui/slidecontroller.py @@ -909,7 +909,9 @@ class SlideController(DisplayController, RegistryProperties): Registry().execute('%s_stop' % old_item.name.lower(), [old_item, self.is_live]) if old_item.is_media() and not self.service_item.is_media(): self.on_media_close() - Registry().execute('slidecontroller_%s_started' % self.type_prefix, [self.service_item]) + if self.is_live: + # This even is only registered for live + Registry().execute('slidecontroller_%s_started' % self.type_prefix, [self.service_item]) def on_slide_selected_index(self, message): """ diff --git a/openlp/plugins/songs/lib/importers/openlp.py b/openlp/plugins/songs/lib/importers/openlp.py index f13ed4620..383ea0483 100644 --- a/openlp/plugins/songs/lib/importers/openlp.py +++ b/openlp/plugins/songs/lib/importers/openlp.py @@ -149,7 +149,12 @@ class OpenLPSongImport(SongImport): class_mapper(OldSongBookEntry) except UnmappedClassError: mapper(OldSongBookEntry, source_songs_songbooks_table, properties={'songbook': relation(OldBook)}) - if has_authors_songs and 'author_type' in source_authors_songs_table.c.values(): + if has_authors_songs: + try: + class_mapper(OldAuthorSong) + except UnmappedClassError: + mapper(OldAuthorSong, source_authors_songs_table) + if has_authors_songs and 'author_type' in source_authors_songs_table.c.keys(): has_author_type = True else: has_author_type = False @@ -190,11 +195,6 @@ class OpenLPSongImport(SongImport): class_mapper(OldTopic) except UnmappedClassError: mapper(OldTopic, source_topics_table) - if has_authors_songs: - try: - class_mapper(OldAuthorSong) - except UnmappedClassError: - mapper(OldAuthorSong, source_authors_songs_table) source_songs = self.source_session.query(OldSong).all() if self.import_wizard: diff --git a/tests/functional/openlp_plugins/songs/test_openlpimporter.py b/tests/functional/openlp_plugins/songs/test_openlpimporter.py index 9682695a9..d0e06d50b 100644 --- a/tests/functional/openlp_plugins/songs/test_openlpimporter.py +++ b/tests/functional/openlp_plugins/songs/test_openlpimporter.py @@ -22,11 +22,32 @@ """ This module contains tests for the OpenLP song importer. """ +import os from unittest import TestCase +from unittest.mock import patch, MagicMock -from openlp.plugins.songs.lib.importers.openlp import OpenLPSongImport from openlp.core.common import Registry -from tests.functional import patch, MagicMock +from openlp.plugins.songs.lib.importers.openlp import OpenLPSongImport + +from tests.helpers.songfileimport import SongImportTestHelper + +TEST_PATH = os.path.abspath( + os.path.join(os.path.dirname(__file__), '..', '..', '..', 'resources', 'openlpsongs')) + + +class TestOpenLPFileImport(SongImportTestHelper): + + def __init__(self, *args, **kwargs): + self.importer_class_name = 'OpenLPSongImport' + self.importer_module_name = 'openlp' + super(TestOpenLPFileImport, self).__init__(*args, **kwargs) + + def test_song_import(self): + """ + Test that loading an OpenSong file works correctly on various files + """ + self.file_import([os.path.join(TEST_PATH, 'songs.sqlite')], + self.load_external_result_data(os.path.join(TEST_PATH, 'AmazingGrace.json'))) class TestOpenLPImport(TestCase): diff --git a/tests/resources/openlpsongs/AmazingGrace.json b/tests/resources/openlpsongs/AmazingGrace.json new file mode 100644 index 000000000..4d76e0834 --- /dev/null +++ b/tests/resources/openlpsongs/AmazingGrace.json @@ -0,0 +1,43 @@ +{ + "authors": [ + "John Newton" + ], + "ccli_number": 22025, + "comments": "", + "copyright": "Public Domain ", + "song_book_name": "", + "song_number": 0, + "title": "Amazing Grace", + "topics": [ + "Grace" + ], + "verse_order_list": [ + "V1", + "V2", + "V3", + "V4", + "V5" + ], + "verses": [ + [ + "Amazing grace! How sweet the sound!\nThat saved a wretch like me!\nI once was lost, but now am found;\nWas blind, but now I see.", + "v1" + ], + [ + "'Twas grace that taught my heart to fear,\nAnd grace my fears relieved.\nHow precious did that grace appear,\nThe hour I first believed.", + "v2" + ], + [ + "The Lord has promised good to me,\nHis Word my hope secures.\nHe will my shield and portion be\nAs long as life endures.", + "v3" + ], + [ + "Thro' many dangers, toils and snares\nI have already come.\n'Tis grace that brought me safe thus far,\nAnd grace will lead me home.", + "v4" + ], + [ + "When we've been there ten thousand years,\nBright shining as the sun,\nWe've no less days to sing God's praise,\nThan when we first begun.", + "v5" + ] + ] +} diff --git a/tests/resources/openlpsongs/songs.sqlite b/tests/resources/openlpsongs/songs.sqlite new file mode 100644 index 000000000..32e9ef820 Binary files /dev/null and b/tests/resources/openlpsongs/songs.sqlite differ diff --git a/tests/resources/opensongsongs/Amazing Grace.json b/tests/resources/opensongsongs/Amazing Grace.json index 97b8c77b7..83c19fb85 100644 --- a/tests/resources/opensongsongs/Amazing Grace.json +++ b/tests/resources/opensongsongs/Amazing Grace.json @@ -39,4 +39,4 @@ "v5" ] ] -} \ No newline at end of file +}