Add detection for presentation files that were uploaded from the cloud.

This commit is contained in:
Chris Witterholt 2023-07-18 20:11:52 +00:00 committed by Raoul Snyman
parent 1affcebb78
commit f7f701abf2
2 changed files with 47 additions and 4 deletions

View File

@ -114,6 +114,23 @@ class PowerpointDocument(PresentationDocument):
Class which holds information and controls a single presentation.
"""
@property
def is_in_cloud(self):
"""Determine if the document is a cloud document."""
return str(self.presentation.FullName).startswith('https://') \
if self.presentation else False
@property
def presentation_file(self):
"""The file name of the presentation, normalised in case of a cloud document."""
return str(self.presentation.Name) if self.is_in_cloud else str(self.presentation.FullName)
@property
def presentation_controller_file(self):
"""The file name of the presentation in the Slide Controller, normalised in case of
a cloud document."""
return str(self.file_path.name) if self.is_in_cloud else str(self.file_path)
def __init__(self, controller, document_path):
"""
Constructor, store information about the file and initialise.
@ -213,13 +230,13 @@ class PowerpointDocument(PresentationDocument):
"""
log.debug('is_loaded')
try:
if self.presentation is None or self.presentation.FullName != str(self.file_path):
if self.presentation is None:
return False
return self.presentation_file == self.presentation_controller_file
except (AttributeError, pywintypes.com_error):
log.exception('Caught exception while in is_loaded')
trace_error_handler(log)
return False
return True
def is_active(self):
"""

View File

@ -21,14 +21,15 @@
"""
Functional tests to test the PowerPointController class and related methods.
"""
import pytest
from pathlib import Path
from unittest.mock import MagicMock, patch
import pytest
from openlp.core.common.platform import is_win
from openlp.core.common.registry import Registry
from openlp.plugins.presentations.lib.powerpointcontroller import PowerpointController, PowerpointDocument, \
_get_text_from_shapes
from tests.utils.constants import RESOURCE_PATH
if is_win():
import pywintypes
@ -226,3 +227,28 @@ def test_unblank_screen(get_thumbnail_folder):
'View.GotoSlide should have been called because of the PowerPoint version'
assert doc.presentation.SlideShowWindow.View.GotoClick.called is True, \
'View.GotoClick should have been called because of the PowerPoint version'
@pytest.mark.parametrize('file_path, expected_is_in_cloud, expected_same_file_name', [
(RESOURCE_PATH / 'presentations' / 'test.pptx', False, True),
(Path('test.pptx'), True, False)
])
def test_presentation_is_in_cloud(file_path, expected_is_in_cloud, expected_same_file_name,
registry, settings):
"""
Test that a presentation from a cloud drive is being detected.
"""
# GIVEN: A Document with mocked controller and presentation.
mocked_plugin = MagicMock()
mocked_plugin.settings_section = 'presentations'
ppc = PowerpointController(mocked_plugin)
doc = PowerpointDocument(ppc, file_path)
doc.presentation = MagicMock(FullName=file_path)
if expected_is_in_cloud:
doc.presentation = MagicMock(FullName='https://' + str(file_path))
else:
doc.presentation = MagicMock(FullName=str(file_path))
assert doc.is_in_cloud == expected_is_in_cloud, \
'is_in_cloud should be false because this file is locally stored'
assert (doc.presentation_file == doc.presentation_controller_file) == expected_same_file_name, \
'presentation_file should have the same value as presentation_controller_file'