forked from openlp/openlp
Fix test
This commit is contained in:
parent
a1e1092b10
commit
5fbcbb3047
@ -35,46 +35,59 @@ from openlp.plugins.songs.lib.mediaitem import SongMediaItem
|
|||||||
from tests.helpers.testmixin import TestMixin
|
from tests.helpers.testmixin import TestMixin
|
||||||
|
|
||||||
__default_settings__ = {
|
__default_settings__ = {
|
||||||
'songs/footer template': """{{title}}<br/>
|
'songs/footer template': """
|
||||||
|
${title}<br/>
|
||||||
|
|
||||||
{{#authors_none}}
|
%if authors_none:
|
||||||
{{#first}}{{authors_none_label}}: {{/first}}
|
<%
|
||||||
{{entry}}{{^last}}, {{/last}}
|
authors = ", ".join(authors_none)
|
||||||
{{#last}}<br/>{{/last}}
|
%>
|
||||||
{{/authors_none}}
|
${authors_none_label}: ${authors}<br/>
|
||||||
{{#authors_words_music}}
|
%endif
|
||||||
{{#first}}{{authors_words_music_label}}: {{/first}}
|
|
||||||
{{entry}}{{^last}}, {{/last}}
|
|
||||||
{{#last}}<br/>{{/last}}
|
|
||||||
{{/authors_words_music}}
|
|
||||||
{{#authors_words}}
|
|
||||||
{{#first}}{{authors_words_label}}: {{/first}}
|
|
||||||
{{entry}}{{^last}}, {{/last}}
|
|
||||||
{{#last}}<br/>{{/last}}
|
|
||||||
{{/authors_words}}
|
|
||||||
{{#authors_music}}
|
|
||||||
{{#first}}{{authors_music_label}}: {{/first}}
|
|
||||||
{{entry}}{{^last}}, {{/last}}
|
|
||||||
{{#last}}<br/>{{/last}}
|
|
||||||
{{/authors_music}}
|
|
||||||
{{#authors_translation}}
|
|
||||||
{{#first}}{{authors_translation_label}}: {{/first}}
|
|
||||||
{{entry}}{{^last}}, {{/last}}
|
|
||||||
{{#last}}<br/>{{/last}}
|
|
||||||
{{/authors_translation}}
|
|
||||||
|
|
||||||
{{#copyright}}
|
%if authors_words_music:
|
||||||
© {{copyright}}<br/>
|
<%
|
||||||
{{/copyright}}
|
authors = ", ".join(authors_words_music)
|
||||||
|
%>
|
||||||
|
${authors_words_music_label}: ${authors}<br/>
|
||||||
|
%endif
|
||||||
|
|
||||||
{{#songbook_entries}}
|
%if authors_words:
|
||||||
{{entry}}{{^last}}, {{/last}}
|
<%
|
||||||
{{#last}}<br/>{{/last}}
|
authors = ", ".join(authors_words)
|
||||||
{{/songbook_entries}}
|
%>
|
||||||
|
${authors_words_label}: ${authors}<br/>
|
||||||
|
%endif
|
||||||
|
|
||||||
{{#ccli_license}}
|
%if authors_music:
|
||||||
{{ccli_license_label}}: {{ccli_license}}<br/>
|
<%
|
||||||
{{/ccli_license}}"""
|
authors = ", ".join(authors_music)
|
||||||
|
%>
|
||||||
|
${authors_music_label}: ${authors}<br/>
|
||||||
|
%endif
|
||||||
|
|
||||||
|
%if authors_translation:
|
||||||
|
<%
|
||||||
|
authors = ", ".join(authors_translation)
|
||||||
|
%>
|
||||||
|
${authors_translation_label}: ${authors}<br/>
|
||||||
|
%endif
|
||||||
|
|
||||||
|
%if copyright:
|
||||||
|
© ${copyright}<br/>
|
||||||
|
%endif
|
||||||
|
|
||||||
|
%if songbook_entries:
|
||||||
|
<%
|
||||||
|
entries = ", ".join(songbook_entries)
|
||||||
|
%>
|
||||||
|
${entries}<br/>
|
||||||
|
%endif
|
||||||
|
|
||||||
|
%if ccli_license:
|
||||||
|
${ccli_license_label} ${ccli_license}<br/>
|
||||||
|
%endif
|
||||||
|
"""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -344,14 +357,13 @@ class TestMediaItem(TestCase, TestMixin):
|
|||||||
"""
|
"""
|
||||||
Test build songs footer with basic song and one author
|
Test build songs footer with basic song and one author
|
||||||
"""
|
"""
|
||||||
# GIVEN: A Song and a Service Item, mocked settings: True for 'songs/display written by'
|
# GIVEN: A Song and a Service Item, mocked settings
|
||||||
# and False for 'core/ccli number' (ccli will cause traceback if true)
|
|
||||||
|
|
||||||
mocked_settings = MagicMock()
|
mocked_settings = MagicMock()
|
||||||
mocked_settings.value.side_effect = [False, "", "0"]
|
mocked_settings.value.side_effect = [False, "", "0"]
|
||||||
MockedSettings.return_value = mocked_settings
|
MockedSettings.return_value = mocked_settings
|
||||||
|
|
||||||
with patch('pystache.Renderer.render') as MockedRenderer:
|
with patch('mako.template.Template.render_unicode') as MockedRenderer:
|
||||||
mock_song = MagicMock()
|
mock_song = MagicMock()
|
||||||
mock_song.title = 'My Song'
|
mock_song.title = 'My Song'
|
||||||
mock_song.alternate_title = ''
|
mock_song.alternate_title = ''
|
||||||
@ -365,27 +377,23 @@ class TestMediaItem(TestCase, TestMixin):
|
|||||||
mock_song.copyright = 'My copyright'
|
mock_song.copyright = 'My copyright'
|
||||||
mock_song.songbook_entries = []
|
mock_song.songbook_entries = []
|
||||||
service_item = ServiceItem(None)
|
service_item = ServiceItem(None)
|
||||||
MockedRenderer.return_value = ""
|
|
||||||
|
|
||||||
# WHEN: I generate the Footer with default settings
|
# WHEN: I generate the Footer with default settings
|
||||||
author_list = self.media_item.generate_footer(service_item, mock_song)
|
author_list = self.media_item.generate_footer(service_item, mock_song)
|
||||||
|
|
||||||
# THEN: I get nothing real returned
|
# THEN: The mako function was called with the following arguments
|
||||||
self.assertEqual(service_item.footer_html, "", 'pystache isnt in scope')
|
args = {'authors_translation': [], 'authors_music_label': 'Music',
|
||||||
|
|
||||||
# AND: The psytache function was called with the following arguments
|
|
||||||
MockedRenderer.assert_called_once_with('', {'authors_translation': [], 'authors_music_label': 'Music',
|
|
||||||
'copyright': 'My copyright', 'songbook_entries': [],
|
'copyright': 'My copyright', 'songbook_entries': [],
|
||||||
'alternate_title': '', 'topics': [], 'authors_music_all': [],
|
'alternate_title': '', 'topics': [], 'authors_music_all': [],
|
||||||
'authors_words_label': 'Words', 'authors_music': [],
|
'authors_words_label': 'Words', 'authors_music': [],
|
||||||
'authors_words_music': [], 'ccli_number': '',
|
'authors_words_music': [], 'ccli_number': '',
|
||||||
'authors_none_label': 'Written by', 'title': 'My Song',
|
'authors_none_label': 'Written by', 'title': 'My Song',
|
||||||
'authors_words_music_label': 'Words and Music',
|
'authors_words_music_label': 'Words and Music',
|
||||||
'authors_none': [{'last_or_penultimate': True, 'last': True,
|
'authors_none': ['my author'],
|
||||||
'entry': 'my author', 'first': True}],
|
|
||||||
'ccli_license_label': 'CCLI License', 'authors_words': [],
|
'ccli_license_label': 'CCLI License', 'authors_words': [],
|
||||||
'ccli_license': '0', 'authors_translation_label': 'Translation',
|
'ccli_license': '0', 'authors_translation_label': 'Translation',
|
||||||
'authors_words_all': []})
|
'authors_words_all': []}
|
||||||
|
MockedRenderer.assert_called_once_with(**args)
|
||||||
self.assertEqual(author_list, ['my author'],
|
self.assertEqual(author_list, ['my author'],
|
||||||
'The author list should be returned correctly with one author')
|
'The author list should be returned correctly with one author')
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user