Ejemplo n.º 1
0
    def create_titles_and_notes_test(self):
        """
        Test PowerpointController.create_titles_and_notes
        """
        # GIVEN: mocked PresentationController.save_titles_and_notes and a pptx file
        doc = PptviewDocument(self.mock_controller, self.mock_presentation)
        doc.file_path = os.path.join(TEST_RESOURCES_PATH, 'presentations', 'test.pptx')
        doc.save_titles_and_notes = MagicMock()

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

        # THEN save_titles_and_notes should have been called once with empty arrays
        doc.save_titles_and_notes.assert_called_once_with(['Test 1\n', '\n', 'Test 2\n', 'Test 4\n', 'Test 3\n'],
                                                          ['Notes for slide 1', 'Inserted', 'Notes for slide 2',
                                                           'Notes \nfor slide 4', 'Notes for slide 3'])
Ejemplo n.º 2
0
    def load_presentation_succesfull_test(self):
        """
        Test the PptviewDocument.load_presentation() method when the PPT is successfully opened
        """
        # GIVEN: A reset mocked_os
        self.mock_os_isdir.reset()

        # WHEN: The temporary directory exists and OpenPPT returns successfully (not -1)
        self.mock_os_isdir.return_value = True
        self.mock_controller.process.OpenPPT.return_value = 0
        instance = PptviewDocument(self.mock_controller, self.mock_presentation)
        instance.file_path = 'test\path.ppt'

        if is_win():
            result = instance.load_presentation()

            # THEN: PptviewDocument.load_presentation should return True
            self.assertTrue(result)
Ejemplo n.º 3
0
    def test_load_presentation_succesfull(self):
        """
        Test the PptviewDocument.load_presentation() method when the PPT is successfully opened
        """
        # GIVEN: A reset mocked_os
        self.mock_os_isdir.reset()

        # WHEN: The temporary directory exists and OpenPPT returns successfully (not -1)
        self.mock_os_isdir.return_value = True
        self.mock_controller.process.OpenPPT.return_value = 0
        instance = PptviewDocument(self.mock_controller,
                                   self.mock_presentation)
        instance.file_path = 'test\path.ppt'

        if is_win():
            result = instance.load_presentation()

            # THEN: PptviewDocument.load_presentation should return True
            self.assertTrue(result)
Ejemplo n.º 4
0
    def create_titles_and_notes_invalid_file_test(self):
        """
        Test PowerpointController.create_titles_and_notes with invalid file
        """
        # GIVEN: mocked PresentationController.save_titles_and_notes and an invalid file
        with patch('builtins.open') as mocked_open, \
                patch('openlp.plugins.presentations.lib.pptviewcontroller.zipfile.is_zipfile') as mocked_is_zf:
            mocked_is_zf.return_value = False
            mocked_open.filesize = 10
            doc = PptviewDocument(self.mock_controller, self.mock_presentation)
            doc.file_path = os.path.join(TEST_RESOURCES_PATH, 'presentations', 'test.ppt')
            doc.save_titles_and_notes = MagicMock()

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

            # THEN:
            doc.save_titles_and_notes.assert_called_once_with(None, None)
            self.assertEqual(mocked_is_zf.call_count, 1, 'is_zipfile should have been called once')
Ejemplo n.º 5
0
    def load_presentation_un_succesfull_test(self):
        """
        Test the PptviewDocument.load_presentation() method when the temporary directory does not exist and the PPT is
        not successfully opened
        """
        # GIVEN: A reset mock_os_isdir
        self.mock_os_isdir.reset()

        # WHEN: The temporary directory does not exist and OpenPPT returns unsuccessfully (-1)
        with patch('openlp.plugins.presentations.lib.pptviewcontroller.os.makedirs') as mock_makedirs:
            self.mock_os_isdir.return_value = False
            self.mock_controller.process.OpenPPT.return_value = -1
            instance = PptviewDocument(self.mock_controller, self.mock_presentation)
            instance.file_path = 'test\path.ppt'
            if is_win():
                result = instance.load_presentation()

                # THEN: The temp folder should be created and PptviewDocument.load_presentation should return False
                mock_makedirs.assert_called_once_with(self.temp_folder)
                self.assertFalse(result)
Ejemplo n.º 6
0
    def create_titles_and_notes_nonexistent_file_test(self):
        """
        Test PowerpointController.create_titles_and_notes with nonexistent file
        """
        # GIVEN: mocked PresentationController.save_titles_and_notes and an nonexistent file
        with patch('builtins.open') as mocked_open, \
                patch('openlp.plugins.presentations.lib.pptviewcontroller.os.path.exists') as mocked_exists, \
                patch('openlp.plugins.presentations.lib.presentationcontroller.check_directory_exists') as \
                mocked_dir_exists:
            mocked_exists.return_value = False
            mocked_dir_exists.return_value = False
            doc = PptviewDocument(self.mock_controller, self.mock_presentation)
            doc.file_path = 'Idontexist.pptx'
            doc.save_titles_and_notes = MagicMock()

            # WHEN: Reading the titles and notes
            doc.create_titles_and_notes()

            # THEN: File existens should have been checked, and not have been opened.
            doc.save_titles_and_notes.assert_called_once_with(None, None)
            mocked_exists.assert_any_call('Idontexist.pptx')
            self.assertEqual(mocked_open.call_count, 0, 'There should be no calls to open a file.')
Ejemplo n.º 7
0
    def test_load_presentation_un_succesfull(self):
        """
        Test the PptviewDocument.load_presentation() method when the temporary directory does not exist and the PPT is
        not successfully opened
        """
        # GIVEN: A reset mock_os_isdir
        self.mock_os_isdir.reset()

        # WHEN: The temporary directory does not exist and OpenPPT returns unsuccessfully (-1)
        with patch(
                'openlp.plugins.presentations.lib.pptviewcontroller.os.makedirs'
        ) as mock_makedirs:
            self.mock_os_isdir.return_value = False
            self.mock_controller.process.OpenPPT.return_value = -1
            instance = PptviewDocument(self.mock_controller,
                                       self.mock_presentation)
            instance.file_path = 'test\path.ppt'
            if is_win():
                result = instance.load_presentation()

                # THEN: The temp folder should be created and PptviewDocument.load_presentation should return False
                mock_makedirs.assert_called_once_with(self.temp_folder)
                self.assertFalse(result)
Ejemplo n.º 8
0
    def test_create_titles_and_notes(self):
        """
        Test PowerpointController.create_titles_and_notes
        """
        # GIVEN: mocked PresentationController.save_titles_and_notes and a pptx file
        doc = PptviewDocument(self.mock_controller, self.mock_presentation)
        doc.file_path = os.path.join(TEST_RESOURCES_PATH, 'presentations',
                                     'test.pptx')
        doc.save_titles_and_notes = MagicMock()

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

        # THEN save_titles_and_notes should have been called once with empty arrays
        doc.save_titles_and_notes.assert_called_once_with(
            ['Test 1\n', '\n', 'Test 2\n', 'Test 4\n', 'Test 3\n'], [
                'Notes for slide 1', 'Inserted', 'Notes for slide 2',
                'Notes \nfor slide 4', 'Notes for slide 3'
            ])
Ejemplo n.º 9
0
    def test_create_titles_and_notes_invalid_file(self):
        """
        Test PowerpointController.create_titles_and_notes with invalid file
        """
        # GIVEN: mocked PresentationController.save_titles_and_notes and an invalid file
        with patch('builtins.open') as mocked_open, \
                patch('openlp.plugins.presentations.lib.pptviewcontroller.zipfile.is_zipfile') as mocked_is_zf:
            mocked_is_zf.return_value = False
            mocked_open.filesize = 10
            doc = PptviewDocument(self.mock_controller, self.mock_presentation)
            doc.file_path = os.path.join(TEST_RESOURCES_PATH, 'presentations',
                                         'test.ppt')
            doc.save_titles_and_notes = MagicMock()

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

            # THEN:
            doc.save_titles_and_notes.assert_called_once_with(None, None)
            self.assertEqual(mocked_is_zf.call_count, 1,
                             'is_zipfile should have been called once')
Ejemplo n.º 10
0
    def test_create_titles_and_notes_nonexistent_file(self):
        """
        Test PowerpointController.create_titles_and_notes with nonexistent file
        """
        # GIVEN: mocked PresentationController.save_titles_and_notes and an nonexistent file
        with patch('builtins.open') as mocked_open, \
                patch('openlp.plugins.presentations.lib.pptviewcontroller.os.path.exists') as mocked_exists, \
                patch('openlp.plugins.presentations.lib.presentationcontroller.check_directory_exists') as \
                mocked_dir_exists:
            mocked_exists.return_value = False
            mocked_dir_exists.return_value = False
            doc = PptviewDocument(self.mock_controller, self.mock_presentation)
            doc.file_path = 'Idontexist.pptx'
            doc.save_titles_and_notes = MagicMock()

            # WHEN: Reading the titles and notes
            doc.create_titles_and_notes()

            # THEN: File existens should have been checked, and not have been opened.
            doc.save_titles_and_notes.assert_called_once_with(None, None)
            mocked_exists.assert_any_call('Idontexist.pptx')
            self.assertEqual(mocked_open.call_count, 0,
                             'There should be no calls to open a file.')