From 97b603a2d6747dadbf1a9e492bd26e5c73857e8f Mon Sep 17 00:00:00 2001 From: Samuel Mehrbrodt Date: Tue, 13 May 2014 11:44:19 +0200 Subject: [PATCH] Add test for author matching --- openlp/plugins/songs/lib/mediaitem.py | 5 ++-- .../openlp_plugins/songs/test_mediaitem.py | 29 +++++++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/openlp/plugins/songs/lib/mediaitem.py b/openlp/plugins/songs/lib/mediaitem.py index 04fa5a77a..e51743413 100644 --- a/openlp/plugins/songs/lib/mediaitem.py +++ b/openlp/plugins/songs/lib/mediaitem.py @@ -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 diff --git a/tests/functional/openlp_plugins/songs/test_mediaitem.py b/tests/functional/openlp_plugins/songs/test_mediaitem.py index 308881c2e..359e27a0f 100644 --- a/tests/functional/openlp_plugins/songs/test_mediaitem.py +++ b/tests/functional/openlp_plugins/songs/test_mediaitem.py @@ -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)