change to unix style lineending

This commit is contained in:
Tomas Groth 2014-07-11 14:54:00 +02:00
parent 9d64837602
commit 52f298fdc1
2 changed files with 325 additions and 325 deletions

View File

@ -1,175 +1,175 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 # vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
############################################################################### ###############################################################################
# OpenLP - Open Source Lyrics Projection # # OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- # # --------------------------------------------------------------------------- #
# Copyright (c) 2008-2014 Raoul Snyman # # Copyright (c) 2008-2014 Raoul Snyman #
# Portions copyright (c) 2008-2014 Tim Bentley, Gerald Britton, Jonathan # # Portions copyright (c) 2008-2014 Tim Bentley, Gerald Britton, Jonathan #
# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, # # Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. # # Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, # # Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, # # Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, # # Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, #
# Frode Woldsund, Martin Zibricky, Patrick Zimmermann # # Frode Woldsund, Martin Zibricky, Patrick Zimmermann #
# --------------------------------------------------------------------------- # # --------------------------------------------------------------------------- #
# This program is free software; you can redistribute it and/or modify it # # 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 # # under the terms of the GNU General Public License as published by the Free #
# Software Foundation; version 2 of the License. # # Software Foundation; version 2 of the License. #
# # # #
# This program is distributed in the hope that it will be useful, but WITHOUT # # This program is distributed in the hope that it will be useful, but WITHOUT #
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
# more details. # # more details. #
# # # #
# You should have received a copy of the GNU General Public License along # # 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 # # with this program; if not, write to the Free Software Foundation, Inc., 59 #
# Temple Place, Suite 330, Boston, MA 02111-1307 USA # # Temple Place, Suite 330, Boston, MA 02111-1307 USA #
############################################################################### ###############################################################################
""" """
Functional tests to test the Impress class and related methods. Functional tests to test the Impress class and related methods.
""" """
from unittest import TestCase from unittest import TestCase
import os import os
from tests.functional import patch, MagicMock from tests.functional import patch, MagicMock
from openlp.plugins.presentations.lib.impresscontroller import \ from openlp.plugins.presentations.lib.impresscontroller import \
ImpressController, ImpressDocument, TextType ImpressController, ImpressDocument, TextType
TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..', 'resources')) TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..', 'resources'))
class TestLibModule(TestCase): class TestLibModule(TestCase):
def setUp(self): def setUp(self):
mocked_plugin = MagicMock() mocked_plugin = MagicMock()
mocked_plugin.settings_section = 'presentations' mocked_plugin.settings_section = 'presentations'
self.file_name = os.path.join(TEST_PATH, 'test.pptx') self.file_name = os.path.join(TEST_PATH, 'test.pptx')
self.ppc = ImpressController(mocked_plugin) self.ppc = ImpressController(mocked_plugin)
self.doc = ImpressDocument(self.ppc, self.file_name) self.doc = ImpressDocument(self.ppc, self.file_name)
def create_titles_and_notes_test(self): def create_titles_and_notes_test(self):
""" """
Test ImpressDocument.create_titles_and_notes Test ImpressDocument.create_titles_and_notes
""" """
# GIVEN: mocked PresentationController.save_titles_and_notes with # GIVEN: mocked PresentationController.save_titles_and_notes with
# 0 pages and the LibreOffice Document # 0 pages and the LibreOffice Document
self.doc.save_titles_and_notes = MagicMock() self.doc.save_titles_and_notes = MagicMock()
self.doc.document = MagicMock() self.doc.document = MagicMock()
self.doc.document.getDrawPages.return_value = MagicMock() self.doc.document.getDrawPages.return_value = MagicMock()
self.doc.document.getDrawPages().getCount.return_value = 0 self.doc.document.getDrawPages().getCount.return_value = 0
# WHEN reading the titles and notes # WHEN reading the titles and notes
self.doc.create_titles_and_notes() self.doc.create_titles_and_notes()
# THEN save_titles_and_notes should have been called with empty arrays # THEN save_titles_and_notes should have been called with empty arrays
self.doc.save_titles_and_notes.assert_called_once_with([], []) self.doc.save_titles_and_notes.assert_called_once_with([], [])
# GIVEN: reset mock and set it to 2 pages # GIVEN: reset mock and set it to 2 pages
self.doc.save_titles_and_notes.reset_mock() self.doc.save_titles_and_notes.reset_mock()
self.doc.document.getDrawPages().getCount.return_value = 2 self.doc.document.getDrawPages().getCount.return_value = 2
# WHEN: a new call to create_titles_and_notes # WHEN: a new call to create_titles_and_notes
self.doc.create_titles_and_notes() self.doc.create_titles_and_notes()
# THEN: save_titles_and_notes should have been called once with # THEN: save_titles_and_notes should have been called once with
# two arrays of two elements # two arrays of two elements
self.doc.save_titles_and_notes.assert_called_once_with(['\n', '\n'], [' ', ' ']) self.doc.save_titles_and_notes.assert_called_once_with(['\n', '\n'], [' ', ' '])
def get_text_from_page_out_of_bound_test(self): def get_text_from_page_out_of_bound_test(self):
""" """
Test ImpressDocument.__get_text_from_page with out-of-bounds index Test ImpressDocument.__get_text_from_page with out-of-bounds index
""" """
# GIVEN: mocked LibreOffice Document with one slide, # GIVEN: mocked LibreOffice Document with one slide,
# two notes and three texts # two notes and three texts
self.doc.document = self._mock_a_LibreOffice_document(1, 2, 3) self.doc.document = self._mock_a_LibreOffice_document(1, 2, 3)
# WHEN: __get_text_from_page is called with an index of 0x00 # WHEN: __get_text_from_page is called with an index of 0x00
result = self.doc._ImpressDocument__get_text_from_page(0, TextType.Notes) result = self.doc._ImpressDocument__get_text_from_page(0, TextType.Notes)
# THEN: the result should be an empty string # THEN: the result should be an empty string
self.assertEqual(result, '', 'Result should be an empty string') self.assertEqual(result, '', 'Result should be an empty string')
# WHEN: regardless of the type of text, index 0x00 is out of bounds # WHEN: regardless of the type of text, index 0x00 is out of bounds
result = self.doc._ImpressDocument__get_text_from_page(0, TextType.Title) result = self.doc._ImpressDocument__get_text_from_page(0, TextType.Title)
# THEN: result should be an empty string # THEN: result should be an empty string
self.assertEqual(result, '', 'Result should be an empty string') self.assertEqual(result, '', 'Result should be an empty string')
# WHEN: when called with 2, it should also be out of bounds # WHEN: when called with 2, it should also be out of bounds
result = self.doc._ImpressDocument__get_text_from_page(2, TextType.SlideText) result = self.doc._ImpressDocument__get_text_from_page(2, TextType.SlideText)
# THEN: result should be an empty string ... and, getByIndex should # THEN: result should be an empty string ... and, getByIndex should
# have never been called # have never been called
self.assertEqual(result, '', 'Result should be an empty string') self.assertEqual(result, '', 'Result should be an empty string')
self.assertEqual(self.doc.document.getDrawPages().getByIndex.call_count, 0, self.assertEqual(self.doc.document.getDrawPages().getByIndex.call_count, 0,
'There should be no call to getByIndex') 'There should be no call to getByIndex')
def get_text_from_page_wrong_type_test(self): def get_text_from_page_wrong_type_test(self):
""" """
Test ImpressDocument.__get_text_from_page with wrong TextType Test ImpressDocument.__get_text_from_page with wrong TextType
""" """
# GIVEN: mocked LibreOffice Document with one slide, two notes and # GIVEN: mocked LibreOffice Document with one slide, two notes and
# three texts # three texts
self.doc.document = self._mock_a_LibreOffice_document(1, 2, 3) self.doc.document = self._mock_a_LibreOffice_document(1, 2, 3)
# WHEN: called with TextType 3 # WHEN: called with TextType 3
result = self.doc._ImpressDocument__get_text_from_page(1, 3) result = self.doc._ImpressDocument__get_text_from_page(1, 3)
# THEN: result should be an empty string # THEN: result should be an empty string
self.assertEqual(result, '', 'Result should be and empty string') self.assertEqual(result, '', 'Result should be and empty string')
self.assertEqual(self.doc.document.getDrawPages().getByIndex.call_count, 0, self.assertEqual(self.doc.document.getDrawPages().getByIndex.call_count, 0,
'There should be no call to getByIndex') 'There should be no call to getByIndex')
def get_text_from_page_valid_params_test(self): def get_text_from_page_valid_params_test(self):
""" """
Test ImpressDocument.__get_text_from_page with valid parameters Test ImpressDocument.__get_text_from_page with valid parameters
""" """
# GIVEN: mocked LibreOffice Document with one slide, # GIVEN: mocked LibreOffice Document with one slide,
# two notes and three texts # two notes and three texts
self.doc.document = self._mock_a_LibreOffice_document(1, 2, 3) self.doc.document = self._mock_a_LibreOffice_document(1, 2, 3)
# WHEN: __get_text_from_page is called to get the Notes # WHEN: __get_text_from_page is called to get the Notes
result = self.doc._ImpressDocument__get_text_from_page(1, TextType.Notes) result = self.doc._ImpressDocument__get_text_from_page(1, TextType.Notes)
# THEN: result should be 'Note\nNote\n' # THEN: result should be 'Note\nNote\n'
self.assertEqual(result, 'Note\nNote\n', 'Result should be \'Note\\n\' times the count of notes in the page') self.assertEqual(result, 'Note\nNote\n', 'Result should be \'Note\\n\' times the count of notes in the page')
# WHEN: get the Title # WHEN: get the Title
result = self.doc._ImpressDocument__get_text_from_page(1, TextType.Title) result = self.doc._ImpressDocument__get_text_from_page(1, TextType.Title)
# THEN: result should be 'Title\n' # THEN: result should be 'Title\n'
self.assertEqual(result, 'Title\n', 'Result should be exactly \'Title\\n\'') self.assertEqual(result, 'Title\n', 'Result should be exactly \'Title\\n\'')
# WHEN: get all text # WHEN: get all text
result = self.doc._ImpressDocument__get_text_from_page(1, TextType.SlideText) result = self.doc._ImpressDocument__get_text_from_page(1, TextType.SlideText)
# THEN: result should be 'Title\nString\nString\n' # THEN: result should be 'Title\nString\nString\n'
self.assertEqual(result, 'Title\nString\nString\n', 'Result should be exactly \'Title\\nString\\nString\\n\'') self.assertEqual(result, 'Title\nString\nString\n', 'Result should be exactly \'Title\\nString\\nString\\n\'')
def _mock_a_LibreOffice_document(self, page_count, note_count, text_count): def _mock_a_LibreOffice_document(self, page_count, note_count, text_count):
pages = MagicMock() pages = MagicMock()
page = MagicMock() page = MagicMock()
pages.getByIndex.return_value = page pages.getByIndex.return_value = page
notes_page = MagicMock() notes_page = MagicMock()
notes_page.getCount.return_value = note_count notes_page.getCount.return_value = note_count
shape = MagicMock() shape = MagicMock()
shape.supportsService.return_value = True shape.supportsService.return_value = True
shape.getString.return_value = 'Note' shape.getString.return_value = 'Note'
notes_page.getByIndex.return_value = shape notes_page.getByIndex.return_value = shape
page.getNotesPage.return_value = notes_page page.getNotesPage.return_value = notes_page
page.getCount.return_value = text_count page.getCount.return_value = text_count
page.getByIndex.side_effect = self._get_page_shape_side_effect page.getByIndex.side_effect = self._get_page_shape_side_effect
pages.getCount.return_value = page_count pages.getCount.return_value = page_count
document = MagicMock() document = MagicMock()
document.getDrawPages.return_value = pages document.getDrawPages.return_value = pages
document.getByIndex.return_value = page document.getByIndex.return_value = page
return document return document
def _get_page_shape_side_effect(*args): def _get_page_shape_side_effect(*args):
page_shape = MagicMock() page_shape = MagicMock()
page_shape.supportsService.return_value = True page_shape.supportsService.return_value = True
if args[1] == 0: if args[1] == 0:
page_shape.getShapeType.return_value = 'com.sun.star.presentation.TitleTextShape' page_shape.getShapeType.return_value = 'com.sun.star.presentation.TitleTextShape'
page_shape.getString.return_value = 'Title' page_shape.getString.return_value = 'Title'
else: else:
page_shape.getString.return_value = 'String' page_shape.getString.return_value = 'String'
return page_shape return page_shape

View File

@ -1,151 +1,151 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 # vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
############################################################################### ###############################################################################
# OpenLP - Open Source Lyrics Projection # # OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- # # --------------------------------------------------------------------------- #
# Copyright (c) 2008-2014 Raoul Snyman # # Copyright (c) 2008-2014 Raoul Snyman #
# Portions copyright (c) 2008-2014 Tim Bentley, Gerald Britton, Jonathan # # Portions copyright (c) 2008-2014 Tim Bentley, Gerald Britton, Jonathan #
# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, # # Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. # # Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, # # Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, # # Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, # # Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, #
# Frode Woldsund, Martin Zibricky, Patrick Zimmermann # # Frode Woldsund, Martin Zibricky, Patrick Zimmermann #
# --------------------------------------------------------------------------- # # --------------------------------------------------------------------------- #
# This program is free software; you can redistribute it and/or modify it # # 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 # # under the terms of the GNU General Public License as published by the Free #
# Software Foundation; version 2 of the License. # # Software Foundation; version 2 of the License. #
# # # #
# This program is distributed in the hope that it will be useful, but WITHOUT # # This program is distributed in the hope that it will be useful, but WITHOUT #
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
# more details. # # more details. #
# # # #
# You should have received a copy of the GNU General Public License along # # 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 # # with this program; if not, write to the Free Software Foundation, Inc., 59 #
# Temple Place, Suite 330, Boston, MA 02111-1307 USA # # Temple Place, Suite 330, Boston, MA 02111-1307 USA #
############################################################################### ###############################################################################
""" """
Functional tests to test the PptviewController class and related methods. Functional tests to test the PptviewController class and related methods.
""" """
from unittest import TestCase, SkipTest from unittest import TestCase, SkipTest
import os import os
if os.name != 'nt': if os.name != 'nt':
raise SkipTest('Not Windows, skipping test') raise SkipTest('Not Windows, skipping test')
from mock import MagicMock, patch, mock_open from mock import MagicMock, patch, mock_open
from openlp.plugins.presentations.lib.pptviewcontroller import PptviewController, PptviewDocument from openlp.plugins.presentations.lib.pptviewcontroller import PptviewController, PptviewDocument
TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..', 'resources')) TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..', 'resources'))
class TestLibModule(TestCase): class TestLibModule(TestCase):
def setUp(self): def setUp(self):
mocked_plugin = MagicMock() mocked_plugin = MagicMock()
mocked_plugin.settings_section = 'presentations' mocked_plugin.settings_section = 'presentations'
self.ppc = PptviewController(mocked_plugin) self.ppc = PptviewController(mocked_plugin)
self.file_name = os.path.join(TEST_PATH, "test.pptx") self.file_name = os.path.join(TEST_PATH, "test.pptx")
self.doc = PptviewDocument(self.ppc, self.file_name) self.doc = PptviewDocument(self.ppc, self.file_name)
#add _test to the function name to enable test #add _test to the function name to enable test
def verify_installation(self): def verify_installation(self):
""" """
Test the installation of PowerpointViewer Test the installation of PowerpointViewer
""" """
# GIVEN: A boolean value set to true # GIVEN: A boolean value set to true
# WHEN: We "convert" it to a bool # WHEN: We "convert" it to a bool
is_installed = self.ppc.check_available() is_installed = self.ppc.check_available()
# THEN: We should get back a True bool # THEN: We should get back a True bool
self.assertEqual(is_installed, True, 'The result should be True') self.assertEqual(is_installed, True, 'The result should be True')
# add _test to the following if necessary to enable test # add _test to the following if necessary to enable test
# I don't have powerpointviewer to verify # I don't have powerpointviewer to verify
def verify_loading_document(self): def verify_loading_document(self):
""" """
Test loading a document in PowerpointViewer Test loading a document in PowerpointViewer
""" """
# GIVEN: the filename # GIVEN: the filename
print(self.file_name) print(self.file_name)
# WHEN: loading the filename # WHEN: loading the filename
self.doc = PptviewDocument(self.ppc, self.file_name) self.doc = PptviewDocument(self.ppc, self.file_name)
self.doc.load_presentation() self.doc.load_presentation()
result = self.doc.is_loaded() result = self.doc.is_loaded()
# THEN: result should be true # THEN: result should be true
self.assertEqual(result, True, 'The result should be True') self.assertEqual(result, True, 'The result should be True')
# disabled # disabled
def verify_titles(self): def verify_titles(self):
""" """
Test reading the titles from PowerpointViewer Test reading the titles from PowerpointViewer
""" """
# GIVEN: # GIVEN:
self.doc = PptviewDocument(self.ppc, self.file_name) self.doc = PptviewDocument(self.ppc, self.file_name)
self.doc.create_titles_and_notes() self.doc.create_titles_and_notes()
# WHEN reading the titles and notes # WHEN reading the titles and notes
titles, notes = self.doc.get_titles_and_notes() titles, notes = self.doc.get_titles_and_notes()
print("titles: ".join(titles)) print("titles: ".join(titles))
print("notes: ".join(notes)) print("notes: ".join(notes))
# THEN there should be exactly 5 titles and 5 notes # THEN there should be exactly 5 titles and 5 notes
self.assertEqual(len(titles), 5, 'There should be five titles') self.assertEqual(len(titles), 5, 'There should be five titles')
self.assertEqual(len(notes), 5, 'There should be five notes') self.assertEqual(len(notes), 5, 'There should be five notes')
def create_titles_and_notes_test(self): def create_titles_and_notes_test(self):
""" """
Test PowerpointController.create_titles_and_notes Test PowerpointController.create_titles_and_notes
""" """
# GIVEN: mocked PresentationController.save_titles_and_notes # GIVEN: mocked PresentationController.save_titles_and_notes
self.doc.save_titles_and_notes = MagicMock() self.doc.save_titles_and_notes = MagicMock()
# WHEN reading the titles and notes # WHEN reading the titles and notes
self.doc.create_titles_and_notes() self.doc.create_titles_and_notes()
# THEN save_titles_and_notes should have been called once with empty arrays # THEN save_titles_and_notes should have been called once with empty arrays
self.doc.save_titles_and_notes.assert_called_once_with(['Test 1\n', '\n', 'Test 2\n', 'Test 4\n', 'Test 3\n'], self.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 for slide 1', 'Inserted', 'Notes for slide 2',
'Notes \nfor slide 4', 'Notes for slide 3']) 'Notes \nfor slide 4', 'Notes for slide 3'])
def create_titles_and_notes_nonexistent_file_test(self): def create_titles_and_notes_nonexistent_file_test(self):
""" """
Test PowerpointController.create_titles_and_notes with nonexistent file Test PowerpointController.create_titles_and_notes with nonexistent file
""" """
# GIVEN: mocked PresentationController.save_titles_and_notes and an nonexistent file # GIVEN: mocked PresentationController.save_titles_and_notes and an nonexistent file
with patch('builtins.open') as mocked_open, \ with patch('builtins.open') as mocked_open, \
patch('openlp.plugins.presentations.lib.pptviewcontroller.os.path.exists') as mocked_exists, \ patch('openlp.plugins.presentations.lib.pptviewcontroller.os.path.exists') as mocked_exists, \
patch('openlp.plugins.presentations.lib.presentationcontroller.check_directory_exists') as \ patch('openlp.plugins.presentations.lib.presentationcontroller.check_directory_exists') as \
mocked_dir_exists: mocked_dir_exists:
mocked_exists.return_value = False mocked_exists.return_value = False
mocked_dir_exists.return_value = False mocked_dir_exists.return_value = False
self.doc = PptviewDocument(self.ppc, 'Idontexist.pptx') self.doc = PptviewDocument(self.ppc, 'Idontexist.pptx')
self.doc.save_titles_and_notes = MagicMock() self.doc.save_titles_and_notes = MagicMock()
# WHEN: reading the titles and notes # WHEN: reading the titles and notes
self.doc.create_titles_and_notes() self.doc.create_titles_and_notes()
# THEN: # THEN:
self.doc.save_titles_and_notes.assert_called_once_with(None, None) self.doc.save_titles_and_notes.assert_called_once_with(None, None)
mocked_exists.assert_any_call('Idontexist.pptx') mocked_exists.assert_any_call('Idontexist.pptx')
self.assertEqual(mocked_open.call_count, 0, 'There should be no calls to open a file') self.assertEqual(mocked_open.call_count, 0, 'There should be no calls to open a file')
def create_titles_and_notes_invalid_file_test(self): def create_titles_and_notes_invalid_file_test(self):
""" """
Test PowerpointController.create_titles_and_notes with invalid file Test PowerpointController.create_titles_and_notes with invalid file
""" """
# GIVEN: mocked PresentationController.save_titles_and_notes and an invalid file # GIVEN: mocked PresentationController.save_titles_and_notes and an invalid file
with patch('builtins.open', mock_open(read_data='this is a test')) as mocked_open, \ with patch('builtins.open', mock_open(read_data='this is a test')) as mocked_open, \
patch('openlp.plugins.presentations.lib.pptviewcontroller.os.path.exists') as mocked_exists, \ patch('openlp.plugins.presentations.lib.pptviewcontroller.os.path.exists') as mocked_exists, \
patch('openlp.plugins.presentations.lib.pptviewcontroller.zipfile.is_zipfile') as mocked_is_zf: patch('openlp.plugins.presentations.lib.pptviewcontroller.zipfile.is_zipfile') as mocked_is_zf:
mocked_is_zf.return_value = False mocked_is_zf.return_value = False
mocked_exists.return_value = True mocked_exists.return_value = True
mocked_open.filesize = 10 mocked_open.filesize = 10
self.doc = PptviewDocument(self.ppc, os.path.join(TEST_PATH, "test.ppt")) self.doc = PptviewDocument(self.ppc, os.path.join(TEST_PATH, "test.ppt"))
self.doc.save_titles_and_notes = MagicMock() self.doc.save_titles_and_notes = MagicMock()
# WHEN: reading the titles and notes # WHEN: reading the titles and notes
self.doc.create_titles_and_notes() self.doc.create_titles_and_notes()
# THEN: # THEN:
self.doc.save_titles_and_notes.assert_called_once_with(None, None) self.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') self.assertEqual(mocked_is_zf.call_count, 1, 'is_zipfile should have been called once')