openlp-core team mailing list archive
-
openlp-core team
-
Mailing list archive
-
Message #28022
[Merge] lp:~raoul-snyman/openlp/song-select-fixes into lp:openlp
Raoul Snyman has proposed merging lp:~raoul-snyman/openlp/song-select-fixes into lp:openlp.
Requested reviews:
OpenLP Core (openlp-core)
For more details, see:
https://code.launchpad.net/~raoul-snyman/openlp/song-select-fixes/+merge/281330
Fix up a potential bug in SongSelect where authors with a single name would crash the importer.
Add this to your merge proposal:
--------------------------------
lp:~raoul-snyman/openlp/song-select-fixes (revision 2578)
[SUCCESS] https://ci.openlp.io/job/Branch-01-Pull/1199/
[SUCCESS] https://ci.openlp.io/job/Branch-02-Functional-Tests/1124/
[SUCCESS] https://ci.openlp.io/job/Branch-03-Interface-Tests/1063/
[FAILURE] https://ci.openlp.io/job/Branch-04a-Windows_Functional_Tests/909/
Stopping after failure
--
Your team OpenLP Core is requested to review the proposed merge of lp:~raoul-snyman/openlp/song-select-fixes into lp:openlp.
=== modified file 'openlp/plugins/songs/lib/songselect.py'
--- openlp/plugins/songs/lib/songselect.py 2015-11-22 14:06:54 +0000
+++ openlp/plugins/songs/lib/songselect.py 2015-12-23 22:04:01 +0000
@@ -210,9 +210,14 @@
for author_name in song['authors']:
author = self.db_manager.get_object_filtered(Author, Author.display_name == author_name)
if not author:
- author = Author.populate(first_name=author_name.rsplit(' ', 1)[0],
- last_name=author_name.rsplit(' ', 1)[1],
- display_name=author_name)
+ name_parts = author_name.rsplit(' ', 1)
+ first_name = name_parts[0]
+ if len(name_parts) == 1:
+ last_name = ''
+ else:
+ last_name = name_parts[1]
+ author = Author.populate(first_name=first_name, last_name=last_name, display_name=author_name)
db_song.add_author(author)
self.db_manager.save_object(db_song)
return db_song
+
=== modified file 'tests/functional/openlp_plugins/songs/test_songselect.py'
--- tests/functional/openlp_plugins/songs/test_songselect.py 2015-12-21 20:27:10 +0000
+++ tests/functional/openlp_plugins/songs/test_songselect.py 2015-12-23 22:04:01 +0000
@@ -402,6 +402,42 @@
self.assertEqual(0, MockedAuthor.populate.call_count, 'A new author should not have been instantiated')
self.assertEqual(1, len(result.authors_songs), 'There should only be one author')
+ @patch('openlp.plugins.songs.lib.songselect.clean_song')
+ @patch('openlp.plugins.songs.lib.songselect.Author')
+ def save_song_unknown_author_test(self, MockedAuthor, mocked_clean_song):
+ """
+ Test that saving a song with an author name of only one word performs the correct actions
+ """
+ # GIVEN: A song to save, and some mocked out objects
+ song_dict = {
+ 'title': 'Arky Arky',
+ 'authors': ['Unknown'],
+ 'verses': [
+ {'label': 'Verse 1', 'lyrics': 'The Lord told Noah: there\'s gonna be a floody, floody'},
+ {'label': 'Chorus 1', 'lyrics': 'So, rise and shine, and give God the glory, glory'},
+ {'label': 'Verse 2', 'lyrics': 'The Lord told Noah to build him an arky, arky'}
+ ],
+ 'copyright': 'Public Domain',
+ 'ccli_number': '123456'
+ }
+ MockedAuthor.display_name.__eq__.return_value = False
+ mocked_db_manager = MagicMock()
+ mocked_db_manager.get_object_filtered.return_value = None
+ importer = SongSelectImport(mocked_db_manager)
+
+ # WHEN: The song is saved to the database
+ result = importer.save_song(song_dict)
+
+ # THEN: The return value should be a Song class and the mocked_db_manager should have been called
+ self.assertIsInstance(result, Song, 'The returned value should be a Song object')
+ mocked_clean_song.assert_called_with(mocked_db_manager, result)
+ self.assertEqual(2, mocked_db_manager.save_object.call_count,
+ 'The save_object() method should have been called twice')
+ mocked_db_manager.get_object_filtered.assert_called_with(MockedAuthor, False)
+ MockedAuthor.populate.assert_called_with(first_name='Unknown', last_name='',
+ display_name='Unknown')
+ self.assertEqual(1, len(result.authors_songs), 'There should only be one author')
+
class TestSongSelectForm(TestCase, TestMixin):
"""
Follow ups