Correctly handle an issue where OpenLP is unable to download the remote version (fixes #1142 #951)

This commit is contained in:
Raoul Snyman 2022-08-10 11:57:43 -07:00
parent 1c7ea6c9fa
commit f2e8b6f60b
2 changed files with 35 additions and 1 deletions

View File

@ -405,7 +405,13 @@ class ApiTab(SettingsTab):
app.process_events()
version_info = download_version_info()
app.process_events()
self.available_version = version_info['latest']['version']
if not version_info:
Registry().get('main_window').error_message(
translate('OpenLP.APITab', 'Error fetching version'),
translate('OpenLP.APITab', 'There was a problem fetching the latest version of the remote')
)
else:
self.available_version = version_info['latest']['version']
app.process_events()
app.set_normal_cursor()
app.process_events()

View File

@ -305,6 +305,34 @@ def test_on_check_for_updates_button_clicked(mocked_download_version_info, mocke
assert api_tab.available_version == '0.9.5'
@patch('openlp.core.api.tab.download_version_info')
def test_on_check_for_updates_error(mocked_download_version_info, mocked_qapp, registry, settings, api_tab):
"""Test that an error message is shown when the remote version cannot be downloaded"""
# GIVEN: An API tab and a couple of mocks
mocked_download_version_info.return_value = None
mocked_main_window = MagicMock()
registry.register('main_window', mocked_main_window)
registry.remove('application')
registry.register('application', mocked_qapp)
# WHEN: The Check for Updates button is clicked
with patch.object(api_tab, 'can_enable_install_button') as mocked_can_enable_install_button:
mocked_can_enable_install_button.return_value = False
api_tab.on_check_for_updates_button_clicked()
assert mocked_can_enable_install_button.call_count == 1
# THEN: The correct methods were called
mocked_qapp.set_busy_cursor.assert_called_once()
assert mocked_qapp.process_events.call_count == 4
mocked_qapp.set_normal_cursor.assert_called_once()
mocked_download_version_info.assert_called_once()
mocked_main_window.error_message.assert_called_once_with(
'Error fetching version', 'There was a problem fetching the latest version of the remote'
)
mocked_main_window.information_message.assert_not_called()
assert api_tab.available_version is None
@patch('openlp.core.api.tab.DownloadProgressDialog')
@patch('openlp.core.api.tab.download_and_install')
@patch('openlp.core.api.tab.sleep')