2013-04-23 19:08:07 +00:00
|
|
|
"""
|
|
|
|
This module contains tests for the lib submodule of the Songs plugin.
|
|
|
|
"""
|
|
|
|
from unittest import TestCase
|
|
|
|
|
2013-07-06 20:17:24 +00:00
|
|
|
from PyQt4 import QtCore, QtGui
|
2013-04-23 19:08:07 +00:00
|
|
|
|
2013-12-13 17:44:05 +00:00
|
|
|
from openlp.core.common import Registry, Settings
|
|
|
|
from openlp.core.lib import ServiceItem
|
2013-04-23 19:08:07 +00:00
|
|
|
from openlp.plugins.songs.lib.mediaitem import SongMediaItem
|
2014-03-30 18:01:03 +00:00
|
|
|
from openlp.plugins.songs.lib.db import AuthorType
|
2013-09-19 21:02:28 +00:00
|
|
|
from tests.functional import patch, MagicMock
|
2014-03-14 22:08:44 +00:00
|
|
|
from tests.helpers.testmixin import TestMixin
|
2013-04-23 19:08:07 +00:00
|
|
|
|
|
|
|
|
2014-03-14 22:08:44 +00:00
|
|
|
class TestMediaItem(TestCase, TestMixin):
|
2013-04-23 19:08:07 +00:00
|
|
|
"""
|
|
|
|
Test the functions in the :mod:`lib` module.
|
|
|
|
"""
|
|
|
|
def setUp(self):
|
|
|
|
"""
|
|
|
|
Set up the components need for all tests.
|
|
|
|
"""
|
|
|
|
Registry.create()
|
2013-08-31 18:17:38 +00:00
|
|
|
Registry().register('service_list', MagicMock())
|
|
|
|
Registry().register('main_window', MagicMock())
|
2013-10-02 21:07:20 +00:00
|
|
|
with patch('openlp.core.lib.mediamanageritem.MediaManagerItem._setup'), \
|
2013-07-17 13:59:35 +00:00
|
|
|
patch('openlp.plugins.songs.forms.editsongform.EditSongForm.__init__'):
|
2013-10-02 21:07:20 +00:00
|
|
|
self.media_item = SongMediaItem(None, MagicMock())
|
2014-05-03 10:42:18 +00:00
|
|
|
self.media_item.display_songbook = False
|
2014-07-09 12:41:55 +00:00
|
|
|
self.media_item.display_copyright_symbol = False
|
2014-10-22 20:43:05 +00:00
|
|
|
self.setup_application()
|
2014-03-14 22:08:44 +00:00
|
|
|
self.build_settings()
|
2013-07-06 20:17:24 +00:00
|
|
|
QtCore.QLocale.setDefault(QtCore.QLocale('en_GB'))
|
2013-04-23 19:08:07 +00:00
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
"""
|
|
|
|
Delete all the C++ objects at the end so that we don't have a segfault
|
|
|
|
"""
|
2014-03-14 22:08:44 +00:00
|
|
|
self.destroy_settings()
|
2013-04-23 19:08:07 +00:00
|
|
|
|
|
|
|
def build_song_footer_one_author_test(self):
|
|
|
|
"""
|
|
|
|
Test build songs footer with basic song and one author
|
|
|
|
"""
|
|
|
|
# GIVEN: A Song and a Service Item
|
|
|
|
mock_song = MagicMock()
|
2013-08-31 18:17:38 +00:00
|
|
|
mock_song.title = 'My Song'
|
2014-03-30 18:01:03 +00:00
|
|
|
mock_song.authors_songs = []
|
2013-04-23 19:08:07 +00:00
|
|
|
mock_author = MagicMock()
|
2013-08-31 18:17:38 +00:00
|
|
|
mock_author.display_name = 'my author'
|
2014-03-30 18:01:03 +00:00
|
|
|
mock_author_song = MagicMock()
|
|
|
|
mock_author_song.author = mock_author
|
|
|
|
mock_song.authors_songs.append(mock_author_song)
|
2013-08-31 18:17:38 +00:00
|
|
|
mock_song.copyright = 'My copyright'
|
2013-04-23 19:08:07 +00:00
|
|
|
service_item = ServiceItem(None)
|
|
|
|
|
|
|
|
# WHEN: I generate the Footer with default settings
|
|
|
|
author_list = self.media_item.generate_footer(service_item, mock_song)
|
|
|
|
|
|
|
|
# THEN: I get the following Array returned
|
2014-07-09 12:19:32 +00:00
|
|
|
self.assertEqual(service_item.raw_footer, ['My Song', 'Written by: my author', 'My copyright'],
|
2013-08-31 18:17:38 +00:00
|
|
|
'The array should be returned correctly with a song, one author and copyright')
|
|
|
|
self.assertEqual(author_list, ['my author'],
|
|
|
|
'The author list should be returned correctly with one author')
|
2013-04-23 19:08:07 +00:00
|
|
|
|
|
|
|
def build_song_footer_two_authors_test(self):
|
|
|
|
"""
|
|
|
|
Test build songs footer with basic song and two authors
|
|
|
|
"""
|
|
|
|
# GIVEN: A Song and a Service Item
|
|
|
|
mock_song = MagicMock()
|
2013-08-31 18:17:38 +00:00
|
|
|
mock_song.title = 'My Song'
|
2014-03-30 18:01:03 +00:00
|
|
|
mock_song.authors_songs = []
|
2013-04-23 19:08:07 +00:00
|
|
|
mock_author = MagicMock()
|
2013-08-31 18:17:38 +00:00
|
|
|
mock_author.display_name = 'my author'
|
2014-03-30 18:01:03 +00:00
|
|
|
mock_author_song = MagicMock()
|
|
|
|
mock_author_song.author = mock_author
|
2014-04-21 10:06:17 +00:00
|
|
|
mock_author_song.author_type = AuthorType.Music
|
2014-03-30 18:01:03 +00:00
|
|
|
mock_song.authors_songs.append(mock_author_song)
|
2013-04-23 19:08:07 +00:00
|
|
|
mock_author = MagicMock()
|
2013-08-31 18:17:38 +00:00
|
|
|
mock_author.display_name = 'another author'
|
2014-03-30 18:01:03 +00:00
|
|
|
mock_author_song = MagicMock()
|
|
|
|
mock_author_song.author = mock_author
|
2014-04-21 10:06:17 +00:00
|
|
|
mock_author_song.author_type = AuthorType.Words
|
2014-03-30 18:01:03 +00:00
|
|
|
mock_song.authors_songs.append(mock_author_song)
|
|
|
|
mock_author = MagicMock()
|
|
|
|
mock_author.display_name = 'translator'
|
|
|
|
mock_author_song = MagicMock()
|
|
|
|
mock_author_song.author = mock_author
|
2014-04-21 10:06:17 +00:00
|
|
|
mock_author_song.author_type = AuthorType.Translation
|
2014-03-30 18:01:03 +00:00
|
|
|
mock_song.authors_songs.append(mock_author_song)
|
2013-08-31 18:17:38 +00:00
|
|
|
mock_song.copyright = 'My copyright'
|
2013-04-23 19:08:07 +00:00
|
|
|
service_item = ServiceItem(None)
|
|
|
|
|
|
|
|
# WHEN: I generate the Footer with default settings
|
|
|
|
author_list = self.media_item.generate_footer(service_item, mock_song)
|
|
|
|
|
|
|
|
# THEN: I get the following Array returned
|
2014-03-30 18:01:03 +00:00
|
|
|
self.assertEqual(service_item.raw_footer, ['My Song', 'Words: another author', 'Music: my author',
|
2014-07-09 12:19:32 +00:00
|
|
|
'Translation: translator', 'My copyright'],
|
2013-08-31 18:17:38 +00:00
|
|
|
'The array should be returned correctly with a song, two authors and copyright')
|
2014-03-30 18:01:03 +00:00
|
|
|
self.assertEqual(author_list, ['another author', 'my author', 'translator'],
|
2013-08-31 18:17:38 +00:00
|
|
|
'The author list should be returned correctly with two authors')
|
2013-04-23 19:08:07 +00:00
|
|
|
|
|
|
|
def build_song_footer_base_ccli_test(self):
|
|
|
|
"""
|
2014-03-30 18:01:03 +00:00
|
|
|
Test build songs footer with basic song and a CCLI number
|
2013-04-23 19:08:07 +00:00
|
|
|
"""
|
|
|
|
# GIVEN: A Song and a Service Item and a configured CCLI license
|
|
|
|
mock_song = MagicMock()
|
2013-08-31 18:17:38 +00:00
|
|
|
mock_song.title = 'My Song'
|
|
|
|
mock_song.copyright = 'My copyright'
|
2013-04-23 19:08:07 +00:00
|
|
|
service_item = ServiceItem(None)
|
2013-08-31 18:17:38 +00:00
|
|
|
Settings().setValue('core/ccli number', '1234')
|
2013-04-23 19:08:07 +00:00
|
|
|
|
|
|
|
# WHEN: I generate the Footer with default settings
|
|
|
|
self.media_item.generate_footer(service_item, mock_song)
|
|
|
|
|
|
|
|
# THEN: I get the following Array returned
|
2014-07-09 12:19:32 +00:00
|
|
|
self.assertEqual(service_item.raw_footer, ['My Song', 'My copyright', 'CCLI License: 1234'],
|
2013-08-31 18:17:38 +00:00
|
|
|
'The array should be returned correctly with a song, an author, copyright and ccli')
|
2013-04-23 19:08:07 +00:00
|
|
|
|
|
|
|
# WHEN: I amend the CCLI value
|
2013-08-31 18:17:38 +00:00
|
|
|
Settings().setValue('core/ccli number', '4321')
|
2013-04-23 19:08:07 +00:00
|
|
|
self.media_item.generate_footer(service_item, mock_song)
|
|
|
|
|
|
|
|
# THEN: I would get an amended footer string
|
2014-07-09 12:19:32 +00:00
|
|
|
self.assertEqual(service_item.raw_footer, ['My Song', 'My copyright', 'CCLI License: 4321'],
|
2013-08-31 18:17:38 +00:00
|
|
|
'The array should be returned correctly with a song, an author, copyright and amended ccli')
|
2014-05-13 09:44:19 +00:00
|
|
|
|
2014-05-13 09:54:12 +00:00
|
|
|
def build_song_footer_base_songbook_test(self):
|
2014-05-03 10:42:18 +00:00
|
|
|
"""
|
|
|
|
Test build songs footer with basic song and a songbook
|
|
|
|
"""
|
2014-05-03 10:53:51 +00:00
|
|
|
# GIVEN: A Song and a Service Item
|
2014-05-03 10:42:18 +00:00
|
|
|
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
|
2014-07-09 12:19:32 +00:00
|
|
|
self.assertEqual(service_item.raw_footer, ['My Song', 'My copyright'])
|
2014-05-03 10:42:18 +00:00
|
|
|
|
|
|
|
# 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
|
2014-07-09 12:19:32 +00:00
|
|
|
self.assertEqual(service_item.raw_footer, ['My Song', 'My copyright', 'My songbook #12'])
|
2014-05-13 09:53:02 +00:00
|
|
|
|
2014-07-12 20:00:58 +00:00
|
|
|
def build_song_footer_copyright_enabled_test(self):
|
2014-07-09 12:41:55 +00:00
|
|
|
"""
|
|
|
|
Test building song footer with displaying the copyright symbol
|
|
|
|
"""
|
|
|
|
# GIVEN: A Song and a Service Item; displaying the copyright symbol is enabled
|
|
|
|
self.media_item.display_copyright_symbol = True
|
|
|
|
mock_song = MagicMock()
|
|
|
|
mock_song.title = 'My Song'
|
|
|
|
mock_song.copyright = 'My copyright'
|
|
|
|
service_item = ServiceItem(None)
|
|
|
|
|
|
|
|
# WHEN: I generate the Footer with default settings
|
|
|
|
self.media_item.generate_footer(service_item, mock_song)
|
|
|
|
|
|
|
|
# THEN: The copyright symbol should be in the footer
|
|
|
|
self.assertEqual(service_item.raw_footer, ['My Song', '© My copyright'])
|
|
|
|
|
2014-07-12 20:00:58 +00:00
|
|
|
def build_song_footer_copyright_disabled_test(self):
|
|
|
|
"""
|
|
|
|
Test building song footer without displaying the copyright symbol
|
|
|
|
"""
|
|
|
|
# GIVEN: A Song and a Service Item; displaying the copyright symbol should be disabled by default
|
|
|
|
mock_song = MagicMock()
|
|
|
|
mock_song.title = 'My Song'
|
|
|
|
mock_song.copyright = 'My copyright'
|
|
|
|
service_item = ServiceItem(None)
|
|
|
|
|
|
|
|
# WHEN: I generate the Footer with default settings
|
|
|
|
self.media_item.generate_footer(service_item, mock_song)
|
|
|
|
|
|
|
|
# THEN: The copyright symbol should not be in the footer
|
|
|
|
self.assertEqual(service_item.raw_footer, ['My Song', 'My copyright'])
|
|
|
|
|
2014-05-21 19:55:16 +00:00
|
|
|
def authors_match_test(self):
|
2014-05-13 09:44:19 +00:00
|
|
|
"""
|
|
|
|
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"
|
|
|
|
|
|
|
|
# WHEN: Checking for matching
|
2014-05-13 17:52:08 +00:00
|
|
|
result = self.media_item._authors_match(song, authors_str)
|
2014-05-13 09:44:19 +00:00
|
|
|
|
|
|
|
# THEN: They should match
|
2014-05-13 17:52:08 +00:00
|
|
|
self.assertTrue(result, "Authors should match")
|
|
|
|
|
2014-05-21 19:55:16 +00:00
|
|
|
def authors_dont_match_test(self):
|
|
|
|
# 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)
|
|
|
|
|
2014-05-13 17:52:08 +00:00
|
|
|
# WHEN: An author is missing in the string
|
|
|
|
authors_str = "Hans Wurst, Max Mustermann"
|
|
|
|
result = self.media_item._authors_match(song, authors_str)
|
|
|
|
|
|
|
|
# THEN: They should not match
|
|
|
|
self.assertFalse(result, "Authors should not match")
|