Added test

This commit is contained in:
Tomas Groth 2015-03-10 23:46:37 +00:00
parent 79c1335d41
commit 8fe254e576

View File

@ -26,7 +26,7 @@ from unittest import TestCase
from openlp.core.common import Registry
from openlp.plugins.presentations.lib.mediaitem import PresentationMediaItem
from tests.functional import patch, MagicMock
from tests.functional import patch, MagicMock, call
from tests.helpers.testmixin import TestMixin
@ -84,3 +84,26 @@ class TestMediaItem(TestCase, TestMixin):
self.assertIn('*.pdf', self.media_item.on_new_file_masks, 'The file mask should contain the pdf extension')
self.assertIn('*.xps', self.media_item.on_new_file_masks, 'The file mask should contain the xps extension')
self.assertIn('*.oxps', self.media_item.on_new_file_masks, 'The file mask should contain the oxps extension')
def clean_up_thumbnails_test(self):
"""
Test that the clean_up_thumbnails method works as expected.
"""
# GIVEN: A mocked controller, and mocked os.path.getmtime
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.getmtime') as mocked_getmtime:
mocked_getmtime.side_effect = [100, 200]
# WHEN: calling clean_up_thumbnails
self.media_item.clean_up_thumbnails(presentation_file, True)
# THEN: doc.presentation_deleted should have been called since the thumbnails mtime will be greater than
# the presentation_file's mtime.
mocked_doc.assert_has_calls([call.get_thumbnail_path(1, True), call.presentation_deleted()], True)