Merge lp:~raoul-snyman/openlp/fix-presentations-cleanup-bug into lp:openlp

Proposed by Raoul Snyman
Status: Merged
Approved by: Raoul Snyman
Approved revision: 2885
Merged at revision: 2884
Proposed branch: lp:~raoul-snyman/openlp/fix-presentations-cleanup-bug
Merge into: lp:openlp
Diff against target: 64 lines (+17/-7)
2 files modified
openlp/plugins/presentations/lib/mediaitem.py (+3/-0)
tests/functional/openlp_plugins/presentations/test_mediaitem.py (+14/-7)
To merge this branch: bzr merge lp:~raoul-snyman/openlp/fix-presentations-cleanup-bug
Reviewer Review Type Date Requested Status
Tomas Groth Approve
Review via email: mp+369624@code.launchpad.net

Commit message

Fix a bug when cleaning up thumbnails where all presentation controllers, whether enabled or not, would be cycled through.

Description of the change

Fix a bug when cleaning up thumbnails where all presentation controllers, whether enabled or not, would be cycled through.

To post a comment you must log in.
Revision history for this message
Raoul Snyman (raoul-snyman) wrote :

Linux tests passed!

Revision history for this message
Raoul Snyman (raoul-snyman) wrote :

Linting passed!

Revision history for this message
Raoul Snyman (raoul-snyman) wrote :

macOS tests passed!

Revision history for this message
Tomas Groth (tomasgroth) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'openlp/plugins/presentations/lib/mediaitem.py'
2--- openlp/plugins/presentations/lib/mediaitem.py 2019-05-22 06:47:00 +0000
3+++ openlp/plugins/presentations/lib/mediaitem.py 2019-07-03 04:00:28 +0000
4@@ -246,6 +246,9 @@
5 :rtype: None
6 """
7 for cidx in self.controllers:
8+ if not self.controllers[cidx].enabled():
9+ # skip presentation controllers that are not enabled
10+ continue
11 file_ext = file_path.suffix[1:]
12 if file_ext in self.controllers[cidx].supports or file_ext in self.controllers[cidx].also_supports:
13 doc = self.controllers[cidx].add_document(file_path)
14
15=== modified file 'tests/functional/openlp_plugins/presentations/test_mediaitem.py'
16--- tests/functional/openlp_plugins/presentations/test_mediaitem.py 2019-05-22 06:47:00 +0000
17+++ tests/functional/openlp_plugins/presentations/test_mediaitem.py 2019-07-03 04:00:28 +0000
18@@ -24,7 +24,7 @@
19 """
20 from pathlib import Path
21 from unittest import TestCase
22-from unittest.mock import MagicMock, call, patch
23+from unittest.mock import MagicMock, PropertyMock, call, patch
24
25 from openlp.core.common.registry import Registry
26 from openlp.plugins.presentations.lib.mediaitem import PresentationMediaItem
27@@ -94,17 +94,23 @@
28 Test that the clean_up_thumbnails method works as expected when files exists.
29 """
30 # GIVEN: A mocked controller, and mocked os.path.getmtime
31- mocked_controller = MagicMock()
32+ mocked_disabled_controller = MagicMock()
33+ mocked_disabled_controller.enabled.return_value = False
34+ mocked_disabled_supports = PropertyMock()
35+ type(mocked_disabled_controller).supports = mocked_disabled_supports
36+ mocked_enabled_controller = MagicMock()
37+ mocked_enabled_controller.enabled.return_value = True
38 mocked_doc = MagicMock(**{'get_thumbnail_path.return_value': Path()})
39- mocked_controller.add_document.return_value = mocked_doc
40- mocked_controller.supports = ['tmp']
41+ mocked_enabled_controller.add_document.return_value = mocked_doc
42+ mocked_enabled_controller.supports = ['tmp']
43 self.media_item.controllers = {
44- 'Mocked': mocked_controller
45+ 'Enabled': mocked_enabled_controller,
46+ 'Disabled': mocked_disabled_controller
47 }
48
49- thmub_path = MagicMock(st_mtime=100)
50+ thumb_path = MagicMock(st_mtime=100)
51 file_path = MagicMock(st_mtime=400)
52- with patch.object(Path, 'stat', side_effect=[thmub_path, file_path]), \
53+ with patch.object(Path, 'stat', side_effect=[thumb_path, file_path]), \
54 patch.object(Path, 'exists', return_value=True):
55 presentation_file = Path('file.tmp')
56
57@@ -114,6 +120,7 @@
58 # THEN: doc.presentation_deleted should have been called since the thumbnails mtime will be greater than
59 # the presentation_file's mtime.
60 mocked_doc.assert_has_calls([call.get_thumbnail_path(1, True), call.presentation_deleted()], True)
61+ assert mocked_disabled_supports.call_count == 0
62
63 def test_clean_up_thumbnails_missing_file(self):
64 """