2013-11-16 10:05:41 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
# OpenLP - Open Source Lyrics Projection #
|
|
|
|
# --------------------------------------------------------------------------- #
|
2014-02-11 20:29:57 +00:00
|
|
|
# Copyright (c) 2008-2014 Raoul Snyman #
|
|
|
|
# Portions copyright (c) 2008-2014 Tim Bentley, Gerald Britton, Jonathan #
|
2013-11-16 10:05:41 +00:00
|
|
|
# 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 #
|
|
|
|
###############################################################################
|
|
|
|
"""
|
2014-02-11 20:29:57 +00:00
|
|
|
This module contains tests for the Presentation Controller.
|
2013-11-16 10:05:41 +00:00
|
|
|
"""
|
|
|
|
from unittest import TestCase
|
|
|
|
|
2014-02-11 20:29:57 +00:00
|
|
|
from openlp.plugins.presentations.lib.presentationcontroller import PresentationController, PresentationDocument
|
2013-11-16 10:16:06 +00:00
|
|
|
from tests.functional import MagicMock, patch
|
|
|
|
|
2014-03-04 20:18:14 +00:00
|
|
|
|
2014-02-11 20:29:57 +00:00
|
|
|
class TestPresentationController(TestCase):
|
|
|
|
"""
|
|
|
|
Test the PresentationController.
|
|
|
|
"""
|
|
|
|
# TODO: Items left to test
|
|
|
|
# PresentationController
|
|
|
|
# __init__
|
|
|
|
# enabled
|
|
|
|
# is_available
|
|
|
|
# check_available
|
|
|
|
# start_process
|
|
|
|
# kill
|
|
|
|
# add_document
|
|
|
|
# remove_doc
|
|
|
|
# close_presentation
|
|
|
|
# _get_plugin_manager
|
|
|
|
|
2014-02-11 21:07:06 +00:00
|
|
|
def constructor_test(self):
|
2014-02-11 20:29:57 +00:00
|
|
|
"""
|
|
|
|
Test the Constructor
|
|
|
|
"""
|
|
|
|
# GIVEN: No presentation controller
|
|
|
|
controller = None
|
2013-11-16 10:05:41 +00:00
|
|
|
|
2014-02-11 20:29:57 +00:00
|
|
|
# WHEN: The presentation controller object is created
|
2014-03-13 20:59:10 +00:00
|
|
|
mock_plugin = MagicMock()
|
|
|
|
mock_plugin.settings_section = ''
|
|
|
|
controller = PresentationController(plugin=mock_plugin)
|
2013-11-16 10:05:41 +00:00
|
|
|
|
2014-02-11 20:29:57 +00:00
|
|
|
# THEN: The name of the presentation controller should be correct
|
|
|
|
self.assertEqual('PresentationController', controller.name,
|
|
|
|
'The name of the presentation controller should be correct')
|
2013-11-16 10:05:41 +00:00
|
|
|
|
2014-03-04 20:18:14 +00:00
|
|
|
|
2013-11-16 10:54:24 +00:00
|
|
|
class TestPresentationDocument(TestCase):
|
2013-11-16 10:05:41 +00:00
|
|
|
"""
|
2013-11-16 10:54:24 +00:00
|
|
|
Test the PresentationDocument Class
|
2013-11-16 10:05:41 +00:00
|
|
|
"""
|
|
|
|
# TODO: Items left to test
|
|
|
|
# PresentationDocument
|
|
|
|
# __init__
|
|
|
|
# load_presentation
|
|
|
|
# presentation_deleted
|
|
|
|
# get_file_name
|
|
|
|
# get_thumbnail_folder
|
|
|
|
# get_temp_folder
|
|
|
|
# check_thumbnails
|
|
|
|
# close_presentation
|
|
|
|
# is_active
|
|
|
|
# is_loaded
|
|
|
|
# blank_screen
|
|
|
|
# unblank_screen
|
|
|
|
# is_blank
|
|
|
|
# stop_presentation
|
|
|
|
# start_presentation
|
|
|
|
# get_slide_number
|
|
|
|
# get_slide_count
|
|
|
|
# goto_slide
|
|
|
|
# next_step
|
|
|
|
# previous_step
|
|
|
|
# convert_thumbnail
|
|
|
|
# get_thumbnail_path
|
|
|
|
# poll_slidenumber
|
|
|
|
# get_slide_text
|
|
|
|
# get_slide_notes
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
"""
|
|
|
|
Set up the patches and mocks need for all tests.
|
|
|
|
"""
|
2014-03-04 20:18:14 +00:00
|
|
|
self.check_directory_exists_patcher = \
|
|
|
|
patch('openlp.plugins.presentations.lib.presentationcontroller.check_directory_exists')
|
|
|
|
self.get_thumbnail_folder_patcher = \
|
|
|
|
patch('openlp.plugins.presentations.lib.presentationcontroller.PresentationDocument.get_thumbnail_folder')
|
|
|
|
self._setup_patcher = \
|
|
|
|
patch('openlp.plugins.presentations.lib.presentationcontroller.PresentationDocument._setup')
|
2013-11-16 10:05:41 +00:00
|
|
|
|
|
|
|
self.mock_check_directory_exists = self.check_directory_exists_patcher.start()
|
|
|
|
self.mock_get_thumbnail_folder = self.get_thumbnail_folder_patcher.start()
|
|
|
|
self.mock_setup = self._setup_patcher.start()
|
|
|
|
|
|
|
|
self.mock_controller = MagicMock()
|
|
|
|
|
|
|
|
self.mock_get_thumbnail_folder.return_value = 'returned/path/'
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
"""
|
|
|
|
Stop the patches
|
|
|
|
"""
|
|
|
|
self.check_directory_exists_patcher.stop()
|
|
|
|
self.get_thumbnail_folder_patcher.stop()
|
|
|
|
self._setup_patcher.stop()
|
|
|
|
|
2014-03-04 20:18:14 +00:00
|
|
|
def initialise_presentation_document_test(self):
|
2013-11-16 10:05:41 +00:00
|
|
|
"""
|
2014-03-04 20:18:14 +00:00
|
|
|
Test the PresentationDocument __init__ method when initialising the PresentationDocument Class
|
2013-11-16 10:05:41 +00:00
|
|
|
"""
|
|
|
|
# GIVEN: A reset mock_setup and mocked controller
|
|
|
|
self.mock_setup.reset()
|
|
|
|
|
|
|
|
# WHEN: Creating an instance of PresentationDocument
|
2014-03-04 20:18:14 +00:00
|
|
|
PresentationDocument(self.mock_controller, 'Name')
|
2013-11-16 10:05:41 +00:00
|
|
|
|
|
|
|
# THEN: PresentationDocument.__init__ should have been called with the correct arguments
|
|
|
|
self.mock_setup.assert_called_once_with('Name')
|
|
|
|
|
|
|
|
def presentation_document_setup_test(self):
|
|
|
|
"""
|
2014-03-04 20:18:14 +00:00
|
|
|
Test the PresentationDocument _setup method when initialising the PresentationDocument Class
|
2013-11-16 10:05:41 +00:00
|
|
|
"""
|
|
|
|
self._setup_patcher.stop()
|
|
|
|
|
|
|
|
# GIVEN: A mocked controller, patched check_directory_exists_patcher and patched get_thumbnail_folder method
|
|
|
|
|
|
|
|
# WHEN: Creating an instance of PresentationDocument
|
2014-03-04 20:18:14 +00:00
|
|
|
PresentationDocument(self.mock_controller, 'Name')
|
2013-11-16 10:05:41 +00:00
|
|
|
|
|
|
|
# THEN: check_directory_exists should have been called with the correct arguments
|
|
|
|
self.mock_check_directory_exists.assert_called_once_with('returned/path/')
|
|
|
|
|
|
|
|
self._setup_patcher.start()
|