forked from openlp/openlp
Improve OpenLyrics import handling of authortypes. Fixes bug 1405172 and 1405175
Fixes: https://launchpad.net/bugs/1405172, https://launchpad.net/bugs/1405175
This commit is contained in:
parent
deb8ae8656
commit
685b2fde32
@ -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:
|
||||
|
@ -73,6 +73,14 @@ result_tags = [{"temporary": False, "protected": False, "desc": "z", "start tag"
|
||||
"start html": "<span class=\"chord\" style=\"display:none\"><strong>", "end html": "</strong></span>",
|
||||
"protected": False}]
|
||||
|
||||
author_xml = '<properties>\
|
||||
<authors>\
|
||||
<author type="words">Test Author1</author>\
|
||||
<author type="music">Test Author1</author>\
|
||||
<author type="words">Test Author2</author>\
|
||||
</authors>\
|
||||
</properties>'
|
||||
|
||||
|
||||
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')
|
||||
|
Loading…
Reference in New Issue
Block a user