forked from openlp/openlp
Fixes 1410456 and adds a couple tests
Fixes: https://launchpad.net/bugs/1410456
This commit is contained in:
parent
de213b0f66
commit
e3f147a226
@ -371,7 +371,7 @@ class ImageMediaItem(MediaManagerItem):
|
|||||||
"""
|
"""
|
||||||
self.application.set_normal_cursor()
|
self.application.set_normal_cursor()
|
||||||
self.load_list(files, target_group)
|
self.load_list(files, target_group)
|
||||||
last_dir = os.path.split(str(files[0]))[0]
|
last_dir = os.path.split(files[0])[0]
|
||||||
Settings().setValue(self.settings_section + '/last directory', last_dir)
|
Settings().setValue(self.settings_section + '/last directory', last_dir)
|
||||||
|
|
||||||
def load_list(self, images, target_group=None, initial_load=False):
|
def load_list(self, images, target_group=None, initial_load=False):
|
||||||
@ -535,7 +535,7 @@ class ImageMediaItem(MediaManagerItem):
|
|||||||
if not items:
|
if not items:
|
||||||
return False
|
return False
|
||||||
# Determine service item title
|
# Determine service item title
|
||||||
if isinstance(items[0].data(0, QtCore.Qt.UserRole), ImageGroups):
|
if isinstance(items[0].data(0, QtCore.Qt.UserRole), ImageGroups) or len(items) == 1:
|
||||||
service_item.title = items[0].text(0)
|
service_item.title = items[0].text(0)
|
||||||
else:
|
else:
|
||||||
service_item.title = str(self.plugin.name_strings['plural'])
|
service_item.title = str(self.plugin.name_strings['plural'])
|
||||||
|
@ -35,9 +35,9 @@ import sys
|
|||||||
from PyQt4 import QtGui
|
from PyQt4 import QtGui
|
||||||
|
|
||||||
if sys.version_info[1] >= 3:
|
if sys.version_info[1] >= 3:
|
||||||
from unittest.mock import MagicMock, patch, mock_open, call
|
from unittest.mock import ANY, MagicMock, patch, mock_open, call
|
||||||
else:
|
else:
|
||||||
from mock import MagicMock, patch, mock_open, call
|
from mock import ANY, MagicMock, patch, mock_open, call
|
||||||
|
|
||||||
# Only one QApplication can be created. Use QtGui.QApplication.instance() when you need to "create" a QApplication.
|
# Only one QApplication can be created. Use QtGui.QApplication.instance() when you need to "create" a QApplication.
|
||||||
application = QtGui.QApplication([])
|
application = QtGui.QApplication([])
|
||||||
|
@ -27,7 +27,7 @@ from unittest import TestCase
|
|||||||
from openlp.core.common import Registry
|
from openlp.core.common import Registry
|
||||||
from openlp.plugins.images.lib.db import ImageFilenames, ImageGroups
|
from openlp.plugins.images.lib.db import ImageFilenames, ImageGroups
|
||||||
from openlp.plugins.images.lib.mediaitem import ImageMediaItem
|
from openlp.plugins.images.lib.mediaitem import ImageMediaItem
|
||||||
from tests.functional import MagicMock, patch
|
from tests.functional import ANY, MagicMock, patch
|
||||||
|
|
||||||
|
|
||||||
class TestImageMediaItem(TestCase):
|
class TestImageMediaItem(TestCase):
|
||||||
@ -38,6 +38,7 @@ class TestImageMediaItem(TestCase):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.mocked_main_window = MagicMock()
|
self.mocked_main_window = MagicMock()
|
||||||
Registry.create()
|
Registry.create()
|
||||||
|
Registry().register('application', MagicMock())
|
||||||
Registry().register('service_list', MagicMock())
|
Registry().register('service_list', MagicMock())
|
||||||
Registry().register('main_window', self.mocked_main_window)
|
Registry().register('main_window', self.mocked_main_window)
|
||||||
Registry().register('live_controller', MagicMock())
|
Registry().register('live_controller', MagicMock())
|
||||||
@ -45,6 +46,43 @@ class TestImageMediaItem(TestCase):
|
|||||||
with patch('openlp.plugins.images.lib.mediaitem.MediaManagerItem._setup'), \
|
with patch('openlp.plugins.images.lib.mediaitem.MediaManagerItem._setup'), \
|
||||||
patch('openlp.plugins.images.lib.mediaitem.ImageMediaItem.setup_item'):
|
patch('openlp.plugins.images.lib.mediaitem.ImageMediaItem.setup_item'):
|
||||||
self.media_item = ImageMediaItem(None, mocked_plugin)
|
self.media_item = ImageMediaItem(None, mocked_plugin)
|
||||||
|
self.media_item.settings_section = 'images'
|
||||||
|
|
||||||
|
def validate_and_load_test(self):
|
||||||
|
"""
|
||||||
|
Test that the validate_and_load_test() method
|
||||||
|
"""
|
||||||
|
# GIVEN: A list of files
|
||||||
|
file_list = ['/path1/image1.jpg', '/path2/image2.jpg']
|
||||||
|
|
||||||
|
with patch('openlp.plugins.images.lib.mediaitem.ImageMediaItem.load_list') as mocked_load_list, \
|
||||||
|
patch('openlp.plugins.images.lib.mediaitem.Settings') as mocked_settings:
|
||||||
|
|
||||||
|
# WHEN: Calling validate_and_load with the list of files
|
||||||
|
self.media_item.validate_and_load(file_list)
|
||||||
|
|
||||||
|
# THEN: load_list should have been called with the file list and None,
|
||||||
|
# the dectory should have been saved to the settings
|
||||||
|
mocked_load_list.assert_called_once_with(file_list, None)
|
||||||
|
mocked_settings().setValue.assert_called_once_with(ANY, '/path1')
|
||||||
|
|
||||||
|
def validate_and_load_group_test(self):
|
||||||
|
"""
|
||||||
|
Test that the validate_and_load_test() method
|
||||||
|
"""
|
||||||
|
# GIVEN: A list of files
|
||||||
|
file_list = ['/path1/image1.jpg', '/path2/image2.jpg']
|
||||||
|
|
||||||
|
with patch('openlp.plugins.images.lib.mediaitem.ImageMediaItem.load_list') as mocked_load_list, \
|
||||||
|
patch('openlp.plugins.images.lib.mediaitem.Settings') as mocked_settings:
|
||||||
|
|
||||||
|
# WHEN: Calling validate_and_load with the list of files and a group
|
||||||
|
self.media_item.validate_and_load(file_list, 'group')
|
||||||
|
|
||||||
|
# THEN: load_list should have been called with the file list and the group name,
|
||||||
|
# the dectory should have been saved to the settings
|
||||||
|
mocked_load_list.assert_called_once_with(file_list, 'group')
|
||||||
|
mocked_settings().setValue.assert_called_once_with(ANY, '/path1')
|
||||||
|
|
||||||
def save_new_images_list_empty_list_test(self):
|
def save_new_images_list_empty_list_test(self):
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user