Merge lp:~phill-ridout/openlp/bug1125956 into lp:openlp
- bug1125956
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Andreas Preikschat |
Approved revision: | 2193 |
Merged at revision: | 2229 |
Proposed branch: | lp:~phill-ridout/openlp/bug1125956 |
Merge into: | lp:openlp |
Diff against target: |
427 lines (+273/-36) 4 files modified
openlp/plugins/songs/lib/__init__.py (+1/-0) openlp/plugins/songs/lib/songimport.py (+4/-1) openlp/plugins/songs/lib/songshowplusimport.py (+33/-35) tests/functional/openlp_plugins/songs/test_songshowplusimport.py (+235/-0) |
To merge this branch: | bzr merge lp:~phill-ridout/openlp/bug1125956 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Andreas Preikschat (community) | Approve | ||
Raoul Snyman | Approve | ||
Review via email: mp+157455@code.launchpad.net |
This proposal supersedes a proposal from 2013-04-04.
Commit message
Description of the change
Fixed importing of songs with verses numbered 1A, or 1.5 etc. in SongShowPlus importer
Added Tests for SongShow Plus importer
Moved the song files as requested
Changed regex string type to raw
Comment added
Removed the use of the call helper object. It works however, it will only ensure that the method has been called wtih the expected calls and not catch any additional calls that maybe made to the method.
Andreas Preikschat (googol-deactivatedaccount) wrote : Posted in a previous version of this proposal | # |
Andreas Preikschat (googol-deactivatedaccount) wrote : Posted in a previous version of this proposal | # |
152 + match = re.match(
For regular expression you use r'' instead of u''
20 - self.verseOrder
21 + if verse_def not in self.verseOrder
22 + self.verseOrder
Why are you changing this? Docs say:
Add a verse. This is the whole verse, lines split by \\n. It will also
attempt to detect duplicates. In this case it will just add to the verse
order.
So we should append the verse_def in any case, shouldn't we?
Phill (phill-ridout) wrote : Posted in a previous version of this proposal | # |
> 20 - self.verseOrder
> 21 + if verse_def not in self.verseOrder
> 22 + self.verseOrder
>
> Why are you changing this? Docs say:
> Add a verse. This is the whole verse, lines split by \\n. It will also
> attempt to detect duplicates. In this case it will just add to the
> verse
> order.
> So we should append the verse_def in any case, shouldn't we?
Because OpenLP does not support verse numbering such as V1A and V1B we are dropping the A and B so we have two verses called V1 being added to a song (instead of V1A and V1B)
Each time V1 appears in the verse order both verses called V1 (actually V1A and V1B) were being added to the verse order.
With out this change V1 was being added to the verse order twice (once for each verse called V1), however because of the above statement the actual verse order shown in the live or preview controller repeated both verses.
This is a bit hard to clearly explain. It is probably easier for you to see the result by checking out this branch and importing the song attached to http://
Import it once with out the change on line 20 and once with the change and you will see the problem.
Phill (phill-ridout) wrote : Posted in a previous version of this proposal | # |
Ok, this is ready to merge providing you approve it!
Andreas Preikschat (googol-deactivatedaccount) wrote : Posted in a previous version of this proposal | # |
> Because OpenLP does not support verse numbering such as V1A and V1B we are dropping the A and B so
> we have two verses called V1 being added to a song (instead of V1A and V1B)
Then please add comment for this. Nobody will remember why this "if" was added.
Raoul Snyman (raoul-snyman) wrote : Posted in a previous version of this proposal | # |
Currently the tests fail because we're using an older version of the mock library on the Jenkins server which doesn't have the "call" function. I don't have access to the server right now to be able to fix anything, but I would prefer if you figure out how to get around the issue.
Raoul Snyman (raoul-snyman) wrote : | # |
You can check for a certain *number* of calls to that method.
assert mocked_
Phill (phill-ridout) wrote : | # |
Andreas,
Would you mind reviewing this?
Andreas Preikschat (googol-deactivatedaccount) : | # |
Preview Diff
1 | === modified file 'openlp/plugins/songs/lib/__init__.py' |
2 | --- openlp/plugins/songs/lib/__init__.py 2013-03-11 21:10:29 +0000 |
3 | +++ openlp/plugins/songs/lib/__init__.py 2013-04-05 18:34:21 +0000 |
4 | @@ -168,6 +168,7 @@ |
5 | translate('SongsPlugin.VerseType', 'Intro'), |
6 | translate('SongsPlugin.VerseType', 'Ending'), |
7 | translate('SongsPlugin.VerseType', 'Other')] |
8 | + |
9 | translated_tags = [name[0].lower() for name in translated_names] |
10 | |
11 | @staticmethod |
12 | |
13 | === modified file 'openlp/plugins/songs/lib/songimport.py' |
14 | --- openlp/plugins/songs/lib/songimport.py 2013-03-07 08:05:43 +0000 |
15 | +++ openlp/plugins/songs/lib/songimport.py 2013-04-05 18:34:21 +0000 |
16 | @@ -260,7 +260,10 @@ |
17 | elif int(verse_def[1:]) > self.verseCounts[verse_def[0]]: |
18 | self.verseCounts[verse_def[0]] = int(verse_def[1:]) |
19 | self.verses.append([verse_def, verse_text.rstrip(), lang]) |
20 | - self.verseOrderListGenerated.append(verse_def) |
21 | + # A verse_def refers to all verses with that name, adding it once adds every instance, so do not add if already |
22 | + # used. |
23 | + if verse_def not in self.verseOrderListGenerated: |
24 | + self.verseOrderListGenerated.append(verse_def) |
25 | |
26 | def repeatVerse(self): |
27 | """ |
28 | |
29 | === modified file 'openlp/plugins/songs/lib/songshowplusimport.py' |
30 | --- openlp/plugins/songs/lib/songshowplusimport.py 2013-03-07 08:05:43 +0000 |
31 | +++ openlp/plugins/songs/lib/songshowplusimport.py 2013-04-05 18:34:21 +0000 |
32 | @@ -32,6 +32,7 @@ |
33 | """ |
34 | import os |
35 | import logging |
36 | +import re |
37 | import struct |
38 | |
39 | from openlp.core.ui.wizard import WizardStrings |
40 | @@ -44,43 +45,36 @@ |
41 | CCLI_NO = 5 |
42 | VERSE = 12 |
43 | CHORUS = 20 |
44 | +BRIDGE = 24 |
45 | TOPIC = 29 |
46 | COMMENTS = 30 |
47 | VERSE_ORDER = 31 |
48 | SONG_BOOK = 35 |
49 | SONG_NUMBER = 36 |
50 | CUSTOM_VERSE = 37 |
51 | -BRIDGE = 24 |
52 | |
53 | log = logging.getLogger(__name__) |
54 | |
55 | class SongShowPlusImport(SongImport): |
56 | """ |
57 | - The :class:`SongShowPlusImport` class provides the ability to import song |
58 | - files from SongShow Plus. |
59 | + The :class:`SongShowPlusImport` class provides the ability to import song files from SongShow Plus. |
60 | |
61 | **SongShow Plus Song File Format:** |
62 | |
63 | The SongShow Plus song file format is as follows: |
64 | |
65 | - * Each piece of data in the song file has some information that precedes |
66 | - it. |
67 | + * Each piece of data in the song file has some information that precedes it. |
68 | * The general format of this data is as follows: |
69 | - 4 Bytes, forming a 32 bit number, a key if you will, this describes what |
70 | - the data is (see blockKey below) |
71 | - 4 Bytes, forming a 32 bit number, which is the number of bytes until the |
72 | - next block starts |
73 | + 4 Bytes, forming a 32 bit number, a key if you will, this describes what the data is (see blockKey below) |
74 | + 4 Bytes, forming a 32 bit number, which is the number of bytes until the next block starts |
75 | 1 Byte, which tells how many bytes follows |
76 | - 1 or 4 Bytes, describes how long the string is, if its 1 byte, the string |
77 | - is less than 255 |
78 | + 1 or 4 Bytes, describes how long the string is, if its 1 byte, the string is less than 255 |
79 | The next bytes are the actual data. |
80 | The next block of data follows on. |
81 | |
82 | - This description does differ for verses. Which includes extra bytes |
83 | - stating the verse type or number. In some cases a "custom" verse is used, |
84 | - in that case, this block will in include 2 strings, with the associated |
85 | - string length descriptors. The first string is the name of the verse, the |
86 | - second is the verse content. |
87 | + This description does differ for verses. Which includes extra bytes stating the verse type or number. In some cases |
88 | + a "custom" verse is used, in that case, this block will in include 2 strings, with the associated string length |
89 | + descriptors. The first string is the name of the verse, the second is the verse content. |
90 | |
91 | The file is ended with four null bytes. |
92 | |
93 | @@ -88,8 +82,9 @@ |
94 | |
95 | * .sbsong |
96 | """ |
97 | - otherList = {} |
98 | - otherCount = 0 |
99 | + |
100 | + other_count = 0 |
101 | + other_list = {} |
102 | |
103 | def __init__(self, manager, **kwargs): |
104 | """ |
105 | @@ -107,9 +102,9 @@ |
106 | for file in self.import_source: |
107 | if self.stop_import_flag: |
108 | return |
109 | - self.sspVerseOrderList = [] |
110 | - other_count = 0 |
111 | - other_list = {} |
112 | + self.ssp_verse_order_list = [] |
113 | + self.other_count = 0 |
114 | + self.other_list = {} |
115 | file_name = os.path.split(file)[1] |
116 | self.import_wizard.increment_progress_bar(WizardStrings.ImportingType % file_name, 0) |
117 | song_data = open(file, 'rb') |
118 | @@ -162,34 +157,37 @@ |
119 | elif block_key == COMMENTS: |
120 | self.comments = unicode(data, u'cp1252') |
121 | elif block_key == VERSE_ORDER: |
122 | - verse_tag = self.toOpenLPVerseTag(data, True) |
123 | + verse_tag = self.to_openlp_verse_tag(data, True) |
124 | if verse_tag: |
125 | if not isinstance(verse_tag, unicode): |
126 | verse_tag = unicode(verse_tag, u'cp1252') |
127 | - self.sspVerseOrderList.append(verse_tag) |
128 | + self.ssp_verse_order_list.append(verse_tag) |
129 | elif block_key == SONG_BOOK: |
130 | self.songBookName = unicode(data, u'cp1252') |
131 | elif block_key == SONG_NUMBER: |
132 | self.songNumber = ord(data) |
133 | elif block_key == CUSTOM_VERSE: |
134 | - verse_tag = self.toOpenLPVerseTag(verse_name) |
135 | + verse_tag = self.to_openlp_verse_tag(verse_name) |
136 | self.addVerse(unicode(data, u'cp1252'), verse_tag) |
137 | else: |
138 | log.debug("Unrecognised blockKey: %s, data: %s" % (block_key, data)) |
139 | song_data.seek(next_block_starts) |
140 | - self.verseOrderList = self.sspVerseOrderList |
141 | + self.verseOrderList = self.ssp_verse_order_list |
142 | song_data.close() |
143 | if not self.finish(): |
144 | self.logError(file) |
145 | |
146 | - def toOpenLPVerseTag(self, verse_name, ignore_unique=False): |
147 | - if verse_name.find(" ") != -1: |
148 | - verse_parts = verse_name.split(" ") |
149 | - verse_type = verse_parts[0] |
150 | - verse_number = verse_parts[1] |
151 | + def to_openlp_verse_tag(self, verse_name, ignore_unique=False): |
152 | + # Have we got any digits? If so, verse number is everything from the digits to the end (OpenLP does not have |
153 | + # concept of part verses, so just ignore any non integers on the end (including floats)) |
154 | + match = re.match(r'(\D*)(\d+)', verse_name) |
155 | + if match: |
156 | + verse_type = match.group(1).strip() |
157 | + verse_number = match.group(2) |
158 | else: |
159 | + # otherwise we assume number 1 and take the whole prefix as the verse tag |
160 | verse_type = verse_name |
161 | - verse_number = "1" |
162 | + verse_number = u'1' |
163 | verse_type = verse_type.lower() |
164 | if verse_type == "verse": |
165 | verse_tag = VerseType.tags[VerseType.Verse] |
166 | @@ -200,11 +198,11 @@ |
167 | elif verse_type == "pre-chorus": |
168 | verse_tag = VerseType.tags[VerseType.PreChorus] |
169 | else: |
170 | - if verse_name not in self.otherList: |
171 | + if verse_name not in self.other_list: |
172 | if ignore_unique: |
173 | return None |
174 | - self.otherCount += 1 |
175 | - self.otherList[verse_name] = str(self.otherCount) |
176 | + self.other_count += 1 |
177 | + self.other_list[verse_name] = str(self.other_count) |
178 | verse_tag = VerseType.tags[VerseType.Other] |
179 | - verse_number = self.otherList[verse_name] |
180 | + verse_number = self.other_list[verse_name] |
181 | return verse_tag + verse_number |
182 | |
183 | === added file 'tests/functional/openlp_plugins/songs/test_songshowplusimport.py' |
184 | --- tests/functional/openlp_plugins/songs/test_songshowplusimport.py 1970-01-01 00:00:00 +0000 |
185 | +++ tests/functional/openlp_plugins/songs/test_songshowplusimport.py 2013-04-05 18:34:21 +0000 |
186 | @@ -0,0 +1,235 @@ |
187 | +""" |
188 | +This module contains tests for the SongShow Plus song importer. |
189 | +""" |
190 | + |
191 | +import os |
192 | +from unittest import TestCase |
193 | +from mock import patch, MagicMock |
194 | + |
195 | +from openlp.plugins.songs.lib import VerseType |
196 | +from openlp.plugins.songs.lib.songshowplusimport import SongShowPlusImport |
197 | + |
198 | +TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), u'../../../resources/songshowplussongs')) |
199 | +SONG_TEST_DATA = {u'Amazing Grace.sbsong': |
200 | + {u'title': u'Amazing Grace (Demonstration)', |
201 | + u'authors': [u'John Newton', u'Edwin Excell', u'John P. Rees'], |
202 | + u'copyright': u'Public Domain ', |
203 | + u'ccli_number': 22025, |
204 | + u'verses': |
205 | + [(u'Amazing grace! How sweet the sound!\r\nThat saved a wretch like me!\r\n' |
206 | + u'I once was lost, but now am found;\r\nWas blind, but now I see.', u'v1'), |
207 | + (u'\'Twas grace that taught my heart to fear,\r\nAnd grace my fears relieved.\r\n' |
208 | + u'How precious did that grace appear,\r\nThe hour I first believed.', u'v2'), |
209 | + (u'The Lord has promised good to me,\r\nHis Word my hope secures.\r\n' |
210 | + u'He will my shield and portion be\r\nAs long as life endures.', u'v3'), |
211 | + (u'Thro\' many dangers, toils and snares\r\nI have already come.\r\n' |
212 | + u'\'Tis grace that brought me safe thus far,\r\nAnd grace will lead me home.', u'v4'), |
213 | + (u'When we\'ve been there ten thousand years,\r\nBright shining as the sun,\r\n' |
214 | + u'We\'ve no less days to sing God\'s praise,\r\nThan when we first begun.', u'v5')], |
215 | + u'topics': [u'Assurance', u'Grace', u'Praise', u'Salvation'], |
216 | + u'comments': u'\n\n\n', |
217 | + u'song_book_name': u'Demonstration Songs', |
218 | + u'song_number': 0, |
219 | + u'verse_order_list': []}, |
220 | + u'Beautiful Garden Of Prayer.sbsong': |
221 | + {u'title': u'Beautiful Garden Of Prayer (Demonstration)', |
222 | + u'authors': [u'Eleanor Allen Schroll', u'James H. Fillmore'], |
223 | + u'copyright': u'Public Domain ', |
224 | + u'ccli_number': 60252, |
225 | + u'verses': |
226 | + [(u'There\'s a garden where Jesus is waiting,\r\nThere\'s a place that is wondrously fair.\r\n' |
227 | + u'For it glows with the light of His presence,\r\n\'Tis the beautiful garden of prayer.', u'v1'), |
228 | + (u'There\'s a garden where Jesus is waiting,\r\nAnd I go with my burden and care.\r\n' |
229 | + u'Just to learn from His lips, words of comfort,\r\nIn the beautiful garden of prayer.', u'v2'), |
230 | + (u'There\'s a garden where Jesus is waiting,\r\nAnd He bids you to come meet Him there,\r\n' |
231 | + u'Just to bow and receive a new blessing,\r\nIn the beautiful garden of prayer.', u'v3'), |
232 | + (u'O the beautiful garden, the garden of prayer,\r\nO the beautiful garden of prayer.\r\n' |
233 | + u'There my Savior awaits, and He opens the gates\r\nTo the beautiful garden of prayer.', u'c1')], |
234 | + u'topics': [u'Devotion', u'Prayer'], |
235 | + u'comments': u'', |
236 | + u'song_book_name': u'', |
237 | + u'song_number': 0, |
238 | + u'verse_order_list': []}} |
239 | + |
240 | + |
241 | +class TestSongShowPlusImport(TestCase): |
242 | + """ |
243 | + Test the functions in the :mod:`songshowplusimport` module. |
244 | + """ |
245 | + def create_importer_test(self): |
246 | + """ |
247 | + Test creating an instance of the SongShow Plus file importer |
248 | + """ |
249 | + # GIVEN: A mocked out SongImport class, and a mocked out "manager" |
250 | + with patch(u'openlp.plugins.songs.lib.songshowplusimport.SongImport'): |
251 | + mocked_manager = MagicMock() |
252 | + |
253 | + # WHEN: An importer object is created |
254 | + importer = SongShowPlusImport(mocked_manager) |
255 | + |
256 | + # THEN: The importer object should not be None |
257 | + self.assertIsNotNone(importer, u'Import should not be none') |
258 | + |
259 | + def invalid_import_source_test(self): |
260 | + """ |
261 | + Test SongShowPlusImport.doImport handles different invalid import_source values |
262 | + """ |
263 | + # GIVEN: A mocked out SongImport class, and a mocked out "manager" |
264 | + with patch(u'openlp.plugins.songs.lib.songshowplusimport.SongImport'): |
265 | + mocked_manager = MagicMock() |
266 | + mocked_import_wizard = MagicMock() |
267 | + importer = SongShowPlusImport(mocked_manager) |
268 | + importer.import_wizard = mocked_import_wizard |
269 | + importer.stop_import_flag = True |
270 | + |
271 | + # WHEN: Import source is not a list |
272 | + for source in [u'not a list', 0]: |
273 | + importer.import_source = source |
274 | + |
275 | + # THEN: doImport should return none and the progress bar maximum should not be set. |
276 | + self.assertIsNone(importer.doImport(), u'doImport should return None when import_source is not a list') |
277 | + self.assertEquals(mocked_import_wizard.progress_bar.setMaximum.called, False, |
278 | + u'setMaxium on import_wizard.progress_bar should not have been called') |
279 | + |
280 | + def valid_import_source_test(self): |
281 | + """ |
282 | + Test SongShowPlusImport.doImport handles different invalid import_source values |
283 | + """ |
284 | + # GIVEN: A mocked out SongImport class, and a mocked out "manager" |
285 | + with patch(u'openlp.plugins.songs.lib.songshowplusimport.SongImport'): |
286 | + mocked_manager = MagicMock() |
287 | + mocked_import_wizard = MagicMock() |
288 | + importer = SongShowPlusImport(mocked_manager) |
289 | + importer.import_wizard = mocked_import_wizard |
290 | + importer.stop_import_flag = True |
291 | + |
292 | + # WHEN: Import source is a list |
293 | + importer.import_source = [u'List', u'of', u'files'] |
294 | + |
295 | + # THEN: doImport should return none and the progress bar setMaximum should be called with the length of |
296 | + # import_source. |
297 | + self.assertIsNone(importer.doImport(), |
298 | + u'doImport should return None when import_source is a list and stop_import_flag is True') |
299 | + mocked_import_wizard.progress_bar.setMaximum.assert_called_with(len(importer.import_source)) |
300 | + |
301 | + def to_openlp_verse_tag_test(self): |
302 | + """ |
303 | + Test to_openlp_verse_tag method by simulating adding a verse |
304 | + """ |
305 | + # GIVEN: A mocked out SongImport class, and a mocked out "manager" |
306 | + with patch(u'openlp.plugins.songs.lib.songshowplusimport.SongImport'): |
307 | + mocked_manager = MagicMock() |
308 | + importer = SongShowPlusImport(mocked_manager) |
309 | + |
310 | + # WHEN: Supplied with the following arguments replicating verses being added |
311 | + test_values = [(u'Verse 1', VerseType.tags[VerseType.Verse] + u'1'), |
312 | + (u'Verse 2', VerseType.tags[VerseType.Verse] + u'2'), |
313 | + (u'verse1', VerseType.tags[VerseType.Verse] + u'1'), |
314 | + (u'Verse', VerseType.tags[VerseType.Verse] + u'1'), |
315 | + (u'Verse1', VerseType.tags[VerseType.Verse] + u'1'), |
316 | + (u'chorus 1', VerseType.tags[VerseType.Chorus] + u'1'), |
317 | + (u'bridge 1', VerseType.tags[VerseType.Bridge] + u'1'), |
318 | + (u'pre-chorus 1', VerseType.tags[VerseType.PreChorus] + u'1'), |
319 | + (u'different 1', VerseType.tags[VerseType.Other] + u'1'), |
320 | + (u'random 1', VerseType.tags[VerseType.Other] + u'2')] |
321 | + |
322 | + # THEN: The returned value should should correlate with the input arguments |
323 | + for original_tag, openlp_tag in test_values: |
324 | + self.assertEquals(importer.to_openlp_verse_tag(original_tag), openlp_tag, |
325 | + u'SongShowPlusImport.to_openlp_verse_tag should return "%s" when called with "%s"' |
326 | + % (openlp_tag, original_tag)) |
327 | + |
328 | + def to_openlp_verse_tag_verse_order_test(self): |
329 | + """ |
330 | + Test to_openlp_verse_tag method by simulating adding a verse to the verse order |
331 | + """ |
332 | + # GIVEN: A mocked out SongImport class, and a mocked out "manager" |
333 | + with patch(u'openlp.plugins.songs.lib.songshowplusimport.SongImport'): |
334 | + mocked_manager = MagicMock() |
335 | + importer = SongShowPlusImport(mocked_manager) |
336 | + |
337 | + # WHEN: Supplied with the following arguments replicating a verse order being added |
338 | + test_values = [(u'Verse 1', VerseType.tags[VerseType.Verse] + u'1'), |
339 | + (u'Verse 2', VerseType.tags[VerseType.Verse] + u'2'), |
340 | + (u'verse1', VerseType.tags[VerseType.Verse] + u'1'), |
341 | + (u'Verse', VerseType.tags[VerseType.Verse] + u'1'), |
342 | + (u'Verse1', VerseType.tags[VerseType.Verse] + u'1'), |
343 | + (u'chorus 1', VerseType.tags[VerseType.Chorus] + u'1'), |
344 | + (u'bridge 1', VerseType.tags[VerseType.Bridge] + u'1'), |
345 | + (u'pre-chorus 1', VerseType.tags[VerseType.PreChorus] + u'1'), |
346 | + (u'different 1', VerseType.tags[VerseType.Other] + u'1'), |
347 | + (u'random 1', VerseType.tags[VerseType.Other] + u'2'), |
348 | + (u'unused 2', None)] |
349 | + |
350 | + # THEN: The returned value should should correlate with the input arguments |
351 | + for original_tag, openlp_tag in test_values: |
352 | + self.assertEquals(importer.to_openlp_verse_tag(original_tag, ignore_unique=True), openlp_tag, |
353 | + u'SongShowPlusImport.to_openlp_verse_tag should return "%s" when called with "%s"' |
354 | + % (openlp_tag, original_tag)) |
355 | + |
356 | + def file_import_test(self): |
357 | + """ |
358 | + Test the actual import of real song files and check that the imported data is correct. |
359 | + """ |
360 | + |
361 | + # GIVEN: Test files with a mocked out SongImport class, a mocked out "manager", a mocked out "import_wizard", |
362 | + # and mocked out "author", "add_copyright", "add_verse", "finish" methods. |
363 | + with patch(u'openlp.plugins.songs.lib.songshowplusimport.SongImport'): |
364 | + for song_file in SONG_TEST_DATA: |
365 | + mocked_manager = MagicMock() |
366 | + mocked_import_wizard = MagicMock() |
367 | + mocked_parse_author = MagicMock() |
368 | + mocked_add_copyright = MagicMock() |
369 | + mocked_add_verse = MagicMock() |
370 | + mocked_finish = MagicMock() |
371 | + mocked_finish.return_value = True |
372 | + importer = SongShowPlusImport(mocked_manager) |
373 | + importer.import_wizard = mocked_import_wizard |
374 | + importer.stop_import_flag = False |
375 | + importer.parse_author = mocked_parse_author |
376 | + importer.addCopyright = mocked_add_copyright |
377 | + importer.addVerse = mocked_add_verse |
378 | + importer.finish = mocked_finish |
379 | + importer.topics = [] |
380 | + |
381 | + # WHEN: Importing each file |
382 | + importer.import_source = [os.path.join(TEST_PATH, song_file)] |
383 | + title = SONG_TEST_DATA[song_file][u'title'] |
384 | + author_calls = SONG_TEST_DATA[song_file][u'authors'] |
385 | + song_copyright = SONG_TEST_DATA[song_file][u'copyright'] |
386 | + ccli_number = SONG_TEST_DATA[song_file][u'ccli_number'] |
387 | + add_verse_calls = SONG_TEST_DATA[song_file][u'verses'] |
388 | + topics = SONG_TEST_DATA[song_file][u'topics'] |
389 | + comments = SONG_TEST_DATA[song_file][u'comments'] |
390 | + song_book_name = SONG_TEST_DATA[song_file][u'song_book_name'] |
391 | + song_number = SONG_TEST_DATA[song_file][u'song_number'] |
392 | + verse_order_list = SONG_TEST_DATA[song_file][u'verse_order_list'] |
393 | + |
394 | + # THEN: doImport should return none, the song data should be as expected, and finish should have been |
395 | + # called. |
396 | + self.assertIsNone(importer.doImport(), u'doImport should return None when it has completed') |
397 | + self.assertEquals(importer.title, title, u'title for %s should be "%s"' % (song_file, title)) |
398 | + for author in author_calls: |
399 | + mocked_parse_author.assert_any_call(author) |
400 | + if song_copyright: |
401 | + mocked_add_copyright.assert_called_with(song_copyright) |
402 | + if ccli_number: |
403 | + self.assertEquals(importer.ccliNumber, ccli_number, u'ccliNumber for %s should be %s' |
404 | + % (song_file, ccli_number)) |
405 | + for verse_text, verse_tag in add_verse_calls: |
406 | + mocked_add_verse.assert_any_call(verse_text, verse_tag) |
407 | + if topics: |
408 | + self.assertEquals(importer.topics, topics, u'topics for %s should be %s' % (song_file, topics)) |
409 | + if comments: |
410 | + self.assertEquals(importer.comments, comments, u'comments for %s should be "%s"' |
411 | + % (song_file, comments)) |
412 | + if song_book_name: |
413 | + self.assertEquals(importer.songBookName, song_book_name, u'songBookName for %s should be "%s"' |
414 | + % (song_file, song_book_name)) |
415 | + if song_number: |
416 | + self.assertEquals(importer.songNumber, song_number, u'songNumber for %s should be %s' |
417 | + % (song_file, song_number)) |
418 | + if verse_order_list: |
419 | + self.assertEquals(importer.verseOrderList, [], u'verseOrderList for %s should be %s' |
420 | + % (song_file, verse_order_list)) |
421 | + mocked_finish.assert_called_with() |
422 | |
423 | === added directory 'tests/resources/songshowplussongs' |
424 | === added file 'tests/resources/songshowplussongs/Amazing Grace.sbsong' |
425 | Binary files tests/resources/songshowplussongs/Amazing Grace.sbsong 1970-01-01 00:00:00 +0000 and tests/resources/songshowplussongs/Amazing Grace.sbsong 2013-04-05 18:34:21 +0000 differ |
426 | === added file 'tests/resources/songshowplussongs/Beautiful Garden Of Prayer.sbsong' |
427 | Binary files tests/resources/songshowplussongs/Beautiful Garden Of Prayer.sbsong 1970-01-01 00:00:00 +0000 and tests/resources/songshowplussongs/Beautiful Garden Of Prayer.sbsong 2013-04-05 18:34:21 +0000 differ |
427 === added file 'tests/ resources/ Amazing Grace.sbsong' resources/ Beautiful Garden Of Prayer.sbsong'
429 === added file 'tests/
Please move them in a dir SongShowPlusSongs or something like that