← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~sam92/openlp/bug-1313538 into lp:openlp

 

Samuel Mehrbrodt has proposed merging lp:~sam92/openlp/bug-1313538 into lp:openlp.

Requested reviews:
  Raoul Snyman (raoul-snyman)
Related bugs:
  Bug #1313538 in OpenLP: "Song duplicates added when using different author types for the same author"
  https://bugs.launchpad.net/openlp/+bug/1313538

For more details, see:
https://code.launchpad.net/~sam92/openlp/bug-1313538/+merge/219326

Song duplicates added when using different author types for the same author

lp:~sam92/openlp/bug-1313538 (revision 2382)
[SUCCESS] http://ci.openlp.org/job/Branch-01-Pull/451/
[SUCCESS] http://ci.openlp.org/job/Branch-02-Functional-Tests/407/
[SUCCESS] http://ci.openlp.org/job/Branch-03-Interface-Tests/352/
[SUCCESS] http://ci.openlp.org/job/Branch-04-Windows_Tests/313/
[SUCCESS] http://ci.openlp.org/job/Branch-05a-Code_Analysis/215/
[SUCCESS] http://ci.openlp.org/job/Branch-05b-Test_Coverage/89/
-- 
https://code.launchpad.net/~sam92/openlp/bug-1313538/+merge/219326
Your team OpenLP Core is subscribed to branch lp:openlp.
=== modified file 'openlp/plugins/songs/lib/mediaitem.py'
--- openlp/plugins/songs/lib/mediaitem.py	2014-05-10 06:43:18 +0000
+++ openlp/plugins/songs/lib/mediaitem.py	2014-05-13 10:00:28 +0000
@@ -527,15 +527,7 @@
         add_song = True
         if search_results:
             for song in search_results:
-                author_list = 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(', ') == '':
+                if self._authors_match(song, item.data_string['authors']):
                     add_song = False
                     edit_id = song.id
                     break
@@ -561,6 +553,23 @@
         self.generate_footer(item, song)
         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):
         """
         Search for some songs

=== modified file 'tests/functional/openlp_core_lib/test_ui.py'
--- tests/functional/openlp_core_lib/test_ui.py	2014-05-07 23:52:51 +0000
+++ tests/functional/openlp_core_lib/test_ui.py	2014-05-13 10:00:28 +0000
@@ -129,6 +129,35 @@
         self.assertEqual('my_btn', btn.objectName())
         self.assertTrue(btn.isEnabled())
 
+    def test_create_horizontal_adjusting_combo_box(self):
+        """
+        Test creating a horizontal adjusting combo box
+        """
+        # GIVEN: A dialog
+        dialog = QtGui.QDialog()
+
+        # WHEN: We create the combobox
+        combo = create_horizontal_adjusting_combo_box(dialog, 'combo1')
+
+        # THEN: We should get a ComboBox
+        self.assertIsInstance(combo, QtGui.QComboBox)
+        self.assertEqual('combo1', combo.objectName())
+        self.assertEqual(QtGui.QComboBox.AdjustToMinimumContentsLength, combo.sizeAdjustPolicy())
+
+    def test_create_widget_action(self):
+        """
+        Test creating an action for a widget
+        """
+        # GIVEN: A button
+        button = QtGui.QPushButton()
+
+        # WHEN: We call the function
+        action = create_widget_action(button, 'some action')
+
+        # THEN: The action should be returned
+        self.assertIsInstance(action, QtGui.QAction)
+        self.assertEqual(action.objectName(), 'some action')
+
     def test_create_action(self):
         """
         Test creating an action

=== modified file 'tests/functional/openlp_plugins/songs/test_mediaitem.py'
--- tests/functional/openlp_plugins/songs/test_mediaitem.py	2014-05-03 10:53:51 +0000
+++ tests/functional/openlp_plugins/songs/test_mediaitem.py	2014-05-13 10:00:28 +0000
@@ -153,3 +153,32 @@
 
         # THEN: The songbook should be in the footer
         self.assertEqual(service_item.raw_footer, ['My Song', 'My copyright', 'My songbook #12'])
+
+    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)


Follow ups