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

Proposed by Phill
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
Tim Bentley Approve
Review via email: mp+309795@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
1=== modified file 'openlp/plugins/bibles/lib/manager.py'
2--- openlp/plugins/bibles/lib/manager.py 2015-12-31 22:46:06 +0000
3+++ openlp/plugins/bibles/lib/manager.py 2016-11-01 20:24:24 +0000
4@@ -126,7 +126,7 @@
5 name = bible.get_name()
6 # Remove corrupted files.
7 if name is None:
8- bible.session.close()
9+ bible.session.close_all()
10 delete_file(os.path.join(self.path, filename))
11 continue
12 log.debug('Bible Name: "%s"', name)
13@@ -173,7 +173,7 @@
14 """
15 log.debug('BibleManager.delete_bible("%s")', name)
16 bible = self.db_cache[name]
17- bible.session.close()
18+ bible.session.close_all()
19 bible.session = None
20 return delete_file(os.path.join(bible.path, bible.file))
21
22
23=== added file 'tests/functional/openlp_plugins/bibles/test_manager.py'
24--- tests/functional/openlp_plugins/bibles/test_manager.py 1970-01-01 00:00:00 +0000
25+++ tests/functional/openlp_plugins/bibles/test_manager.py 2016-11-01 20:24:24 +0000
26@@ -0,0 +1,69 @@
27+# -*- coding: utf-8 -*-
28+# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
29+
30+###############################################################################
31+# OpenLP - Open Source Lyrics Projection #
32+# --------------------------------------------------------------------------- #
33+# Copyright (c) 2008-2016 OpenLP Developers #
34+# --------------------------------------------------------------------------- #
35+# This program is free software; you can redistribute it and/or modify it #
36+# under the terms of the GNU General Public License as published by the Free #
37+# Software Foundation; version 2 of the License. #
38+# #
39+# This program is distributed in the hope that it will be useful, but WITHOUT #
40+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
41+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
42+# more details. #
43+# #
44+# You should have received a copy of the GNU General Public License along #
45+# with this program; if not, write to the Free Software Foundation, Inc., 59 #
46+# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
47+###############################################################################
48+"""
49+This module contains tests for the manager submodule of the Bibles plugin.
50+"""
51+from unittest import TestCase
52+from unittest.mock import MagicMock, patch
53+
54+from openlp.plugins.bibles.lib.manager import BibleManager
55+
56+
57+class TestManager(TestCase):
58+ """
59+ Test the functions in the :mod:`manager` module.
60+ """
61+
62+ def setUp(self):
63+ app_location_patcher = patch('openlp.plugins.bibles.lib.manager.AppLocation')
64+ self.addCleanup(app_location_patcher.stop)
65+ app_location_patcher.start()
66+ log_patcher = patch('openlp.plugins.bibles.lib.manager.log')
67+ self.addCleanup(log_patcher.stop)
68+ self.mocked_log = log_patcher.start()
69+ settings_patcher = patch('openlp.plugins.bibles.lib.manager.Settings')
70+ self.addCleanup(settings_patcher.stop)
71+ settings_patcher.start()
72+
73+ def test_delete_bible(self):
74+ """
75+ Test the BibleManager delete_bible method
76+ """
77+ # GIVEN: An instance of BibleManager and a mocked bible
78+ with patch.object(BibleManager, 'reload_bibles'), \
79+ patch('openlp.plugins.bibles.lib.manager.os.path.join', side_effect=lambda x, y: '{}/{}'.format(x, y)),\
80+ patch('openlp.plugins.bibles.lib.manager.delete_file', return_value=True) as mocked_delete_file:
81+ instance = BibleManager(MagicMock())
82+ # We need to keep a reference to the mock for close_all as it gets set to None later on!
83+ mocked_close_all = MagicMock()
84+ mocked_bible = MagicMock(file='KJV.sqlite', path='bibles', **{'session.close_all': mocked_close_all})
85+ instance.db_cache = {'KJV': mocked_bible}
86+
87+ # WHEN: Calling delete_bible with 'KJV'
88+ result = instance.delete_bible('KJV')
89+
90+ # THEN: The session should have been closed and set to None, the bible should be deleted, and the result of
91+ # the deletion returned.
92+ self.assertTrue(result)
93+ mocked_close_all.assert_called_once_with()
94+ self.assertIsNone(mocked_bible.session)
95+ mocked_delete_file.assert_called_once_with('bibles/KJV.sqlite')

Subscribers

People subscribed via source and target branches

to all changes: