functional more bits

This commit is contained in:
Tim Bentley 2017-12-22 21:04:29 +00:00
parent e17386d5ab
commit 19918d0aa9
13 changed files with 235 additions and 243 deletions

View File

@ -53,9 +53,9 @@ class TestBibleMediaItemModulefunctions(TestCase):
# THEN: The expected result should be returned
if expected_result is None:
self.assertIsNone(result, expected_result)
assert result is None, expected_result
else:
self.assertEqual(result.regs, expected_result)
assert result.regs == expected_result
def test_get_reference_separators(self):
"""
@ -69,7 +69,7 @@ class TestBibleMediaItemModulefunctions(TestCase):
# THEN: The result should contain the 'verse', 'range', 'list' keys and get_reference_separator should have
# been called with the expected values.
self.assertTrue(all(key in result for key in ('verse', 'range', 'list')))
assert all(key in result for key in ('verse', 'range', 'list')) is True
mocked_get_reference_separator.assert_has_calls(
[call('sep_v_display'), call('sep_r_display'), call('sep_l_display')])
@ -80,9 +80,9 @@ class TestBibleMediaItemModulefunctions(TestCase):
# GIVEN: The BibleSearch class
# WHEN: Testing its attributes
# THEN: The BibleSearch class should have the following enumrations
self.assertTrue(hasattr(BibleSearch, 'Combined'))
self.assertTrue(hasattr(BibleSearch, 'Reference'))
self.assertTrue(hasattr(BibleSearch, 'Text'))
assert hasattr(BibleSearch, 'Combined')
assert hasattr(BibleSearch, 'Reference')
assert hasattr(BibleSearch, 'Text')
def test_bible_media_item_subclass(self):
"""
@ -91,7 +91,7 @@ class TestBibleMediaItemModulefunctions(TestCase):
# GIVEN: The :class:`BibleMediaItem`
# WHEN: Checking if it is a subclass of MediaManagerItem
# THEN: BibleMediaItem should be a subclass of MediaManagerItem
self.assertTrue(issubclass(BibleMediaItem, MediaManagerItem))
assert issubclass(BibleMediaItem, MediaManagerItem)
def test_bible_media_item_signals(self):
"""
@ -99,10 +99,10 @@ class TestBibleMediaItemModulefunctions(TestCase):
"""
# GIVEN: The :class:`BibleMediaItem`
# THEN: The :class:`BibleMediaItem` should contain the following pyqtSignal's
self.assertTrue(hasattr(BibleMediaItem, 'bibles_go_live'))
self.assertTrue(hasattr(BibleMediaItem, 'bibles_add_to_service'))
self.assertTrue(isinstance(BibleMediaItem.bibles_go_live, QtCore.pyqtSignal))
self.assertTrue(isinstance(BibleMediaItem.bibles_add_to_service, QtCore.pyqtSignal))
assert hasattr(BibleMediaItem, 'bibles_go_live')
assert hasattr(BibleMediaItem, 'bibles_add_to_service')
assert isinstance(BibleMediaItem.bibles_go_live, QtCore.pyqtSignal)
assert isinstance(BibleMediaItem.bibles_add_to_service, QtCore.pyqtSignal)
class TestMediaItem(TestCase, TestMixin):
@ -166,7 +166,7 @@ class TestMediaItem(TestCase, TestMixin):
# GIVEN: An instance of :class:`BibleMediaItem`
# WEHN: Checking its class
# THEN: It should be a subclass of :class:`MediaManagerItem`
self.assertTrue(isinstance(self.media_item, MediaManagerItem))
assert isinstance(self.media_item, MediaManagerItem)
def test_steup_item(self):
"""
@ -193,11 +193,11 @@ class TestMediaItem(TestCase, TestMixin):
self.media_item.required_icons()
# THEN: The correct icons should be set
self.assertTrue(self.media_item.has_import_icon, 'Check that the icon is as True.')
self.assertFalse(self.media_item.has_new_icon, 'Check that the icon is called as False.')
self.assertTrue(self.media_item.has_edit_icon, 'Check that the icon is called as True.')
self.assertTrue(self.media_item.has_delete_icon, 'Check that the icon is called as True.')
self.assertFalse(self.media_item.add_to_service_item, 'Check that the icon is called as False')
assert self.media_item.has_import_icon is True, 'Check that the icon is as True.'
assert self.media_item.has_new_icon is False, 'Check that the icon is called as False.'
assert self.media_item.has_edit_icon is True, 'Check that the icon is called as True.'
assert self.media_item.has_delete_icon is True, 'Check that the icon is called as True.'
assert self.media_item.add_to_service_item is False, 'Check that the icon is called as False'
def test_on_focus_search_tab_visible(self):
"""
@ -305,8 +305,8 @@ class TestMediaItem(TestCase, TestMixin):
self.media_item.initialise()
# THEN: The search_edit search types should have been set.
self.assertTrue(self.media_item.search_edit.set_search_types.called)
self.assertFalse(self.media_item.search_edit.set_current_search_type.called)
assert self.media_item.search_edit.set_search_types.called is True
assert self.media_item.search_edit.set_current_search_type.called is False
def test_initalise_reset_search_type(self):
"""
@ -323,7 +323,7 @@ class TestMediaItem(TestCase, TestMixin):
# THEN: The search_edit search types should have been set and that the current search type should be set to
# 'Combined'
self.assertTrue(self.media_item.search_edit.set_search_types.called)
assert self.media_item.search_edit.set_search_types.called is True
self.media_item.search_edit.set_current_search_type.assert_called_once_with(BibleSearch.Combined)
def test_populate_bible_combo_boxes(self):
@ -373,7 +373,7 @@ class TestMediaItem(TestCase, TestMixin):
result = self.media_item.get_common_books(self.mocked_bible_1)
# THEN: The book of the bible should be returned
self.assertEqual(result, self.book_list_1)
assert result == self.book_list_1
def test_get_common_books_second_book(self):
"""
@ -384,7 +384,7 @@ class TestMediaItem(TestCase, TestMixin):
result = self.media_item.get_common_books(self.mocked_bible_1, self.mocked_bible_2)
# THEN: Only the books contained in both bibles should be returned
self.assertEqual(result, [self.mocked_book_2, self.mocked_book_3])
assert result == [self.mocked_book_2, self.mocked_book_3]
def test_initialise_advanced_bible_no_bible(self):
"""
@ -399,7 +399,7 @@ class TestMediaItem(TestCase, TestMixin):
result = self.media_item.initialise_advanced_bible()
# THEN: initialise_advanced_bible should return with put calling get_common_books
self.assertIsNone(result)
assert result is None
mocked_get_common_books.assert_not_called()
def test_initialise_advanced_bible_add_books_with_last_id_found(self):
@ -515,8 +515,8 @@ class TestMediaItem(TestCase, TestMixin):
self.media_item.on_import_click()
# THEN: BibleImport wizard should have been instianted and reload_bibles should not have been called
self.assertTrue(mocked_bible_import_form.called)
self.assertFalse(mocked_reload_bibles.called)
assert mocked_bible_import_form.called is True
assert mocked_reload_bibles.called is False
def test_on_import_click_wizard_not_canceled(self):
"""
@ -532,8 +532,8 @@ class TestMediaItem(TestCase, TestMixin):
self.media_item.on_import_click()
# THEN: BibleImport wizard should have been instianted and reload_bibles should not have been called
self.assertFalse(mocked_import_wizard.called)
self.assertTrue(mocked_reload_bibles.called)
assert mocked_import_wizard.called is False
assert mocked_reload_bibles.called is True
def test_on_edit_click_no_bible(self):
"""
@ -547,7 +547,7 @@ class TestMediaItem(TestCase, TestMixin):
self.media_item.on_edit_click()
# THEN: EditBibleForm should not have been instianted
self.assertFalse(mocked_edit_bible_form.called)
assert mocked_edit_bible_form.called is False
def test_on_edit_click_user_cancel_edit_form(self):
"""
@ -565,8 +565,8 @@ class TestMediaItem(TestCase, TestMixin):
self.media_item.on_edit_click()
# THEN: EditBibleForm should have been been instianted but reload_bibles should not have been called
self.assertTrue(mocked_edit_bible_form.called)
self.assertFalse(mocked_reload_bibles.called)
assert mocked_edit_bible_form.called is True
assert mocked_reload_bibles.called is False
def test_on_edit_click_user_accepts_edit_form(self):
"""
@ -585,8 +585,8 @@ class TestMediaItem(TestCase, TestMixin):
self.media_item.on_edit_click()
# THEN: EditBibleForm should have been been instianted and reload_bibles should have been called
self.assertTrue(mocked_edit_bible_form.called)
self.assertTrue(mocked_reload_bibles.called)
assert mocked_edit_bible_form.called is True
assert mocked_reload_bibles.called is True
def test_on_delete_click_no_bible(self):
"""
@ -600,7 +600,7 @@ class TestMediaItem(TestCase, TestMixin):
self.media_item.on_delete_click()
# THEN: QMessageBox.question should not have been called
self.assertFalse(mocked_qmessage_box.question.called)
assert mocked_qmessage_box.question.called is False
def test_on_delete_click_response_no(self):
"""
@ -615,8 +615,8 @@ class TestMediaItem(TestCase, TestMixin):
self.media_item.on_delete_click()
# THEN: QMessageBox.question should have been called, but the delete_bible should not have been called
self.assertTrue(mocked_qmessage_box.called)
self.assertFalse(self.mocked_plugin.manager.delete_bible.called)
assert mocked_qmessage_box.called is True
assert self.mocked_plugin.manager.delete_bible.called is False
def test_on_delete_click_response_yes(self):
"""
@ -632,8 +632,8 @@ class TestMediaItem(TestCase, TestMixin):
self.media_item.on_delete_click()
# THEN: QMessageBox.question should and delete_bible should not have been called
self.assertTrue(mocked_qmessage_box.called)
self.assertTrue(self.mocked_plugin.manager.delete_bible.called)
assert mocked_qmessage_box.called is True
assert self.mocked_plugin.manager.delete_bible.called is True
def test_on_search_tab_bar_current_changed_search_tab_selected(self):
"""
@ -711,8 +711,8 @@ class TestMediaItem(TestCase, TestMixin):
self.media_item.on_clear_button_clicked()
# THEN: The list_view and the search_edit should be cleared
self.assertEqual(self.media_item.current_results, [])
self.assertEqual(self.media_item.list_view.takeItem.call_count, 2)
assert self.media_item.current_results == []
assert self.media_item.list_view.takeItem.call_count == 2
self.media_item.list_view.row.assert_has_calls([call('Some'), call('Results')])
def test_on_save_results_button_clicked(self):
@ -733,7 +733,7 @@ class TestMediaItem(TestCase, TestMixin):
# THEN: The selected results in the list_view should be added to the 'saved_results' list. And the saved_tab
# total should be updated.
self.assertEqual(self.media_item.saved_results, ['R1', 'R2', 'R3'])
assert self.media_item.saved_results == ['R1', 'R2', 'R3']
mocked_on_results_view_tab_total_update.assert_called_once_with(ResultsTab.Saved)
def test_on_style_combo_box_changed(self):
@ -746,8 +746,8 @@ class TestMediaItem(TestCase, TestMixin):
# WHEN: Calling on_style_combo_box_index_changed
self.media_item.on_style_combo_box_index_changed(2)
# THEN: The layput_style settimg should have been set
self.assertEqual(self.media_item.settings.layout_style, 2)
# THEN: The layout_style setting should have been set
assert self.media_item.settings.layout_style, 2
self.media_item.settings.layout_style_combo_box.setCurrentIndex.assert_called_once_with(2)
self.mocked_settings_instance.setValue.assert_called_once_with('bibles/verse layout style', 2)
@ -763,9 +763,9 @@ class TestMediaItem(TestCase, TestMixin):
# WHEN: Calling on_version_combo_box_index_changed
self.media_item.on_version_combo_box_index_changed()
# THEN: The vesion should be saved to settings and the 'select tab' should be initialised
self.assertFalse(self.mocked_settings_instance.setValue.called)
self.assertTrue(self.media_item.initialise_advanced_bible.called)
# THEN: The version should be saved to settings and the 'select tab' should be initialised
assert self.mocked_settings_instance.setValue.called is False
assert self.media_item.initialise_advanced_bible.called is True
def test_on_version_combo_box_index_changed_bible_selected(self):
"""
@ -781,9 +781,9 @@ class TestMediaItem(TestCase, TestMixin):
# WHEN: Calling on_version_combo_box_index_changed
self.media_item.on_version_combo_box_index_changed()
# THEN: The vesion should be saved to settings and the 'select tab' should be initialised
# THEN: The version should be saved to settings and the 'select tab' should be initialised
self.mocked_settings_instance.setValue.assert_called_once_with('bibles/primary bible', 'ABC')
self.assertTrue(self.media_item.initialise_advanced_bible.called)
assert self.media_item.initialise_advanced_bible.called is True
def test_on_second_combo_box_index_changed_mode_not_changed(self):
"""
@ -798,15 +798,15 @@ class TestMediaItem(TestCase, TestMixin):
patch('openlp.plugins.bibles.lib.mediaitem.critical_error_message_box') \
as mocked_critical_error_message_box:
# WHEN: The previously selected bible is one bible and the new selection is annother bible
# WHEN: The previously selected bible is one bible and the new selection is another bible
self.media_item.second_bible = self.mocked_bible_1
self.media_item.second_combo_box = MagicMock(**{'currentData.return_value': self.mocked_bible_2})
self.media_item.on_second_combo_box_index_changed(5)
# THEN: The new bible should now be the current bible
self.assertFalse(mocked_critical_error_message_box.called)
assert mocked_critical_error_message_box.called is False
self.media_item.style_combo_box.setEnabled.assert_called_once_with(False)
self.assertEqual(self.media_item.second_bible, self.mocked_bible_2)
assert self.media_item.second_bible == self.mocked_bible_2
def test_on_second_combo_box_index_changed_single_to_dual_user_abort(self):
"""
@ -828,11 +828,11 @@ class TestMediaItem(TestCase, TestMixin):
self.media_item.saved_results = ['saved_results']
self.media_item.on_second_combo_box_index_changed(5)
# THEN: The list_view should be cleared and the currently selected bible should not be channged
self.assertTrue(mocked_critical_error_message_box.called)
self.assertTrue(self.media_item.second_combo_box.setCurrentIndex.called)
self.assertFalse(self.media_item.style_combo_box.setEnabled.called)
self.assertEqual(self.media_item.second_bible, None)
# THEN: The list_view should be cleared and the currently selected bible should not be changed
assert mocked_critical_error_message_box.called is True
assert self.media_item.second_combo_box.setCurrentIndex.called is True
assert self.media_item.style_combo_box.setEnabled.called is False
assert self.media_item.second_bible is None
def test_on_second_combo_box_index_changed_single_to_dual(self):
"""
@ -857,10 +857,10 @@ class TestMediaItem(TestCase, TestMixin):
self.media_item.on_second_combo_box_index_changed(5)
# THEN: The selected bible should be set as the current bible
self.assertTrue(mocked_critical_error_message_box.called)
assert mocked_critical_error_message_box.called is True
self.media_item.style_combo_box.setEnabled.assert_called_once_with(False)
self.assertTrue(mocked_initialise_advanced_bible.called)
self.assertEqual(self.media_item.second_bible, self.mocked_bible_1)
assert mocked_initialise_advanced_bible.called is True
assert self.media_item.second_bible == self.mocked_bible_1
def test_on_second_combo_box_index_changed_dual_to_single(self):
"""
@ -884,10 +884,10 @@ class TestMediaItem(TestCase, TestMixin):
self.media_item.on_second_combo_box_index_changed(0)
# THEN: The selected bible should be set as the current bible
self.assertTrue(mocked_critical_error_message_box.called)
assert mocked_critical_error_message_box.called is True
self.media_item.style_combo_box.setEnabled.assert_called_once_with(True)
self.assertFalse(mocked_initialise_advanced_bible.called)
self.assertEqual(self.media_item.second_bible, None)
assert mocked_initialise_advanced_bible.called is False
assert self.media_item.second_bible is None
def test_on_advanced_book_combo_box(self):
"""
@ -907,7 +907,7 @@ class TestMediaItem(TestCase, TestMixin):
# THEN: The user should be informed that the bible cannot be used and the search button should be disabled
self.mocked_plugin.manager.get_book_by_id.assert_called_once_with('Bible 1', 2)
self.media_item.search_button.setEnabled.assert_called_once_with(False)
self.assertTrue(mocked_critical_error_message_box.called)
assert mocked_critical_error_message_box.called is True
def test_on_advanced_book_combo_box_set_up_comboboxes(self):
"""
@ -930,7 +930,7 @@ class TestMediaItem(TestCase, TestMixin):
# THEN: The verse selection combobox's should be set up
self.mocked_plugin.manager.get_book_by_id.assert_called_once_with('Bible 1', 2)
self.media_item.search_button.setEnabled.assert_called_once_with(True)
self.assertEqual(mocked_adjust_combo_box.call_count, 4)
assert mocked_adjust_combo_box.call_count == 4
def test_on_from_chapter_activated_invalid_to_chapter(self):
"""
@ -951,9 +951,9 @@ class TestMediaItem(TestCase, TestMixin):
self.media_item.on_from_chapter_activated()
# THEN: The to_verse and to_chapter comboboxes should be updated appropriately
self.assertEqual(mocked_adjust_combo_box.call_args_list, [
assert mocked_adjust_combo_box.call_args_list == [
call(1, 20, self.media_item.from_verse), call(1, 20, self.media_item.to_verse, False),
call(10, 25, self.media_item.to_chapter, False)])
call(10, 25, self.media_item.to_chapter, False)]
def test_on_from_chapter_activated_same_chapter(self):
"""
@ -974,9 +974,9 @@ class TestMediaItem(TestCase, TestMixin):
self.media_item.on_from_chapter_activated()
# THEN: The to_verse and to_chapter comboboxes should be updated appropriately
self.assertEqual(mocked_adjust_combo_box.call_args_list, [
assert mocked_adjust_combo_box.call_args_list == [
call(1, 20, self.media_item.from_verse), call(1, 20, self.media_item.to_verse, True),
call(5, 25, self.media_item.to_chapter, False)])
call(5, 25, self.media_item.to_chapter, False)]
def test_on_from_chapter_activated_lower_chapter(self):
"""
@ -996,8 +996,8 @@ class TestMediaItem(TestCase, TestMixin):
self.media_item.on_from_chapter_activated()
# THEN: The to_verse and to_chapter comboboxes should be updated appropriately
self.assertEqual(mocked_adjust_combo_box.call_args_list, [
call(1, 20, self.media_item.from_verse), call(5, 25, self.media_item.to_chapter, True)])
assert mocked_adjust_combo_box.call_args_list == [
call(1, 20, self.media_item.from_verse), call(5, 25, self.media_item.to_chapter, True)]
def test_on_from_verse(self):
"""
@ -1012,7 +1012,7 @@ class TestMediaItem(TestCase, TestMixin):
self.media_item.on_from_verse()
# THEN: select_book_combo_box.currentData should nto be called
self.assertFalse(self.media_item.select_book_combo_box.currentData.called)
assert self.media_item.select_book_combo_box.currentData.called is False
def test_on_from_verse_equal(self):
"""
@ -1107,8 +1107,8 @@ class TestMediaItem(TestCase, TestMixin):
# THEN: The combo_box should be cleared, and new items added
mocked_combo_box.clear.assert_called_once_with()
self.assertEqual(mocked_combo_box.addItem.call_args_list,
[call('10', 10), call('11', 11), call('12', 12), call('13', 13)])
assert mocked_combo_box.addItem.call_args_list == \
[call('10', 10), call('11', 11), call('12', 12), call('13', 13)]
def test_adjust_combo_box_restore_found(self):
"""
@ -1123,8 +1123,8 @@ class TestMediaItem(TestCase, TestMixin):
# THEN: The combo_box should be cleared, and new items added. Finally the previously selected item should be
# reselected
mocked_combo_box.clear.assert_called_once_with()
self.assertEqual(mocked_combo_box.addItem.call_args_list,
[call('10', 10), call('11', 11), call('12', 12), call('13', 13)])
assert mocked_combo_box.addItem.call_args_list == \
[call('10', 10), call('11', 11), call('12', 12), call('13', 13)]
mocked_combo_box.setCurrentIndex.assert_called_once_with(2)
def test_adjust_combo_box_restore_not_found(self):
@ -1140,8 +1140,8 @@ class TestMediaItem(TestCase, TestMixin):
# THEN: The combo_box should be cleared, and new items added. Finally the first item should be selected
mocked_combo_box.clear.assert_called_once_with()
self.assertEqual(mocked_combo_box.addItem.call_args_list,
[call('10', 10), call('11', 11), call('12', 12), call('13', 13)])
assert mocked_combo_box.addItem.call_args_list == \
[call('10', 10), call('11', 11), call('12', 12), call('13', 13)]
mocked_combo_box.setCurrentIndex.assert_called_once_with(0)
def test_on_search_button_no_bible(self):
@ -1154,7 +1154,7 @@ class TestMediaItem(TestCase, TestMixin):
self.media_item.on_search_button_clicked()
# THEN: The user should be informed that there are no bibles selected
self.assertEqual(self.mocked_main_window.information_message.call_count, 1)
assert self.mocked_main_window.information_message.call_count == 1
def test_on_search_button_search_tab(self):
"""
@ -1207,7 +1207,7 @@ class TestMediaItem(TestCase, TestMixin):
self.media_item.select_search()
# THEN: reference_search should only be called once
self.assertEqual(self.mocked_plugin.manager.get_verses.call_count, 1)
assert self.mocked_plugin.manager.get_verses.call_count == 1
mocked_display_results.assert_called_once_with()
def test_select_search_dual_bibles(self):
@ -1228,7 +1228,7 @@ class TestMediaItem(TestCase, TestMixin):
self.media_item.select_search()
# THEN: reference_search should be called twice
self.assertEqual(self.mocked_plugin.manager.get_verses.call_count, 2)
assert self.mocked_plugin.manager.get_verses.call_count == 2
mocked_display_results.assert_called_once_with()
def test_text_reference_search_single_bible(self):
@ -1244,7 +1244,7 @@ class TestMediaItem(TestCase, TestMixin):
self.media_item.text_reference_search('Search Text')
# THEN: reference_search should only be called once
self.assertEqual(self.mocked_plugin.manager.get_verses.call_count, 1)
assert self.mocked_plugin.manager.get_verses.call_count == 1
mocked_display_results.assert_called_once_with()
def text_reference_search(self, search_text, search_while_type=False):
@ -1272,7 +1272,7 @@ class TestMediaItem(TestCase, TestMixin):
self.media_item.text_reference_search('Search Text')
# THEN: reference_search should only be called once
self.assertEqual(self.mocked_plugin.manager.get_verses.call_count, 1)
assert self.mocked_plugin.manager.get_verses.call_count == 1
mocked_display_results.assert_called_once_with()
def test_text_reference_search_dual_bible(self):
@ -1288,7 +1288,7 @@ class TestMediaItem(TestCase, TestMixin):
self.media_item.text_reference_search('Search Text')
# THEN: reference_search should be called twice
self.assertEqual(self.mocked_plugin.manager.get_verses.call_count, 2)
assert self.mocked_plugin.manager.get_verses.call_count == 2
mocked_display_results.assert_called_once_with()
def test_on_text_search_single_bible(self):
@ -1305,7 +1305,7 @@ class TestMediaItem(TestCase, TestMixin):
self.media_item.on_text_search('Search Text')
# THEN: The search results should be the same as those returned by plugin.manager.verse_search
self.assertEqual(self.media_item.search_results, ['results', 'list'])
assert self.media_item.search_results == ['results', 'list']
mocked_display_results.assert_called_once_with()
def test_on_text_search_no_results(self):
@ -1322,7 +1322,7 @@ class TestMediaItem(TestCase, TestMixin):
self.media_item.on_text_search('Search Text')
# THEN: The search results should be an empty list
self.assertEqual(self.media_item.search_results, [])
assert self.media_item.search_results == []
mocked_display_results.assert_called_once_with()
def test_on_text_search_all_results_in_both_books(self):
@ -1345,10 +1345,10 @@ class TestMediaItem(TestCase, TestMixin):
self.media_item.on_text_search('Search Text')
# THEN: The search results for both bibles should be returned
self.assertEqual(self.media_item.search_results, [mocked_verse_1, mocked_verse_2])
self.assertEqual(self.media_item.second_search_results, [mocked_verse_1a, mocked_verse_2a])
self.assertFalse(self.mocked_log.debug.called)
self.assertFalse(self.mocked_main_window.information_message.called)
assert self.media_item.search_results == [mocked_verse_1, mocked_verse_2]
assert self.media_item.second_search_results == [mocked_verse_1a, mocked_verse_2a]
assert self.mocked_log.debug.called is False
assert self.mocked_main_window.information_message.called is False
mocked_display_results.assert_called_once_with()
def test_on_text_search_not_all_results_in_both_books(self):
@ -1372,10 +1372,10 @@ class TestMediaItem(TestCase, TestMixin):
# THEN: The search results included in both bibles should be returned and the user should be notified of
# the missing verses
self.assertEqual(self.media_item.search_results, [mocked_verse_1])
self.assertEqual(self.media_item.second_search_results, [mocked_verse_1a])
self.assertEqual(self.mocked_log.debug.call_count, 2)
self.assertTrue(self.mocked_main_window.information_message.called)
assert self.media_item.search_results == [mocked_verse_1]
assert self.media_item.second_search_results == [mocked_verse_1a]
assert self.mocked_log.debug.call_count == 2
assertTrue(self.mocked_main_window.information_message.called)
mocked_display_results.assert_called_once_with()
def test_on_search_edit_text_changed_search_while_typing_disabled(self):
@ -1391,7 +1391,7 @@ class TestMediaItem(TestCase, TestMixin):
self.media_item.on_search_edit_text_changed()
# THEN: The method should not have checked if the timer is active
self.assertFalse(self.media_item.search_timer.isActive.called)
assertFalse(self.media_item.search_timer.isActive.called)
def test_on_search_edit_text_changed_search_while_typing_enabled(self):
"""
@ -1422,7 +1422,7 @@ class TestMediaItem(TestCase, TestMixin):
self.media_item.on_search_timer_timeout()
# THEN: The search_status should be set to SearchAsYouType and text_search should have been called
self.assertEqual(self.media_item.search_status, SearchStatus.SearchAsYouType)
assert self.media_item.search_status == SearchStatus.SearchAsYouType
mocked_text_search.assert_called_once_with()
def test_display_results_no_results(self):
@ -1441,7 +1441,7 @@ class TestMediaItem(TestCase, TestMixin):
self.media_item.display_results()
# THEN: No items should be added to the list
self.assertFalse(self.media_item.list_view.addItem.called)
assertFalse(self.media_item.list_view.addItem.called)
def test_display_results_results(self):
"""

View File

@ -71,7 +71,7 @@ class MediaItemTest(TestCase, TestMixin):
# WHEN: Retrieving the test file
result = self.media_item.search('test.mp4', False)
# THEN: a file should be found
self.assertEqual(result, [['test.mp4', 'test.mp4']], 'The result file contain the file name')
assert result == [['test.mp4', 'test.mp4']], 'The result file contain the file name'
def test_search_not_found(self):
"""
@ -82,4 +82,4 @@ class MediaItemTest(TestCase, TestMixin):
# WHEN: Retrieving the test file
result = self.media_item.search('test.mpx', False)
# THEN: a file should be found
self.assertEqual(result, [], 'The result file should be empty')
assert result == [], 'The result file should be empty'

View File

@ -69,8 +69,7 @@ class TestImpressController(TestCase, TestMixin):
controller = ImpressController(plugin=self.mock_plugin)
# THEN: The name of the presentation controller should be correct
self.assertEqual('Impress', controller.name,
'The name of the presentation controller should be correct')
assert 'Impress' == controller.name, 'The name of the presentation controller should be correct'
@patch('openlp.plugins.presentations.lib.impresscontroller.log')
def test_check_available(self, mocked_log):
@ -179,22 +178,21 @@ class TestImpressDocument(TestCase):
result = self.doc._ImpressDocument__get_text_from_page(0, TextType.Notes)
# THEN: the result should be an empty string
self.assertEqual(result, '', 'Result should be an empty string')
assert result == '', 'Result should be an empty string'
# WHEN: regardless of the type of text, index 0x00 is out of bounds
result = self.doc._ImpressDocument__get_text_from_page(0, TextType.Title)
# THEN: result should be an empty string
self.assertEqual(result, '', 'Result should be an empty string')
assert result == '', 'Result should be an empty string'
# WHEN: when called with 2, it should also be out of bounds
result = self.doc._ImpressDocument__get_text_from_page(2, TextType.SlideText)
# THEN: result should be an empty string ... and, getByIndex should
# have never been called
self.assertEqual(result, '', 'Result should be an empty string')
self.assertEqual(self.doc.document.getDrawPages().getByIndex.call_count, 0,
'There should be no call to getByIndex')
assert result == '', 'Result should be an empty string'
assert self.doc.document.getDrawPages().getByIndex.call_count == 0, 'There should be no call to getByIndex'
def test_get_text_from_page_wrong_type(self):
"""
@ -208,9 +206,8 @@ class TestImpressDocument(TestCase):
result = self.doc._ImpressDocument__get_text_from_page(1, 3)
# THEN: result should be an empty string
self.assertEqual(result, '', 'Result should be and empty string')
self.assertEqual(self.doc.document.getDrawPages().getByIndex.call_count, 0,
'There should be no call to getByIndex')
assert result == '', 'Result should be and empty string'
assert self.doc.document.getDrawPages().getByIndex.call_count == 0, 'There should be no call to getByIndex'
def test_get_text_from_page_valid_params(self):
"""
@ -224,19 +221,19 @@ class TestImpressDocument(TestCase):
result = self.doc._ImpressDocument__get_text_from_page(1, TextType.Notes)
# THEN: result should be 'Note\nNote\n'
self.assertEqual(result, 'Note\nNote\n', 'Result should be \'Note\\n\' times the count of notes in the page')
assert result == 'Note\nNote\n', 'Result should be \'Note\\n\' times the count of notes in the page'
# WHEN: get the Title
result = self.doc._ImpressDocument__get_text_from_page(1, TextType.Title)
# THEN: result should be 'Title\n'
self.assertEqual(result, 'Title\n', 'Result should be exactly \'Title\\n\'')
assert result == 'Title\n', 'Result should be exactly \'Title\\n\''
# WHEN: get all text
result = self.doc._ImpressDocument__get_text_from_page(1, TextType.SlideText)
# THEN: result should be 'Title\nString\nString\n'
self.assertEqual(result, 'Title\nString\nString\n', 'Result should be exactly \'Title\\nString\\nString\\n\'')
assert result == 'Title\nString\nString\n', 'Result should be exactly \'Title\\nString\\nString\\n\''
def _mock_a_LibreOffice_document(self, page_count, note_count, text_count):
"""

View File

@ -81,11 +81,11 @@ class TestMediaItem(TestCase, TestMixin):
self.media_item.build_file_mask_string()
# THEN: The file mask should be generated correctly
self.assertIn('*.odp', self.media_item.on_new_file_masks, 'The file mask should contain the odp extension')
self.assertIn('*.ppt', self.media_item.on_new_file_masks, 'The file mask should contain the ppt extension')
self.assertIn('*.pdf', self.media_item.on_new_file_masks, 'The file mask should contain the pdf extension')
self.assertIn('*.xps', self.media_item.on_new_file_masks, 'The file mask should contain the xps extension')
self.assertIn('*.oxps', self.media_item.on_new_file_masks, 'The file mask should contain the oxps extension')
assertIn('*.odp', self.media_item.on_new_file_masks, 'The file mask should contain the odp extension')
assertIn('*.ppt', self.media_item.on_new_file_masks, 'The file mask should contain the ppt extension')
assertIn('*.pdf', self.media_item.on_new_file_masks, 'The file mask should contain the pdf extension')
assertIn('*.xps', self.media_item.on_new_file_masks, 'The file mask should contain the xps extension')
assertIn('*.oxps', self.media_item.on_new_file_masks, 'The file mask should contain the oxps extension')
def test_clean_up_thumbnails(self):
"""

View File

@ -148,4 +148,4 @@ class TestController(TestCase, TestMixin):
controller.add_handler(mocked_doc_controller, MagicMock(), True, 0)
# THEN: slidenumber should be 0
self.assertEqual(controller.doc.slidenumber, 0, 'doc.slidenumber should be 0')
assert controller.doc.slidenumber == 0, 'doc.slidenumber should be 0'

View File

@ -92,7 +92,7 @@ class TestPdfController(TestCase, TestMixin):
controller = PdfController(plugin=self.mock_plugin)
# THEN: The name of the presentation controller should be correct
self.assertEqual('Pdf', controller.name, 'The name of the presentation controller should be correct')
assert'Pdf' == controller.name, 'The name of the presentation controller should be correct'
def test_load_pdf(self):
"""
@ -111,8 +111,8 @@ class TestPdfController(TestCase, TestMixin):
loaded = document.load_presentation()
# THEN: The load should succeed and we should be able to get a pagecount
self.assertTrue(loaded, 'The loading of the PDF should succeed.')
self.assertEqual(3, document.get_slide_count(), 'The pagecount of the PDF should be 3.')
assert loaded is True, 'The loading of the PDF should succeed.'
assert 3 == document.get_slide_count(), 'The pagecount of the PDF should be 3.'
def test_load_pdf_pictures(self):
"""
@ -135,11 +135,11 @@ class TestPdfController(TestCase, TestMixin):
image = QtGui.QImage(os.path.join(str(self.temp_folder_path), 'pdf_test1.pdf', 'mainslide001.png'))
# Based on the converter used the resolution will differ a bit
if controller.gsbin:
self.assertEqual(760, image.height(), 'The height should be 760')
self.assertEqual(537, image.width(), 'The width should be 537')
assert 760 == image.height(), 'The height should be 760'
assert 537 == image.width(), 'The width should be 537'
else:
self.assertEqual(768, image.height(), 'The height should be 768')
self.assertEqual(543, image.width(), 'The width should be 543')
assert 768 == image.height(), 'The height should be 768'
assert 543 == image.width(), 'The width should be 543'
@patch('openlp.plugins.presentations.lib.pdfcontroller.check_binary_exists')
def test_process_check_binary_mudraw(self, mocked_check_binary_exists):
@ -157,7 +157,7 @@ class TestPdfController(TestCase, TestMixin):
ret = PdfController.process_check_binary('test')
# THEN: mudraw should be detected
self.assertEqual('mudraw', ret, 'mudraw should have been detected')
assert 'mudraw' == ret, 'mudraw should have been detected'
@patch('openlp.plugins.presentations.lib.pdfcontroller.check_binary_exists')
def test_process_check_binary_new_motool(self, mocked_check_binary_exists):
@ -177,7 +177,7 @@ class TestPdfController(TestCase, TestMixin):
ret = PdfController.process_check_binary('test')
# THEN: mutool should be detected
self.assertEqual('mutool', ret, 'mutool should have been detected')
assert 'mutool' == ret, 'mutool should have been detected'
@patch('openlp.plugins.presentations.lib.pdfcontroller.check_binary_exists')
def test_process_check_binary_old_motool(self, mocked_check_binary_exists):
@ -194,7 +194,7 @@ class TestPdfController(TestCase, TestMixin):
ret = PdfController.process_check_binary('test')
# THEN: mutool should be detected
self.assertIsNone(ret, 'old mutool should not be accepted!')
assert ret is None, 'old mutool should not be accepted!'
@patch('openlp.plugins.presentations.lib.pdfcontroller.check_binary_exists')
def test_process_check_binary_gs(self, mocked_check_binary_exists):
@ -210,4 +210,4 @@ class TestPdfController(TestCase, TestMixin):
ret = PdfController.process_check_binary('test')
# THEN: mutool should be detected
self.assertEqual('gs', ret, 'mutool should have been detected')
assert 'gs' == ret, 'mutool should have been detected'

View File

@ -77,8 +77,7 @@ class TestPowerpointController(TestCase, TestMixin):
controller = PowerpointController(plugin=self.mock_plugin)
# THEN: The name of the presentation controller should be correct
self.assertEqual('Powerpoint', controller.name,
'The name of the presentation controller should be correct')
assert 'Powerpoint' == controller.name, 'The name of the presentation controller should be correct'
class TestPowerpointDocument(TestCase, TestMixin):
@ -157,7 +156,7 @@ class TestPowerpointDocument(TestCase, TestMixin):
result = doc.is_loaded()
# THEN: result should be true
self.assertEqual(result, True, 'The result should be True')
assert result == True, 'The result should be True'
else:
self.skipTest('Powerpoint not available, skipping test.')
@ -217,7 +216,7 @@ class TestPowerpointDocument(TestCase, TestMixin):
result = _get_text_from_shapes(shapes)
# THEN: it should return the text
self.assertEqual(result, 'slideText\nslideText\n', 'result should match \'slideText\nslideText\n\'')
assert result == 'slideText\nslideText\n', 'result should match \'slideText\nslideText\n\''
def test_get_text_from_shapes_with_no_shapes(self):
"""
@ -230,7 +229,7 @@ class TestPowerpointDocument(TestCase, TestMixin):
result = _get_text_from_shapes(shapes)
# THEN: it should not fail but return empty string
self.assertEqual(result, '', 'result should be empty')
assert result == '', 'result should be empty'
def test_goto_slide(self):
"""
@ -250,7 +249,7 @@ class TestPowerpointDocument(TestCase, TestMixin):
doc.goto_slide(1)
# THEN: next_step() should be call to try to advance to the next effect.
self.assertTrue(doc.next_step.called, 'next_step() should have been called!')
assertTrue(doc.next_step.called, 'next_step() should have been called!')
def test_blank_screen(self):
"""
@ -268,9 +267,9 @@ class TestPowerpointDocument(TestCase, TestMixin):
doc.blank_screen()
# THEN: The view state, doc.blank_slide and doc.blank_click should have new values
self.assertEquals(doc.presentation.SlideShowWindow.View.State, 3, 'The View State should be 3')
self.assertEquals(doc.blank_slide, 2, 'doc.blank_slide should be 2 because of the PowerPoint version')
self.assertEquals(doc.blank_click, 3, 'doc.blank_click should be 3 because of the PowerPoint version')
assert doc.presentation.SlideShowWindow.View.State == 3, 'The View State should be 3'
assert doc.blank_slide == 2, 'doc.blank_slide should be 2 because of the PowerPoint version'
assert doc.blank_click == 3, 'doc.blank_click should be 3 because of the PowerPoint version'
def test_unblank_screen(self):
"""
@ -295,10 +294,10 @@ class TestPowerpointDocument(TestCase, TestMixin):
doc.unblank_screen()
# THEN: The view state have new value, and several function should have been called
self.assertEquals(doc.presentation.SlideShowWindow.View.State, 1, 'The View State should be 1')
self.assertEquals(doc.presentation.SlideShowWindow.Activate.called, True,
'SlideShowWindow.Activate should have been called')
self.assertEquals(doc.presentation.SlideShowWindow.View.GotoSlide.called, True,
'View.GotoSlide should have been called because of the PowerPoint version')
self.assertEquals(doc.presentation.SlideShowWindow.View.GotoClick.called, True,
'View.GotoClick should have been called because of the PowerPoint version')
assert doc.presentation.SlideShowWindow.View.State == 1, 'The View State should be 1'
assert doc.presentation.SlideShowWindow.Activate.called is True, \
'SlideShowWindow.Activate should have been called'
assert doc.presentation.SlideShowWindow.View.GotoSlide.called is True, \
'View.GotoSlide should have been called because of the PowerPoint version'
assert doc.presentation.SlideShowWindow.View.GotoClick.called is True, \
'View.GotoClick should have been called because of the PowerPoint version'

View File

@ -67,8 +67,7 @@ class TestPptviewController(TestCase, TestMixin):
controller = PptviewController(plugin=self.mock_plugin)
# THEN: The name of the presentation controller should be correct
self.assertEqual('Powerpoint Viewer', controller.name,
'The name of the presentation controller should be correct')
assert'Powerpoint Viewer' == controller.name, 'The name of the presentation controller should be correct'
def test_check_available(self):
"""
@ -86,9 +85,9 @@ class TestPptviewController(TestCase, TestMixin):
# THEN: On windows it should return True, on other platforms False
if is_win():
self.assertTrue(available, 'check_available should return True on windows.')
assert available is True, 'check_available should return True on windows.'
else:
self.assertFalse(available, 'check_available should return False when not on windows.')
assert available is False, 'check_available should return False when not on windows.'
class TestPptviewDocument(TestCase):
@ -205,7 +204,7 @@ class TestPptviewDocument(TestCase):
# THEN: File existens should have been checked, and not have been opened.
doc.save_titles_and_notes.assert_called_once_with(None, None)
mocked_path_exists.assert_called_with()
self.assertEqual(mocked_open.call_count, 0, 'There should be no calls to open a file.')
assert mocked_open.call_count == 0, 'There should be no calls to open a file.'
def test_create_titles_and_notes_invalid_file(self):
"""
@ -225,4 +224,4 @@ class TestPptviewDocument(TestCase):
# THEN:
doc.save_titles_and_notes.assert_called_once_with(None, None)
self.assertEqual(mocked_is_zf.call_count, 1, 'is_zipfile should have been called once')
assert mocked_is_zf.call_count == 1, 'is_zipfile should have been called once'

View File

@ -76,7 +76,7 @@ class TestPresentationController(TestCase):
self.document.save_titles_and_notes(titles, notes)
# THEN: the last call to open should have been for slideNotes2.txt
self.assertEqual(mocked_write_text.call_count, 3, 'There should be exactly three files written')
assert mocked_write_text.call_count == 3, 'There should be exactly three files written'
mocked_write_text.assert_has_calls([call('uno\ndos'), call('one'), call('two')])
def test_save_titles_and_notes_with_None(self):
@ -93,7 +93,7 @@ class TestPresentationController(TestCase):
self.document.save_titles_and_notes(titles, notes)
# THEN: No file should have been created
self.assertEqual(mocked_open.call_count, 0, 'No file should be created')
assert mocked_open.call_count == 0, 'No file should be created'
def test_get_titles_and_notes(self):
"""
@ -112,11 +112,11 @@ class TestPresentationController(TestCase):
result_titles, result_notes = self.document.get_titles_and_notes()
# THEN: it should return two items for the titles and two empty strings for the notes
self.assertIs(type(result_titles), list, 'result_titles should be of type list')
self.assertEqual(len(result_titles), 2, 'There should be two items in the titles')
self.assertIs(type(result_notes), list, 'result_notes should be of type list')
self.assertEqual(len(result_notes), 2, 'There should be two items in the notes')
self.assertEqual(mocked_read_text.call_count, 3, 'Three files should be read')
assert type(result_titles) is list, 'result_titles should be of type list'
assert len(result_titles) == 2, 'There should be two items in the titles'
assert type(result_notes) is list, 'result_notes should be of type list'
assert len(result_notes) == 2, 'There should be two items in the notes'
assert mocked_read_text.call_count == 3, 'Three files should be read'
def test_get_titles_and_notes_with_file_not_found(self):
"""
@ -151,7 +151,7 @@ class TestPresentationController(TestCase):
result_titles, result_notes = self.document.get_titles_and_notes()
# THEN: it should return two empty lists
self.assertIs(type(result_titles), list, 'result_titles should be a list')
assertIs(type(result_titles), list, 'result_titles should be a list')
class TestPresentationDocument(TestCase):
@ -226,4 +226,4 @@ class TestPresentationDocument(TestCase):
result = instance.load_presentation()
# THEN: load_presentation should return false
self.assertFalse(result, "PresentationDocument.load_presentation should return false.")
assertFalse(result, "PresentationDocument.load_presentation should return false.")

View File

@ -106,9 +106,9 @@ class TestOpenSongImport(TestCase):
importer.import_source = source
# THEN: do_import should return none and the progress bar maximum should not be set.
self.assertIsNone(importer.do_import(), 'do_import should return None when import_source is not a list')
self.assertEqual(mocked_import_wizard.progress_bar.setMaximum.called, False,
'setMaximum on import_wizard.progress_bar should not have been called')
assert importer.do_import() is None, 'do_import should return None when import_source is not a list'
assert mocked_import_wizard.progress_bar.setMaximum.called is False, \
'setMaximum on import_wizard.progress_bar should not have been called'
def test_valid_import_source(self):
"""
@ -127,6 +127,6 @@ class TestOpenSongImport(TestCase):
# THEN: do_import should return none and the progress bar setMaximum should be called with the length of
# import_source.
self.assertIsNone(importer.do_import(), 'do_import should return None when import_source is a list '
'and stop_import_flag is True')
assert importer.do_import() is None, \
'do_import should return None when import_source is a list and stop_import_flag is True'
mocked_import_wizard.progress_bar.setMaximum.assert_called_with(len(importer.import_source))

View File

@ -89,7 +89,7 @@ class TestOpsProSongImport(TestCase):
importer = OPSProImport(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.opspro.SongImport')
def test_detect_chorus(self, mocked_songimport):
@ -108,8 +108,8 @@ class TestOpsProSongImport(TestCase):
# THEN: The imported data should look like expected
result_file = open(os.path.join(TEST_PATH, 'You are so faithful.json'), 'rb')
result_data = json.loads(result_file.read().decode())
self.assertListEqual(importer.verses, _get_item(result_data, 'verses'))
self.assertListEqual(importer.verse_order_list_generated, _get_item(result_data, 'verse_order_list'))
assert importer.verses == _get_item(result_data, 'verses')
assert importer.verse_order_list_generated == _get_item(result_data, 'verse_order_list')
@patch('openlp.plugins.songs.lib.importers.opspro.SongImport')
def test_join_and_split(self, mocked_songimport):
@ -128,8 +128,8 @@ class TestOpsProSongImport(TestCase):
# THEN: The imported data should look like expected
result_file = open(os.path.join(TEST_PATH, 'Amazing Grace.json'), 'rb')
result_data = json.loads(result_file.read().decode())
self.assertListEqual(importer.verses, _get_item(result_data, 'verses'))
self.assertListEqual(importer.verse_order_list_generated, _get_item(result_data, 'verse_order_list'))
assert importer.verses == _get_item(result_data, 'verses')
assert importer.verse_order_list_generated == _get_item(result_data, 'verse_order_list')
@patch('openlp.plugins.songs.lib.importers.opspro.SongImport')
def test_trans_off_tag(self, mocked_songimport):
@ -148,8 +148,8 @@ class TestOpsProSongImport(TestCase):
# THEN: The imported data should look like expected
result_file = open(os.path.join(TEST_PATH, 'Amazing Grace.json'), 'rb')
result_data = json.loads(result_file.read().decode())
self.assertListEqual(importer.verses, _get_item(result_data, 'verses'))
self.assertListEqual(importer.verse_order_list_generated, _get_item(result_data, 'verse_order_list'))
assert importer.verses == _get_item(result_data, 'verses')
assert importer.verse_order_list_generated == _get_item(result_data, 'verse_order_list')
@patch('openlp.plugins.songs.lib.importers.opspro.SongImport')
def test_trans_tag(self, mocked_songimport):
@ -168,5 +168,5 @@ class TestOpsProSongImport(TestCase):
# THEN: The imported data should look like expected
result_file = open(os.path.join(TEST_PATH, 'Amazing Grace3.json'), 'rb')
result_data = json.loads(result_file.read().decode())
self.assertListEqual(importer.verses, _get_item(result_data, 'verses'))
self.assertListEqual(importer.verse_order_list_generated, _get_item(result_data, 'verse_order_list'))
assert importer.verses == _get_item(result_data, 'verses')
assert importer.verse_order_list_generated == _get_item(result_data, 'verse_order_list')

View File

@ -57,10 +57,10 @@ class TestSongSelectImport(TestCase, TestMixin):
importer = SongSelectImport(None)
# THEN: The object should have the correct properties
self.assertIsNone(importer.db_manager, 'The db_manager should be None')
self.assertIsNotNone(importer.html_parser, 'There should be a valid html_parser object')
self.assertIsNotNone(importer.opener, 'There should be a valid opener object')
self.assertEqual(1, mocked_build_opener.call_count, 'The build_opener method should have been called once')
assert importer.db_manager is None, 'The db_manager should be None'
assert importer.html_parser is not None, 'There should be a valid html_parser object'
assert importer.opener is not None, 'There should be a valid opener object'
assert 1 == mocked_build_opener.call_count, 'The build_opener method should have been called once'
@patch('openlp.plugins.songs.lib.songselect.build_opener')
@patch('openlp.plugins.songs.lib.songselect.BeautifulSoup')
@ -83,11 +83,11 @@ class TestSongSelectImport(TestCase, TestMixin):
result = importer.login('username', 'password', mock_callback)
# THEN: callback was called 3 times, open was called twice, find was called twice, and False was returned
self.assertEqual(3, mock_callback.call_count, 'callback should have been called 3 times')
self.assertEqual(2, mocked_login_page.find.call_count, 'find should have been called twice')
self.assertEqual(1, mocked_posted_page.find.call_count, 'find should have been called once')
self.assertEqual(2, mocked_opener.open.call_count, 'opener should have been called twice')
self.assertFalse(result, 'The login method should have returned False')
assert 3 == mock_callback.call_count, 'callback should have been called 3 times'
assert 2 == mocked_login_page.find.call_count, 'find should have been called twice'
assert 1 == mocked_posted_page.find.call_count, 'find should have been called once'
assert 2 == mocked_opener.open.call_count, 'opener should have been called twice'
assert result is False, 'The login method should have returned False'
@patch('openlp.plugins.songs.lib.songselect.build_opener')
def test_login_except(self, mocked_build_opener):
@ -103,8 +103,8 @@ class TestSongSelectImport(TestCase, TestMixin):
result = importer.login('username', 'password', mock_callback)
# THEN: callback was called 1 time and False was returned
self.assertEqual(1, mock_callback.call_count, 'callback should have been called 1 times')
self.assertFalse(result, 'The login method should have returned False')
assert 1 == mock_callback.call_count, 'callback should have been called 1 times'
assert result is False, 'The login method should have returned False'
@patch('openlp.plugins.songs.lib.songselect.build_opener')
@patch('openlp.plugins.songs.lib.songselect.BeautifulSoup')
@ -127,11 +127,11 @@ class TestSongSelectImport(TestCase, TestMixin):
result = importer.login('username', 'password', mock_callback)
# THEN: callback was called 3 times, open was called twice, find was called twice, and True was returned
self.assertEqual(3, mock_callback.call_count, 'callback should have been called 3 times')
self.assertEqual(2, mocked_login_page.find.call_count, 'find should have been called twice on the login page')
self.assertEqual(1, mocked_posted_page.find.call_count, 'find should have been called once on the posted page')
self.assertEqual(2, mocked_opener.open.call_count, 'opener should have been called twice')
self.assertTrue(result, 'The login method should have returned True')
assert 3 == mock_callback.call_count, 'callback should have been called 3 times'
assert 2 == mocked_login_page.find.call_count, 'find should have been called twice on the login page'
assert 1 == mocked_posted_page.find.call_count, 'find should have been called once on the posted page'
assert 2 == mocked_opener.open.call_count, 'opener should have been called twice'
assert result is True, 'The login method should have returned True'
@patch('openlp.plugins.songs.lib.songselect.build_opener')
@patch('openlp.plugins.songs.lib.songselect.BeautifulSoup')
@ -156,11 +156,11 @@ class TestSongSelectImport(TestCase, TestMixin):
result = importer.login('username', 'password', mock_callback)
# THEN: callback was called 3 times, open was called twice, find was called twice, and True was returned
self.assertEqual(3, mock_callback.call_count, 'callback should have been called 3 times')
self.assertEqual(2, mocked_login_page.find.call_count, 'find should have been called twice on the login page')
self.assertEqual(1, mocked_posted_page.find.call_count, 'find should have been called once on the posted page')
self.assertEqual('https://profile.ccli.com/do/login', mocked_opener.open.call_args_list[1][0][0])
self.assertTrue(result, 'The login method should have returned True')
assert 3 == mock_callback.call_count, 'callback should have been called 3 times'
assert 2 == mocked_login_page.find.call_count, 'find should have been called twice on the login page'
assert 1 == mocked_posted_page.find.call_count, 'find should have been called once on the posted page'
assert 'https://profile.ccli.com/do/login', mocked_opener.open.call_args_list[1][0][0]
assert result is True, 'The login method should have returned True'
@patch('openlp.plugins.songs.lib.songselect.build_opener')
def test_logout(self, mocked_build_opener):
@ -176,7 +176,7 @@ class TestSongSelectImport(TestCase, TestMixin):
importer.logout()
# THEN: The opener is called once with the logout url
self.assertEqual(1, mocked_opener.open.call_count, 'opener should have been called once')
assert 1 == mocked_opener.open.call_count, 'opener should have been called once'
mocked_opener.open.assert_called_with(LOGOUT_URL)
@patch('openlp.plugins.songs.lib.songselect.build_opener')
@ -198,11 +198,11 @@ class TestSongSelectImport(TestCase, TestMixin):
results = importer.search('text', 1000, mock_callback)
# THEN: callback was never called, open was called once, find_all was called once, an empty list returned
self.assertEqual(0, mock_callback.call_count, 'callback should not have been called')
self.assertEqual(1, mocked_opener.open.call_count, 'open should have been called once')
self.assertEqual(1, mocked_results_page.find_all.call_count, 'find_all should have been called once')
assert 0 == mock_callback.call_count, 'callback should not have been called'
assert 1 == mocked_opener.open.call_count, 'open should have been called once'
assert 1 == mocked_results_page.find_all.call_count, 'find_all should have been called once'
mocked_results_page.find_all.assert_called_with('div', 'song-result')
self.assertEqual([], results, 'The search method should have returned an empty list')
assert [] == results, 'The search method should have returned an empty list'
@patch('openlp.plugins.songs.lib.songselect.build_opener')
@patch('openlp.plugins.songs.lib.songselect.BeautifulSoup')
@ -238,15 +238,15 @@ class TestSongSelectImport(TestCase, TestMixin):
results = importer.search('text', 1000, mock_callback)
# THEN: callback was never called, open was called once, find_all was called once, an empty list returned
self.assertEqual(2, mock_callback.call_count, 'callback should have been called twice')
self.assertEqual(2, mocked_opener.open.call_count, 'open should have been called twice')
self.assertEqual(2, mocked_results_page.find_all.call_count, 'find_all should have been called twice')
assert 2 == mock_callback.call_count, 'callback should have been called twice'
assert 2 == mocked_opener.open.call_count, 'open should have been called twice'
assert 2 == mocked_results_page.find_all.call_count, 'find_all should have been called twice'
mocked_results_page.find_all.assert_called_with('div', 'song-result')
expected_list = [
{'title': 'Title 1', 'authors': ['James', 'John'], 'link': BASE_URL + '/url1'},
{'title': 'Title 2', 'authors': ['Philip'], 'link': BASE_URL + '/url2'}
]
self.assertListEqual(expected_list, results, 'The search method should have returned two songs')
assert expected_list == results, 'The search method should have returned two songs'
@patch('openlp.plugins.songs.lib.songselect.build_opener')
@patch('openlp.plugins.songs.lib.songselect.BeautifulSoup')
@ -289,13 +289,13 @@ class TestSongSelectImport(TestCase, TestMixin):
results = importer.search('text', 2, mock_callback)
# THEN: callback was called twice, open was called twice, find_all was called twice, max results returned
self.assertEqual(2, mock_callback.call_count, 'callback should have been called twice')
self.assertEqual(2, mocked_opener.open.call_count, 'open should have been called twice')
self.assertEqual(2, mocked_results_page.find_all.call_count, 'find_all should have been called twice')
assert 2 == mock_callback.call_count, 'callback should have been called twice'
assert 2 == mocked_opener.open.call_count, 'open should have been called twice'
assert 2 == mocked_results_page.find_all.call_count, 'find_all should have been called twice'
mocked_results_page.find_all.assert_called_with('div', 'song-result')
expected_list = [{'title': 'Title 1', 'authors': ['James', 'John'], 'link': BASE_URL + '/url1'},
{'title': 'Title 2', 'authors': ['Philip'], 'link': BASE_URL + '/url2'}]
self.assertListEqual(expected_list, results, 'The search method should have returned two songs')
assert expected_list == results, 'The search method should have returned two songs'
@patch('openlp.plugins.songs.lib.songselect.build_opener')
@patch('openlp.plugins.songs.lib.songselect.BeautifulSoup')
@ -311,7 +311,7 @@ class TestSongSelectImport(TestCase, TestMixin):
importer.stop()
# THEN: Searching should have stopped
self.assertFalse(importer.run_search, 'Searching should have been stopped')
assertFalse(importer.run_search, 'Searching should have been stopped')
@patch('openlp.plugins.songs.lib.songselect.build_opener')
def test_get_song_page_raises_exception(self, mocked_build_opener):
@ -330,7 +330,7 @@ class TestSongSelectImport(TestCase, TestMixin):
# THEN: The callback should have been called once and None should be returned
mocked_callback.assert_called_with()
self.assertIsNone(result, 'The get_song() method should have returned None')
assertIsNone(result, 'The get_song() method should have returned None')
@patch('openlp.plugins.songs.lib.songselect.build_opener')
@patch('openlp.plugins.songs.lib.songselect.BeautifulSoup')
@ -347,8 +347,8 @@ class TestSongSelectImport(TestCase, TestMixin):
result = importer.get_song({'link': 'link'}, callback=mocked_callback)
# THEN: The callback should have been called twice and None should be returned
self.assertEqual(2, mocked_callback.call_count, 'The callback should have been called twice')
self.assertIsNone(result, 'The get_song() method should have returned None')
assert 2 == mocked_callback.call_count, 'The callback should have been called twice'
assert result is None, 'The get_song() method should have returned None'
@patch('openlp.plugins.songs.lib.songselect.build_opener')
@patch('openlp.plugins.songs.lib.songselect.BeautifulSoup')
@ -384,19 +384,18 @@ class TestSongSelectImport(TestCase, TestMixin):
result = importer.get_song(fake_song, callback=mocked_callback)
# THEN: The callback should have been called three times and the song should be returned
self.assertEqual(3, mocked_callback.call_count, 'The callback should have been called twice')
self.assertIsNotNone(result, 'The get_song() method should have returned a song dictionary')
self.assertEqual(2, mocked_lyrics_page.find.call_count, 'The find() method should have been called twice')
self.assertEqual(2, mocked_find_all.call_count, 'The find_all() method should have been called twice')
self.assertEqual([call('div', 'song-viewer lyrics'), call('div', 'song-viewer lyrics')],
mocked_lyrics_page.find.call_args_list,
'The find() method should have been called with the right arguments')
self.assertEqual([call('p'), call('h3')], mocked_find_all.call_args_list,
'The find_all() method should have been called with the right arguments')
self.assertIn('copyright', result, 'The returned song should have a copyright')
self.assertIn('ccli_number', result, 'The returned song should have a CCLI number')
self.assertIn('verses', result, 'The returned song should have verses')
self.assertEqual(3, len(result['verses']), 'Three verses should have been returned')
assert 3 == mocked_callback.call_count, 'The callback should have been called twice'
assert result is not None, 'The get_song() method should have returned a song dictionary'
assert 2 == mocked_lyrics_page.find.call_count, 'The find() method should have been called twice'
assert 2 == mocked_find_all.call_count, 'The find_all() method should have been called twice'
assert [call('div', 'song-viewer lyrics'), call('div', 'song-viewer lyrics')] == \
mocked_lyrics_page.find.call_args_list, 'The find() method should have been called with the right arguments'
assert [call('p'), call('h3')], mocked_find_all.call_args_list == \
'The find_all() method should have been called with the right arguments'
assert 'copyright' in result, 'The returned song should have a copyright'
assert 'ccli_number' in result, 'The returned song should have a CCLI number'
assert 'verses' in result, 'The returned song should have verses'
assert 3 == len(result['verses']), 'Three verses should have been returned'
@patch('openlp.plugins.songs.lib.songselect.clean_song')
@patch('openlp.plugins.songs.lib.songselect.Topic')
@ -429,12 +428,11 @@ class TestSongSelectImport(TestCase, TestMixin):
# THEN: The return value should be a Song class and the mocked_db_manager should have been called
assert isinstance(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')
assert 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='Public', last_name='Domain',
display_name='Public Domain')
self.assertEqual(1, len(result.authors_songs), 'There should only be one author')
MockedAuthor.populate.assert_called_with(first_name='Public', last_name='Domain', display_name='Public Domain')
assert 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.Author')
@ -465,11 +463,11 @@ class TestSongSelectImport(TestCase, TestMixin):
# THEN: The return value should be a Song class and the mocked_db_manager should have been called
assert isinstance(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')
assert 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)
self.assertEqual(0, MockedAuthor.populate.call_count, 'A new author should not have been instantiated')
self.assertEqual(1, len(result.authors_songs), 'There should only be one author')
assert 0 == MockedAuthor.populate.call_count, 'A new author should not have been instantiated'
assert 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.Author')
@ -500,12 +498,11 @@ class TestSongSelectImport(TestCase, TestMixin):
# THEN: The return value should be a Song class and the mocked_db_manager should have been called
assert isinstance(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')
assert 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')
MockedAuthor.populate.assert_called_with(first_name='Unknown', last_name='', display_name='Unknown')
assert 1 == len(result.authors_songs), 'There should only be one author'
class TestSongSelectForm(TestCase, TestMixin):
@ -534,8 +531,8 @@ class TestSongSelectForm(TestCase, TestMixin):
ssform = SongSelectForm(None, mocked_plugin, mocked_db_manager)
# THEN: The correct properties should have been assigned
self.assertEqual(mocked_plugin, ssform.plugin, 'The correct plugin should have been assigned')
self.assertEqual(mocked_db_manager, ssform.db_manager, 'The correct db_manager should have been assigned')
assertEqual(mocked_plugin, ssform.plugin, 'The correct plugin should have been assigned')
assertEqual(mocked_db_manager, ssform.db_manager, 'The correct db_manager should have been assigned')
@patch('openlp.plugins.songs.forms.songselectform.SongSelectImport')
@patch('openlp.plugins.songs.forms.songselectform.QtWidgets.QMessageBox.critical')
@ -570,9 +567,9 @@ class TestSongSelectForm(TestCase, TestMixin):
expected_login_spacer_calls = [call(False), call(True)]
expected_login_progress_visible_calls = [call(True), call(False)]
expected_login_progress_value_calls = [call(0), call(0)]
self.assertEqual(expected_username_calls, mocked_username_edit.setEnabled.call_args_list,
assertEqual(expected_username_calls, mocked_username_edit.setEnabled.call_args_list,
'The username edit should be disabled then enabled')
self.assertEqual(expected_password_calls, mocked_password_edit.setEnabled.call_args_list,
assertEqual(expected_password_calls, mocked_password_edit.setEnabled.call_args_list,
'The password edit should be disabled then enabled')
self.assertEqual(expected_save_password_calls, mocked_save_password_checkbox.setEnabled.call_args_list,
'The save password checkbox should be disabled then enabled')

View File

@ -62,8 +62,8 @@ class TestSongUsage(TestCase):
# THEN: It should be initialised correctly
MockedManager.assert_called_with('songusage', init_schema, upgrade_mod=upgrade)
self.assertEqual(mocked_manager, song_usage.manager)
self.assertFalse(song_usage.song_usage_active)
assert mocked_manager == song_usage.manager
assert song_usage.song_usage_active is False
@patch('openlp.plugins.songusage.songusageplugin.Manager')
def test_check_pre_conditions(self, MockedManager):