Exemple #1
0
    def test_unblank_screen(self):
        """
        Test that unblank_screen works as expected
        """
        # GIVEN: A Document with mocked controller, presentation, ScreenList, and mocked function get_slide_number
        with patch('openlp.plugins.presentations.lib.powerpointcontroller.ScreenList') as mocked_screen_list:
            mocked_screen_list_ret = MagicMock()
            mocked_screen_list_ret.screen_list = [1]
            mocked_screen_list.return_value = mocked_screen_list_ret
            doc = PowerpointDocument(self.mock_controller, self.mock_presentation)
            doc.presentation = MagicMock()
            doc.presentation.SlideShowWindow.View.GetClickIndex.return_value = 3
            doc.presentation.Application.Version = 14.0
            doc.get_slide_number = MagicMock()
            doc.get_slide_number.return_value = 2
            doc.index_map[1] = 1
            doc.blank_slide = 1
            doc.blank_click = 1

            # WHEN: Calling goto_slide
            doc.unblank_screen()

            # THEN: The view state have new value, and several function should have been called
            self.assertEquals(doc.presentation.SlideShowWindow.View.State, 1, 'The View State should be 1')
            self.assertEquals(doc.presentation.SlideShowWindow.Activate.called, True,
                              'SlideShowWindow.Activate should have been called')
            self.assertEquals(doc.presentation.SlideShowWindow.View.GotoSlide.called, True,
                              'View.GotoSlide should have been called because of the PowerPoint version')
            self.assertEquals(doc.presentation.SlideShowWindow.View.GotoClick.called, True,
                              'View.GotoClick should have been called because of the PowerPoint version')
    def unblank_screen_test(self):
        """
        Test that unblank_screen works as expected
        """
        # GIVEN: A Document with mocked controller, presentation, ScreenList, and mocked function get_slide_number
        with patch('openlp.plugins.presentations.lib.powerpointcontroller.ScreenList') as mocked_screen_list:
            mocked_screen_list_ret = MagicMock()
            mocked_screen_list_ret.screen_list = [1]
            mocked_screen_list.return_value = mocked_screen_list_ret
            doc = PowerpointDocument(self.mock_controller, self.mock_presentation)
            doc.presentation = MagicMock()
            doc.presentation.SlideShowWindow.View.GetClickIndex.return_value = 3
            doc.presentation.Application.Version = 14.0
            doc.get_slide_number = MagicMock()
            doc.get_slide_number.return_value = 2
            doc.index_map[1] = 1
            doc.blank_slide = 1
            doc.blank_click = 1

            # WHEN: Calling goto_slide
            doc.unblank_screen()

            # THEN: The view state have new value, and several function should have been called
            self.assertEquals(doc.presentation.SlideShowWindow.View.State, 1, 'The View State should be 1')
            self.assertEquals(doc.presentation.SlideShowWindow.Activate.called, True,
                              'SlideShowWindow.Activate should have been called')
            self.assertEquals(doc.presentation.SlideShowWindow.View.GotoSlide.called, True,
                              'View.GotoSlide should have been called because of the PowerPoint version')
            self.assertEquals(doc.presentation.SlideShowWindow.View.GotoClick.called, True,
                              'View.GotoClick should have been called because of the PowerPoint version')
Exemple #3
0
    def test_create_titles_and_notes_with_no_slides(self):
        """
        Test creating the titles from PowerPoint when it returns no slides
        """
        # GIVEN: mocked save_titles_and_notes, _get_text_from_shapes and two mocked slides
        doc = PowerpointDocument(self.mock_controller, self.file_name)
        doc.save_titles_and_notes = MagicMock()
        doc._PowerpointDocument__get_text_from_shapes = MagicMock()
        pres = MagicMock()
        pres.Slides = []
        doc.presentation = pres

        # WHEN reading the titles and notes
        doc.create_titles_and_notes()

        # THEN the save should have been called exactly once with empty titles and notes
        doc.save_titles_and_notes.assert_called_once_with([], [])
    def create_titles_and_notes_with_no_slides_test(self):
        """
        Test creating the titles from PowerPoint when it returns no slides
        """
        # GIVEN: mocked save_titles_and_notes, _get_text_from_shapes and two mocked slides
        doc = PowerpointDocument(self.mock_controller, self.file_name)
        doc.save_titles_and_notes = MagicMock()
        doc._PowerpointDocument__get_text_from_shapes = MagicMock()
        pres = MagicMock()
        pres.Slides = []
        doc.presentation = pres

        # WHEN reading the titles and notes
        doc.create_titles_and_notes()

        # THEN the save should have been called exactly once with empty titles and notes
        doc.save_titles_and_notes.assert_called_once_with([], [])
Exemple #5
0
    def test_blank_screen(self):
        """
        Test that blank_screen works as expected
        """
        # GIVEN: A Document with mocked controller, presentation, and mocked function get_slide_number
        doc = PowerpointDocument(self.mock_controller, self.mock_presentation)
        doc.presentation = MagicMock()
        doc.presentation.SlideShowWindow.View.GetClickIndex.return_value = 3
        doc.presentation.Application.Version = 14.0
        doc.get_slide_number = MagicMock()
        doc.get_slide_number.return_value = 2

        # WHEN: Calling goto_slide
        doc.blank_screen()

        # THEN: The view state, doc.blank_slide and doc.blank_click should have new values
        self.assertEquals(doc.presentation.SlideShowWindow.View.State, 3, 'The View State should be 3')
        self.assertEquals(doc.blank_slide, 2, 'doc.blank_slide should be 2 because of the PowerPoint version')
        self.assertEquals(doc.blank_click, 3, 'doc.blank_click should be 3 because of the PowerPoint version')
Exemple #6
0
    def test_goto_slide(self):
        """
        Test that goto_slide goes to next effect if the slide is already displayed
        """
        # GIVEN: A Document with mocked controller, presentation, and mocked functions get_slide_number and next_step
        doc = PowerpointDocument(self.mock_controller, self.mock_presentation)
        doc.presentation = MagicMock()
        doc.presentation.SlideShowWindow.View.GetClickIndex.return_value = 1
        doc.presentation.SlideShowWindow.View.GetClickCount.return_value = 2
        doc.get_slide_number = MagicMock()
        doc.get_slide_number.return_value = 1
        doc.next_step = MagicMock()
        doc.index_map[1] = 1

        # WHEN: Calling goto_slide
        doc.goto_slide(1)

        # THEN: next_step() should be call to try to advance to the next effect.
        self.assertTrue(doc.next_step.called, 'next_step() should have been called!')
    def blank_screen_test(self):
        """
        Test that blank_screen works as expected
        """
        # GIVEN: A Document with mocked controller, presentation, and mocked function get_slide_number
        doc = PowerpointDocument(self.mock_controller, self.mock_presentation)
        doc.presentation = MagicMock()
        doc.presentation.SlideShowWindow.View.GetClickIndex.return_value = 3
        doc.presentation.Application.Version = 14.0
        doc.get_slide_number = MagicMock()
        doc.get_slide_number.return_value = 2

        # WHEN: Calling goto_slide
        doc.blank_screen()

        # THEN: The view state, doc.blank_slide and doc.blank_click should have new values
        self.assertEquals(doc.presentation.SlideShowWindow.View.State, 3, 'The View State should be 3')
        self.assertEquals(doc.blank_slide, 2, 'doc.blank_slide should be 2 because of the PowerPoint version')
        self.assertEquals(doc.blank_click, 3, 'doc.blank_click should be 3 because of the PowerPoint version')
    def goto_slide_test(self):
        """
        Test that goto_slide goes to next effect if the slide is already displayed
        """
        # GIVEN: A Document with mocked controller, presentation, and mocked functions get_slide_number and next_step
        doc = PowerpointDocument(self.mock_controller, self.mock_presentation)
        doc.presentation = MagicMock()
        doc.presentation.SlideShowWindow.View.GetClickIndex.return_value = 1
        doc.presentation.SlideShowWindow.View.GetClickCount.return_value = 2
        doc.get_slide_number = MagicMock()
        doc.get_slide_number.return_value = 1
        doc.next_step = MagicMock()
        doc.index_map[1] = 1

        # WHEN: Calling goto_slide
        doc.goto_slide(1)

        # THEN: next_step() should be call to try to advance to the next effect.
        self.assertTrue(doc.next_step.called, 'next_step() should have been called!')
Exemple #9
0
    def test_show_error_msg(self):
        """
        Test the PowerpointDocument.show_error_msg() method gets called on com exception
        """
        if is_win():
            # GIVEN: A PowerpointDocument with mocked controller and presentation
            with patch('openlp.plugins.presentations.lib.powerpointcontroller.critical_error_message_box') as \
                    mocked_critical_error_message_box:
                instance = PowerpointDocument(self.mock_controller, self.mock_presentation)
                instance.presentation = MagicMock()
                instance.presentation.SlideShowWindow.View.GotoSlide = MagicMock(side_effect=pywintypes.com_error('1'))
                instance.index_map[42] = 42

                # WHEN: Calling goto_slide which will throw an exception
                instance.goto_slide(42)

                # THEN: mocked_critical_error_message_box should have been called
                mocked_critical_error_message_box.assert_called_with('Error', 'An error occurred in the Powerpoint '
                                                                     'integration and the presentation will be stopped.'
                                                                     ' Restart the presentation if you wish to '
                                                                     'present it.')
    def show_error_msg_test(self):
        """
        Test the PowerpointDocument.show_error_msg() method gets called on com exception
        """
        if is_win():
            # GIVEN: A PowerpointDocument with mocked controller and presentation
            with patch('openlp.plugins.presentations.lib.powerpointcontroller.critical_error_message_box') as \
                    mocked_critical_error_message_box:
                instance = PowerpointDocument(self.mock_controller, self.mock_presentation)
                instance.presentation = MagicMock()
                instance.presentation.SlideShowWindow.View.GotoSlide = MagicMock(side_effect=pywintypes.com_error('1'))
                instance.index_map[42] = 42

                # WHEN: Calling goto_slide which will throw an exception
                instance.goto_slide(42)

                # THEN: mocked_critical_error_message_box should have been called
                mocked_critical_error_message_box.assert_called_with('Error', 'An error occurred in the Powerpoint '
                                                                     'integration and the presentation will be stopped.'
                                                                     ' Restart the presentation if you wish to '
                                                                     'present it.')