forked from openlp/openlp
Fix up the topics problem and split it into its own test
This commit is contained in:
parent
358667356f
commit
b789a7809d
@ -250,6 +250,7 @@ class SongSelectImport(object):
|
|||||||
last_name = name_parts[1]
|
last_name = name_parts[1]
|
||||||
author = Author.populate(first_name=first_name, last_name=last_name, display_name=author_name)
|
author = Author.populate(first_name=first_name, last_name=last_name, display_name=author_name)
|
||||||
db_song.add_author(author)
|
db_song.add_author(author)
|
||||||
|
db_song.topics = []
|
||||||
for topic_name in song.get('topics', []):
|
for topic_name in song.get('topics', []):
|
||||||
topic = self.db_manager.get_object_filtered(Topic, Topic.name == topic_name)
|
topic = self.db_manager.get_object_filtered(Topic, Topic.name == topic_name)
|
||||||
if not topic:
|
if not topic:
|
||||||
|
@ -536,9 +536,8 @@ class TestSongSelectImport(TestCase, TestMixin):
|
|||||||
self.assertEqual(1, len(result.authors_songs), 'There should only be one author')
|
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.clean_song')
|
||||||
@patch('openlp.plugins.songs.lib.songselect.Topic')
|
|
||||||
@patch('openlp.plugins.songs.lib.songselect.Author')
|
@patch('openlp.plugins.songs.lib.songselect.Author')
|
||||||
def save_song_unknown_author_test(self, MockedAuthor, MockedTopic, mocked_clean_song):
|
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
|
Test that saving a song with an author name of only one word performs the correct actions
|
||||||
"""
|
"""
|
||||||
@ -552,6 +551,44 @@ class TestSongSelectImport(TestCase, TestMixin):
|
|||||||
{'label': 'Verse 2', 'lyrics': 'The Lord told Noah to build him an arky, arky'}
|
{'label': 'Verse 2', 'lyrics': 'The Lord told Noah to build him an arky, arky'}
|
||||||
],
|
],
|
||||||
'copyright': 'Public Domain',
|
'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')
|
||||||
|
# self.assertEqual(2, len(result.topics), 'There should only be two topics')
|
||||||
|
|
||||||
|
@patch('openlp.plugins.songs.lib.songselect.clean_song')
|
||||||
|
@patch('openlp.plugins.songs.lib.songselect.Topic')
|
||||||
|
@patch('openlp.plugins.songs.lib.songselect.Author')
|
||||||
|
def save_song_topics_test(self, MockedAuthor, MockedTopic, mocked_clean_song):
|
||||||
|
"""
|
||||||
|
Test that saving a song with topics performs the correct actions
|
||||||
|
"""
|
||||||
|
# GIVEN: A song to save, and some mocked out objects
|
||||||
|
song_dict = {
|
||||||
|
'title': 'Arky Arky',
|
||||||
|
'authors': ['Public Domain'],
|
||||||
|
'verses': [
|
||||||
|
{'label': 'Verse 1', 'lyrics': 'The Lord told Noah: there\'s gonna be a floody, floody'},
|
||||||
|
{'label': 'Chorus', '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',
|
'ccli_number': '123456',
|
||||||
'topics': ['Grace', 'Love']
|
'topics': ['Grace', 'Love']
|
||||||
}
|
}
|
||||||
@ -569,11 +606,9 @@ class TestSongSelectImport(TestCase, TestMixin):
|
|||||||
mocked_clean_song.assert_called_with(mocked_db_manager, result)
|
mocked_clean_song.assert_called_with(mocked_db_manager, result)
|
||||||
self.assertEqual(2, mocked_db_manager.save_object.call_count,
|
self.assertEqual(2, mocked_db_manager.save_object.call_count,
|
||||||
'The save_object() method should have been called twice')
|
'The save_object() method should have been called twice')
|
||||||
mocked_db_manager.get_object_filtered.assert_called_with(MockedAuthor, False)
|
mocked_db_manager.get_object_filtered.assert_called_with(MockedTopic, False)
|
||||||
MockedAuthor.populate.assert_called_with(first_name='Unknown', last_name='',
|
self.assertEqual([call(name='Grace'), call(name='Love')], MockedTopic.populate.call_args_list)
|
||||||
display_name='Unknown')
|
self.assertEqual(2, len(result.topics), 'There should be two topics')
|
||||||
self.assertEqual(1, len(result.authors_songs), 'There should only be one author')
|
|
||||||
# self.assertEqual(2, len(result.topics), 'There should only be two topics')
|
|
||||||
|
|
||||||
|
|
||||||
class TestSongSelectForm(TestCase, TestMixin):
|
class TestSongSelectForm(TestCase, TestMixin):
|
||||||
|
Loading…
Reference in New Issue
Block a user