forked from openlp/openlp
Added test + small fixes.
This commit is contained in:
parent
7e406e7005
commit
f8084059ba
@ -27,6 +27,7 @@ from distutils.version import LooseVersion
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import threading
|
import threading
|
||||||
|
import sys
|
||||||
|
|
||||||
from PyQt4 import QtGui
|
from PyQt4 import QtGui
|
||||||
|
|
||||||
@ -62,7 +63,8 @@ if VLC_AVAILABLE:
|
|||||||
if LooseVersion(VERSION.split()[0]) < LooseVersion('1.1.0'):
|
if LooseVersion(VERSION.split()[0]) < LooseVersion('1.1.0'):
|
||||||
VLC_AVAILABLE = False
|
VLC_AVAILABLE = False
|
||||||
log.debug('VLC could not be loaded, because the vlc version is too old: %s' % VERSION)
|
log.debug('VLC could not be loaded, because the vlc version is too old: %s' % VERSION)
|
||||||
if VLC_AVAILABLE and is_linux():
|
# On linux we need to initialise X threads, but not when running tests.
|
||||||
|
if VLC_AVAILABLE and is_linux() and 'nose' not in sys.argv[0]:
|
||||||
import ctypes
|
import ctypes
|
||||||
try:
|
try:
|
||||||
x11 = ctypes.cdll.LoadLibrary('libX11.so')
|
x11 = ctypes.cdll.LoadLibrary('libX11.so')
|
||||||
|
@ -245,8 +245,8 @@ class PresentationMediaItem(MediaManagerItem):
|
|||||||
doc = self.controllers[cidx].add_document(filepath)
|
doc = self.controllers[cidx].add_document(filepath)
|
||||||
if clean_for_update:
|
if clean_for_update:
|
||||||
thumb_path = doc.get_thumbnail_path(1, True)
|
thumb_path = doc.get_thumbnail_path(1, True)
|
||||||
if not thumb_path or (os.path.exists(filepath)
|
if not thumb_path or not os.path.exists(filepath) or os.path.getmtime(
|
||||||
and os.path.getmtime(thumb_path) < os.path.getmtime(filepath)):
|
thumb_path) < os.path.getmtime(filepath):
|
||||||
doc.presentation_deleted()
|
doc.presentation_deleted()
|
||||||
else:
|
else:
|
||||||
doc.presentation_deleted()
|
doc.presentation_deleted()
|
||||||
|
@ -87,7 +87,7 @@ class TestMediaItem(TestCase, TestMixin):
|
|||||||
|
|
||||||
def clean_up_thumbnails_test(self):
|
def clean_up_thumbnails_test(self):
|
||||||
"""
|
"""
|
||||||
Test that the clean_up_thumbnails method works as expected.
|
Test that the clean_up_thumbnails method works as expected when files exists.
|
||||||
"""
|
"""
|
||||||
# GIVEN: A mocked controller, and mocked os.path.getmtime
|
# GIVEN: A mocked controller, and mocked os.path.getmtime
|
||||||
mocked_controller = MagicMock()
|
mocked_controller = MagicMock()
|
||||||
@ -98,8 +98,10 @@ class TestMediaItem(TestCase, TestMixin):
|
|||||||
'Mocked': mocked_controller
|
'Mocked': mocked_controller
|
||||||
}
|
}
|
||||||
presentation_file = 'file.tmp'
|
presentation_file = 'file.tmp'
|
||||||
with patch('openlp.plugins.presentations.lib.mediaitem.os.path.getmtime') as mocked_getmtime:
|
with patch('openlp.plugins.presentations.lib.mediaitem.os.path.getmtime') as mocked_getmtime, \
|
||||||
|
patch('openlp.plugins.presentations.lib.mediaitem.os.path.exists') as mocked_exists:
|
||||||
mocked_getmtime.side_effect = [100, 200]
|
mocked_getmtime.side_effect = [100, 200]
|
||||||
|
mocked_exists.return_value = True
|
||||||
|
|
||||||
# WHEN: calling clean_up_thumbnails
|
# WHEN: calling clean_up_thumbnails
|
||||||
self.media_item.clean_up_thumbnails(presentation_file, True)
|
self.media_item.clean_up_thumbnails(presentation_file, True)
|
||||||
@ -107,3 +109,25 @@ class TestMediaItem(TestCase, TestMixin):
|
|||||||
# THEN: doc.presentation_deleted should have been called since the thumbnails mtime will be greater than
|
# THEN: doc.presentation_deleted should have been called since the thumbnails mtime will be greater than
|
||||||
# the presentation_file's mtime.
|
# the presentation_file's mtime.
|
||||||
mocked_doc.assert_has_calls([call.get_thumbnail_path(1, True), call.presentation_deleted()], True)
|
mocked_doc.assert_has_calls([call.get_thumbnail_path(1, True), call.presentation_deleted()], True)
|
||||||
|
|
||||||
|
def clean_up_thumbnails_missing_file_test(self):
|
||||||
|
"""
|
||||||
|
Test that the clean_up_thumbnails method works as expected when file is missing.
|
||||||
|
"""
|
||||||
|
# GIVEN: A mocked controller, and mocked os.path.exists
|
||||||
|
mocked_controller = MagicMock()
|
||||||
|
mocked_doc = MagicMock()
|
||||||
|
mocked_controller.add_document.return_value = mocked_doc
|
||||||
|
mocked_controller.supports = ['tmp']
|
||||||
|
self.media_item.controllers = {
|
||||||
|
'Mocked': mocked_controller
|
||||||
|
}
|
||||||
|
presentation_file = 'file.tmp'
|
||||||
|
with patch('openlp.plugins.presentations.lib.mediaitem.os.path.exists') as mocked_exists:
|
||||||
|
mocked_exists.return_value = False
|
||||||
|
|
||||||
|
# WHEN: calling clean_up_thumbnails
|
||||||
|
self.media_item.clean_up_thumbnails(presentation_file, True)
|
||||||
|
|
||||||
|
# THEN: doc.presentation_deleted should have been called since the presentation file did not exists.
|
||||||
|
mocked_doc.assert_has_calls([call.get_thumbnail_path(1, True), call.presentation_deleted()], True)
|
||||||
|
Loading…
Reference in New Issue
Block a user