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

Proposed by Phill on 2016-11-01
Status: Merged
Merged at revision: 2657
Proposed branch: lp:~phill-ridout/openlp/bug1623711-2.4
Merge into: lp:openlp/2.4
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-2.4
Reviewer Review Type Date Requested Status
Tomas Groth Approve on 2016-11-06
Tim Bentley 2016-11-01 Approve on 2016-11-02
Review via email: mp+309795@code.launchpad.net
To post a comment you must log in.
Tim Bentley (trb143) :
review: Approve
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 2015-12-31 22:46:06 +0000
+++ openlp/plugins/bibles/lib/manager.py 2016-11-01 20:24:24 +0000
@@ -126,7 +126,7 @@
126 name = bible.get_name()126 name = bible.get_name()
127 # Remove corrupted files.127 # Remove corrupted files.
128 if name is None:128 if name is None:
129 bible.session.close()129 bible.session.close_all()
130 delete_file(os.path.join(self.path, filename))130 delete_file(os.path.join(self.path, filename))
131 continue131 continue
132 log.debug('Bible Name: "%s"', name)132 log.debug('Bible Name: "%s"', name)
@@ -173,7 +173,7 @@
173 """173 """
174 log.debug('BibleManager.delete_bible("%s")', name)174 log.debug('BibleManager.delete_bible("%s")', name)
175 bible = self.db_cache[name]175 bible = self.db_cache[name]
176 bible.session.close()176 bible.session.close_all()
177 bible.session = None177 bible.session = None
178 return delete_file(os.path.join(bible.path, bible.file))178 return delete_file(os.path.join(bible.path, bible.file))
179179
180180
=== 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 20:24:24 +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')

Subscribers

People subscribed via source and target branches

to all changes: