Merge lp:~tomasgroth/openlp/bug719514 into lp:openlp

Proposed by Tomas Groth
Status: Superseded
Proposed branch: lp:~tomasgroth/openlp/bug719514
Merge into: lp:openlp
Diff against target: 146 lines (+120/-1)
3 files modified
openlp/core/ui/thememanager.py (+1/-1)
tests/functional/openlp_core_ui/test_thememanager.py (+115/-0)
tests/utils/test_bzr_tags.py (+4/-0)
To merge this branch: bzr merge lp:~tomasgroth/openlp/bug719514
Reviewer Review Type Date Requested Status
Raoul Snyman Needs Fixing
Samuel Mehrbrodt (community) Approve
Review via email: mp+225383@code.launchpad.net

This proposal has been superseded by a proposal from 2014-07-07.

Description of the change

To post a comment you must log in.
Revision history for this message
Tomas Groth (tomasgroth) wrote :
Revision history for this message
Samuel Mehrbrodt (sam92) :
review: Approve
Revision history for this message
Raoul Snyman (raoul-snyman) wrote :

Some minor fixes to your tests, but otherwise looking good. Technically you also want to test the case where the files are the same (it should be simple to do if you just copy the current test and modify it where necessary)

review: Needs Fixing
lp:~tomasgroth/openlp/bug719514 updated
2397. By Tomas Groth

Suggested changes to tests

2398. By Tomas Groth

trunk

2399. By Tomas Groth

Fix tag tests

2400. By Tomas Groth

Merged with trunk and reverted changes to the tag test

2401. By Tomas Groth

Updated jenkins script to match tests

2402. By Tomas Groth

pep8 fix

2403. By Tomas Groth

trunk

2404. By Tomas Groth

deleted file leftover from merge

2405. By Tomas Groth

Fixed windows test failure by removing special char from filenames

2406. By Tomas Groth

Fixed another windows test by properly constructing paths.

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'openlp/core/ui/thememanager.py'
2--- openlp/core/ui/thememanager.py 2014-03-20 19:10:31 +0000
3+++ openlp/core/ui/thememanager.py 2014-07-07 17:28:50 +0000
4@@ -650,7 +650,7 @@
5 finally:
6 if out_file:
7 out_file.close()
8- if image_from and image_from != image_to:
9+ if image_from and os.path.abspath(image_from) != os.path.abspath(image_to):
10 try:
11 encoding = get_filesystem_encoding()
12 shutil.copyfile(str(image_from).encode(encoding), str(image_to).encode(encoding))
13
14=== added file 'tests/functional/openlp_core_ui/test_thememanager.py'
15--- tests/functional/openlp_core_ui/test_thememanager.py 1970-01-01 00:00:00 +0000
16+++ tests/functional/openlp_core_ui/test_thememanager.py 2014-07-07 17:28:50 +0000
17@@ -0,0 +1,115 @@
18+# -*- coding: utf-8 -*-
19+# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
20+
21+###############################################################################
22+# OpenLP - Open Source Lyrics Projection #
23+# --------------------------------------------------------------------------- #
24+# Copyright (c) 2008-2014 Raoul Snyman #
25+# Portions copyright (c) 2008-2014 Tim Bentley, Gerald Britton, Jonathan #
26+# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
27+# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
28+# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
29+# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
30+# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, #
31+# Frode Woldsund, Martin Zibricky, Patrick Zimmermann #
32+# --------------------------------------------------------------------------- #
33+# This program is free software; you can redistribute it and/or modify it #
34+# under the terms of the GNU General Public License as published by the Free #
35+# Software Foundation; version 2 of the License. #
36+# #
37+# This program is distributed in the hope that it will be useful, but WITHOUT #
38+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
39+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
40+# more details. #
41+# #
42+# You should have received a copy of the GNU General Public License along #
43+# with this program; if not, write to the Free Software Foundation, Inc., 59 #
44+# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
45+###############################################################################
46+"""
47+Package to test the openlp.core.ui.slidecontroller package.
48+"""
49+import os
50+
51+from unittest import TestCase
52+
53+from openlp.core.common import Registry
54+from openlp.core.ui import ThemeManager
55+
56+from tests.utils.constants import TEST_RESOURCES_PATH
57+from tests.interfaces import MagicMock, patch
58+
59+
60+class TestThemeManager(TestCase):
61+
62+ def setUp(self):
63+ """
64+ Set up the tests
65+ """
66+ Registry.create()
67+
68+ def initial_theme_manager_test(self):
69+ """
70+ Test the instantiation of theme manager.
71+ """
72+ # GIVEN: A new service manager instance.
73+ ThemeManager(None)
74+
75+ # WHEN: the default theme manager is built.
76+ # THEN: The the controller should be registered in the registry.
77+ self.assertIsNotNone(Registry().get('theme_manager'), 'The base theme manager should be registered')
78+
79+ def write_theme_same_image_test(self):
80+ """
81+ Test that we don't try to overwrite a theme background image with itself
82+ """
83+ # GIVEN: A new theme manager instance, with mocked builtins.open, shutil.copyfile,
84+ # theme, check_directory_exists and thememanager-attributes.
85+ with patch('builtins.open') as mocked_open, \
86+ patch('openlp.core.ui.thememanager.shutil.copyfile') as mocked_copyfile, \
87+ patch('openlp.core.ui.thememanager.check_directory_exists') as mocked_check_directory_exists:
88+ mocked_open.return_value = MagicMock()
89+ theme_manager = ThemeManager(None)
90+ theme_manager.old_background_image = None
91+ theme_manager.generate_and_save_image = MagicMock()
92+ theme_manager.path = ''
93+ mocked_theme = MagicMock()
94+ mocked_theme.theme_name = 'themename'
95+ mocked_theme.extract_formatted_xml = MagicMock()
96+ mocked_theme.extract_formatted_xml.return_value = 'fake_theme_xml'.encode()
97+
98+ # WHEN: Calling _write_theme with path to the same image, but the path written slightly different
99+ file_name1 = os.path.join(TEST_RESOURCES_PATH, 'church.jpg')
100+ # Do replacement from end of string to avoid problems with path start
101+ file_name2 = file_name1[::-1].replace(os.sep, os.sep + os.sep, 2)[::-1]
102+ theme_manager._write_theme(mocked_theme, file_name1, file_name2)
103+
104+ # THEN: The mocked_copyfile should not have been called
105+ self.assertFalse(mocked_copyfile.called, 'shutil.copyfile should not be called')
106+
107+ def write_theme_diff_images_test(self):
108+ """
109+ Test that we do overwrite a theme background image when a new is submitted
110+ """
111+ # GIVEN: A new theme manager instance, with mocked builtins.open, shutil.copyfile,
112+ # theme, check_directory_exists and thememanager-attributes.
113+ with patch('builtins.open') as mocked_open, \
114+ patch('openlp.core.ui.thememanager.shutil.copyfile') as mocked_copyfile, \
115+ patch('openlp.core.ui.thememanager.check_directory_exists') as mocked_check_directory_exists:
116+ mocked_open.return_value = MagicMock()
117+ theme_manager = ThemeManager(None)
118+ theme_manager.old_background_image = None
119+ theme_manager.generate_and_save_image = MagicMock()
120+ theme_manager.path = ''
121+ mocked_theme = MagicMock()
122+ mocked_theme.theme_name = 'themename'
123+ mocked_theme.extract_formatted_xml = MagicMock()
124+ mocked_theme.extract_formatted_xml.return_value = 'fake_theme_xml'.encode()
125+
126+ # WHEN: Calling _write_theme with path to different images
127+ file_name1 = os.path.join(TEST_RESOURCES_PATH, 'church.jpg')
128+ file_name2 = os.path.join(TEST_RESOURCES_PATH, 'church2.jpg')
129+ theme_manager._write_theme(mocked_theme, file_name1, file_name2)
130+
131+ # THEN: The mocked_copyfile should not have been called
132+ self.assertTrue(mocked_copyfile.called, 'shutil.copyfile should be called')
133
134=== modified file 'tests/utils/test_bzr_tags.py'
135--- tests/utils/test_bzr_tags.py 2014-06-26 09:21:46 +0000
136+++ tests/utils/test_bzr_tags.py 2014-07-07 17:28:50 +0000
137@@ -50,6 +50,10 @@
138 ['1.9.11', '2039'],
139 ['1.9.12', '2063'],
140 ['2.0', '2118'],
141+ ['2.0.1', '?'],
142+ ['2.0.2', '?'],
143+ ['2.0.3', '?'],
144+ ['2.0.4', '?'],
145 ['2.1.0', '2119']
146 ]
147