openlp/tests/functional/openlp_plugins/presentations/test_pdfcontroller.py

109 lines
4.8 KiB
Python
Raw Normal View History

2013-12-29 19:46:04 +00:00
# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
# Copyright (c) 2008-2014 Raoul Snyman #
# Portions copyright (c) 2008-2014 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 #
###############################################################################
"""
This module contains tests for the PdfController
"""
import os
import shutil
from unittest import TestCase, SkipTest
2014-03-14 22:08:44 +00:00
from tempfile import mkdtemp
2013-12-29 19:46:04 +00:00
from openlp.plugins.presentations.lib.pdfcontroller import PdfController, PdfDocument
from tests.functional import MagicMock
from openlp.core.common import Settings
from openlp.core.lib import ScreenList
from tests.utils.constants import TEST_RESOURCES_PATH
2014-03-14 22:08:44 +00:00
from tests.helpers.testmixin import TestMixin
2013-12-29 19:46:04 +00:00
__default_settings__ = {
'presentations/enable_pdf_program': False
}
2014-03-14 22:08:44 +00:00
class TestPdfController(TestCase, TestMixin):
2013-12-29 19:46:04 +00:00
"""
Test the PdfController.
"""
def setUp(self):
"""
Set up the components need for all tests.
"""
2014-03-14 22:08:44 +00:00
self.get_application()
self.build_settings()
ScreenList.create(self.app.desktop())
2013-12-29 19:46:04 +00:00
Settings().extend_default_settings(__default_settings__)
self.temp_folder = mkdtemp()
self.thumbnail_folder = mkdtemp()
2014-03-13 20:59:10 +00:00
self.mock_plugin = MagicMock()
self.mock_plugin.settings_section = self.temp_folder
2013-12-29 19:46:04 +00:00
def tearDown(self):
"""
Delete all the C++ objects at the end so that we don't have a segfault
"""
try:
2014-03-14 22:08:44 +00:00
self.destroy_settings()
2013-12-29 19:46:04 +00:00
shutil.rmtree(self.thumbnail_folder)
shutil.rmtree(self.temp_folder)
except OSError:
pass
def constructor_test(self):
"""
2014-03-04 20:18:14 +00:00
Test the Constructor from the PdfController
2013-12-29 19:46:04 +00:00
"""
# GIVEN: No presentation controller
controller = None
# WHEN: The presentation controller object is created
2014-03-13 20:59:10 +00:00
controller = PdfController(plugin=self.mock_plugin)
2013-12-29 19:46:04 +00:00
# THEN: The name of the presentation controller should be correct
self.assertEqual('Pdf', controller.name, 'The name of the presentation controller should be correct')
def load_pdf_test(self):
"""
2014-03-04 20:18:14 +00:00
Test loading of a Pdf using the PdfController
2013-12-29 19:46:04 +00:00
"""
# GIVEN: A Pdf-file
test_file = os.path.join(TEST_RESOURCES_PATH, 'presentations', 'pdf_test1.pdf')
2013-12-29 19:46:04 +00:00
# WHEN: The Pdf is loaded
2014-03-13 20:59:10 +00:00
controller = PdfController(plugin=self.mock_plugin)
2013-12-29 19:46:04 +00:00
if not controller.check_available():
raise SkipTest('Could not detect mudraw or ghostscript, so skipping PDF test')
controller.temp_folder = self.temp_folder
controller.thumbnail_folder = self.thumbnail_folder
document = PdfDocument(controller, test_file)
loaded = document.load_presentation()
2013-12-29 19:46:04 +00:00
# THEN: The load should succeed and we should be able to get a pagecount
self.assertTrue(loaded, 'The loading of the PDF should succeed.')
self.assertEqual(3, document.get_slide_count(), 'The pagecount of the PDF should be 3.')