Add test for author matching

This commit is contained in:
Samuel Mehrbrodt 2014-05-13 11:44:19 +02:00
parent 9b173dc0fe
commit 97b603a2d6
2 changed files with 31 additions and 3 deletions

View File

@ -556,18 +556,17 @@ class SongMediaItem(MediaManagerItem):
: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.
: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 = author_list.remove(author.display_name)
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):
"""
Search for some songs

View File

@ -128,3 +128,32 @@ class TestMediaItem(TestCase, TestMixin):
# THEN: I would get an amended footer string
self.assertEqual(service_item.raw_footer, ['My Song', 'My copyright', 'CCLI License: 4321'],
'The array should be returned correctly with a song, an author, copyright and amended ccli')
def match_authors_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"
authors_str_wrong = "Hans Wurst, Max Mustermann"
# WHEN: Checking for matching
correct_result = self.media_item._authors_match(song, authors_str)
wrong_result = self.media_item._authors_match(song, authors_str_wrong)
# THEN: They should match
self.assertTrue(correct_result)
self.assertFalse(wrong_result)