コード例 #1
0
    def title_combobox_test(self):
        """
        Test the behavior when the title combobox is updated
        """
        # GIVEN: Mocked methods and some entries in the title combobox.
        with patch('PyQt4.QtGui.QDialog.exec_') as mocked_exec:
            self.form.exec_()
            self.form.vlc_media_player.get_length.return_value = 1000
            self.form.audio_tracks_combobox.itemData = MagicMock()
            self.form.subtitle_tracks_combobox.itemData = MagicMock()
            self.form.audio_tracks_combobox.itemData.return_value = None
            self.form.subtitle_tracks_combobox.itemData.return_value = None
            self.form.titles_combo_box.insertItem(0, 'Test Title 0')
            self.form.titles_combo_box.insertItem(1, 'Test Title 1')

            # WHEN: There exists audio and subtitle tracks and the index is updated.
            self.form.vlc_media_player.audio_get_track_description.return_value = [
                (-1, b'Disabled'), (0, b'Audio Track 1')
            ]
            self.form.vlc_media_player.video_get_spu_description.return_value = [
                (-1, b'Disabled'), (0, b'Subtitle Track 1')
            ]
            self.form.titles_combo_box.setCurrentIndex(1)

            # THEN: The subtitle and audio track comboboxes should be updated and get signals and call itemData.
            self.form.audio_tracks_combobox.itemData.assert_any_call(0)
            self.form.audio_tracks_combobox.itemData.assert_any_call(1)
            self.form.subtitle_tracks_combobox.itemData.assert_any_call(0)
コード例 #2
0
 def setUp(self):
     """
     Create the UI
     """
     Registry.create()
     self.registry = Registry()
     self.setup_application()
     # Mock cursor busy/normal methods.
     self.app.set_busy_cursor = MagicMock()
     self.app.set_normal_cursor = MagicMock()
     self.app.args = []
     Registry().register('application', self.app)
     # Mock classes and methods used by mainwindow.
     with patch('openlp.core.ui.mainwindow.SettingsForm') as mocked_settings_form, \
             patch('openlp.core.ui.mainwindow.ImageManager') as mocked_image_manager, \
             patch('openlp.core.ui.mainwindow.LiveController') as mocked_live_controller, \
             patch('openlp.core.ui.mainwindow.PreviewController') as mocked_preview_controller, \
             patch('openlp.core.ui.mainwindow.OpenLPDockWidget') as mocked_dock_widget, \
             patch('openlp.core.ui.mainwindow.QtWidgets.QToolBox') as mocked_q_tool_box_class, \
             patch('openlp.core.ui.mainwindow.QtWidgets.QMainWindow.addDockWidget') as mocked_add_dock_method, \
             patch('openlp.core.ui.mainwindow.ServiceManager') as mocked_service_manager, \
             patch('openlp.core.ui.mainwindow.ThemeManager') as mocked_theme_manager, \
             patch('openlp.core.ui.mainwindow.ProjectorManager') as mocked_projector_manager, \
             patch('openlp.core.ui.mainwindow.Renderer') as mocked_renderer:
         self.main_window = MainWindow()
コード例 #3
0
 def setUp(self):
     """
     Set up the environment for testing bible parse reference
     """
     self.build_settings()
     Registry.create()
     Registry().register('service_list', MagicMock())
     Registry().register('application', MagicMock())
     bible_settings = {
         'bibles/proxy name': '',
         'bibles/db type': 'sqlite',
         'bibles/book name language': LanguageSelection.Bible,
         'bibles/verse separator': '',
         'bibles/range separator': '',
         'bibles/list separator': '',
         'bibles/end separator': '',
     }
     Settings().extend_default_settings(bible_settings)
     with patch('openlp.core.common.applocation.Settings') as mocked_class, \
             patch('openlp.core.common.AppLocation.get_section_data_path') as mocked_get_section_data_path, \
             patch('openlp.core.common.AppLocation.get_files') as mocked_get_files:
         # GIVEN: A mocked out Settings class and a mocked out AppLocation.get_files()
         mocked_settings = mocked_class.return_value
         mocked_settings.contains.return_value = False
         mocked_get_files.return_value = ["tests.sqlite"]
         mocked_get_section_data_path.return_value = TEST_RESOURCES_PATH + "/bibles"
         self.manager = BibleManager(MagicMock())
コード例 #4
0
ファイル: test_lib_http.py プロジェクト: jkunle/paul
 def setUp(self):
     """
     Set up the Registry
     """
     Registry.create()
     Registry().register('service_list', MagicMock())
     Registry().register('application', MagicMock())
コード例 #5
0
 def setUp(self):
     """
     Create the UI
     """
     Registry.create()
     self.setup_application()
     self.main_window = QtWidgets.QMainWindow()
     Registry().register('main_window', self.main_window)
     Registry().register('theme_manager', MagicMock())
     self.form = EditSongForm(MagicMock(), self.main_window, MagicMock())
コード例 #6
0
 def setUp(self):
     """
     Create the UI
     """
     Registry.create()
     self.setup_application()
     self.main_window = QtGui.QMainWindow()
     Registry().register('main_window', self.main_window)
     media_item = MagicMock()
     manager = MagicMock()
     self.form = EditCustomForm(media_item, self.main_window, manager)
コード例 #7
0
 def setUp(self):
     """
     Some pre-test setup required.
     """
     self.dummy1 = MagicMock()
     self.dummy2 = MagicMock()
     self.dummy3 = MagicMock()
     self.desktop = MagicMock()
     self.setup_application()
     self.desktop.primaryScreen.return_value = SCREEN['primary']
     self.desktop.screenCount.return_value = SCREEN['number']
     self.desktop.screenGeometry.return_value = SCREEN['size']
     self.screens = ScreenList.create(self.desktop)
     Registry.create()
     self.form = settingsform.SettingsForm()
コード例 #8
0
    def test_update_slide_list(self):
        """
        Test the update_slide_list() method
        """
        # GIVEN: Mocked slide_list_view with a slide with 3 lines
        self.form.slide_list_view = MagicMock()
        self.form.slide_list_view.count.return_value = 1
        self.form.slide_list_view.currentRow.return_value = 0
        self.form.slide_list_view.item.return_value = MagicMock(
            return_value='1st Slide\n2nd Slide\n3rd Slide')

        # WHEN: updating the slide by splitting the lines into slides
        self.form.update_slide_list(['1st Slide', '2nd Slide', '3rd Slide'])

        # THEN: The slides should be created in correct order
        self.form.slide_list_view.addItems.assert_called_with(
            ['1st Slide', '2nd Slide', '3rd Slide'])
コード例 #9
0
    def validate_not_valid_part2_test(self):
        """
        Test the _validate() method.
        """
        # GIVEN: Mocked methods.
        with patch('openlp.plugins.custom.forms.editcustomform.critical_error_message_box') as \
                mocked_critical_error_message_box:
            self.form.title_edit.displayText = MagicMock(
                return_value='something')
            self.form.slide_list_view.count = MagicMock(return_value=0)

            # WHEN: Call the method.
            result = self.form._validate()

            # THEN: The validate method should have returned False.
            assert not result, 'The _validate() method should have retured False'
            mocked_critical_error_message_box.assert_called_with(
                message='You need to add at least one slide.')
コード例 #10
0
 def test_parse_reference_two(self):
     """
     Test the parse_reference method with 1 Timothy 1:1-2
     """
     # GIVEN given a bible in the bible manager
     # WHEN asking to parse the bible reference
     results = parse_reference('1 Timothy 1:1-2', self.manager.db_cache['tests'], MagicMock(), 54)
     # THEN a verse array should be returned
     self.assertEqual([(54, 1, 1, 2)], results, "The bible verses should matches the expected results")
コード例 #11
0
 def test_parse_reference_four(self):
     """
     Test the parse_reference method with non existence book
     """
     # GIVEN given a bible in the bible manager
     # WHEN asking to parse the bible reference
     results = parse_reference('Raoul 1', self.manager.db_cache['tests'], MagicMock())
     # THEN a verse array should be returned
     self.assertEqual(False, results, "The bible Search should return False")
コード例 #12
0
    def test_bug_1170435(self):
        """
        Regression test for bug 1170435 (test if "no verse order" message is shown)
        """
        # GIVEN: Mocked methods.
        given_verse_order = ''
        self.form.verse_list_widget.rowCount = MagicMock(return_value=1)
        # Mock out the verse. (We want a verse type to be returned).
        mocked_verse = MagicMock()
        mocked_verse.data.return_value = 'V1'
        self.form.verse_list_widget.item = MagicMock(return_value=mocked_verse)
        self.form._extract_verse_order = MagicMock(return_value=[])
        self.form.verse_order_edit.text = MagicMock(return_value=given_verse_order)
        # WHEN: Call the method.
        self.form.on_verse_order_text_changed(given_verse_order)

        # THEN: The no-verse-order message should be shown.
        assert self.form.warning_label.text() == self.form.no_verse_order_entered_warning,  \
            'The no-verse-order message should be shown.'
コード例 #13
0
    def validate_not_valid_part1_test(self):
        """
        Test the _validate() method.
        """
        # GIVEN: Mocked methods.
        with patch('openlp.plugins.custom.forms.editcustomform.critical_error_message_box') as \
                mocked_critical_error_message_box:
            self.form.title_edit.displayText = MagicMock(return_value='')
            mocked_setFocus = MagicMock()
            self.form.title_edit.setFocus = mocked_setFocus

            # WHEN: Call the method.
            result = self.form._validate()

            # THEN: The validate method should have returned False.
            assert not result, 'The _validate() method should have retured False'
            mocked_setFocus.assert_called_with()
            mocked_critical_error_message_box.assert_called_with(
                message='You need to type in a title.')
コード例 #14
0
    def test_verse_order_no_warning(self):
        """
        Test if the verse order warning is not shown
        """
        # GIVEN: Mocked methods.
        given_verse_order = 'V1 V2'
        self.form.verse_list_widget.rowCount = MagicMock(return_value=2)
        # Mock out the verse.
        first_verse = MagicMock()
        first_verse.data.return_value = 'V1'
        second_verse = MagicMock()
        second_verse.data.return_value = 'V2'
        self.form.verse_list_widget.item = MagicMock(side_effect=[first_verse, second_verse])
        self.form._extract_verse_order = MagicMock(return_value=given_verse_order.split())

        # WHEN: Call the method.
        self.form.on_verse_order_text_changed(given_verse_order)

        # THEN: No text should be shown.
        assert self.form.warning_label.text() == '', 'There should be no warning.'
コード例 #15
0
    def test_verse_order_incomplete_warning(self):
        """
        Test if the verse-order-incomple warning is shown
        """
        # GIVEN: Mocked methods.
        given_verse_order = 'V1'
        self.form.verse_list_widget.rowCount = MagicMock(return_value=2)
        # Mock out the verse.
        first_verse = MagicMock()
        first_verse.data.return_value = 'V1'
        second_verse = MagicMock()
        second_verse.data.return_value = 'V2'
        self.form.verse_list_widget.item = MagicMock(side_effect=[first_verse, second_verse])
        self.form._extract_verse_order = MagicMock(return_value=[given_verse_order])

        # WHEN: Call the method.
        self.form.on_verse_order_text_changed(given_verse_order)

        # THEN: The verse-order-incomplete text should be shown.
        assert self.form.warning_label.text() == self.form.not_all_verses_used_warning, \
            'The verse-order-incomplete warning should be shown.'
コード例 #16
0
 def setUp(self):
     """
     Some pre-test setup required.
     """
     self.setup_application()
     self.build_settings()
     self.temp_dir = mkdtemp('openlp')
     Settings().setValue('advanced/data path', self.temp_dir)
     Registry.create()
     Registry().register('service_list', MagicMock())
     self.main_window = QtWidgets.QMainWindow()
     Registry().register('main_window', self.main_window)
コード例 #17
0
 def setUp(self):
     """
     Create the UI.
     """
     Registry.create()
     self.setup_application()
     self.main_window = QtWidgets.QMainWindow()
     self.image = QtGui.QImage(1, 1, QtGui.QImage.Format_RGB32)
     self.image_manager = MagicMock()
     self.image_manager.get_image.return_value = self.image
     Registry().register('image_manager', self.image_manager)
     self.preview_widget = ListPreviewWidget(self.main_window, 2)
コード例 #18
0
 def verify_service_refreshed_when_refresh_button_clicked_test(self):
     """
     Test that a service is refreshed when the "Refresh Service" button is clicked
     """
     # GIVEN: An SelectPlanForm instance with airplane mode enabled, resources available, many mocked functions
     with patch('PyQt5.QtWidgets.QDialog.exec'), \
             patch('openlp.core.lib.db.Manager.__init__'), \
             patch('openlp.plugins.planningcenter.lib.songimport.PlanningCenterSongImport.add_song') as mock_add_song, \
             patch('openlp.plugins.planningcenter.lib.customimport.PlanningCenterCustomImport.add_slide') as mock_add_slide:
         Registry().register('application', MagicMock())
         Registry().register('service_manager', MagicMock())
         Registry().register('songs', MagicMock())
         Registry().register('custom', MagicMock())
         self.form.exec()
         # WHEN: The Service Type combo is set to index 1 and the Select Plan combo box is set to index 3 and the "Import New" button is clicked
         self.form.service_type_combo_box.setCurrentIndex(1)
         self.form.plan_selection_combo_box.setCurrentIndex(3)
         QtTest.QTest.mouseClick(self.form.update_existing_button, QtCore.Qt.LeftButton)
     # THEN: The add_song function was called 2 times and add_slide once
     mock_add_slide.assert_called_once()
     self.assertEqual(mock_add_song.call_count, 2, 'Add_song should be called 2 times')
コード例 #19
0
 def verify_service_type_changed_called_when_service_type_combo_changed_test(self):
     """
     Test that the "on_service_type_combobox_changed" function is executed when the service_type_combobox is changed
     """
     # GIVEN: An SelectPlanForm instance with airplane mode enabled, resources available, 
     with patch('PyQt5.QtWidgets.QDialog.exec'):
         self.form.on_service_type_combobox_changed = MagicMock()
         self.form.exec()
         # WHEN: The Service Type combo is set to index 1
         self.form.service_type_combo_box.setCurrentIndex(1)
     # THEN: The on_import_as_new_button_cliced function is called
     self.form.on_service_type_combobox_changed.assert_called_with(1)
コード例 #20
0
 def setUp(self):
     """
     Create the UI
     """
     Registry.create()
     self.setup_application()
     self.main_window = QtWidgets.QMainWindow()
     Registry().register('main_window', self.main_window)
     self.form = SelectPlanForm()
     self.form.planning_center_api.airplane_mode = True
     self.form.planning_center_api.airplane_mode_directory = TEST_PATH
     theme_manager = ThemeManager(None)
     theme_manager.get_themes = MagicMock()
     theme_manager.get_themes.return_value = ['themeA','themeB']
コード例 #21
0
 def verify_import_function_called_when_import_button_clicked_test(self):
     """
     Test that the "on_import_as_new_button_clicked" function is executed when the "Import New" button is clicked
     """
     # GIVEN: An SelectPlanForm instance with airplane mode enabled, resources available, 
     with patch('PyQt5.QtWidgets.QDialog.exec'):
         self.form.on_import_as_new_button_clicked = MagicMock()
         self.form.exec()
         # WHEN: The Service Type combo is set to index 1 and the Select Plan combo box is set to index 3 and the "Import New" button is clicked
         self.form.service_type_combo_box.setCurrentIndex(1)
         self.form.plan_selection_combo_box.setCurrentIndex(3)
         QtTest.QTest.mouseClick(self.form.import_as_new_button, QtCore.Qt.LeftButton)
     # THEN: The on_import_as_new_button_cliced function is called
     self.form.on_import_as_new_button_clicked.assert_called_with(False)
コード例 #22
0
    def test_click_on_new_service(self):
        """
        Test the on_new_service event handler is called by the UI
        """
        # GIVEN: An initial form
        mocked_event = MagicMock()
        self.service_manager.on_new_service_clicked = mocked_event
        self.service_manager.setup_ui(self.service_manager)

        # WHEN displaying the UI and pressing cancel
        new_service = self.service_manager.toolbar.actions['newService']
        new_service.trigger()

        assert mocked_event.call_count == 1, 'The on_new_service_clicked method should have been called once'
コード例 #23
0
    def line_edit_focus_test(self):
        """
        Regression test for bug1067251
        Test that the file_name_edit setFocus has called with True when executed
        """
        # GIVEN: A mocked QDialog.exec_() method and mocked file_name_edit.setFocus() method.
        with patch('PyQt4.QtGui.QDialog.exec_'):
            mocked_set_focus = MagicMock()
            self.form.file_name_edit.setFocus = mocked_set_focus

            # WHEN: The form is executed
            self.form.exec_()

            # THEN: the setFocus method of the file_name_edit has been called with True
            mocked_set_focus.assert_called_with()
コード例 #24
0
    def test_escape_key_press_event(self):
        """
        Test the keyPressEvent when the escape key was pressed
        """
        # GIVEN: A key event that is an escape
        mocked_event = MagicMock()
        mocked_event.key.return_value = QtCore.Qt.Key_Escape

        # WHEN: The event is handled
        with patch.object(self.form, 'close') as mocked_close:
            self.form.keyPressEvent(mocked_event)

            # THEN: The key should be released
            mocked_event.accept.assert_called_with()
            mocked_close.assert_called_with()
コード例 #25
0
 def setUp(self):
     """
     Create the UI
     """
     Registry.create()
     self.setup_application()
     self.main_window = QtGui.QMainWindow()
     Registry().register('main_window', self.main_window)
     # Mock VLC so we don't actually use it
     self.vlc_patcher = patch(
         'openlp.plugins.media.forms.mediaclipselectorform.vlc')
     self.vlc_patcher.start()
     Registry().register('application', self.app)
     # Mock the media item
     self.mock_media_item = MagicMock()
     # create form to test
     self.form = MediaClipSelectorForm(self.mock_media_item,
                                       self.main_window, None)
     mock_media_state_wait = MagicMock()
     mock_media_state_wait.return_value = True
     self.form.media_state_wait = mock_media_state_wait
     self.form.application.set_busy_cursor = MagicMock()
     self.form.application.set_normal_cursor = MagicMock()
     self.form.find_optical_devices = MagicMock()
コード例 #26
0
    def click_load_button_test(self):
        """
        Test that the correct function is called when load is clicked, and that it behaves as expected.
        """
        # GIVEN: Mocked methods.
        with patch('openlp.plugins.media.forms.mediaclipselectorform.critical_error_message_box') as \
                mocked_critical_error_message_box,\
                patch('openlp.plugins.media.forms.mediaclipselectorform.os.path.exists') as mocked_os_path_exists,\
                patch('PyQt4.QtGui.QDialog.exec_') as mocked_exec:
            self.form.exec_()

            # WHEN: The load button is clicked with no path set
            QtTest.QTest.mouseClick(self.form.load_disc_button,
                                    QtCore.Qt.LeftButton)

            # THEN: we should get an error
            mocked_critical_error_message_box.assert_called_with(
                message='No path was given')

            # WHEN: The load button is clicked with a non-existing path
            mocked_os_path_exists.return_value = False
            self.form.media_path_combobox.insertItem(
                0, '/non-existing/test-path.test')
            self.form.media_path_combobox.setCurrentIndex(0)
            QtTest.QTest.mouseClick(self.form.load_disc_button,
                                    QtCore.Qt.LeftButton)

            # THEN: we should get an error
            assert self.form.media_path_combobox.currentText() == '/non-existing/test-path.test',\
                'The media path should be the given one.'
            mocked_critical_error_message_box.assert_called_with(
                message='Given path does not exists')

            # WHEN: The load button is clicked with a mocked existing path
            mocked_os_path_exists.return_value = True
            self.form.vlc_media_player = MagicMock()
            self.form.vlc_media_player.play.return_value = -1
            self.form.media_path_combobox.insertItem(
                0, '/existing/test-path.test')
            self.form.media_path_combobox.setCurrentIndex(0)
            QtTest.QTest.mouseClick(self.form.load_disc_button,
                                    QtCore.Qt.LeftButton)

            # THEN: we should get an error
            assert self.form.media_path_combobox.currentText() == '/existing/test-path.test',\
                'The media path should be the given one.'
            mocked_critical_error_message_box.assert_called_with(
                message='VLC player failed playing the media')
コード例 #27
0
    def test_space_key_press_event(self):
        """
        Test the keyPressEvent when the spacebar was pressed
        """
        # GIVEN: A key event that is a space
        mocked_event = MagicMock()
        mocked_event.key.return_value = QtCore.Qt.Key_Space

        # WHEN: The event is handled
        with patch.object(self.form,
                          'keyReleaseEvent') as mocked_key_release_event:
            self.form.keyPressEvent(mocked_event)

            # THEN: The key should be released
            mocked_key_release_event.assert_called_with(mocked_event)
            self.assertEqual(0, mocked_event.accept.call_count)
コード例 #28
0
    def test_auto_start_context_menu(self):
        """
        Test the context_menu() method with can auto start
        """
        # GIVEN: A service item added
        self.service_manager.setup_ui(self.service_manager)
        with patch('PyQt5.QtWidgets.QTreeWidget.itemAt') as mocked_item_at_method, \
                patch('PyQt5.QtWidgets.QWidget.mapToGlobal'), \
                patch('PyQt5.QtWidgets.QMenu.exec'):
            mocked_item = MagicMock()
            mocked_item.parent.return_value = None
            mocked_item_at_method.return_value = mocked_item
            # We want 1 to be returned for the position
            mocked_item.data.return_value = 1
            # A service item without capabilities.
            service_item = ServiceItem()
            service_item.add_capability(ItemCapabilities.CanAutoStartForLive)
            self.service_manager.service_items = [{'service_item': service_item}]
            q_point = None
            # Mocked actions.
            self.service_manager.edit_action.setVisible = MagicMock()
            self.service_manager.create_custom_action.setVisible = MagicMock()
            self.service_manager.maintain_action.setVisible = MagicMock()
            self.service_manager.notes_action.setVisible = MagicMock()
            self.service_manager.time_action.setVisible = MagicMock()
            self.service_manager.auto_start_action.setVisible = MagicMock()
            self.service_manager.rename_action.setVisible = MagicMock()

            # WHEN: Show the context menu.
            self.service_manager.context_menu(q_point)

            # THEN: The following actions should be not visible.
            self.service_manager.edit_action.setVisible.assert_called_once_with(False), \
                'The action should be set invisible.'
            self.service_manager.create_custom_action.setVisible.assert_called_once_with(False), \
                'The action should be set invisible.'
            self.service_manager.maintain_action.setVisible.assert_called_once_with(False), \
                'The action should be set invisible.'
            self.service_manager.notes_action.setVisible.assert_called_with(True), 'The action should be set visible.'
            self.service_manager.time_action.setVisible.assert_called_once_with(False), \
                'The action should be set invisible.'
            self.service_manager.auto_start_action.setVisible.assert_called_with(True), \
                'The action should be set visible.'
            self.service_manager.rename_action.setVisible.assert_called_once_with(False), \
                'The action should be set invisible.'
コード例 #29
0
    def test_primary_push_button_checked_key_press_event(self):
        """
        Test the keyPressEvent when the primary push button is checked
        """
        # GIVEN: The primary push button is checked
        with patch.object(self.form, 'keyReleaseEvent') as mocked_key_release_event, \
                patch.object(self.form.primary_push_button, 'isChecked') as mocked_is_checked:
            mocked_is_checked.return_value = True
            mocked_event = MagicMock()

            # WHEN: The event is handled
            self.form.keyPressEvent(mocked_event)

            # THEN: The key should be released
            mocked_key_release_event.assert_called_with(mocked_event)
            self.assertEqual(0, mocked_event.accept.call_count)
コード例 #30
0
ファイル: test_customslideform.py プロジェクト: jkunle/paul
    def set_text_test(self):
        """
        Test the set_text() method.
        """
        # GIVEN: A mocked QDialog.exec_() method
        with patch('PyQt4.QtGui.QDialog.exec_') as mocked_exec:
            mocked_set_focus = MagicMock()
            self.form.slide_text_edit.setFocus = mocked_set_focus
            wanted_text = 'THIS TEXT SHOULD BE SHOWN.'

            # WHEN: Show the dialog and set the text.
            self.form.exec_()
            self.form.set_text(wanted_text)

            # THEN: The dialog should show the text.
            assert self.form.slide_text_edit.toPlainText() == wanted_text, \
                'The text editor should show the correct text.'

            # THEN: The dialog should have focus.
            mocked_set_focus.assert_called_with()