forked from openlp/openlp
Song duplicates added when using different author types for the same author
bzr-revno: 2386
This commit is contained in:
commit
9f5895dd82
@ -527,15 +527,7 @@ class SongMediaItem(MediaManagerItem):
|
|||||||
add_song = True
|
add_song = True
|
||||||
if search_results:
|
if search_results:
|
||||||
for song in search_results:
|
for song in search_results:
|
||||||
author_list = item.data_string['authors']
|
if self._authors_match(song, item.data_string['authors']):
|
||||||
same_authors = True
|
|
||||||
for author in song.authors:
|
|
||||||
if author.display_name in author_list:
|
|
||||||
author_list = author_list.replace(author.display_name, '', 1)
|
|
||||||
else:
|
|
||||||
same_authors = False
|
|
||||||
break
|
|
||||||
if same_authors and author_list.strip(', ') == '':
|
|
||||||
add_song = False
|
add_song = False
|
||||||
edit_id = song.id
|
edit_id = song.id
|
||||||
break
|
break
|
||||||
@ -561,6 +553,23 @@ class SongMediaItem(MediaManagerItem):
|
|||||||
self.generate_footer(item, song)
|
self.generate_footer(item, song)
|
||||||
return item
|
return item
|
||||||
|
|
||||||
|
def _authors_match(self, song, authors):
|
||||||
|
"""
|
||||||
|
Checks whether authors from a song in the database match the authors of the song to be imported.
|
||||||
|
|
||||||
|
:param song: A list of authors from the song in the database
|
||||||
|
:param authors: A string with authors from the song to be imported
|
||||||
|
:return: True when Authors do match, else False.
|
||||||
|
"""
|
||||||
|
author_list = authors.split(', ')
|
||||||
|
for author in song.authors:
|
||||||
|
if author.display_name in author_list:
|
||||||
|
author_list.remove(author.display_name)
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
# List must be empty at the end
|
||||||
|
return not author_list
|
||||||
|
|
||||||
def search(self, string, show_error):
|
def search(self, string, show_error):
|
||||||
"""
|
"""
|
||||||
Search for some songs
|
Search for some songs
|
||||||
|
@ -153,3 +153,52 @@ class TestMediaItem(TestCase, TestMixin):
|
|||||||
|
|
||||||
# THEN: The songbook should be in the footer
|
# THEN: The songbook should be in the footer
|
||||||
self.assertEqual(service_item.raw_footer, ['My Song', 'My copyright', 'My songbook #12'])
|
self.assertEqual(service_item.raw_footer, ['My Song', 'My copyright', 'My songbook #12'])
|
||||||
|
|
||||||
|
def authors_match_test(self):
|
||||||
|
"""
|
||||||
|
Test the author matching when importing a song from a service
|
||||||
|
"""
|
||||||
|
# GIVEN: A song and a string with authors
|
||||||
|
song = MagicMock()
|
||||||
|
song.authors = []
|
||||||
|
author = MagicMock()
|
||||||
|
author.display_name = "Hans Wurst"
|
||||||
|
song.authors.append(author)
|
||||||
|
author2 = MagicMock()
|
||||||
|
author2.display_name = "Max Mustermann"
|
||||||
|
song.authors.append(author2)
|
||||||
|
# There are occasions where an author appears twice in a song (with different types).
|
||||||
|
# We need to make sure that this case works (lp#1313538)
|
||||||
|
author3 = MagicMock()
|
||||||
|
author3.display_name = "Max Mustermann"
|
||||||
|
song.authors.append(author3)
|
||||||
|
authors_str = "Hans Wurst, Max Mustermann, Max Mustermann"
|
||||||
|
|
||||||
|
# WHEN: Checking for matching
|
||||||
|
result = self.media_item._authors_match(song, authors_str)
|
||||||
|
|
||||||
|
# THEN: They should match
|
||||||
|
self.assertTrue(result, "Authors should match")
|
||||||
|
|
||||||
|
def authors_dont_match_test(self):
|
||||||
|
# GIVEN: A song and a string with authors
|
||||||
|
song = MagicMock()
|
||||||
|
song.authors = []
|
||||||
|
author = MagicMock()
|
||||||
|
author.display_name = "Hans Wurst"
|
||||||
|
song.authors.append(author)
|
||||||
|
author2 = MagicMock()
|
||||||
|
author2.display_name = "Max Mustermann"
|
||||||
|
song.authors.append(author2)
|
||||||
|
# There are occasions where an author appears twice in a song (with different types).
|
||||||
|
# We need to make sure that this case works (lp#1313538)
|
||||||
|
author3 = MagicMock()
|
||||||
|
author3.display_name = "Max Mustermann"
|
||||||
|
song.authors.append(author3)
|
||||||
|
|
||||||
|
# WHEN: An author is missing in the string
|
||||||
|
authors_str = "Hans Wurst, Max Mustermann"
|
||||||
|
result = self.media_item._authors_match(song, authors_str)
|
||||||
|
|
||||||
|
# THEN: They should not match
|
||||||
|
self.assertFalse(result, "Authors should not match")
|
||||||
|
Loading…
Reference in New Issue
Block a user