Merge lp:~phill-ridout/openlp/bug1623711 into lp:openlp

Proposed by Phill
Status: Merged
Merged at revision: 2702
Proposed branch: lp:~phill-ridout/openlp/bug1623711
Merge into: lp:openlp
Diff against target: 95 lines (+71/-2)
2 files modified
openlp/plugins/bibles/lib/manager.py (+2/-2)
tests/functional/openlp_plugins/bibles/test_manager.py (+69/-0)
To merge this branch: bzr merge lp:~phill-ridout/openlp/bug1623711
Reviewer Review Type Date Requested Status
Tomas Groth Approve
Tim Bentley Approve
Review via email: mp+309786@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Tim Bentley (trb143) :
review: Approve
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
=== modified file 'openlp/plugins/bibles/lib/manager.py'
--- openlp/plugins/bibles/lib/manager.py 2016-09-16 19:54:25 +0000
+++ openlp/plugins/bibles/lib/manager.py 2016-11-01 19:35:38 +0000
@@ -131,7 +131,7 @@
131 name = bible.get_name()131 name = bible.get_name()
132 # Remove corrupted files.132 # Remove corrupted files.
133 if name is None:133 if name is None:
134 bible.session.close()134 bible.session.close_all()
135 delete_file(os.path.join(self.path, filename))135 delete_file(os.path.join(self.path, filename))
136 continue136 continue
137 log.debug('Bible Name: "{name}"'.format(name=name))137 log.debug('Bible Name: "{name}"'.format(name=name))
@@ -178,7 +178,7 @@
178 """178 """
179 log.debug('BibleManager.delete_bible("{name}")'.format(name=name))179 log.debug('BibleManager.delete_bible("{name}")'.format(name=name))
180 bible = self.db_cache[name]180 bible = self.db_cache[name]
181 bible.session.close()181 bible.session.close_all()
182 bible.session = None182 bible.session = None
183 return delete_file(os.path.join(bible.path, bible.file))183 return delete_file(os.path.join(bible.path, bible.file))
184184
185185
=== added file 'tests/functional/openlp_plugins/bibles/test_manager.py'
--- tests/functional/openlp_plugins/bibles/test_manager.py 1970-01-01 00:00:00 +0000
+++ tests/functional/openlp_plugins/bibles/test_manager.py 2016-11-01 19:35:38 +0000
@@ -0,0 +1,69 @@
1# -*- coding: utf-8 -*-
2# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
3
4###############################################################################
5# OpenLP - Open Source Lyrics Projection #
6# --------------------------------------------------------------------------- #
7# Copyright (c) 2008-2016 OpenLP Developers #
8# --------------------------------------------------------------------------- #
9# This program is free software; you can redistribute it and/or modify it #
10# under the terms of the GNU General Public License as published by the Free #
11# Software Foundation; version 2 of the License. #
12# #
13# This program is distributed in the hope that it will be useful, but WITHOUT #
14# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
15# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
16# more details. #
17# #
18# You should have received a copy of the GNU General Public License along #
19# with this program; if not, write to the Free Software Foundation, Inc., 59 #
20# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
21###############################################################################
22"""
23This module contains tests for the manager submodule of the Bibles plugin.
24"""
25from unittest import TestCase
26from unittest.mock import MagicMock, patch
27
28from openlp.plugins.bibles.lib.manager import BibleManager
29
30
31class TestManager(TestCase):
32 """
33 Test the functions in the :mod:`manager` module.
34 """
35
36 def setUp(self):
37 app_location_patcher = patch('openlp.plugins.bibles.lib.manager.AppLocation')
38 self.addCleanup(app_location_patcher.stop)
39 app_location_patcher.start()
40 log_patcher = patch('openlp.plugins.bibles.lib.manager.log')
41 self.addCleanup(log_patcher.stop)
42 self.mocked_log = log_patcher.start()
43 settings_patcher = patch('openlp.plugins.bibles.lib.manager.Settings')
44 self.addCleanup(settings_patcher.stop)
45 settings_patcher.start()
46
47 def test_delete_bible(self):
48 """
49 Test the BibleManager delete_bible method
50 """
51 # GIVEN: An instance of BibleManager and a mocked bible
52 with patch.object(BibleManager, 'reload_bibles'), \
53 patch('openlp.plugins.bibles.lib.manager.os.path.join', side_effect=lambda x, y: '{}/{}'.format(x, y)),\
54 patch('openlp.plugins.bibles.lib.manager.delete_file', return_value=True) as mocked_delete_file:
55 instance = BibleManager(MagicMock())
56 # We need to keep a reference to the mock for close_all as it gets set to None later on!
57 mocked_close_all = MagicMock()
58 mocked_bible = MagicMock(file='KJV.sqlite', path='bibles', **{'session.close_all': mocked_close_all})
59 instance.db_cache = {'KJV': mocked_bible}
60
61 # WHEN: Calling delete_bible with 'KJV'
62 result = instance.delete_bible('KJV')
63
64 # THEN: The session should have been closed and set to None, the bible should be deleted, and the result of
65 # the deletion returned.
66 self.assertTrue(result)
67 mocked_close_all.assert_called_once_with()
68 self.assertIsNone(mocked_bible.session)
69 mocked_delete_file.assert_called_once_with('bibles/KJV.sqlite')