コード例 #1
0
    def test_accept_method(self, mocked_qwizard_accept, *args):
        """
        Test the FirstTimeForm.accept method
        """
        # GIVEN: An instance of FirstTimeForm
        frw = FirstTimeForm(None)
        with patch.object(frw, '_set_plugin_status') as mocked_set_plugin_status, \
                patch.multiple(frw, songs_check_box=DEFAULT, bible_check_box=DEFAULT, presentation_check_box=DEFAULT,
                               image_check_box=DEFAULT, media_check_box=DEFAULT, custom_check_box=DEFAULT,
                               song_usage_check_box=DEFAULT, alert_check_box=DEFAULT) as mocked_check_boxes, \
                patch.object(frw, 'screen_selection_widget') as mocked_screen_selection_widget:

            # WHEN: Calling accept
            frw.accept()

            # THEN: The selected plugins should be enabled, the screen selection saved and the super method called
            mocked_set_plugin_status.assert_has_calls([
                call(mocked_check_boxes['songs_check_box'], 'songs/status'),
                call(mocked_check_boxes['bible_check_box'], 'bibles/status'),
                call(mocked_check_boxes['presentation_check_box'],
                     'presentations/status'),
                call(mocked_check_boxes['image_check_box'], 'images/status'),
                call(mocked_check_boxes['media_check_box'], 'media/status'),
                call(mocked_check_boxes['custom_check_box'], 'custom/status'),
                call(mocked_check_boxes['song_usage_check_box'],
                     'songusage/status'),
                call(mocked_check_boxes['alert_check_box'], 'alerts/status')
            ])
            mocked_screen_selection_widget.save.assert_called_once()
            mocked_qwizard_accept.assert_called_once()
コード例 #2
0
ファイル: test_firsttimeform.py プロジェクト: imkernel/openlp
    def test_on_cancel_button_clicked(self):
        """
        Test that the cancel button click slot shuts down the threads correctly
        """
        # GIVEN: A FRW, some mocked threads and workers (that isn't quite done) and other mocked stuff
        frw = FirstTimeForm(None)
        frw.initialize(MagicMock())
        mocked_worker = MagicMock()
        mocked_thread = MagicMock()
        mocked_thread.isRunning.side_effect = [True, False]
        frw.theme_screenshot_workers.append(mocked_worker)
        frw.theme_screenshot_threads.append(mocked_thread)
        with patch('openlp.core.ui.firsttimeform.time') as mocked_time, \
                patch.object(frw.application, 'set_normal_cursor') as mocked_set_normal_cursor:

            # WHEN: on_cancel_button_clicked() is called
            frw.on_cancel_button_clicked()

            # THEN: The right things should be called in the right order
            self.assertTrue(frw.was_cancelled, 'The was_cancelled property should have been set to True')
            mocked_worker.set_download_canceled.assert_called_with(True)
            mocked_thread.isRunning.assert_called_with()
            self.assertEqual(2, mocked_thread.isRunning.call_count, 'isRunning() should have been called twice')
            mocked_time.sleep.assert_called_with(0.1)
            self.assertEqual(1, mocked_time.sleep.call_count, 'sleep() should have only been called once')
            mocked_set_normal_cursor.assert_called_with()
コード例 #3
0
ファイル: app.py プロジェクト: simhnna/openlp
    def run(self, args):
        """
        Run the OpenLP application.

        :param args: Some Args
        """
        self.is_event_loop_active = False
        # On Windows, the args passed into the constructor are ignored. Not very handy, so set the ones we want to use.
        # On Linux and FreeBSD, in order to set the WM_CLASS property for X11, we pass "OpenLP" in as a command line
        # argument. This interferes with files being passed in as command line arguments, so we remove it from the list.
        if 'OpenLP' in args:
            args.remove('OpenLP')
        self.args.extend(args)
        # Decide how many screens we have and their size
        screens = ScreenList.create(self.desktop())
        # First time checks in settings
        has_run_wizard = Settings().value('core/has run wizard')
        if not has_run_wizard:
            ftw = FirstTimeForm()
            ftw.initialize(screens)
            if ftw.exec() == QtWidgets.QDialog.Accepted:
                Settings().setValue('core/has run wizard', True)
            elif ftw.was_cancelled:
                QtCore.QCoreApplication.exit()
                sys.exit()
        # Correct stylesheet bugs
        application_stylesheet = get_application_stylesheet()
        if application_stylesheet:
            self.setStyleSheet(application_stylesheet)
        can_show_splash = Settings().value('core/show splash')
        if can_show_splash:
            self.splash = SplashScreen()
            self.splash.show()
        # make sure Qt really display the splash screen
        self.processEvents()
        # Check if OpenLP has been upgrade and if a backup of data should be created
        self.backup_on_upgrade(has_run_wizard, can_show_splash)
        # start the main app window
        self.main_window = MainWindow()
        Registry().execute('bootstrap_initialise')
        Registry().execute('bootstrap_post_set_up')
        Registry().initialise = False
        self.main_window.show()
        if can_show_splash:
            # now kill the splashscreen
            log.debug('Splashscreen closing')
            self.splash.close()
            log.debug('Splashscreen closed')
        # make sure Qt really display the splash screen
        self.processEvents()
        self.main_window.repaint()
        self.processEvents()
        if not has_run_wizard:
            self.main_window.first_time()
        if Settings().value('core/update check'):
            check_for_update(self.main_window)
        self.main_window.is_display_blank()
        self.main_window.app_startup()
        return self.exec()
コード例 #4
0
    def test_on_custom_button_clicked(self, mocked_proxy_dialog):
        """
        Test _on_custom_button when it is called whe the 'internet settings' (CustomButton1) button is not clicked.
        """
        # GIVEN: An instance of the FirstTimeForm
        frw = FirstTimeForm(None)

        # WHEN: Calling _on_custom_button_clicked with a different button to the 'internet settings button.
        frw._on_custom_button_clicked(QtWidgets.QWizard.CustomButton2)

        # THEN: The ProxyDialog should not be shown.
        mocked_proxy_dialog.assert_not_called()
コード例 #5
0
    def test_exec(self, mocked_qwizard_exec):

        # GIVEN: An instance of FirstTimeForm
        frw = FirstTimeForm(None)
        with patch.object(frw, 'set_defaults') as mocked_set_defaults:

            # WHEN: exec is called
            frw.exec()

            # THEN: The wizard should be reset and the exec methon on the super class should have been called
            mocked_set_defaults.assert_called_once()
            mocked_qwizard_exec.assert_called_once()
コード例 #6
0
    def test_accept_method_theme_not_selected(self, mocked_settings):
        """
        Test the FirstTimeForm.accept method when there is no default theme selected
        """
        # GIVEN: An instance of FirstTimeForm
        frw = FirstTimeForm(None)
        with patch.object(frw, '_set_plugin_status'), patch.object(frw, 'screen_selection_widget'), \
                patch.object(frw, 'theme_combo_box', **{'currentIndex.return_value': -1}):

            # WHEN: Calling accept and the currentIndex method of the theme_combo_box returns -1
            frw.accept()

            # THEN: OpenLP should not try to save a theme name
            mocked_settings().setValue.assert_not_called()
コード例 #7
0
    def test__parse_config_invalid_config(self,
                                          mocked_critical_error_message_box):
        """
        Test `FirstTimeForm._parse_config` when called with invalid data
        """
        # GIVEN: An instance of `FirstTimeForm`
        first_time_form = FirstTimeForm(None)

        # WHEN: Calling _parse_config with a string containing invalid data
        result = first_time_form._parse_config(INVALID_CONFIG)

        # THEN: _parse_data should return False and the user should have should have been informed.
        assert result is False
        mocked_critical_error_message_box.assert_called_once()
コード例 #8
0
ファイル: test_firsttimeform.py プロジェクト: imkernel/openlp
    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')
コード例 #9
0
    def test_on_custom_button_clicked_internet_settings(
            self, mocked_proxy_dialog):
        """
        Test _on_custom_button when it is called when the 'internet settings' (CustomButton1) button is clicked.
        """
        # GIVEN: An instance of the FirstTimeForm
        frw = FirstTimeForm(None)

        # WHEN: Calling _on_custom_button_clicked with the constant for the 'internet settings' button (CustomButton1)
        frw._on_custom_button_clicked(QtWidgets.QWizard.CustomButton1)

        # THEN: The ProxyDialog should be shown.
        mocked_proxy_dialog.assert_called_with(frw)
        mocked_proxy_dialog().retranslate_ui.assert_called_once()
        mocked_proxy_dialog().exec.assert_called_once()
コード例 #10
0
    def socket_timeout_test(self, mocked_urlopen):
        """
        Test socket timeout gets caught
        """
        # GIVEN: Mocked urlopen to fake a network disconnect in the middle of a download
        first_time_form = FirstTimeForm(None)
        first_time_form.initialize(MagicMock())
        mocked_urlopen.side_effect = socket.timeout()

        # WHEN: Attempt to retrieve a file
        first_time_form.url_get_file(url='http://localhost/test', f_path=self.tempfile)

        # THEN: socket.timeout should have been caught
        # NOTE: Test is if $tmpdir/tempfile is still there, then test fails since ftw deletes bad downloaded files
        self.assertFalse(os.path.exists(self.tempfile), 'FTW url_get_file should have caught socket.timeout')
コード例 #11
0
    def test_initialise(self):
        """
        Test if we can intialise the FirstTimeForm
        """
        # GIVEN: A First Time Wizard and an expected screen object
        frw = FirstTimeForm(None)
        expected_screens = MagicMock()

        # WHEN: The First Time Wizard is initialised
        frw.initialize(expected_screens)

        # THEN: The screens should be set up, and the default values initialised
        assert expected_screens == frw.screens, 'The screens should be correct'
        assert frw.has_web_access is True, 'The default value of self.web_access should be True'
        assert [] == frw.thumbnail_download_threads, 'The list of threads should be empty'
        assert frw.has_run_wizard is False, 'has_run_wizard should be False'
コード例 #12
0
    def test_accept_method_theme_selected(self, mocked_settings):
        """
        Test the FirstTimeForm.accept method when a default theme is selected
        """
        # GIVEN: An instance of FirstTimeForm
        frw = FirstTimeForm(None)
        with patch.object(frw, '_set_plugin_status'), \
                patch.object(frw, 'screen_selection_widget'), \
                patch.object(
                frw, 'theme_combo_box', **{'currentIndex.return_value': 0, 'currentText.return_value': 'Test Item'}):

            # WHEN: Calling accept and the currentIndex method of the theme_combo_box returns 0
            frw.accept()

            # THEN: The 'currentItem' in the combobox should have been set as the default theme.
            mocked_settings().setValue.assert_called_once_with(
                'themes/global theme', 'Test Item')
コード例 #13
0
    def test_reject_method(self, mocked_is_thread_finished,
                           mocked_get_thread_worker, mocked_time,
                           mocked_qwizard_reject):
        """
        Test that the reject method shuts down the threads correctly
        """
        # GIVEN: A FRW, some mocked threads and workers (that isn't quite done) and other mocked stuff
        mocked_worker = MagicMock()
        mocked_get_thread_worker.return_value = mocked_worker
        mocked_is_thread_finished.side_effect = [False, True]
        frw = FirstTimeForm(None)
        frw.initialize(MagicMock())
        frw.thumbnail_download_threads = ['test_thread']
        with patch.object(frw.application,
                          'set_normal_cursor') as mocked_set_normal_cursor:

            # WHEN: the reject method is called
            frw.reject()

            # THEN: The right things should be called in the right order
            mocked_get_thread_worker.assert_called_once_with('test_thread')
            mocked_worker.cancel_download.assert_called_once()
            mocked_is_thread_finished.assert_called_with('test_thread')
            assert mocked_is_thread_finished.call_count == 2, 'isRunning() should have been called twice'
            mocked_time.sleep.assert_called_once_with(0.1)
            mocked_set_normal_cursor.assert_called_once()
            mocked_qwizard_reject.assert_called_once()
コード例 #14
0
ファイル: test_firsttimeform.py プロジェクト: simhnna/openlp
    def test_on_cancel_button_clicked(self, mocked_is_thread_finished,
                                      mocked_get_thread_worker, mocked_time):
        """
        Test that the cancel button click slot shuts down the threads correctly
        """
        # GIVEN: A FRW, some mocked threads and workers (that isn't quite done) and other mocked stuff
        mocked_worker = MagicMock()
        mocked_get_thread_worker.return_value = mocked_worker
        mocked_is_thread_finished.side_effect = [False, True]
        frw = FirstTimeForm(None)
        frw.initialize(MagicMock())
        frw.theme_screenshot_threads = ['test_thread']
        with patch.object(frw.application,
                          'set_normal_cursor') as mocked_set_normal_cursor:

            # WHEN: on_cancel_button_clicked() is called
            frw.on_cancel_button_clicked()

            # THEN: The right things should be called in the right order
            assert frw.was_cancelled is True, 'The was_cancelled property should have been set to True'
            mocked_get_thread_worker.assert_called_once_with('test_thread')
            mocked_worker.set_download_canceled.assert_called_with(True)
            mocked_is_thread_finished.assert_called_with('test_thread')
            assert mocked_is_thread_finished.call_count == 2, 'isRunning() should have been called twice'
            mocked_time.sleep.assert_called_once_with(0.1)
            mocked_set_normal_cursor.assert_called_once_with()
コード例 #15
0
ファイル: test_firsttimeform.py プロジェクト: imkernel/openlp
    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')
コード例 #16
0
    def test_initialise(self):
        """
        Test if we can intialise the FirstTimeForm
        """
        # GIVEN: A First Time Wizard and an expected screen object
        frw = FirstTimeForm(None)
        expected_screens = MagicMock()

        # WHEN: The First Time Wizard is initialised
        frw.initialize(expected_screens)

        # THEN: The screens should be set up, and the default values initialised
        self.assertEqual(expected_screens, frw.screens, 'The screens should be correct')
        self.assertTrue(frw.web_access, 'The default value of self.web_access should be True')
        self.assertFalse(frw.was_cancelled, 'The default value of self.was_cancelled should be False')
        self.assertListEqual([], frw.theme_screenshot_threads, 'The list of threads should be empty')
        self.assertListEqual([], frw.theme_screenshot_workers, 'The list of workers should be empty')
        self.assertFalse(frw.has_run_wizard, 'has_run_wizard should be False')
コード例 #17
0
ファイル: test_firsttimeform.py プロジェクト: imkernel/openlp
    def test_initialise(self):
        """
        Test if we can intialise the FirstTimeForm
        """
        # GIVEN: A First Time Wizard and an expected screen object
        frw = FirstTimeForm(None)
        expected_screens = MagicMock()

        # WHEN: The First Time Wizard is initialised
        frw.initialize(expected_screens)

        # THEN: The screens should be set up, and the default values initialised
        self.assertEqual(expected_screens, frw.screens, 'The screens should be correct')
        self.assertTrue(frw.web_access, 'The default value of self.web_access should be True')
        self.assertFalse(frw.was_cancelled, 'The default value of self.was_cancelled should be False')
        self.assertListEqual([], frw.theme_screenshot_threads, 'The list of threads should be empty')
        self.assertListEqual([], frw.theme_screenshot_workers, 'The list of workers should be empty')
        self.assertFalse(frw.has_run_wizard, 'has_run_wizard should be False')
コード例 #18
0
    def test_on_projectors_check_box_unchecked(self, MockSettings):
        """
        Test that the projector panel is shown when the checkbox in the first time wizard is checked
        """
        # GIVEN: A First Time Wizard and a mocked settings object
        frw = FirstTimeForm(None)
        mocked_settings = MagicMock()
        mocked_settings.value.return_value = False
        MockSettings.return_value = mocked_settings

        # WHEN: on_projectors_check_box_clicked() is called
        frw.on_projectors_check_box_clicked()

        # THEN: The visibility of the projects panel should have been set
        mocked_settings.value.assert_called_once_with(
            'projector/show after wizard')
        mocked_settings.setValue.assert_called_once_with(
            'projector/show after wizard', True)
コード例 #19
0
    def test_on_cancel_button_clicked(self):
        """
        Test that the cancel button click slot shuts down the threads correctly
        """
        # GIVEN: A FRW, some mocked threads and workers (that isn't quite done) and other mocked stuff
        frw = FirstTimeForm(None)
        frw.initialize(MagicMock())
        mocked_worker = MagicMock()
        mocked_thread = MagicMock()
        mocked_thread.isRunning.side_effect = [True, False]
        frw.theme_screenshot_workers.append(mocked_worker)
        frw.theme_screenshot_threads.append(mocked_thread)
        with patch('openlp.core.ui.firsttimeform.time') as mocked_time, \
                patch.object(frw.application, 'set_normal_cursor') as mocked_set_normal_cursor:

            # WHEN: on_cancel_button_clicked() is called
            frw.on_cancel_button_clicked()

            # THEN: The right things should be called in the right order
            self.assertTrue(frw.was_cancelled, 'The was_cancelled property should have been set to True')
            mocked_worker.set_download_canceled.assert_called_with(True)
            mocked_thread.isRunning.assert_called_with()
            self.assertEqual(2, mocked_thread.isRunning.call_count, 'isRunning() should have been called twice')
            mocked_time.sleep.assert_called_with(0.1)
            self.assertEqual(1, mocked_time.sleep.call_count, 'sleep() should have only been called once')
            mocked_set_normal_cursor.assert_called_with()
コード例 #20
0
ファイル: test_firsttimeform.py プロジェクト: imkernel/openlp
    def test_update_screen_list_combo(self):
        """
        Test that the update_screen_list_combo() method works correctly
        """
        # GIVEN: A mocked Screen() object and an initialised First Run Wizard and a mocked display_combo_box
        expected_screen_list = ['Screen 1', 'Screen 2']
        mocked_screens = MagicMock()
        mocked_screens.get_screen_list.return_value = expected_screen_list
        frw = FirstTimeForm(None)
        frw.initialize(mocked_screens)
        with patch.object(frw, 'display_combo_box') as mocked_display_combo_box:
            mocked_display_combo_box.count.return_value = 2

            # WHEN: update_screen_list_combo() is called
            frw.update_screen_list_combo()

            # THEN: The combobox should have been updated
            mocked_display_combo_box.clear.assert_called_with()
            mocked_screens.get_screen_list.assert_called_with()
            mocked_display_combo_box.addItems.assert_called_with(expected_screen_list)
            mocked_display_combo_box.count.assert_called_with()
            mocked_display_combo_box.setCurrentIndex.assert_called_with(1)
コード例 #21
0
ファイル: test_firsttimeform.py プロジェクト: imkernel/openlp
    def test_set_defaults(self):
        """
        Test that the default values are set when set_defaults() is run
        """
        # GIVEN: An initialised FRW and a whole lot of stuff mocked out
        frw = FirstTimeForm(None)
        frw.initialize(MagicMock())
        with patch.object(frw, 'restart') as mocked_restart, \
                patch.object(frw, 'cancel_button') as mocked_cancel_button, \
                patch.object(frw, 'no_internet_finish_button') as mocked_no_internet_finish_btn, \
                patch.object(frw, 'currentIdChanged') as mocked_currentIdChanged, \
                patch.object(Registry, 'register_function') as mocked_register_function, \
                patch('openlp.core.ui.firsttimeform.Settings') as MockedSettings, \
                patch('openlp.core.ui.firsttimeform.gettempdir') as mocked_gettempdir, \
                patch('openlp.core.ui.firsttimeform.check_directory_exists') as mocked_check_directory_exists, \
                patch.object(frw.application, 'set_normal_cursor') as mocked_set_normal_cursor:
            mocked_settings = MagicMock()
            mocked_settings.value.return_value = True
            MockedSettings.return_value = mocked_settings
            mocked_gettempdir.return_value = 'temp'
            expected_temp_path = os.path.join('temp', 'openlp')

            # WHEN: The set_defaults() method is run
            frw.set_defaults()

            # THEN: The default values should have been set
            mocked_restart.assert_called_with()
            self.assertEqual('http://openlp.org/files/frw/', frw.web, 'The default URL should be set')
            mocked_cancel_button.clicked.connect.assert_called_with(frw.on_cancel_button_clicked)
            mocked_no_internet_finish_btn.clicked.connect.assert_called_with(frw.on_no_internet_finish_button_clicked)
            mocked_currentIdChanged.connect.assert_called_with(frw.on_current_id_changed)
            mocked_register_function.assert_called_with('config_screen_changed', frw.update_screen_list_combo)
            mocked_no_internet_finish_btn.setVisible.assert_called_with(False)
            mocked_settings.value.assert_called_with('core/has run wizard')
            mocked_gettempdir.assert_called_with()
            mocked_check_directory_exists.assert_called_with(expected_temp_path)
コード例 #22
0
    def test_socket_timeout(self, mocked_urlopen):
        """
        Test socket timeout gets caught
        """
        # GIVEN: Mocked urlopen to fake a network disconnect in the middle of a download
        first_time_form = FirstTimeForm(None)
        first_time_form.initialize(MagicMock())
        mocked_urlopen.side_effect = socket.timeout()

        # WHEN: Attempt to retrieve a file
        first_time_form.url_get_file(url='http://localhost/test', f_path=self.tempfile)

        # THEN: socket.timeout should have been caught
        # NOTE: Test is if $tmpdir/tempfile is still there, then test fails since ftw deletes bad downloaded files
        self.assertFalse(os.path.exists(self.tempfile), 'FTW url_get_file should have caught socket.timeout')
コード例 #23
0
    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')
コード例 #24
0
ファイル: test_firsttimeform.py プロジェクト: simhnna/openlp
    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'
コード例 #25
0
ファイル: test_firsttimeform.py プロジェクト: simhnna/openlp
    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')
コード例 #26
0
    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')
コード例 #27
0
    def test_set_defaults(self):
        """
        Test that the default values are set when set_defaults() is run
        """
        # GIVEN: An initialised FRW and a whole lot of stuff mocked out
        frw = FirstTimeForm(None)
        frw.initialize(MagicMock())
        mocked_settings = MagicMock()
        mocked_settings.value.side_effect = lambda key: {
            'core/has run wizard': False
        }[key]
        with patch.object(frw, 'restart') as mocked_restart, \
                patch.object(frw, 'currentIdChanged') as mocked_currentIdChanged, \
                patch.object(frw, 'theme_combo_box') as mocked_theme_combo_box, \
                patch.object(frw, 'songs_check_box') as mocked_songs_check_box, \
                patch.object(Registry, 'register_function') as mocked_register_function, \
                patch('openlp.core.ui.firsttimeform.Settings', return_value=mocked_settings), \
                patch('openlp.core.ui.firsttimeform.gettempdir', return_value='temp') as mocked_gettempdir, \
                patch('openlp.core.ui.firsttimeform.create_paths') as mocked_create_paths, \
                patch.object(frw.application, 'set_normal_cursor'):
            mocked_theme_manager = MagicMock()
            Registry().register('theme_manager', mocked_theme_manager)

            # WHEN: The set_defaults() method is run
            frw.set_defaults()

            # THEN: The default values should have been set
            mocked_restart.assert_called_once()
            assert 'https://get.openlp.org/ftw/' == frw.web, 'The default URL should be set'
            mocked_currentIdChanged.connect.assert_called_once_with(
                frw.on_current_id_changed)
            mocked_register_function.assert_called_once_with(
                'config_screen_changed', frw.screen_selection_widget.load)
            mocked_settings.value.assert_has_calls(
                [call('core/has run wizard')])
            mocked_gettempdir.assert_called_once()
            mocked_create_paths.assert_called_once_with(Path('temp', 'openlp'))
            mocked_theme_combo_box.clear.assert_called_once()
            mocked_theme_manager.assert_not_called()
            mocked_songs_check_box.assert_not_called()
コード例 #28
0
ファイル: test_firsttimeform.py プロジェクト: simhnna/openlp
    def test_set_defaults(self):
        """
        Test that the default values are set when set_defaults() is run
        """
        # GIVEN: An initialised FRW and a whole lot of stuff mocked out
        frw = FirstTimeForm(None)
        frw.initialize(MagicMock())
        with patch.object(frw, 'restart') as mocked_restart, \
                patch.object(frw, 'cancel_button') as mocked_cancel_button, \
                patch.object(frw, 'no_internet_finish_button') as mocked_no_internet_finish_btn, \
                patch.object(frw, 'currentIdChanged') as mocked_currentIdChanged, \
                patch.object(Registry, 'register_function') as mocked_register_function, \
                patch('openlp.core.ui.firsttimeform.Settings') as MockedSettings, \
                patch('openlp.core.ui.firsttimeform.gettempdir') as mocked_gettempdir, \
                patch('openlp.core.ui.firsttimeform.create_paths') as mocked_create_paths, \
                patch.object(frw.application, 'set_normal_cursor'):
            mocked_settings = MagicMock()
            mocked_settings.value.return_value = True
            MockedSettings.return_value = mocked_settings
            mocked_gettempdir.return_value = 'temp'
            expected_temp_path = Path('temp', 'openlp')

            # WHEN: The set_defaults() method is run
            frw.set_defaults()

            # THEN: The default values should have been set
            mocked_restart.assert_called_with()
            assert 'http://openlp.org/files/frw/' == frw.web, 'The default URL should be set'
            mocked_cancel_button.clicked.connect.assert_called_with(
                frw.on_cancel_button_clicked)
            mocked_no_internet_finish_btn.clicked.connect.assert_called_with(
                frw.on_no_internet_finish_button_clicked)
            mocked_currentIdChanged.connect.assert_called_with(
                frw.on_current_id_changed)
            mocked_register_function.assert_called_with(
                'config_screen_changed', frw.update_screen_list_combo)
            mocked_no_internet_finish_btn.setVisible.assert_called_with(False)
            mocked_settings.value.assert_called_with('core/has run wizard')
            mocked_gettempdir.assert_called_with()
            mocked_create_paths.assert_called_with(expected_temp_path)
コード例 #29
0
    def test_update_screen_list_combo(self):
        """
        Test that the update_screen_list_combo() method works correctly
        """
        # GIVEN: A mocked Screen() object and an initialised First Run Wizard and a mocked display_combo_box
        expected_screen_list = ['Screen 1', 'Screen 2']
        mocked_screens = MagicMock()
        mocked_screens.get_screen_list.return_value = expected_screen_list
        frw = FirstTimeForm(None)
        frw.initialize(mocked_screens)
        with patch.object(frw, 'display_combo_box') as mocked_display_combo_box:
            mocked_display_combo_box.count.return_value = 2

            # WHEN: update_screen_list_combo() is called
            frw.update_screen_list_combo()

            # THEN: The combobox should have been updated
            mocked_display_combo_box.clear.assert_called_with()
            mocked_screens.get_screen_list.assert_called_with()
            mocked_display_combo_box.addItems.assert_called_with(expected_screen_list)
            mocked_display_combo_box.count.assert_called_with()
            mocked_display_combo_box.setCurrentIndex.assert_called_with(1)
コード例 #30
0
ファイル: __init__.py プロジェクト: BlazingAsher/OpenLP-WCAC
    def run(self, args):
        """
        Run the OpenLP application.

        :param args: Some Args
        """
        self.is_event_loop_active = False
        # On Windows, the args passed into the constructor are ignored. Not very handy, so set the ones we want to use.
        # On Linux and FreeBSD, in order to set the WM_CLASS property for X11, we pass "OpenLP" in as a command line
        # argument. This interferes with files being passed in as command line arguments, so we remove it from the list.
        if 'OpenLP' in args:
            args.remove('OpenLP')
        self.args.extend(args)
        # Decide how many screens we have and their size
        screens = ScreenList.create(self.desktop())
        # First time checks in settings
        has_run_wizard = Settings().value('core/has run wizard')
        if not has_run_wizard:
            ftw = FirstTimeForm()
            ftw.initialize(screens)
            if ftw.exec() == QtWidgets.QDialog.Accepted:
                Settings().setValue('core/has run wizard', True)
            elif ftw.was_cancelled:
                QtCore.QCoreApplication.exit()
                sys.exit()
        # Correct stylesheet bugs
        application_stylesheet = ''
        if not Settings().value('advanced/alternate rows'):
            base_color = self.palette().color(QtGui.QPalette.Active,
                                              QtGui.QPalette.Base)
            alternate_rows_repair_stylesheet = \
                'QTableWidget, QListWidget, QTreeWidget {alternate-background-color: ' + base_color.name() + ';}\n'
            application_stylesheet += alternate_rows_repair_stylesheet
        if is_win():
            application_stylesheet += WIN_REPAIR_STYLESHEET
        if application_stylesheet:
            self.setStyleSheet(application_stylesheet)
        can_show_splash = Settings().value('core/show splash')
        if can_show_splash:
            self.splash = SplashScreen()
            self.splash.show()
        # make sure Qt really display the splash screen
        self.processEvents()
        # Check if OpenLP has been upgrade and if a backup of data should be created
        self.backup_on_upgrade(has_run_wizard, can_show_splash)
        # start the main app window
        self.main_window = MainWindow()
        Registry().execute('bootstrap_initialise')
        Registry().execute('bootstrap_post_set_up')
        Registry().initialise = False
        self.main_window.show()
        if can_show_splash:
            # now kill the splashscreen
            self.splash.finish(self.main_window)
            log.debug('Splashscreen closed')
        # make sure Qt really display the splash screen
        self.processEvents()
        self.main_window.repaint()
        self.processEvents()
        if not has_run_wizard:
            self.main_window.first_time()
        update_check = Settings().value('core/update check')
        if update_check:
            version = VersionThread(self.main_window)
            version.start()
        self.main_window.is_display_blank()
        self.main_window.app_startup()
        return self.exec()
コード例 #31
0
ファイル: __init__.py プロジェクト: crossroadchurch/paul
    def run(self, args):
        """
        Run the OpenLP application.

        :param args: Some Args
        """
        self.is_event_loop_active = False
        # On Windows, the args passed into the constructor are ignored. Not very handy, so set the ones we want to use.
        # On Linux and FreeBSD, in order to set the WM_CLASS property for X11, we pass "OpenLP" in as a command line
        # argument. This interferes with files being passed in as command line arguments, so we remove it from the list.
        if 'OpenLP' in args:
            args.remove('OpenLP')
        self.args.extend(args)
        # Decide how many screens we have and their size
        screens = ScreenList.create(self.desktop())
        # First time checks in settings
        has_run_wizard = Settings().value('core/has run wizard')
        if not has_run_wizard:
            ftw = FirstTimeForm()
            ftw.initialize(screens)
            if ftw.exec_() == QtGui.QDialog.Accepted:
                Settings().setValue('core/has run wizard', True)
            elif ftw.was_cancelled:
                QtCore.QCoreApplication.exit()
                sys.exit()
        # Correct stylesheet bugs
        application_stylesheet = ''
        if not Settings().value('advanced/alternate rows'):
            base_color = self.palette().color(QtGui.QPalette.Active, QtGui.QPalette.Base)
            alternate_rows_repair_stylesheet = \
                'QTableWidget, QListWidget, QTreeWidget {alternate-background-color: ' + base_color.name() + ';}\n'
            application_stylesheet += alternate_rows_repair_stylesheet
        if is_win():
            application_stylesheet += WIN_REPAIR_STYLESHEET
        if application_stylesheet:
            self.setStyleSheet(application_stylesheet)
        show_splash = Settings().value('core/show splash')
        if show_splash:
            self.splash = SplashScreen()
            self.splash.show()
        # make sure Qt really display the splash screen
        self.processEvents()
        # Check if OpenLP has been upgrade and if a backup of data should be created
        self.backup_on_upgrade(has_run_wizard)
        # start the main app window
        self.main_window = MainWindow()
        Registry().execute('bootstrap_initialise')
        Registry().execute('bootstrap_post_set_up')
        Registry().initialise = False
        self.main_window.show()
        if show_splash:
            # now kill the splashscreen
            self.splash.finish(self.main_window)
            log.debug('Splashscreen closed')
        # make sure Qt really display the splash screen
        self.processEvents()
        self.main_window.repaint()
        self.processEvents()
        if not has_run_wizard:
            self.main_window.first_time()
        update_check = Settings().value('core/update check')
        #if update_check:
        #    version = VersionThread(self.main_window)
        #    version.start()
        self.main_window.is_display_blank()
        self.main_window.app_startup()
        return self.exec_()
コード例 #32
0
    def test_set_defaults_rerun(self):
        """
        Test that the default values are set when set_defaults() is run
        """
        # GIVEN: An initialised FRW and a whole lot of stuff mocked out
        frw = FirstTimeForm(None)
        frw.initialize(MagicMock())
        mocked_settings = MagicMock()
        mocked_settings.value.side_effect = \
            lambda key: {'core/has run wizard': True, 'themes/global theme': 'Default Theme'}[key]
        with patch.object(frw, 'restart') as mocked_restart, \
                patch.object(frw, 'currentIdChanged') as mocked_currentIdChanged, \
                patch.object(frw, 'theme_combo_box', **{'findText.return_value': 3}) as mocked_theme_combo_box, \
                patch.multiple(frw, songs_check_box=DEFAULT, bible_check_box=DEFAULT, presentation_check_box=DEFAULT,
                               image_check_box=DEFAULT, media_check_box=DEFAULT, custom_check_box=DEFAULT,
                               song_usage_check_box=DEFAULT, alert_check_box=DEFAULT), \
                patch.object(Registry, 'register_function') as mocked_register_function, \
                patch('openlp.core.ui.firsttimeform.Settings', return_value=mocked_settings), \
                patch('openlp.core.ui.firsttimeform.gettempdir', return_value='temp') as mocked_gettempdir, \
                patch('openlp.core.ui.firsttimeform.create_paths') as mocked_create_paths, \
                patch.object(frw.application, 'set_normal_cursor'):
            mocked_plugin_manager = MagicMock()
            mocked_theme_manager = MagicMock(
                **{'get_theme_names.return_value': ['b', 'a', 'c']})
            Registry().register('plugin_manager', mocked_plugin_manager)
            Registry().register('theme_manager', mocked_theme_manager)

            # WHEN: The set_defaults() method is run
            frw.set_defaults()

            # THEN: The default values should have been set
            mocked_restart.assert_called_once()
            assert 'https://get.openlp.org/ftw/' == frw.web, 'The default URL should be set'
            mocked_currentIdChanged.connect.assert_called_once_with(
                frw.on_current_id_changed)
            mocked_register_function.assert_called_once_with(
                'config_screen_changed', frw.screen_selection_widget.load)
            mocked_settings.value.assert_has_calls(
                [call('core/has run wizard'),
                 call('themes/global theme')])
            mocked_gettempdir.assert_called_once()
            mocked_create_paths.assert_called_once_with(Path('temp', 'openlp'))
            mocked_theme_manager.get_theme_names.assert_called_once()
            mocked_theme_combo_box.clear.assert_called_once()
            mocked_plugin_manager.get_plugin_by_name.assert_has_calls(
                [
                    call('songs'),
                    call('bibles'),
                    call('presentations'),
                    call('images'),
                    call('media'),
                    call('custom'),
                    call('songusage'),
                    call('alerts')
                ],
                any_order=True)
            mocked_plugin_manager.get_plugin_by_name.assert_has_calls(
                [call().is_active()] * 8, any_order=True)
            mocked_theme_combo_box.addItems.assert_called_once_with(
                ['a', 'b', 'c'])
            mocked_theme_combo_box.findText.assert_called_once_with(
                'Default Theme')
            mocked_theme_combo_box.setCurrentIndex(3)