mirror of https://gitlab.com/openlp/openlp.git
Fix traceback on bible import when no bible available
This commit is contained in:
parent
a58a403d06
commit
0cd960494b
|
@ -30,6 +30,7 @@ from PyQt5 import QtCore, QtWidgets
|
|||
|
||||
from openlp.core.common.i18n import translate
|
||||
from openlp.core.common.registry import Registry
|
||||
from openlp.core.lib.ui import warning_message_box
|
||||
from openlp.plugins.bibles.lib import parse_reference
|
||||
from openlp.plugins.planningcenter.forms.selectplandialog import Ui_SelectPlanDialog
|
||||
from openlp.plugins.planningcenter.lib.customimport import PlanningCenterCustomImport
|
||||
|
@ -68,10 +69,10 @@ class SelectPlanForm(QtWidgets.QDialog, Ui_SelectPlanDialog):
|
|||
# check our credentials and connection to the PlanningCenter server
|
||||
organization = self.planning_center_api.check_credentials()
|
||||
if len(organization) == 0:
|
||||
QtWidgets.QMessageBox.warning(self.parent(), 'Authentication Failed',
|
||||
'Authentiation Failed. '
|
||||
'Check your credentials in OpenLP Settings.',
|
||||
QtWidgets.QMessageBox.Ok)
|
||||
warning_message_box(translate('PlanningCenterPlugin.PlanningCenterForm', 'Authentication Failed'),
|
||||
translate('PlanningCenterPlugin.PlanningCenterForm',
|
||||
'Authentiation Failed. Check your credentials in OpenLP Settings.'),
|
||||
self.parent())
|
||||
return
|
||||
# set the Service Type Dropdown Box from PCO
|
||||
service_types_list = self.planning_center_api.get_service_type_list()
|
||||
|
@ -237,15 +238,21 @@ class SelectPlanForm(QtWidgets.QDialog, Ui_SelectPlanDialog):
|
|||
# if we have no bible in the version_combo_box, but we have
|
||||
# one or more bibles available, use one of those
|
||||
bible = next(iter(bibles))
|
||||
language_selection = bible_media.plugin.manager.get_language_selection(bible)
|
||||
# replace long dashes with normal dashes -- why do these get inserted in PCO?
|
||||
tmp_item_title = re.sub('–', '-', item_title)
|
||||
ref_list = parse_reference(tmp_item_title, bibles[bible], language_selection)
|
||||
if ref_list:
|
||||
bible_media.search_results = bibles[bible].get_verses(ref_list)
|
||||
bible_media.list_view.clear()
|
||||
bible_media.display_results()
|
||||
bible_media.add_to_service()
|
||||
if len(bible) > 0:
|
||||
language_selection = bible_media.plugin.manager.get_language_selection(bible)
|
||||
# replace long dashes with normal dashes -- why do these get inserted in PCO?
|
||||
tmp_item_title = re.sub('–', '-', item_title)
|
||||
ref_list = parse_reference(tmp_item_title, bibles[bible], language_selection)
|
||||
if ref_list:
|
||||
bible_media.search_results = bibles[bible].get_verses(ref_list)
|
||||
bible_media.list_view.clear()
|
||||
bible_media.display_results()
|
||||
bible_media.add_to_service()
|
||||
else:
|
||||
warning_message_box(translate('PlanningCenterPlugin.PlanningCenterForm', 'Import failed'),
|
||||
translate('PlanningCenterPlugin.PlanningCenterForm',
|
||||
'Could not import bible text because no bible is installed.'),
|
||||
self)
|
||||
service_manager.main_window.increment_progress_bar()
|
||||
if update:
|
||||
for old_service_item in old_service_items:
|
||||
|
|
|
@ -206,13 +206,15 @@ def test_import_function_called_when_import_button_clicked(mocked_do_import: Mag
|
|||
|
||||
|
||||
@patch('PyQt5.QtWidgets.QDialog.exec')
|
||||
@patch('openlp.plugins.planningcenter.forms.selectplanform.warning_message_box')
|
||||
@patch('openlp.plugins.planningcenter.lib.songimport.PlanningCenterSongImport.finish')
|
||||
@patch('openlp.plugins.planningcenter.lib.customimport.CustomSlide')
|
||||
@patch('openlp.plugins.planningcenter.forms.selectplanform.parse_reference')
|
||||
@patch('openlp.plugins.planningcenter.forms.selectplanform.date')
|
||||
def test_service_imported_when_import_button_clicked(mocked_date: MagicMock, mocked_parse_reference: MagicMock,
|
||||
MockCustomSlide: MagicMock, mocked_finish: MagicMock,
|
||||
mocked_exec: MagicMock, form: SelectPlanForm):
|
||||
mocked_warning_box: MagicMock, mocked_exec: MagicMock,
|
||||
form: SelectPlanForm):
|
||||
"""
|
||||
Test that a service is imported when the "Import New" button is clicked
|
||||
"""
|
||||
|
@ -222,10 +224,12 @@ def test_service_imported_when_import_button_clicked(mocked_date: MagicMock, moc
|
|||
mocked_date.today.return_value = date(2019, 9, 29)
|
||||
mocked_date.side_effect = lambda *args, **kw: date(*args, **kw)
|
||||
form.exec()
|
||||
mocked_bible_plugin = MagicMock()
|
||||
mocked_bible_plugin.version_combo_box.currentText.return_value = 'mocked_bible'
|
||||
Registry().register('service_manager', MagicMock())
|
||||
Registry().register('plugin_manager', MagicMock())
|
||||
Registry().register('songs', MagicMock())
|
||||
Registry().register('bibles', MagicMock())
|
||||
Registry().register('bibles', mocked_bible_plugin)
|
||||
Registry().register('custom', MagicMock())
|
||||
# WHEN: The Service Type combo is set to index 1 and the Select Plan combo box is set to
|
||||
# index 1 and the "Import New" button is clicked
|
||||
|
@ -236,16 +240,19 @@ def test_service_imported_when_import_button_clicked(mocked_date: MagicMock, moc
|
|||
mocked_finish.assert_called_once()
|
||||
assert MockCustomSlide.call_count == 4, '4 custom slide added via custom_media_item'
|
||||
assert mocked_parse_reference.call_count == 2, '2 bible verses submitted for parsing'
|
||||
assert mocked_warning_box.call_count == 0, 'No warnings triggered'
|
||||
|
||||
|
||||
@patch('PyQt5.QtWidgets.QDialog.exec')
|
||||
@patch('openlp.plugins.planningcenter.forms.selectplanform.warning_message_box')
|
||||
@patch('openlp.plugins.planningcenter.lib.songimport.PlanningCenterSongImport.finish')
|
||||
@patch('openlp.plugins.planningcenter.lib.customimport.CustomSlide')
|
||||
@patch('openlp.plugins.planningcenter.forms.selectplanform.parse_reference')
|
||||
@patch('openlp.plugins.planningcenter.forms.selectplanform.date')
|
||||
def test_service_refreshed_when_refresh_button_clicked(mocked_date: MagicMock, mocked_parse_reference: MagicMock,
|
||||
MockCustomSlide: MagicMock, mocked_finish: MagicMock,
|
||||
mocked_exec: MagicMock, form: SelectPlanForm):
|
||||
mocked_warning_box: MagicMock, mocked_exec: MagicMock,
|
||||
form: SelectPlanForm):
|
||||
"""
|
||||
Test that a service is refreshed when the "Refresh Service" button is clicked
|
||||
"""
|
||||
|
@ -255,10 +262,12 @@ def test_service_refreshed_when_refresh_button_clicked(mocked_date: MagicMock, m
|
|||
mocked_date.today.return_value = date(2019, 9, 29)
|
||||
mocked_date.side_effect = lambda *args, **kw: date(*args, **kw)
|
||||
form.exec()
|
||||
mocked_bible_plugin = MagicMock()
|
||||
mocked_bible_plugin.version_combo_box.currentText.return_value = 'mocked_bible'
|
||||
Registry().register('service_manager', MagicMock())
|
||||
Registry().register('plugin_manager', MagicMock())
|
||||
Registry().register('songs', MagicMock())
|
||||
Registry().register('bibles', MagicMock())
|
||||
Registry().register('bibles', mocked_bible_plugin)
|
||||
Registry().register('custom', MagicMock())
|
||||
# WHEN: The Service Type combo is set to index 1 and the Select Plan combo box is
|
||||
# set to index 1 and the "Update" button is clicked
|
||||
|
@ -269,16 +278,19 @@ def test_service_refreshed_when_refresh_button_clicked(mocked_date: MagicMock, m
|
|||
mocked_finish.assert_called_once()
|
||||
assert MockCustomSlide.call_count == 4, '4 custom slide added via custom_media_item'
|
||||
assert mocked_parse_reference.call_count == 2, '2 bible verses submitted for parsing'
|
||||
assert mocked_warning_box.call_count == 0, 'No warnings triggered'
|
||||
|
||||
|
||||
@patch('PyQt5.QtWidgets.QDialog.exec')
|
||||
@patch('openlp.plugins.planningcenter.forms.selectplanform.warning_message_box')
|
||||
@patch('openlp.plugins.planningcenter.lib.songimport.PlanningCenterSongImport.finish')
|
||||
@patch('openlp.plugins.planningcenter.lib.customimport.CustomSlide')
|
||||
@patch('openlp.plugins.planningcenter.forms.selectplanform.parse_reference')
|
||||
@patch('openlp.plugins.planningcenter.forms.selectplanform.date')
|
||||
def test_other_bible_is_used_when_bible_gui_form_is_blank(mocked_date: MagicMock, mocked_parse_reference: MagicMock,
|
||||
MockCustomSlide: MagicMock, mocked_finish: MagicMock,
|
||||
mocked_exec: MagicMock, form: SelectPlanForm):
|
||||
mocked_warning_box: MagicMock, mocked_exec: MagicMock,
|
||||
form: SelectPlanForm):
|
||||
"""
|
||||
Test that an other bible is used when the GUI has an empty string for current selected bible
|
||||
"""
|
||||
|
@ -287,10 +299,12 @@ def test_other_bible_is_used_when_bible_gui_form_is_blank(mocked_date: MagicMock
|
|||
# need to always return 9/29/2019 for date.today()
|
||||
mocked_date.today.return_value = date(2019, 9, 29)
|
||||
mocked_date.side_effect = lambda *args, **kw: date(*args, **kw)
|
||||
mocked_bible_plugin = MagicMock()
|
||||
mocked_bible_plugin.version_combo_box.currentText.return_value = 'mocked_bible'
|
||||
Registry().register('service_manager', MagicMock())
|
||||
Registry().register('plugin_manager', MagicMock())
|
||||
Registry().register('songs', MagicMock())
|
||||
Registry().register('bibles', MagicMock())
|
||||
Registry().register('bibles', mocked_bible_plugin)
|
||||
Registry().register('custom', MagicMock())
|
||||
form.exec()
|
||||
# WHEN: The Service Type combo is set to index 1 and the Select Plan combo box
|
||||
|
@ -299,6 +313,42 @@ def test_other_bible_is_used_when_bible_gui_form_is_blank(mocked_date: MagicMock
|
|||
QtTest.QTest.mouseClick(form.import_as_new_button, QtCore.Qt.LeftButton)
|
||||
# THEN: There should be 2 bible verse parse attempts
|
||||
assert mocked_parse_reference.call_count == 2, '2 bible verses submitted for parsing'
|
||||
assert mocked_warning_box.call_count == 0, 'No warnings triggered'
|
||||
|
||||
|
||||
@patch('PyQt5.QtWidgets.QDialog.exec')
|
||||
@patch('openlp.plugins.planningcenter.forms.selectplanform.warning_message_box')
|
||||
@patch('openlp.plugins.planningcenter.lib.songimport.PlanningCenterSongImport.finish')
|
||||
@patch('openlp.plugins.planningcenter.lib.customimport.CustomSlide')
|
||||
@patch('openlp.plugins.planningcenter.forms.selectplanform.parse_reference')
|
||||
@patch('openlp.plugins.planningcenter.forms.selectplanform.date')
|
||||
def test_warning_importing_bible_with_no_bible_available(mocked_date: MagicMock, mocked_parse_reference: MagicMock,
|
||||
MockCustomSlide: MagicMock, mocked_finish: MagicMock,
|
||||
mocked_warning_box: MagicMock, mocked_exec: MagicMock,
|
||||
form: SelectPlanForm):
|
||||
"""
|
||||
Test that a warning is shown when trying to import a bible text without having a bible installed
|
||||
"""
|
||||
# GIVEN: An SelectPlanForm instance with airplane mode enabled, resources available,
|
||||
# mocked out "on_new_service_clicked"
|
||||
# need to always return 9/29/2019 for date.today()
|
||||
mocked_date.today.return_value = date(2019, 9, 29)
|
||||
mocked_date.side_effect = lambda *args, **kw: date(*args, **kw)
|
||||
mocked_bible_plugin = MagicMock()
|
||||
mocked_bible_plugin.version_combo_box.currentText.return_value = ''
|
||||
Registry().register('service_manager', MagicMock())
|
||||
Registry().register('plugin_manager', MagicMock())
|
||||
Registry().register('songs', MagicMock())
|
||||
Registry().register('bibles', mocked_bible_plugin)
|
||||
Registry().register('custom', MagicMock())
|
||||
form.exec()
|
||||
# WHEN: The Service Type combo is set to index 1 and the Select Plan combo box
|
||||
# is set to index 1 and the "Import New" button is clicked
|
||||
form.service_type_combo_box.setCurrentIndex(1)
|
||||
QtTest.QTest.mouseClick(form.import_as_new_button, QtCore.Qt.LeftButton)
|
||||
# THEN: There should be 2 bible verse parse attempts
|
||||
assert mocked_parse_reference.call_count == 0, '0 bible verses submitted for parsing'
|
||||
assert mocked_warning_box.call_count == 2, '2 warnings should be triggered'
|
||||
|
||||
|
||||
@pytest.mark.skip('fails to run when executed with all other openlp tests. awaiting pytest fixtures to enable again')
|
||||
|
|
Loading…
Reference in New Issue