functional more bits

This commit is contained in:
Tim Bentley 2017-12-22 17:51:59 +00:00
parent 1abc6e6316
commit e17386d5ab
6 changed files with 42 additions and 48 deletions

View File

@ -133,9 +133,9 @@ class TestPresentationController(TestCase):
# THEN: it should return two empty lists
assert isinstance(result_titles, list), 'result_titles should be of type list'
self.assertEqual(len(result_titles), 0, 'there be no titles')
assert len(result_titles) == 0, 'there be no titles'
assert isinstance(result_notes, list), 'result_notes should be a list'
self.assertEqual(len(result_notes), 0, 'but the list should be empty')
assert len(result_notes) == 0, 'but the list should be empty'
def test_get_titles_and_notes_with_file_error(self):
"""

View File

@ -71,7 +71,7 @@ class TestEditVerseForm(TestCase, TestMixin):
self.edit_verse_form.update_suggested_verse_number()
# THEN the verse number must not be changed
self.assertEqual(3, self.edit_verse_form.verse_number_box.value(), 'The verse number should be 3')
assert 3 == self.edit_verse_form.verse_number_box.value(), 'The verse number should be 3'
def test_on_divide_split_button_clicked(self):
"""
@ -84,8 +84,8 @@ class TestEditVerseForm(TestCase, TestMixin):
# WHEN the method is called
self.edit_verse_form.on_forced_split_button_clicked()
# THEN the verse number must not be changed
self.assertEqual('[--}{--]\nText\n', self.edit_verse_form.verse_text_edit.toPlainText(),
'The verse number should be [--}{--]\nText\n')
assert '[--}{--]\nText\n' == self.edit_verse_form.verse_text_edit.toPlainText(), \
'The verse number should be [--}{--]\nText\n'
def test_on_split_button_clicked(self):
"""
@ -98,5 +98,5 @@ class TestEditVerseForm(TestCase, TestMixin):
# WHEN the method is called
self.edit_verse_form.on_overflow_split_button_clicked()
# THEN the verse number must not be changed
self.assertEqual('[---]\nText\n', self.edit_verse_form.verse_text_edit.toPlainText(),
'The verse number should be [---]\nText\n')
assert '[---]\nText\n' == self.edit_verse_form.verse_text_edit.toPlainText(), \
'The verse number should be [---]\nText\n'

View File

@ -324,10 +324,9 @@ class TestMediaItem(TestCase, TestMixin):
author_list = self.media_item.generate_footer(service_item, mock_song)
# THEN: I get the following Array returned
self.assertEqual(service_item.raw_footer, ['My Song', 'Written by: my author', 'My copyright'],
'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')
assert service_item.raw_footer == ['My Song', 'Written by: my author', 'My copyright'], \
'The array should be returned correctly with a song, one author and copyright'
assert author_list == ['my author'], 'The author list should be returned correctly with one author'
@patch(u'openlp.plugins.songs.lib.mediaitem.Settings')
def test_build_song_footer_one_author_hide_written_by(self, MockedSettings):
@ -356,11 +355,10 @@ class TestMediaItem(TestCase, TestMixin):
author_list = self.media_item.generate_footer(service_item, mock_song)
# THEN: I get the following Array returned
self.assertEqual(service_item.raw_footer, ['My Song', 'my author', 'My copyright'],
'The array should be returned correctly with a song, one author and copyright,'
'text Written by should not be part of the text.')
self.assertEqual(author_list, ['my author'],
'The author list should be returned correctly with one author')
assert service_item.raw_footer == ['My Song', 'my author', 'My copyright'], \
'The array should be returned correctly with a song, one author and copyright, ' \
'text Written by should not be part of the text.'
assert author_list == ['my author'], 'The author list should be returned correctly with one author'
def test_build_song_footer_two_authors(self):
"""
@ -395,11 +393,11 @@ class TestMediaItem(TestCase, TestMixin):
author_list = self.media_item.generate_footer(service_item, mock_song)
# THEN: I get the following Array returned
self.assertEqual(service_item.raw_footer, ['My Song', 'Words: another author', 'Music: my author',
'Translation: translator', 'My copyright'],
'The array should be returned correctly with a song, two authors and copyright')
self.assertEqual(author_list, ['another author', 'my author', 'translator'],
'The author list should be returned correctly with two authors')
assert service_item.raw_footer == ['My Song', 'Words: another author', 'Music: my author',
'Translation: translator', 'My copyright'], \
'The array should be returned correctly with a song, two authors and copyright'
assert author_list == ['another author', 'my author', 'translator'], \
'The author list should be returned correctly with two authors'
def test_build_song_footer_base_ccli(self):
"""
@ -416,16 +414,16 @@ class TestMediaItem(TestCase, TestMixin):
self.media_item.generate_footer(service_item, mock_song)
# THEN: I get the following Array returned
self.assertEqual(service_item.raw_footer, ['My Song', 'My copyright', 'CCLI License: 1234'],
'The array should be returned correctly with a song, an author, copyright and ccli')
assert service_item.raw_footer == ['My Song', 'My copyright', 'CCLI License: 1234'], \
'The array should be returned correctly with a song, an author, copyright and ccli'
# WHEN: I amend the CCLI value
Settings().setValue('core/ccli number', '4321')
self.media_item.generate_footer(service_item, mock_song)
# THEN: I would get an amended footer string
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')
assert 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'
def test_build_song_footer_base_songbook(self):
"""
@ -451,14 +449,14 @@ class TestMediaItem(TestCase, TestMixin):
self.media_item.generate_footer(service_item, song)
# THEN: The songbook should not be in the footer
self.assertEqual(service_item.raw_footer, ['My Song', 'My copyright'])
assert 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, song)
# THEN: The songbook should be in the footer
self.assertEqual(service_item.raw_footer, ['My Song', 'My copyright', 'My songbook #12, Thy songbook #502A'])
assert service_item.raw_footer == ['My Song', 'My copyright', 'My songbook #12, Thy songbook #502A']
def test_build_song_footer_copyright_enabled(self):
"""
@ -475,7 +473,7 @@ class TestMediaItem(TestCase, TestMixin):
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'])
assert service_item.raw_footer == ['My Song', '© My copyright']
def test_build_song_footer_copyright_disabled(self):
"""
@ -491,7 +489,7 @@ class TestMediaItem(TestCase, TestMixin):
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'])
assert service_item.raw_footer == ['My Song', 'My copyright']
def test_authors_match(self):
"""
@ -517,7 +515,7 @@ class TestMediaItem(TestCase, TestMixin):
result = self.media_item._authors_match(song, authors_str)
# THEN: They should match
self.assertTrue(result, "Authors should match")
assert result is True, "Authors should match"
def test_authors_dont_match(self):
# GIVEN: A song and a string with authors
@ -540,7 +538,7 @@ class TestMediaItem(TestCase, TestMixin):
result = self.media_item._authors_match(song, authors_str)
# THEN: They should not match
self.assertFalse(result, "Authors should not match")
assert result is False, "Authors should not match"
def test_build_remote_search(self):
"""
@ -559,7 +557,7 @@ class TestMediaItem(TestCase, TestMixin):
search_results = self.media_item.search('My Song', False)
# THEN: The correct formatted results are returned
self.assertEqual(search_results, [[123, 'My Song', 'My alternative']])
assert search_results == [[123, 'My Song', 'My alternative']]
@patch('openlp.plugins.songs.lib.mediaitem.Book')
@patch('openlp.plugins.songs.lib.mediaitem.SongBookEntry')
@ -590,4 +588,4 @@ class TestMediaItem(TestCase, TestMixin):
mocked_or.assert_called_once_with('%jesus%', '%jesus%', '%jesus%', '%jesus%', '%jesus%')
self.mocked_plugin.manager.session.query.assert_called_once_with(MockedSong)
self.assertEqual(self.mocked_plugin.manager.session.query.mock_calls[4][0], '().join().join().filter().all')
assert self.mocked_plugin.manager.session.query.mock_calls[4][0] == '().join().join().filter().all'

View File

@ -72,9 +72,7 @@ class TestOpenLyricsExport(TestCase, TestMixin):
ol_export.do_export()
# THEN: The exporter should have created 2 files
self.assertTrue((self.temp_folder /
'{title} ({display_name}).xml'.format(
title=song.title, display_name=author.display_name)).exists())
self.assertTrue((self.temp_folder /
'{title} ({display_name})-1.xml'.format(
title=song.title, display_name=author.display_name)).exists())
assert (self.temp_folder / '{title} ({display_name}).xml'.format(
title=song.title, display_name=author.display_name)).exists() is True
assert (self.temp_folder / '{title} ({display_name})-1.xml'.format(
title=song.title, display_name=author.display_name)).exists() is True

View File

@ -59,7 +59,7 @@ class TestOpenOfficeImport(TestCase, TestMixin):
importer = OpenOfficeImport(mocked_manager, file_paths=[])
# THEN: The importer object should not be None
self.assertIsNotNone(importer, 'Import should not be none')
assert importer is not None, 'Import should not be none'
@patch('openlp.plugins.songs.lib.importers.openoffice.SongImport')
def test_close_ooo_file(self, mocked_songimport):
@ -76,4 +76,4 @@ class TestOpenOfficeImport(TestCase, TestMixin):
importer.close_ooo_file()
# THEN: The document attribute should be None even if an exception is raised')
self.assertIsNone(importer.document, 'Document should be None even if an exception is raised')
assert importer.document is None, 'Document should be None even if an exception is raised'

View File

@ -156,7 +156,7 @@ class TestWorshipCenterProSongImport(TestCase):
importer = WorshipCenterProImport(mocked_manager, file_paths=[])
# THEN: The importer object should not be None
self.assertIsNotNone(importer, 'Import should not be none')
assert importer is not None, 'Import should not be none'
def test_pyodbc_exception(self):
"""
@ -181,7 +181,7 @@ class TestWorshipCenterProSongImport(TestCase):
return_value = importer.do_import()
# THEN: do_import should return None, and pyodbc, translate & log_error are called with known calls
self.assertIsNone(return_value, 'do_import should return None when pyodbc raises an exception.')
assert return_value is None, 'do_import should return None when pyodbc raises an exception.'
mocked_pyodbc_connect.assert_called_with('DRIVER={Microsoft Access Driver (*.mdb)};DBQ=import_source')
mocked_translate.assert_called_with('SongsPlugin.WorshipCenterProImport',
'Unable to connect the WorshipCenter Pro database.')
@ -220,7 +220,7 @@ class TestWorshipCenterProSongImport(TestCase):
# THEN: do_import should return None, and pyodbc, import_wizard, importer.title and add_verse are called
# with known calls
self.assertIsNone(return_value, 'do_import should return None when pyodbc raises an exception.')
assert return_value is None, 'do_import should return None when pyodbc raises an exception.'
mocked_pyodbc.connect.assert_called_with('DRIVER={Microsoft Access Driver (*.mdb)};DBQ=import_source')
mocked_pyodbc.connect().cursor.assert_any_call()
mocked_pyodbc.connect().cursor().execute.assert_called_with('SELECT ID, Field, Value FROM __SONGDATA')
@ -229,8 +229,7 @@ class TestWorshipCenterProSongImport(TestCase):
add_verse_call_count = 0
for song_data in SONG_TEST_DATA:
title_value = song_data['title']
self.assertIn(title_value, importer._title_assignment_list,
'title should have been set to %s' % title_value)
assert title_value in importer._title_assignment_list, 'title should have been set to %s' % title_value
verse_calls = song_data['verses']
add_verse_call_count += len(verse_calls)
for call in verse_calls:
@ -241,5 +240,4 @@ class TestWorshipCenterProSongImport(TestCase):
mocked_add_comment.assert_any_call(song_data['comments'])
if 'copyright' in song_data:
mocked_add_copyright.assert_any_call(song_data['copyright'])
self.assertEqual(mocked_add_verse.call_count, add_verse_call_count,
'Incorrect number of calls made to add_verse')
assert mocked_add_verse.call_count == add_verse_call_count, 'Incorrect number of calls made to add_verse'