2013-10-19 23:18:31 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
# OpenLP - Open Source Lyrics Projection #
|
|
|
|
# --------------------------------------------------------------------------- #
|
|
|
|
# Copyright (c) 2008-2013 Raoul Snyman #
|
|
|
|
# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan #
|
|
|
|
# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
|
|
|
|
# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
|
|
|
|
# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
|
|
|
|
# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
|
|
|
|
# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, #
|
|
|
|
# Frode Woldsund, Martin Zibricky, Patrick Zimmermann #
|
|
|
|
# --------------------------------------------------------------------------- #
|
|
|
|
# This program is free software; you can redistribute it and/or modify it #
|
|
|
|
# under the terms of the GNU General Public License as published by the Free #
|
|
|
|
# Software Foundation; version 2 of the License. #
|
|
|
|
# #
|
|
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT #
|
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
|
|
|
|
# more details. #
|
|
|
|
# #
|
|
|
|
# You should have received a copy of the GNU General Public License along #
|
|
|
|
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
|
|
|
|
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
|
|
|
###############################################################################
|
|
|
|
"""
|
|
|
|
Functional tests to test the PowerPointController class and related methods.
|
|
|
|
"""
|
|
|
|
from unittest import TestCase
|
|
|
|
import os
|
2013-10-28 02:33:28 +00:00
|
|
|
from mock import MagicMock
|
|
|
|
from openlp.plugins.presentations.lib.powerpointcontroller import \
|
|
|
|
PowerpointController, PowerpointDocument, _get_text_from_shapes
|
2013-10-19 23:18:31 +00:00
|
|
|
|
2013-10-28 02:33:28 +00:00
|
|
|
TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..',
|
|
|
|
'..', 'resources'))
|
2013-10-19 23:18:31 +00:00
|
|
|
|
|
|
|
class TestLibModule(TestCase):
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
mocked_plugin = MagicMock()
|
|
|
|
mocked_plugin.settings_section = 'presentations'
|
|
|
|
self.ppc = PowerpointController(mocked_plugin)
|
2013-10-28 15:16:22 +00:00
|
|
|
self.file_name = os.path.join(TEST_PATH, "test.pptx")
|
|
|
|
self.doc = PowerpointDocument(self.ppc, self.file_name)
|
2013-10-25 01:15:44 +00:00
|
|
|
|
|
|
|
# add _test to the name to enable
|
|
|
|
def verify_installation(self):
|
2013-10-19 23:18:31 +00:00
|
|
|
"""
|
|
|
|
Test the installation of Powerpoint
|
|
|
|
"""
|
|
|
|
# GIVEN: A boolean value set to true
|
|
|
|
# WHEN: We "convert" it to a bool
|
2013-10-28 02:33:28 +00:00
|
|
|
is_installed = self.ppc.check_available()
|
2013-10-19 23:18:31 +00:00
|
|
|
# THEN: We should get back a True bool
|
2013-10-28 02:33:28 +00:00
|
|
|
self.assertEqual(is_installed, True, 'The result should be True')
|
2013-10-19 23:18:31 +00:00
|
|
|
|
|
|
|
# add _test to the following if necessary
|
|
|
|
def verify_loading_document(self):
|
|
|
|
"""
|
|
|
|
Test loading a document in PowerPoint
|
|
|
|
"""
|
|
|
|
# GIVEN: the filename
|
|
|
|
print(self.file_name)
|
|
|
|
# WHEN: loading the filename
|
2013-10-28 15:16:22 +00:00
|
|
|
self.doc = PowerpointDocument(self.ppc, self.file_name)
|
2013-10-19 23:18:31 +00:00
|
|
|
self.doc.load_presentation()
|
|
|
|
result = self.doc.is_loaded()
|
|
|
|
# THEN: result should be true
|
2013-10-28 02:33:28 +00:00
|
|
|
self.assertEqual(result, True, 'The result should be True')
|
2013-10-19 23:18:31 +00:00
|
|
|
|
2013-10-25 01:15:44 +00:00
|
|
|
def create_titles_and_notes_test(self):
|
2013-10-19 23:18:31 +00:00
|
|
|
"""
|
2013-10-25 01:15:44 +00:00
|
|
|
Test creating the titles from PowerPoint
|
2013-10-19 23:18:31 +00:00
|
|
|
"""
|
2013-10-25 01:15:44 +00:00
|
|
|
# GIVEN: mocked save_titles_and_notes, _get_text_from_shapes and two mocked slides
|
2013-10-28 15:16:22 +00:00
|
|
|
self.doc = PowerpointDocument(self.ppc, self.file_name)
|
2013-10-25 01:15:44 +00:00
|
|
|
self.doc.save_titles_and_notes = MagicMock()
|
|
|
|
self.doc._PowerpointDocument__get_text_from_shapes = MagicMock()
|
|
|
|
slide = MagicMock()
|
|
|
|
slide.Shapes.Title.TextFrame.TextRange.Text = 'SlideText'
|
|
|
|
pres = MagicMock()
|
2013-10-28 15:16:22 +00:00
|
|
|
pres.Slides = [slide, slide]
|
2013-10-25 01:15:44 +00:00
|
|
|
self.doc.presentation = pres
|
|
|
|
# WHEN reading the titles and notes
|
2013-10-19 23:18:31 +00:00
|
|
|
self.doc.create_titles_and_notes()
|
2013-10-25 01:15:44 +00:00
|
|
|
# THEN the save should have been called exactly once with 2 titles and 2 notes
|
2013-10-28 02:33:28 +00:00
|
|
|
self.doc.save_titles_and_notes.assert_called_once_with(
|
|
|
|
['SlideText\n', 'SlideText\n'], [' ', ' '])
|
2013-10-25 01:15:44 +00:00
|
|
|
|
|
|
|
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
|
2013-10-28 15:16:22 +00:00
|
|
|
self.doc = PowerpointDocument(self.ppc, self.file_name)
|
2013-10-25 01:15:44 +00:00
|
|
|
self.doc.save_titles_and_notes = MagicMock()
|
|
|
|
self.doc._PowerpointDocument__get_text_from_shapes = MagicMock()
|
|
|
|
pres = MagicMock()
|
|
|
|
pres.Slides = []
|
|
|
|
self.doc.presentation = pres
|
2013-10-19 23:18:31 +00:00
|
|
|
# WHEN reading the titles and notes
|
2013-10-25 01:15:44 +00:00
|
|
|
self.doc.create_titles_and_notes()
|
|
|
|
# THEN the save should have been called exactly once with empty titles and notes
|
|
|
|
self.doc.save_titles_and_notes.assert_called_once_with([], [])
|
|
|
|
|
|
|
|
def get_text_from_shapes_test(self):
|
|
|
|
"""
|
|
|
|
Test getting text from powerpoint shapes
|
|
|
|
"""
|
|
|
|
# GIVEN: mocked
|
|
|
|
shape = MagicMock()
|
|
|
|
shape.PlaceholderFormat.Type = 2
|
|
|
|
shape.HasTextFrame = shape.TextFrame.HasText = True
|
|
|
|
shape.TextFrame.TextRange.Text = 'slideText'
|
2013-10-28 15:16:22 +00:00
|
|
|
shapes = [shape, shape]
|
2013-10-25 01:15:44 +00:00
|
|
|
result = _get_text_from_shapes(shapes)
|
2013-10-28 02:33:28 +00:00
|
|
|
self.assertEqual(result, 'slideText\nslideText\n',
|
|
|
|
'result should match \'slideText\nslideText\n\'')
|
|
|
|
|
2013-10-25 01:15:44 +00:00
|
|
|
def get_text_from_shapes_with_no_shapes_test(self):
|
|
|
|
"""
|
|
|
|
Test getting text from powerpoint shapes with no shapes
|
|
|
|
"""
|
|
|
|
# GIVEN: mocked
|
|
|
|
shapes = []
|
|
|
|
result = _get_text_from_shapes(shapes)
|
2013-10-28 02:33:28 +00:00
|
|
|
self.assertEqual(result, '', 'result should be empty')
|