Fix up presentation tests

This commit is contained in:
Tim Bentley 2014-03-04 20:18:14 +00:00
parent 43f156d9fe
commit 1301b4cfa3
4 changed files with 33 additions and 31 deletions

View File

@ -93,11 +93,7 @@ class TestMediaItem(TestCase):
self.media_item.build_file_mask_string()
# THEN: The file mask should be generated correctly
self.assertIn('*.odp', self.media_item.on_new_file_masks,
'The file mask should contain the odp extension')
self.assertIn('*.ppt', self.media_item.on_new_file_masks,
'The file mask should contain the ppt extension')
self.assertIn('*.pdf', self.media_item.on_new_file_masks,
'The file mask should contain the pdf extension')
self.assertIn('*.xps', self.media_item.on_new_file_masks,
'The file mask should contain the xps extension')
self.assertIn('*.odp', self.media_item.on_new_file_masks, 'The file mask should contain the odp extension')
self.assertIn('*.ppt', self.media_item.on_new_file_masks, 'The file mask should contain the ppt extension')
self.assertIn('*.pdf', self.media_item.on_new_file_masks, 'The file mask should contain the pdf extension')
self.assertIn('*.xps', self.media_item.on_new_file_masks, 'The file mask should contain the xps extension')

View File

@ -77,7 +77,7 @@ class TestPdfController(TestCase):
def constructor_test(self):
"""
Test the Constructor
Test the Constructor from the PdfController
"""
# GIVEN: No presentation controller
controller = None
@ -90,7 +90,7 @@ class TestPdfController(TestCase):
def load_pdf_test(self):
"""
Test loading of a Pdf
Test loading of a Pdf using the PdfController
"""
# GIVEN: A Pdf-file
test_file = os.path.join(TEST_RESOURCES_PATH, 'presentations', 'pdf_test1.pdf')

View File

@ -29,7 +29,7 @@
"""
This module contains tests for the pptviewcontroller module of the Presentations plugin.
"""
import os
from unittest import TestCase
from tests.functional import MagicMock, patch
@ -43,6 +43,7 @@ from openlp.plugins.presentations.lib.pptviewcontroller import PptviewDocument
# start_process(self)
# kill
class TestPptviewDocument(TestCase):
"""
Test the PptviewDocument Class
@ -78,8 +79,8 @@ class TestPptviewDocument(TestCase):
'openlp.plugins.presentations.lib.pptviewcontroller.PresentationDocument.get_temp_folder')
self.presentation_document_setup_patcher = patch(
'openlp.plugins.presentations.lib.pptviewcontroller.PresentationDocument._setup')
self.rect_patcher = patch('openlp.plugins.presentations.lib.pptviewcontroller.RECT')
self.screen_list_patcher = patch('openlp.plugins.presentations.lib.pptviewcontroller.ScreenList')
self.rect_patcher = MagicMock()
self.mock_os = self.os_patcher.start()
self.mock_pptview_document_create_thumbnails = self.pptview_document_create_thumbnails_patcher.start()
@ -118,12 +119,14 @@ class TestPptviewDocument(TestCase):
self.mock_controller.process.OpenPPT.return_value = 0
instance = PptviewDocument(self.mock_controller, self.mock_presentation)
instance.filepath = 'test\path.ppt'
result = instance.load_presentation()
# THEN: PptviewDocument.load_presentation should return True
self.assertTrue(result)
if os.name == 'nt':
result = instance.load_presentation()
def load_presentation_unsuccesfull_test(self):
# THEN: PptviewDocument.load_presentation should return True
self.assertTrue(result)
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
@ -136,8 +139,9 @@ class TestPptviewDocument(TestCase):
self.mock_controller.process.OpenPPT.return_value = -1
instance = PptviewDocument(self.mock_controller, self.mock_presentation)
instance.filepath = 'test\path.ppt'
result = instance.load_presentation()
if os.name == 'nt':
result = instance.load_presentation()
# THEN: The temporary directory should be created and PptviewDocument.load_presentation should return False
self.mock_os.makedirs.assert_called_once_with('temp folder')
self.assertFalse(result)
# THEN: The temporary directory should be created and PptviewDocument.load_presentation should return False
self.mock_os.makedirs.assert_called_once_with('temp folder')
self.assertFalse(result)

View File

@ -34,6 +34,7 @@ from unittest import TestCase
from openlp.plugins.presentations.lib.presentationcontroller import PresentationController, PresentationDocument
from tests.functional import MagicMock, patch
class TestPresentationController(TestCase):
"""
Test the PresentationController.
@ -65,6 +66,7 @@ class TestPresentationController(TestCase):
self.assertEqual('PresentationController', controller.name,
'The name of the presentation controller should be correct')
class TestPresentationDocument(TestCase):
"""
Test the PresentationDocument Class
@ -101,12 +103,12 @@ class TestPresentationDocument(TestCase):
"""
Set up the patches and mocks need for all tests.
"""
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')
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')
self.mock_check_directory_exists = self.check_directory_exists_patcher.start()
self.mock_get_thumbnail_folder = self.get_thumbnail_folder_patcher.start()
@ -124,29 +126,29 @@ class TestPresentationDocument(TestCase):
self.get_thumbnail_folder_patcher.stop()
self._setup_patcher.stop()
def initalise_presentation_document_test(self):
def initialise_presentation_document_test(self):
"""
Test the PresentationDocument __init__ method when initalising the PresentationDocument Class
Test the PresentationDocument __init__ method when initialising the PresentationDocument Class
"""
# GIVEN: A reset mock_setup and mocked controller
self.mock_setup.reset()
# WHEN: Creating an instance of PresentationDocument
instance = PresentationDocument(self.mock_controller, 'Name')
PresentationDocument(self.mock_controller, 'Name')
# 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):
"""
Test the PresentationDocument _setup method when initalising the PresentationDocument Class
Test the PresentationDocument _setup method when initialising the PresentationDocument Class
"""
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
instance = PresentationDocument(self.mock_controller, 'Name')
PresentationDocument(self.mock_controller, 'Name')
# THEN: check_directory_exists should have been called with the correct arguments
self.mock_check_directory_exists.assert_called_once_with('returned/path/')