diff --git a/openlp/plugins/songs/lib/openlyricsxml.py b/openlp/plugins/songs/lib/openlyricsxml.py index a22818b09..d27eeb2eb 100644 --- a/openlp/plugins/songs/lib/openlyricsxml.py +++ b/openlp/plugins/songs/lib/openlyricsxml.py @@ -511,8 +511,19 @@ class OpenLyrics(object): for author in properties.authors.author: display_name = self._text(author) author_type = author.get('type', '') + # As of 0.8 OpenLyrics supports these 3 author types + if author_type not in ('words', 'music', 'translation'): + author_type = '' if display_name: - authors.append((display_name, author_type)) + # Check if an author is listed for both music and words. In that case we use a special type + if author_type == 'words' and (display_name, 'music') in authors: + authors.remove((display_name, 'music')) + authors.append((display_name, 'words+music')) + elif author_type == 'music' and (display_name, 'words') in authors: + authors.remove((display_name, 'words')) + authors.append((display_name, 'words+music')) + else: + authors.append((display_name, author_type)) for (display_name, author_type) in authors: author = self.manager.get_object_filtered(Author, Author.display_name == display_name) if author is None: diff --git a/tests/functional/openlp_plugins/songs/test_openlyricsimport.py b/tests/functional/openlp_plugins/songs/test_openlyricsimport.py index 5f8699e35..d5c2e5c59 100644 --- a/tests/functional/openlp_plugins/songs/test_openlyricsimport.py +++ b/tests/functional/openlp_plugins/songs/test_openlyricsimport.py @@ -73,6 +73,14 @@ result_tags = [{"temporary": False, "protected": False, "desc": "z", "start tag" "start html": "", "end html": "", "protected": False}] +author_xml = '\ + \ + Test Author1\ + Test Author1\ + Test Author2\ + \ + ' + class TestOpenLyricsImport(TestCase, TestMixin): """ @@ -146,3 +154,22 @@ class TestOpenLyricsImport(TestCase, TestMixin): self.assertListEqual(json.loads(json.dumps(result_tags)), json.loads(str(Settings().value('formattingTags/html_tags'))), 'The formatting tags should contain both the old and the new') + + def process_author_test(self): + """ + Test that _process_authors works + """ + # GIVEN: A OpenLyric XML with authors and a mocked out manager + with patch('openlp.plugins.songs.lib.openlyricsxml.Author') as mocked_author: + mocked_manager = MagicMock() + mocked_manager.get_object_filtered.return_value = None + ol = OpenLyrics(mocked_manager) + properties_xml = objectify.fromstring(author_xml) + mocked_song = MagicMock() + + # WHEN: processing the author xml + ol._process_authors(properties_xml, mocked_song) + + # THEN: add_author should have been called twice + self.assertEquals(mocked_song.method_calls[0][1][1], 'words+music') + self.assertEquals(mocked_song.method_calls[1][1][1], 'words')