Add test for songbook display

This commit is contained in:
Samuel Mehrbrodt 2014-05-03 12:42:18 +02:00
parent e0d813db3f
commit a98ea19306
2 changed files with 30 additions and 4 deletions

View File

@ -124,7 +124,8 @@ class SongMediaItem(MediaManagerItem):
log.debug('config_updated') log.debug('config_updated')
self.search_as_you_type = Settings().value(self.settings_section + '/search as type') self.search_as_you_type = Settings().value(self.settings_section + '/search as type')
self.update_service_on_edit = Settings().value(self.settings_section + '/update service on edit') self.update_service_on_edit = Settings().value(self.settings_section + '/update service on edit')
self.add_song_from_service = Settings().value(self.settings_section + '/add song from service',) self.add_song_from_service = Settings().value(self.settings_section + '/add song from service')
self.display_songbook = Settings().value(self.settings_section + '/display songbook')
def retranslateUi(self): def retranslateUi(self):
self.search_text_label.setText('%s:' % UiStrings().Search) self.search_text_label.setText('%s:' % UiStrings().Search)
@ -506,7 +507,7 @@ class SongMediaItem(MediaManagerItem):
item.raw_footer.append("%s: %s" % (AuthorType.Types[AuthorType.Translation], item.raw_footer.append("%s: %s" % (AuthorType.Types[AuthorType.Translation],
create_separated_list(authors_translation))) create_separated_list(authors_translation)))
item.raw_footer.append(song.copyright) item.raw_footer.append(song.copyright)
if Settings().value('songs/display songbook') and song.book: if self.display_songbook and song.book:
item.raw_footer.append("%s #%s" % (song.book.name, song.song_number)) item.raw_footer.append("%s #%s" % (song.book.name, song.song_number))
if Settings().value('core/ccli number'): if Settings().value('core/ccli number'):
item.raw_footer.append(translate('SongsPlugin.MediaItem', item.raw_footer.append(translate('SongsPlugin.MediaItem',

View File

@ -1,8 +1,6 @@
""" """
This module contains tests for the lib submodule of the Songs plugin. This module contains tests for the lib submodule of the Songs plugin.
""" """
import os
from tempfile import mkstemp
from unittest import TestCase from unittest import TestCase
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
@ -29,6 +27,7 @@ class TestMediaItem(TestCase, TestMixin):
with patch('openlp.core.lib.mediamanageritem.MediaManagerItem._setup'), \ with patch('openlp.core.lib.mediamanageritem.MediaManagerItem._setup'), \
patch('openlp.plugins.songs.forms.editsongform.EditSongForm.__init__'): patch('openlp.plugins.songs.forms.editsongform.EditSongForm.__init__'):
self.media_item = SongMediaItem(None, MagicMock()) self.media_item = SongMediaItem(None, MagicMock())
self.media_item.display_songbook = False
self.get_application() self.get_application()
self.build_settings() self.build_settings()
QtCore.QLocale.setDefault(QtCore.QLocale('en_GB')) QtCore.QLocale.setDefault(QtCore.QLocale('en_GB'))
@ -128,3 +127,29 @@ class TestMediaItem(TestCase, TestMixin):
# THEN: I would get an amended footer string # THEN: I would get an amended footer string
self.assertEqual(service_item.raw_footer, ['My Song', 'My copyright', 'CCLI License: 4321'], 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') 'The array should be returned correctly with a song, an author, copyright and amended ccli')
def build_song_footer_base_songbook_test(self):
"""
Test build songs footer with basic song and a songbook
"""
# GIVEN: A Song and a Service Item and a configured CCLI license
mock_song = MagicMock()
mock_song.title = 'My Song'
mock_song.copyright = 'My copyright'
mock_song.book = MagicMock()
mock_song.book.name = "My songbook"
mock_song.song_number = 12
service_item = ServiceItem(None)
# WHEN: I generate the Footer with default settings
self.media_item.generate_footer(service_item, mock_song)
# THEN: The songbook should not be in the footer
self.assertEqual(service_item.raw_footer, ['My Song', 'My copyright'])
# WHEN: I activate the "display songbook" option
self.media_item.display_songbook = True
self.media_item.generate_footer(service_item, mock_song)
# THEN: The songbook should be in the footer
self.assertEqual(service_item.raw_footer, ['My Song', 'My copyright', 'My songbook #12'])