forked from openlp/openlp
Fix First Time Wizard fail on URL error (ex: proxy authorization)
Fix spelling bzr-revno: 2478 Fixes: https://launchpad.net/bugs/1409627
This commit is contained in:
commit
deb8ae8656
@ -182,7 +182,18 @@ class FirstTimeForm(QtGui.QWizard, UiFirstTimeWizard, RegistryProperties):
|
||||
self.config = ConfigParser()
|
||||
user_agent = 'OpenLP/' + Registry().get('application').applicationVersion()
|
||||
self.application.process_events()
|
||||
web_config = get_web_page('%s%s' % (self.web, 'download.cfg'), header=('User-Agent', user_agent))
|
||||
try:
|
||||
web_config = get_web_page('%s%s' % (self.web, 'download.cfg'), header=('User-Agent', user_agent))
|
||||
except (urllib.error.URLError, ConnectionError) as err:
|
||||
msg = QtGui.QMessageBox()
|
||||
title = translate('OpenLP.FirstTimeWizard', 'Network Error')
|
||||
msg.setText('{} {}'.format(title, err.code if hasattr(err, 'code') else ''))
|
||||
msg.setInformativeText(translate('OpenLP.FirstTimeWizard',
|
||||
'There was a network error attempting to'
|
||||
'connect to retrieve initial configuration information'))
|
||||
msg.setStandardButtons(msg.Ok)
|
||||
ans = msg.exec_()
|
||||
web_config = False
|
||||
if web_config:
|
||||
files = web_config.read()
|
||||
try:
|
||||
|
@ -30,6 +30,7 @@
|
||||
Package to test the openlp.core.ui.firsttimeform package.
|
||||
"""
|
||||
import os
|
||||
import urllib
|
||||
from unittest import TestCase
|
||||
|
||||
from openlp.core.common import Registry
|
||||
@ -214,3 +215,24 @@ class TestFirstTimeForm(TestCase, TestMixin):
|
||||
|
||||
# THEN: The First Time Form should not have web access
|
||||
self.assertFalse(first_time_form.web_access, 'There should not be web access with an invalid config file')
|
||||
|
||||
@patch('openlp.core.ui.firsttimeform.get_web_page')
|
||||
@patch('openlp.core.ui.firsttimeform.QtGui.QMessageBox')
|
||||
def network_error_test(self, mocked_message_box, mocked_get_web_page):
|
||||
"""
|
||||
Test we catch a network error in First Time Wizard - bug 1409627
|
||||
"""
|
||||
# GIVEN: Initial setup and mocks
|
||||
first_time_form = FirstTimeForm(None)
|
||||
first_time_form.initialize(MagicMock())
|
||||
mocked_get_web_page.side_effect = urllib.error.HTTPError(url='http//localhost',
|
||||
code=407,
|
||||
msg='Network proxy error',
|
||||
hdrs=None,
|
||||
fp=None)
|
||||
# WHEN: the First Time Wizard calls to get the initial configuration
|
||||
first_time_form._download_index()
|
||||
|
||||
# THEN: the critical_error_message_box should have been called
|
||||
self.assertEquals(mocked_message_box.mock_calls[1][1][0], 'Network Error 407',
|
||||
'first_time_form should have caught Network Error')
|
||||
|
Loading…
Reference in New Issue
Block a user