def test_invalid_config(self): """ Test if we can handle an config file in invalid format """ # GIVEN: A mocked get_web_page, a First Time Wizard, an expected screen object, and a mocked invalid config file with patch('openlp.core.ui.firsttimeform.get_web_page') as mocked_get_web_page: first_time_form = FirstTimeForm(None) first_time_form.initialize(MagicMock()) mocked_get_web_page.return_value.read.return_value = FAKE_INVALID_CONFIG # WHEN: The First Time Wizard is downloads the config file first_time_form._download_index() # 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')
def test_broken_config(self): """ Test if we can handle an config file with missing data """ # GIVEN: A mocked get_web_page, a First Time Wizard, an expected screen object, and a mocked broken config file with patch('openlp.core.ui.firsttimeform.get_web_page' ) as mocked_get_web_page: first_time_form = FirstTimeForm(None) first_time_form.initialize(MagicMock()) mocked_get_web_page.return_value = FAKE_BROKEN_CONFIG # WHEN: The First Time Wizard is downloads the config file first_time_form._download_index() # THEN: The First Time Form should not have web access assert first_time_form.web_access is False, 'There should not be web access with a broken config file'
def test_network_error(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 = ConnectionError('') mocked_message_box.Ok = 'OK' # 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 mocked_message_box.critical.assert_called_once_with( first_time_form, 'Network Error', 'There was a network error attempting to connect to retrieve ' 'initial configuration information', 'OK')
def test_network_error(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')