mirror of https://gitlab.com/openlp/openlp.git
Merge branch 'master' into remote-sync
This commit is contained in:
commit
c02c3568da
|
@ -39,7 +39,7 @@ def index(path):
|
|||
'index.html', mimetype='text/html')
|
||||
|
||||
|
||||
@main_views.route('/assets/<path>')
|
||||
@main_views.route('/assets/<path:path>')
|
||||
def assets(path):
|
||||
return send_from_directory(str(AppLocation.get_section_data_path('remotes') / 'assets'),
|
||||
path, mimetype=get_mime_type(path))
|
||||
|
|
|
@ -356,10 +356,12 @@ class UiStrings(metaclass=Singleton):
|
|||
self.BibleNoBibles = translate('OpenLP.Ui', '<strong>There are no Bibles currently installed.</strong><br><br>'
|
||||
'Please use the Import Wizard to install one or more Bibles.')
|
||||
self.Bottom = translate('OpenLP.Ui', 'Bottom')
|
||||
self.Bridge = translate('SongsPlugin.VerseType', 'Bridge')
|
||||
self.Browse = translate('OpenLP.Ui', 'Browse...')
|
||||
self.Cancel = translate('OpenLP.Ui', 'Cancel')
|
||||
self.CCLINumberLabel = translate('OpenLP.Ui', 'CCLI number:')
|
||||
self.CCLISongNumberLabel = translate('OpenLP.Ui', 'CCLI song number:')
|
||||
self.Chorus = translate('SongsPlugin.VerseType', 'Chorus')
|
||||
self.CreateService = translate('OpenLP.Ui', 'Create a new service.')
|
||||
self.ConfirmDelete = translate('OpenLP.Ui', 'Confirm Delete')
|
||||
self.Continuous = translate('OpenLP.Ui', 'Continuous')
|
||||
|
@ -371,14 +373,20 @@ class UiStrings(metaclass=Singleton):
|
|||
'.html#strftime-strptime-behavior for more information.')
|
||||
self.Delete = translate('OpenLP.Ui', '&Delete')
|
||||
self.DisplayStyle = translate('OpenLP.Ui', 'Display style:')
|
||||
self.Down = translate('SongsPlugin.EditVerseForm', 'Down')
|
||||
self.Duplicate = translate('OpenLP.Ui', 'Duplicate Error')
|
||||
self.Edit = translate('OpenLP.Ui', '&Edit')
|
||||
self.EditVerse = translate('SongsPlugin.EditVerseForm', 'Edit Verse')
|
||||
self.EmptyField = translate('OpenLP.Ui', 'Empty Field')
|
||||
self.Ending = translate('SongsPlugin.VerseType', 'Ending')
|
||||
self.Error = translate('OpenLP.Ui', 'Error')
|
||||
self.Export = translate('OpenLP.Ui', 'Export')
|
||||
self.File = translate('OpenLP.Ui', 'File')
|
||||
self.FileCorrupt = translate('OpenLP.Ui', 'File appears to be corrupt.')
|
||||
self.FontSizePtUnit = translate('OpenLP.Ui', 'pt', 'Abbreviated font point size unit')
|
||||
self.ForcedSplit = translate('SongsPlugin.EditVerseForm', '&Forced Split')
|
||||
self.ForcedSplitToolTip = translate('SongsPlugin.EditVerseForm', 'Split the verse when displayed '
|
||||
'regardless of the screen size.')
|
||||
self.Help = translate('OpenLP.Ui', 'Help')
|
||||
self.Hours = translate('OpenLP.Ui', 'h', 'The abbreviated unit for hours')
|
||||
self.IFdSs = translate('OpenLP.Ui', 'Invalid Folder Selected', 'Singular')
|
||||
|
@ -386,6 +394,10 @@ class UiStrings(metaclass=Singleton):
|
|||
self.IFSp = translate('OpenLP.Ui', 'Invalid Files Selected', 'Plural')
|
||||
self.Image = translate('OpenLP.Ui', 'Image')
|
||||
self.Import = translate('OpenLP.Ui', 'Import')
|
||||
self.Insert = translate('SongsPlugin.EditVerseForm', '&Insert')
|
||||
self.InsertToolTip = translate('SongsPlugin.EditVerseForm',
|
||||
'Split a slide into two by inserting a verse splitter.')
|
||||
self.Intro = translate('SongsPlugin.VerseType', 'Intro')
|
||||
self.LayoutStyle = translate('OpenLP.Ui', 'Layout style:')
|
||||
self.Live = translate('OpenLP.Ui', 'Live')
|
||||
self.LiveStream = translate('OpenLP.Ui', 'Live Stream')
|
||||
|
@ -414,8 +426,10 @@ class UiStrings(metaclass=Singleton):
|
|||
self.OpenService = translate('OpenLP.Ui', 'Open service.')
|
||||
self.OptionalShowInFooter = translate('OpenLP.Ui', 'Optional, this will be displayed in footer.')
|
||||
self.OptionalHideInFooter = translate('OpenLP.Ui', 'Optional, this won\'t be displayed in footer.')
|
||||
self.Other = translate('SongsPlugin.VerseType', 'Other')
|
||||
self.PlaySlidesInLoop = translate('OpenLP.Ui', 'Play Slides in Loop')
|
||||
self.PlaySlidesToEnd = translate('OpenLP.Ui', 'Play Slides to End')
|
||||
self.PreChorus = translate('SongsPlugin.VerseType', 'Pre-Chorus')
|
||||
self.Preview = translate('OpenLP.Ui', 'Preview')
|
||||
self.PreviewToolbar = translate('OpenLP.Ui', 'Preview Toolbar')
|
||||
self.PrintService = translate('OpenLP.Ui', 'Print Service')
|
||||
|
@ -449,9 +463,13 @@ class UiStrings(metaclass=Singleton):
|
|||
self.Themes = translate('OpenLP.Ui', 'Themes', 'Plural')
|
||||
self.Tools = translate('OpenLP.Ui', 'Tools')
|
||||
self.Top = translate('OpenLP.Ui', 'Top')
|
||||
self.Transpose = translate('SongsPlugin.EditVerseForm', 'Transpose:')
|
||||
self.UnsupportedFile = translate('OpenLP.Ui', 'Unsupported File')
|
||||
self.Up = translate('SongsPlugin.EditVerseForm', 'Up')
|
||||
self.Verse = translate('SongsPlugin.VerseType', 'Verse')
|
||||
self.VersePerSlide = translate('OpenLP.Ui', 'Verse Per Slide')
|
||||
self.VersePerLine = translate('OpenLP.Ui', 'Verse Per Line')
|
||||
self.VerseType = translate('SongsPlugin.EditVerseForm', '&Verse type:')
|
||||
self.Version = translate('OpenLP.Ui', 'Version')
|
||||
self.View = translate('OpenLP.Ui', 'View')
|
||||
self.ViewMode = translate('OpenLP.Ui', 'View Mode')
|
||||
|
|
|
@ -35,6 +35,9 @@ from openlp.core.common.i18n import UiStrings, translate
|
|||
log = logging.getLogger(__name__ + '.__init__')
|
||||
|
||||
|
||||
DEFAULT_THUMBNAIL_HEIGHT = 88
|
||||
|
||||
|
||||
class DataType(IntEnum):
|
||||
U8 = 1
|
||||
U16 = 2
|
||||
|
@ -301,8 +304,8 @@ def create_thumb(image_path, thumb_path, return_icon=True, size=None):
|
|||
:param Path image_path: The image file to create the icon from.
|
||||
:param Path thumb_path: The filename to save the thumbnail to.
|
||||
:param return_icon: States if an icon should be build and returned from the thumb. Defaults to ``True``.
|
||||
:param size: Allows to state a own size (QtCore.QSize) to use. Defaults to ``None``, which means that a default
|
||||
height of 88 is used.
|
||||
:param size: Allows to state a own size (QtCore.QSize) to use. Defaults to ``None``, which means it uses the value
|
||||
from DEFAULT_THUMBNAIL_HEIGHT.
|
||||
:return: The final icon.
|
||||
"""
|
||||
reader = QtGui.QImageReader(str(image_path))
|
||||
|
@ -312,7 +315,7 @@ def create_thumb(image_path, thumb_path, return_icon=True, size=None):
|
|||
ratio = 1
|
||||
else:
|
||||
ratio = reader.size().width() / reader.size().height()
|
||||
reader.setScaledSize(QtCore.QSize(int(ratio * 88), 88))
|
||||
reader.setScaledSize(QtCore.QSize(int(ratio * DEFAULT_THUMBNAIL_HEIGHT), DEFAULT_THUMBNAIL_HEIGHT))
|
||||
elif size.isValid():
|
||||
# Complete size given
|
||||
reader.setScaledSize(size)
|
||||
|
@ -330,7 +333,7 @@ def create_thumb(image_path, thumb_path, return_icon=True, size=None):
|
|||
reader.setScaledSize(QtCore.QSize(int(ratio * size.height()), size.height()))
|
||||
else:
|
||||
# Invalid; use default height of 88
|
||||
reader.setScaledSize(QtCore.QSize(int(ratio * 88), 88))
|
||||
reader.setScaledSize(QtCore.QSize(int(ratio * DEFAULT_THUMBNAIL_HEIGHT), DEFAULT_THUMBNAIL_HEIGHT))
|
||||
thumb = reader.read()
|
||||
thumb.save(str(thumb_path), thumb_path.suffix[1:].lower())
|
||||
if not return_icon:
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
import logging
|
||||
from pathlib import Path
|
||||
from typing import Union
|
||||
|
||||
from PyQt5 import QtCore, QtWidgets
|
||||
|
||||
|
@ -159,7 +160,11 @@ class ImageMediaItem(FolderLibraryItem):
|
|||
if validate_thumb(file_path, thumbnail_path):
|
||||
icon = build_icon(thumbnail_path)
|
||||
else:
|
||||
icon = create_thumb(file_path, thumbnail_path)
|
||||
size: Union[QtCore.QSize, None] = None
|
||||
slide_height: Union[int, None] = self.settings.value('advanced/slide max height')
|
||||
if slide_height and slide_height > 0:
|
||||
size = QtCore.QSize(-1, slide_height)
|
||||
icon = create_thumb(file_path, thumbnail_path, size=size)
|
||||
tree_item = QtWidgets.QTreeWidgetItem([file_name])
|
||||
tree_item.setData(0, QtCore.Qt.UserRole, item)
|
||||
tree_item.setIcon(0, icon)
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
|
||||
from PyQt5 import QtWidgets
|
||||
|
||||
from openlp.core.common.i18n import UiStrings, translate
|
||||
from openlp.core.common.i18n import UiStrings
|
||||
from openlp.core.lib.ui import create_button_box
|
||||
from openlp.core.ui.icons import UiIcons
|
||||
from openlp.core.widgets.edits import SpellTextEdit
|
||||
|
@ -87,8 +87,18 @@ class Ui_EditVerseDialog(object):
|
|||
self.retranslate_ui(edit_verse_dialog)
|
||||
|
||||
def retranslate_ui(self, edit_verse_dialog):
|
||||
edit_verse_dialog.setWindowTitle(translate('SongsPlugin.EditVerseForm', 'Edit Verse'))
|
||||
self.verse_type_label.setText(translate('SongsPlugin.EditVerseForm', '&Verse type:'))
|
||||
VerseType.translated_names = [
|
||||
UiStrings().Verse,
|
||||
UiStrings().Chorus,
|
||||
UiStrings().Bridge,
|
||||
UiStrings().PreChorus,
|
||||
UiStrings().Intro,
|
||||
UiStrings().Ending,
|
||||
UiStrings().Other
|
||||
]
|
||||
VerseType.translated_tags = [name[0].lower() for name in VerseType.translated_names]
|
||||
edit_verse_dialog.setWindowTitle(UiStrings().EditVerse)
|
||||
self.verse_type_label.setText(UiStrings().VerseType)
|
||||
self.verse_type_combo_box.setItemText(VerseType.Verse, VerseType.translated_names[VerseType.Verse])
|
||||
self.verse_type_combo_box.setItemText(VerseType.Chorus, VerseType.translated_names[VerseType.Chorus])
|
||||
self.verse_type_combo_box.setItemText(VerseType.Bridge, VerseType.translated_names[VerseType.Bridge])
|
||||
|
@ -98,12 +108,10 @@ class Ui_EditVerseDialog(object):
|
|||
self.verse_type_combo_box.setItemText(VerseType.Other, VerseType.translated_names[VerseType.Other])
|
||||
self.overflow_split_button.setText(UiStrings().Split)
|
||||
self.overflow_split_button.setToolTip(UiStrings().SplitToolTip)
|
||||
self.forced_split_button.setText(translate('SongsPlugin.EditVerseForm', '&Forced Split'))
|
||||
self.forced_split_button.setToolTip(translate('SongsPlugin.EditVerseForm', 'Split the verse when displayed '
|
||||
'regardless of the screen size.'))
|
||||
self.insert_button.setText(translate('SongsPlugin.EditVerseForm', '&Insert'))
|
||||
self.insert_button.setToolTip(translate('SongsPlugin.EditVerseForm',
|
||||
'Split a slide into two by inserting a verse splitter.'))
|
||||
self.transpose_label.setText(translate('SongsPlugin.EditVerseForm', 'Transpose:'))
|
||||
self.transpose_up_button.setText(translate('SongsPlugin.EditVerseForm', 'Up'))
|
||||
self.transpose_down_button.setText(translate('SongsPlugin.EditVerseForm', 'Down'))
|
||||
self.forced_split_button.setText(UiStrings().ForcedSplit)
|
||||
self.forced_split_button.setToolTip(UiStrings().ForcedSplitToolTip)
|
||||
self.insert_button.setText(UiStrings().Insert)
|
||||
self.insert_button.setToolTip(UiStrings().InsertToolTip)
|
||||
self.transpose_label.setText(UiStrings().Transpose)
|
||||
self.transpose_up_button.setText(UiStrings().Up)
|
||||
self.transpose_down_button.setText(UiStrings().Down)
|
||||
|
|
|
@ -144,17 +144,8 @@ class VerseType(object):
|
|||
|
||||
names = ['Verse', 'Chorus', 'Bridge', 'Pre-Chorus', 'Intro', 'Ending', 'Other']
|
||||
tags = [name[0].lower() for name in names]
|
||||
|
||||
translated_names = [
|
||||
translate('SongsPlugin.VerseType', 'Verse'),
|
||||
translate('SongsPlugin.VerseType', 'Chorus'),
|
||||
translate('SongsPlugin.VerseType', 'Bridge'),
|
||||
translate('SongsPlugin.VerseType', 'Pre-Chorus'),
|
||||
translate('SongsPlugin.VerseType', 'Intro'),
|
||||
translate('SongsPlugin.VerseType', 'Ending'),
|
||||
translate('SongsPlugin.VerseType', 'Other')]
|
||||
|
||||
translated_tags = [name[0].lower() for name in translated_names]
|
||||
translated_names = names
|
||||
translated_tags = tags
|
||||
|
||||
@staticmethod
|
||||
def translated_tag(verse_tag, default=Other):
|
||||
|
|
|
@ -30,7 +30,9 @@ from unittest.mock import MagicMock, patch
|
|||
from PyQt5 import QtCore, QtGui
|
||||
|
||||
from openlp.core.lib import DataType, build_icon, check_item_selected, create_separated_list, create_thumb, \
|
||||
get_text_file_string, image_to_byte, read_or_fail, read_int, resize_image, seek_or_fail, str_to_bool, validate_thumb
|
||||
get_text_file_string, image_to_byte, read_or_fail, read_int, resize_image, seek_or_fail, str_to_bool, \
|
||||
validate_thumb
|
||||
from openlp.core.common.registry import Registry
|
||||
from tests.utils.constants import RESOURCE_PATH
|
||||
|
||||
|
||||
|
@ -275,7 +277,7 @@ def test_image_to_byte_base_64():
|
|||
assert 'byte_array base64ified' == result, 'The result should be the return value of the mocked base64 method'
|
||||
|
||||
|
||||
def test_create_thumb_with_size(registry):
|
||||
def test_create_thumb_with_size(registry: Registry):
|
||||
"""
|
||||
Test the create_thumb() function with a given size.
|
||||
"""
|
||||
|
@ -310,7 +312,7 @@ def test_create_thumb_with_size(registry):
|
|||
pass
|
||||
|
||||
|
||||
def test_create_thumb_no_size(registry):
|
||||
def test_create_thumb_no_size(registry: Registry):
|
||||
"""
|
||||
Test the create_thumb() function with no size specified.
|
||||
"""
|
||||
|
@ -345,7 +347,7 @@ def test_create_thumb_no_size(registry):
|
|||
pass
|
||||
|
||||
|
||||
def test_create_thumb_invalid_size(registry):
|
||||
def test_create_thumb_invalid_size(registry: Registry):
|
||||
"""
|
||||
Test the create_thumb() function with invalid size specified.
|
||||
"""
|
||||
|
@ -381,7 +383,7 @@ def test_create_thumb_invalid_size(registry):
|
|||
pass
|
||||
|
||||
|
||||
def test_create_thumb_width_only(registry):
|
||||
def test_create_thumb_width_only(registry: Registry):
|
||||
"""
|
||||
Test the create_thumb() function with a size of only width specified.
|
||||
"""
|
||||
|
@ -417,7 +419,7 @@ def test_create_thumb_width_only(registry):
|
|||
pass
|
||||
|
||||
|
||||
def test_create_thumb_height_only(registry):
|
||||
def test_create_thumb_height_only(registry: Registry):
|
||||
"""
|
||||
Test the create_thumb() function with a size of only height specified.
|
||||
"""
|
||||
|
@ -453,7 +455,7 @@ def test_create_thumb_height_only(registry):
|
|||
pass
|
||||
|
||||
|
||||
def test_create_thumb_empty_img(registry):
|
||||
def test_create_thumb_empty_img(registry: Registry):
|
||||
"""
|
||||
Test the create_thumb() function with a size of only height specified.
|
||||
"""
|
||||
|
@ -504,7 +506,7 @@ def test_create_thumb_empty_img(registry):
|
|||
|
||||
@patch('openlp.core.lib.QtGui.QImageReader')
|
||||
@patch('openlp.core.lib.build_icon')
|
||||
def test_create_thumb_path_fails(mocked_build_icon, MockQImageReader, registry):
|
||||
def test_create_thumb_path_fails(mocked_build_icon: MagicMock, MockQImageReader: MagicMock, registry: Registry):
|
||||
"""
|
||||
Test that build_icon() is run against the image_path when the thumbnail fails to be created
|
||||
"""
|
||||
|
@ -539,7 +541,7 @@ def test_check_item_selected_true():
|
|||
assert result is True, 'The result should be True'
|
||||
|
||||
|
||||
def test_check_item_selected_false(registry):
|
||||
def test_check_item_selected_false(registry: Registry):
|
||||
"""
|
||||
Test that the check_item_selected() function returns False when there are no selected indexes.
|
||||
"""
|
||||
|
@ -610,7 +612,7 @@ def test_validate_thumb_file_exists_and_older():
|
|||
assert result is False, 'The result should be False'
|
||||
|
||||
|
||||
def test_resize_thumb(registry):
|
||||
def test_resize_thumb(registry: Registry):
|
||||
"""
|
||||
Test the resize_thumb() function
|
||||
"""
|
||||
|
@ -632,7 +634,7 @@ def test_resize_thumb(registry):
|
|||
assert image.pixel(0, 0) == wanted_background_rgb, 'The background should be white.'
|
||||
|
||||
|
||||
def test_resize_thumb_ignoring_aspect_ratio(registry):
|
||||
def test_resize_thumb_ignoring_aspect_ratio(registry: Registry):
|
||||
"""
|
||||
Test the resize_thumb() function ignoring aspect ratio
|
||||
"""
|
||||
|
@ -654,7 +656,7 @@ def test_resize_thumb_ignoring_aspect_ratio(registry):
|
|||
assert image.pixel(0, 0) == wanted_background_rgb, 'The background should be white.'
|
||||
|
||||
|
||||
def test_resize_thumb_width_aspect_ratio(registry):
|
||||
def test_resize_thumb_width_aspect_ratio(registry: Registry):
|
||||
"""
|
||||
Test the resize_thumb() function using the image's width as the reference
|
||||
"""
|
||||
|
@ -672,7 +674,7 @@ def test_resize_thumb_width_aspect_ratio(registry):
|
|||
assert wanted_width == result_size.width(), 'The image should have the requested width.'
|
||||
|
||||
|
||||
def test_resize_thumb_same_aspect_ratio(registry):
|
||||
def test_resize_thumb_same_aspect_ratio(registry: Registry):
|
||||
"""
|
||||
Test the resize_thumb() function when the image and the wanted aspect ratio are the same
|
||||
"""
|
||||
|
@ -691,7 +693,7 @@ def test_resize_thumb_same_aspect_ratio(registry):
|
|||
|
||||
|
||||
@patch('openlp.core.lib.QtCore.QLocale.createSeparatedList')
|
||||
def test_create_separated_list_qlocate(mocked_createSeparatedList):
|
||||
def test_create_separated_list_qlocate(mocked_createSeparatedList: MagicMock):
|
||||
"""
|
||||
Test the create_separated_list function using the Qt provided method
|
||||
"""
|
||||
|
|
|
@ -22,17 +22,20 @@
|
|||
This module contains tests for the lib submodule of the Images plugin.
|
||||
"""
|
||||
from pathlib import Path
|
||||
from tempfile import TemporaryDirectory
|
||||
from unittest.mock import ANY, MagicMock, patch
|
||||
|
||||
import pytest
|
||||
from PyQt5 import QtCore, QtWidgets
|
||||
|
||||
from openlp.core.common.registry import Registry
|
||||
from openlp.core.common.enum import ImageThemeMode
|
||||
from openlp.core.common.registry import Registry
|
||||
from openlp.core.db.manager import DBManager
|
||||
from openlp.core.lib import build_icon, create_thumb
|
||||
from openlp.core.lib.serviceitem import ItemCapabilities
|
||||
from openlp.core.widgets.views import TreeWidgetWithDnD
|
||||
from openlp.plugins.images.lib.mediaitem import ImageMediaItem
|
||||
from tests.utils.constants import TEST_RESOURCES_PATH
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
@ -258,3 +261,64 @@ def test_generate_thumbnail_path_filename(media_item):
|
|||
|
||||
# THEN: The path should be correct
|
||||
assert result == Path('.') / 'myimage.jpg'
|
||||
|
||||
|
||||
@patch('openlp.plugins.images.lib.mediaitem.create_thumb')
|
||||
def test_load_item_file_not_exist(mocked_create_thumb: MagicMock, media_item: ImageMediaItem):
|
||||
"""Test the load_item method when the file does not exist"""
|
||||
# GIVEN: A media item and an Item to load
|
||||
item = MagicMock(file_path=Path('myimage.jpg'), file_hash=None)
|
||||
|
||||
# WHEN load_item() is called with the Item
|
||||
result = media_item.load_item(item)
|
||||
|
||||
# THEN: A QTreeWidgetItem with a "delete" icon should be returned
|
||||
assert isinstance(result, QtWidgets.QTreeWidgetItem)
|
||||
assert result.text(0) == 'myimage.jpg'
|
||||
mocked_create_thumb.assert_not_called()
|
||||
|
||||
|
||||
@patch('openlp.plugins.images.lib.mediaitem.validate_thumb')
|
||||
@patch('openlp.plugins.images.lib.mediaitem.create_thumb', wraps=create_thumb)
|
||||
@patch('openlp.plugins.images.lib.mediaitem.build_icon', wraps=build_icon)
|
||||
def test_load_item_valid_thumbnail(mocked_build_icon: MagicMock, mocked_create_thumb: MagicMock,
|
||||
mocked_validate_thumb: MagicMock, media_item: ImageMediaItem, registry: Registry):
|
||||
"""Test the load_item method with an existing thumbnail"""
|
||||
# GIVEN: A media item and an Item to load
|
||||
media_item.service_path = Path(TEST_RESOURCES_PATH) / 'images'
|
||||
mocked_validate_thumb.return_value = True
|
||||
image_path = Path(TEST_RESOURCES_PATH) / 'images' / 'tractor.jpg'
|
||||
item = MagicMock(file_path=image_path, file_hash=None)
|
||||
|
||||
# WHEN load_item() is called with the Item
|
||||
result = media_item.load_item(item)
|
||||
|
||||
# THEN: A QTreeWidgetItem with a "delete" icon should be returned
|
||||
assert isinstance(result, QtWidgets.QTreeWidgetItem)
|
||||
assert result.text(0) == 'tractor.jpg'
|
||||
assert result.toolTip(0) == str(image_path)
|
||||
mocked_create_thumb.assert_not_called()
|
||||
mocked_build_icon.assert_called_once_with(image_path)
|
||||
|
||||
|
||||
@patch('openlp.plugins.images.lib.mediaitem.validate_thumb')
|
||||
@patch('openlp.plugins.images.lib.mediaitem.create_thumb', wraps=create_thumb)
|
||||
def test_load_item_missing_thumbnail(mocked_create_thumb: MagicMock, mocked_validate_thumb: MagicMock,
|
||||
media_item: ImageMediaItem, registry: Registry):
|
||||
"""Test the load_item method with no valid thumbnails"""
|
||||
# GIVEN: A media item and an Item to load
|
||||
with TemporaryDirectory() as tmpdir:
|
||||
media_item.service_path = Path(tmpdir)
|
||||
mocked_validate_thumb.return_value = False
|
||||
image_path = Path(TEST_RESOURCES_PATH) / 'images' / 'tractor.jpg'
|
||||
item = MagicMock(file_path=image_path, file_hash=None)
|
||||
registry.get('settings').value.return_value = 400
|
||||
|
||||
# WHEN load_item() is called with the Item
|
||||
result = media_item.load_item(item)
|
||||
|
||||
# THEN: A QTreeWidgetItem with a "delete" icon should be returned
|
||||
assert isinstance(result, QtWidgets.QTreeWidgetItem)
|
||||
assert result.text(0) == 'tractor.jpg'
|
||||
assert result.toolTip(0) == str(image_path)
|
||||
mocked_create_thumb.assert_called_once_with(image_path, Path(tmpdir, 'tractor.jpg'), size=QtCore.QSize(-1, 400))
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 675 KiB |
Loading…
Reference in New Issue