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

Proposed by Phill
Status: Merged
Approved by: Raoul Snyman
Approved revision: 2783
Merged at revision: 2786
Proposed branch: lp:~phill-ridout/openlp/pathlib9
Merge into: lp:openlp
Diff against target: 2016 lines (+307/-416)
19 files modified
openlp/plugins/bibles/forms/bibleimportform.py (+98/-188)
openlp/plugins/bibles/lib/bibleimport.py (+14/-14)
openlp/plugins/bibles/lib/biblestab.py (+2/-2)
openlp/plugins/bibles/lib/db.py (+18/-16)
openlp/plugins/bibles/lib/importers/__init__.py (+0/-21)
openlp/plugins/bibles/lib/importers/csvbible.py (+12/-11)
openlp/plugins/bibles/lib/importers/opensong.py (+6/-5)
openlp/plugins/bibles/lib/importers/osis.py (+4/-4)
openlp/plugins/bibles/lib/importers/sword.py (+1/-1)
openlp/plugins/bibles/lib/importers/wordproject.py (+11/-16)
openlp/plugins/bibles/lib/importers/zefania.py (+4/-4)
openlp/plugins/bibles/lib/manager.py (+9/-10)
tests/functional/openlp_plugins/bibles/test_bibleimport.py (+24/-23)
tests/functional/openlp_plugins/bibles/test_csvimport.py (+29/-20)
tests/functional/openlp_plugins/bibles/test_opensongimport.py (+18/-17)
tests/functional/openlp_plugins/bibles/test_osisimport.py (+26/-25)
tests/functional/openlp_plugins/bibles/test_swordimport.py (+2/-2)
tests/functional/openlp_plugins/bibles/test_wordprojectimport.py (+23/-32)
tests/functional/openlp_plugins/bibles/test_zefaniaimport.py (+6/-5)
To merge this branch: bzr merge lp:~phill-ridout/openlp/pathlib9
Reviewer Review Type Date Requested Status
Tim Bentley Approve
Raoul Snyman Approve
Review via email: mp+333718@code.launchpad.net

This proposal supersedes a proposal from 2017-10-11.

Description of the change

Add this to your merge proposal:
--------------------------------------------------------------------------------
lp:~phill-ridout/openlp/pathlib9 (revision 2783)
https://ci.openlp.io/job/Branch-01-Pull/2286/ [WAITING]
[RUNNING]
[SUCCESS]
https://ci.openlp.io/job/Branch-02-Functional-Tests/2187/ [WAITING]
[RUNNING]
[SUCCESS]
https://ci.openlp.io/job/Branch-03-Interface-Tests/2068/ [WAITING]
[RUNNING]
[SUCCESS]
https://ci.openlp.io/job/Branch-04a-Code_Analysis/1396/ [WAITING]
[RUNNING]
[SUCCESS]
https://ci.openlp.io/job/Branch-04b-Test_Coverage/1221/ [WAITING]
[RUNNING]
[SUCCESS]
https://ci.openlp.io/job/Branch-04c-Code_Analysis2/351/ [WAITING]
[RUNNING]
[SUCCESS]
https://ci.openlp.io/job/Branch-05-AppVeyor-Tests/183/ [WAITING]
[RUNNING]
[FAILURE]
Stopping after failure, see https://ci.openlp.io/job/Branch-05-AppVeyor-Tests/183/console for more details

To post a comment you must log in.
Revision history for this message
Phill (phill-ridout) wrote : Posted in a previous version of this proposal

Superfly, when you get a mo, could you tell me if 1048, 1828, 1860, 1892 are acceptable, or if I've got it wrong?

Revision history for this message
Tim Bentley (trb143) wrote : Posted in a previous version of this proposal

Looks good but subject answers from superfly.

review: Approve
Revision history for this message
Raoul Snyman (raoul-snyman) wrote : Posted in a previous version of this proposal

I think there's one instance you need to change. Please see my comments below for more guidance.

review: Needs Fixing
Revision history for this message
Raoul Snyman (raoul-snyman) :
review: Approve
Revision history for this message
Tim Bentley (trb143) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'openlp/plugins/bibles/forms/bibleimportform.py'
--- openlp/plugins/bibles/forms/bibleimportform.py 2017-10-23 22:09:57 +0000
+++ openlp/plugins/bibles/forms/bibleimportform.py 2017-11-14 23:03:10 +0000
@@ -23,7 +23,6 @@
23The bible import functions for OpenLP23The bible import functions for OpenLP
24"""24"""
25import logging25import logging
26import os
27import urllib.error26import urllib.error
28from lxml import etree27from lxml import etree
2928
@@ -41,6 +40,7 @@
41from openlp.core.lib.db import delete_database40from openlp.core.lib.db import delete_database
42from openlp.core.lib.exceptions import ValidationError41from openlp.core.lib.exceptions import ValidationError
43from openlp.core.lib.ui import critical_error_message_box42from openlp.core.lib.ui import critical_error_message_box
43from openlp.core.widgets.edits import PathEdit
44from openlp.core.widgets.wizard import OpenLPWizard, WizardStrings44from openlp.core.widgets.wizard import OpenLPWizard, WizardStrings
45from openlp.plugins.bibles.lib.db import clean_filename45from openlp.plugins.bibles.lib.db import clean_filename
46from openlp.plugins.bibles.lib.importers.http import CWExtract, BGExtract, BSExtract46from openlp.plugins.bibles.lib.importers.http import CWExtract, BGExtract, BSExtract
@@ -122,15 +122,9 @@
122 Set up the signals used in the bible importer.122 Set up the signals used in the bible importer.
123 """123 """
124 self.web_source_combo_box.currentIndexChanged.connect(self.on_web_source_combo_box_index_changed)124 self.web_source_combo_box.currentIndexChanged.connect(self.on_web_source_combo_box_index_changed)
125 self.osis_browse_button.clicked.connect(self.on_osis_browse_button_clicked)
126 self.csv_books_button.clicked.connect(self.on_csv_books_browse_button_clicked)
127 self.csv_verses_button.clicked.connect(self.on_csv_verses_browse_button_clicked)
128 self.open_song_browse_button.clicked.connect(self.on_open_song_browse_button_clicked)
129 self.zefania_browse_button.clicked.connect(self.on_zefania_browse_button_clicked)
130 self.wordproject_browse_button.clicked.connect(self.on_wordproject_browse_button_clicked)
131 self.web_update_button.clicked.connect(self.on_web_update_button_clicked)125 self.web_update_button.clicked.connect(self.on_web_update_button_clicked)
132 self.sword_browse_button.clicked.connect(self.on_sword_browse_button_clicked)126 self.sword_folder_path_edit.pathChanged.connect(self.on_sword_folder_path_edit_path_changed)
133 self.sword_zipbrowse_button.clicked.connect(self.on_sword_zipbrowse_button_clicked)127 self.sword_zipfile_path_edit.pathChanged.connect(self.on_sword_zipfile_path_edit_path_changed)
134128
135 def add_custom_pages(self):129 def add_custom_pages(self):
136 """130 """
@@ -161,17 +155,12 @@
161 self.osis_layout.setObjectName('OsisLayout')155 self.osis_layout.setObjectName('OsisLayout')
162 self.osis_file_label = QtWidgets.QLabel(self.osis_widget)156 self.osis_file_label = QtWidgets.QLabel(self.osis_widget)
163 self.osis_file_label.setObjectName('OsisFileLabel')157 self.osis_file_label.setObjectName('OsisFileLabel')
164 self.osis_file_layout = QtWidgets.QHBoxLayout()158 self.osis_path_edit = PathEdit(
165 self.osis_file_layout.setObjectName('OsisFileLayout')159 self.osis_widget,
166 self.osis_file_edit = QtWidgets.QLineEdit(self.osis_widget)160 default_path=Settings().value('bibles/last directory import'),
167 self.osis_file_edit.setSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Preferred)161 dialog_caption=WizardStrings.OpenTypeFile.format(file_type=WizardStrings.OSIS),
168 self.osis_file_edit.setObjectName('OsisFileEdit')162 show_revert=False)
169 self.osis_file_layout.addWidget(self.osis_file_edit)163 self.osis_layout.addRow(self.osis_file_label, self.osis_path_edit)
170 self.osis_browse_button = QtWidgets.QToolButton(self.osis_widget)
171 self.osis_browse_button.setIcon(self.open_icon)
172 self.osis_browse_button.setObjectName('OsisBrowseButton')
173 self.osis_file_layout.addWidget(self.osis_browse_button)
174 self.osis_layout.addRow(self.osis_file_label, self.osis_file_layout)
175 self.osis_layout.setItem(1, QtWidgets.QFormLayout.LabelRole, self.spacer)164 self.osis_layout.setItem(1, QtWidgets.QFormLayout.LabelRole, self.spacer)
176 self.select_stack.addWidget(self.osis_widget)165 self.select_stack.addWidget(self.osis_widget)
177 self.csv_widget = QtWidgets.QWidget(self.select_page)166 self.csv_widget = QtWidgets.QWidget(self.select_page)
@@ -181,30 +170,27 @@
181 self.csv_layout.setObjectName('CsvLayout')170 self.csv_layout.setObjectName('CsvLayout')
182 self.csv_books_label = QtWidgets.QLabel(self.csv_widget)171 self.csv_books_label = QtWidgets.QLabel(self.csv_widget)
183 self.csv_books_label.setObjectName('CsvBooksLabel')172 self.csv_books_label.setObjectName('CsvBooksLabel')
184 self.csv_books_layout = QtWidgets.QHBoxLayout()173 self.csv_books_path_edit = PathEdit(
185 self.csv_books_layout.setObjectName('CsvBooksLayout')174 self.csv_widget,
186 self.csv_books_edit = QtWidgets.QLineEdit(self.csv_widget)175 default_path=Settings().value('bibles/last directory import'),
187 self.csv_books_edit.setSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Preferred)176 dialog_caption=WizardStrings.OpenTypeFile.format(file_type=WizardStrings.CSV),
188 self.csv_books_edit.setObjectName('CsvBooksEdit')177 show_revert=False,
189 self.csv_books_layout.addWidget(self.csv_books_edit)178 )
190 self.csv_books_button = QtWidgets.QToolButton(self.csv_widget)179 self.csv_books_path_edit.filters = \
191 self.csv_books_button.setIcon(self.open_icon)180 '{name} (*.csv)'.format(name=translate('BiblesPlugin.ImportWizardForm', 'CSV File'))
192 self.csv_books_button.setObjectName('CsvBooksButton')181 self.csv_layout.addRow(self.csv_books_label, self.csv_books_path_edit)
193 self.csv_books_layout.addWidget(self.csv_books_button)
194 self.csv_layout.addRow(self.csv_books_label, self.csv_books_layout)
195 self.csv_verses_label = QtWidgets.QLabel(self.csv_widget)182 self.csv_verses_label = QtWidgets.QLabel(self.csv_widget)
196 self.csv_verses_label.setObjectName('CsvVersesLabel')183 self.csv_verses_label.setObjectName('CsvVersesLabel')
197 self.csv_verses_layout = QtWidgets.QHBoxLayout()184 self.csv_verses_path_edit = PathEdit(
198 self.csv_verses_layout.setObjectName('CsvVersesLayout')185 self.csv_widget,
199 self.csv_verses_edit = QtWidgets.QLineEdit(self.csv_widget)186 default_path=Settings().value('bibles/last directory import'),
200 self.csv_verses_edit.setSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Preferred)187 dialog_caption=WizardStrings.OpenTypeFile.format(file_type=WizardStrings.CSV),
201 self.csv_verses_edit.setObjectName('CsvVersesEdit')188 show_revert=False,
202 self.csv_verses_layout.addWidget(self.csv_verses_edit)189 )
203 self.csv_verses_button = QtWidgets.QToolButton(self.csv_widget)190 self.csv_verses_path_edit.filters = \
204 self.csv_verses_button.setIcon(self.open_icon)191 '{name} (*.csv)'.format(name=translate('BiblesPlugin.ImportWizardForm', 'CSV File'))
205 self.csv_verses_button.setObjectName('CsvVersesButton')192 self.csv_layout.addRow(self.csv_books_label, self.csv_books_path_edit)
206 self.csv_verses_layout.addWidget(self.csv_verses_button)193 self.csv_layout.addRow(self.csv_verses_label, self.csv_verses_path_edit)
207 self.csv_layout.addRow(self.csv_verses_label, self.csv_verses_layout)
208 self.csv_layout.setItem(3, QtWidgets.QFormLayout.LabelRole, self.spacer)194 self.csv_layout.setItem(3, QtWidgets.QFormLayout.LabelRole, self.spacer)
209 self.select_stack.addWidget(self.csv_widget)195 self.select_stack.addWidget(self.csv_widget)
210 self.open_song_widget = QtWidgets.QWidget(self.select_page)196 self.open_song_widget = QtWidgets.QWidget(self.select_page)
@@ -214,17 +200,13 @@
214 self.open_song_layout.setObjectName('OpenSongLayout')200 self.open_song_layout.setObjectName('OpenSongLayout')
215 self.open_song_file_label = QtWidgets.QLabel(self.open_song_widget)201 self.open_song_file_label = QtWidgets.QLabel(self.open_song_widget)
216 self.open_song_file_label.setObjectName('OpenSongFileLabel')202 self.open_song_file_label.setObjectName('OpenSongFileLabel')
217 self.open_song_file_layout = QtWidgets.QHBoxLayout()203 self.open_song_path_edit = PathEdit(
218 self.open_song_file_layout.setObjectName('OpenSongFileLayout')204 self.open_song_widget,
219 self.open_song_file_edit = QtWidgets.QLineEdit(self.open_song_widget)205 default_path=Settings().value('bibles/last directory import'),
220 self.open_song_file_edit.setSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Preferred)206 dialog_caption=WizardStrings.OpenTypeFile.format(file_type=WizardStrings.OS),
221 self.open_song_file_edit.setObjectName('OpenSongFileEdit')207 show_revert=False,
222 self.open_song_file_layout.addWidget(self.open_song_file_edit)208 )
223 self.open_song_browse_button = QtWidgets.QToolButton(self.open_song_widget)209 self.open_song_layout.addRow(self.open_song_file_label, self.open_song_path_edit)
224 self.open_song_browse_button.setIcon(self.open_icon)
225 self.open_song_browse_button.setObjectName('OpenSongBrowseButton')
226 self.open_song_file_layout.addWidget(self.open_song_browse_button)
227 self.open_song_layout.addRow(self.open_song_file_label, self.open_song_file_layout)
228 self.open_song_layout.setItem(1, QtWidgets.QFormLayout.LabelRole, self.spacer)210 self.open_song_layout.setItem(1, QtWidgets.QFormLayout.LabelRole, self.spacer)
229 self.select_stack.addWidget(self.open_song_widget)211 self.select_stack.addWidget(self.open_song_widget)
230 self.web_tab_widget = QtWidgets.QTabWidget(self.select_page)212 self.web_tab_widget = QtWidgets.QTabWidget(self.select_page)
@@ -292,17 +274,14 @@
292 self.zefania_layout.setObjectName('ZefaniaLayout')274 self.zefania_layout.setObjectName('ZefaniaLayout')
293 self.zefania_file_label = QtWidgets.QLabel(self.zefania_widget)275 self.zefania_file_label = QtWidgets.QLabel(self.zefania_widget)
294 self.zefania_file_label.setObjectName('ZefaniaFileLabel')276 self.zefania_file_label.setObjectName('ZefaniaFileLabel')
295 self.zefania_file_layout = QtWidgets.QHBoxLayout()277 self.zefania_path_edit = PathEdit(
296 self.zefania_file_layout.setObjectName('ZefaniaFileLayout')278 self.zefania_widget,
297 self.zefania_file_edit = QtWidgets.QLineEdit(self.zefania_widget)279 default_path=Settings().value('bibles/last directory import'),
298 self.zefania_file_edit.setObjectName('ZefaniaFileEdit')280 dialog_caption=WizardStrings.OpenTypeFile.format(file_type=WizardStrings.ZEF),
299 self.zefania_file_layout.addWidget(self.zefania_file_edit)281 show_revert=False,
300 self.zefania_browse_button = QtWidgets.QToolButton(self.zefania_widget)282 )
301 self.zefania_browse_button.setIcon(self.open_icon)283 self.zefania_layout.addRow(self.zefania_file_label, self.zefania_path_edit)
302 self.zefania_browse_button.setObjectName('ZefaniaBrowseButton')284 self.zefania_layout.setItem(2, QtWidgets.QFormLayout.LabelRole, self.spacer)
303 self.zefania_file_layout.addWidget(self.zefania_browse_button)
304 self.zefania_layout.addRow(self.zefania_file_label, self.zefania_file_layout)
305 self.zefania_layout.setItem(5, QtWidgets.QFormLayout.LabelRole, self.spacer)
306 self.select_stack.addWidget(self.zefania_widget)285 self.select_stack.addWidget(self.zefania_widget)
307 self.sword_widget = QtWidgets.QWidget(self.select_page)286 self.sword_widget = QtWidgets.QWidget(self.select_page)
308 self.sword_widget.setObjectName('SwordWidget')287 self.sword_widget.setObjectName('SwordWidget')
@@ -318,16 +297,13 @@
318 self.sword_folder_label = QtWidgets.QLabel(self.sword_folder_tab)297 self.sword_folder_label = QtWidgets.QLabel(self.sword_folder_tab)
319 self.sword_folder_label.setObjectName('SwordSourceLabel')298 self.sword_folder_label.setObjectName('SwordSourceLabel')
320 self.sword_folder_label.setObjectName('SwordFolderLabel')299 self.sword_folder_label.setObjectName('SwordFolderLabel')
321 self.sword_folder_edit = QtWidgets.QLineEdit(self.sword_folder_tab)300 self.sword_folder_path_edit = PathEdit(
322 self.sword_folder_edit.setSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Preferred)301 self.sword_folder_tab,
323 self.sword_folder_edit.setObjectName('SwordFolderEdit')302 default_path=Settings().value('bibles/last directory import'),
324 self.sword_browse_button = QtWidgets.QToolButton(self.sword_folder_tab)303 dialog_caption=WizardStrings.OpenTypeFile.format(file_type=WizardStrings.SWORD),
325 self.sword_browse_button.setIcon(self.open_icon)304 show_revert=False,
326 self.sword_browse_button.setObjectName('SwordBrowseButton')305 )
327 self.sword_folder_layout = QtWidgets.QHBoxLayout()306 self.sword_folder_tab_layout.addRow(self.sword_folder_label, self.sword_folder_path_edit)
328 self.sword_folder_layout.addWidget(self.sword_folder_edit)
329 self.sword_folder_layout.addWidget(self.sword_browse_button)
330 self.sword_folder_tab_layout.addRow(self.sword_folder_label, self.sword_folder_layout)
331 self.sword_bible_label = QtWidgets.QLabel(self.sword_folder_tab)307 self.sword_bible_label = QtWidgets.QLabel(self.sword_folder_tab)
332 self.sword_bible_label.setObjectName('SwordBibleLabel')308 self.sword_bible_label.setObjectName('SwordBibleLabel')
333 self.sword_bible_combo_box = QtWidgets.QComboBox(self.sword_folder_tab)309 self.sword_bible_combo_box = QtWidgets.QComboBox(self.sword_folder_tab)
@@ -342,16 +318,13 @@
342 self.sword_zip_layout.setObjectName('SwordZipLayout')318 self.sword_zip_layout.setObjectName('SwordZipLayout')
343 self.sword_zipfile_label = QtWidgets.QLabel(self.sword_zip_tab)319 self.sword_zipfile_label = QtWidgets.QLabel(self.sword_zip_tab)
344 self.sword_zipfile_label.setObjectName('SwordZipFileLabel')320 self.sword_zipfile_label.setObjectName('SwordZipFileLabel')
345 self.sword_zipfile_edit = QtWidgets.QLineEdit(self.sword_zip_tab)321 self.sword_zipfile_path_edit = PathEdit(
346 self.sword_zipfile_edit.setSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Preferred)322 self.sword_zip_tab,
347 self.sword_zipfile_edit.setObjectName('SwordZipFileEdit')323 default_path=Settings().value('bibles/last directory import'),
348 self.sword_zipbrowse_button = QtWidgets.QToolButton(self.sword_zip_tab)324 dialog_caption=WizardStrings.OpenTypeFile.format(file_type=WizardStrings.SWORD),
349 self.sword_zipbrowse_button.setIcon(self.open_icon)325 show_revert=False,
350 self.sword_zipbrowse_button.setObjectName('SwordZipBrowseButton')326 )
351 self.sword_zipfile_layout = QtWidgets.QHBoxLayout()327 self.sword_zip_layout.addRow(self.sword_zipfile_label, self.sword_zipfile_path_edit)
352 self.sword_zipfile_layout.addWidget(self.sword_zipfile_edit)
353 self.sword_zipfile_layout.addWidget(self.sword_zipbrowse_button)
354 self.sword_zip_layout.addRow(self.sword_zipfile_label, self.sword_zipfile_layout)
355 self.sword_zipbible_label = QtWidgets.QLabel(self.sword_folder_tab)328 self.sword_zipbible_label = QtWidgets.QLabel(self.sword_folder_tab)
356 self.sword_zipbible_label.setObjectName('SwordZipBibleLabel')329 self.sword_zipbible_label.setObjectName('SwordZipBibleLabel')
357 self.sword_zipbible_combo_box = QtWidgets.QComboBox(self.sword_zip_tab)330 self.sword_zipbible_combo_box = QtWidgets.QComboBox(self.sword_zip_tab)
@@ -372,18 +345,13 @@
372 self.wordproject_layout.setObjectName('WordProjectLayout')345 self.wordproject_layout.setObjectName('WordProjectLayout')
373 self.wordproject_file_label = QtWidgets.QLabel(self.wordproject_widget)346 self.wordproject_file_label = QtWidgets.QLabel(self.wordproject_widget)
374 self.wordproject_file_label.setObjectName('WordProjectFileLabel')347 self.wordproject_file_label.setObjectName('WordProjectFileLabel')
375 self.wordproject_file_layout = QtWidgets.QHBoxLayout()348 self.wordproject_path_edit = PathEdit(
376 self.wordproject_file_layout.setObjectName('WordProjectFileLayout')349 self.wordproject_widget,
377 self.wordproject_file_edit = QtWidgets.QLineEdit(self.wordproject_widget)350 default_path=Settings().value('bibles/last directory import'),
378 self.wordproject_file_edit.setSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Preferred)351 dialog_caption=WizardStrings.OpenTypeFile.format(file_type=WizardStrings.WordProject),
379 self.wordproject_file_edit.setObjectName('WordProjectFileEdit')352 show_revert=False)
380 self.wordproject_file_layout.addWidget(self.wordproject_file_edit)353 self.wordproject_layout.addRow(self.wordproject_file_label, self.wordproject_path_edit)
381 self.wordproject_browse_button = QtWidgets.QToolButton(self.wordproject_widget)354 self.wordproject_layout.setItem(1, QtWidgets.QFormLayout.LabelRole, self.spacer)
382 self.wordproject_browse_button.setIcon(self.open_icon)
383 self.wordproject_browse_button.setObjectName('WordProjectBrowseButton')
384 self.wordproject_file_layout.addWidget(self.wordproject_browse_button)
385 self.wordproject_layout.addRow(self.wordproject_file_label, self.wordproject_file_layout)
386 self.wordproject_layout.setItem(5, QtWidgets.QFormLayout.LabelRole, self.spacer)
387 self.select_stack.addWidget(self.wordproject_widget)355 self.select_stack.addWidget(self.wordproject_widget)
388 self.select_page_layout.addLayout(self.select_stack)356 self.select_page_layout.addLayout(self.select_stack)
389 self.addPage(self.select_page)357 self.addPage(self.select_page)
@@ -468,8 +436,6 @@
468 self.sword_bible_label.setText(translate('BiblesPlugin.ImportWizardForm', 'Bibles:'))436 self.sword_bible_label.setText(translate('BiblesPlugin.ImportWizardForm', 'Bibles:'))
469 self.sword_folder_label.setText(translate('BiblesPlugin.ImportWizardForm', 'SWORD data folder:'))437 self.sword_folder_label.setText(translate('BiblesPlugin.ImportWizardForm', 'SWORD data folder:'))
470 self.sword_zipfile_label.setText(translate('BiblesPlugin.ImportWizardForm', 'SWORD zip-file:'))438 self.sword_zipfile_label.setText(translate('BiblesPlugin.ImportWizardForm', 'SWORD zip-file:'))
471 self.sword_folder_edit.setPlaceholderText(translate('BiblesPlugin.ImportWizardForm',
472 'Defaults to the standard SWORD data folder'))
473 self.sword_zipbible_label.setText(translate('BiblesPlugin.ImportWizardForm', 'Bibles:'))439 self.sword_zipbible_label.setText(translate('BiblesPlugin.ImportWizardForm', 'Bibles:'))
474 self.sword_tab_widget.setTabText(self.sword_tab_widget.indexOf(self.sword_folder_tab),440 self.sword_tab_widget.setTabText(self.sword_tab_widget.indexOf(self.sword_folder_tab),
475 translate('BiblesPlugin.ImportWizardForm', 'Import from folder'))441 translate('BiblesPlugin.ImportWizardForm', 'Import from folder'))
@@ -518,7 +484,7 @@
518 if self.field('source_format') == BibleFormat.OSIS:484 if self.field('source_format') == BibleFormat.OSIS:
519 if not self.field('osis_location'):485 if not self.field('osis_location'):
520 critical_error_message_box(UiStrings().NFSs, WizardStrings.YouSpecifyFile % WizardStrings.OSIS)486 critical_error_message_box(UiStrings().NFSs, WizardStrings.YouSpecifyFile % WizardStrings.OSIS)
521 self.osis_file_edit.setFocus()487 self.osis_path_edit.setFocus()
522 return False488 return False
523 elif self.field('source_format') == BibleFormat.CSV:489 elif self.field('source_format') == BibleFormat.CSV:
524 if not self.field('csv_booksfile'):490 if not self.field('csv_booksfile'):
@@ -538,18 +504,18 @@
538 elif self.field('source_format') == BibleFormat.OpenSong:504 elif self.field('source_format') == BibleFormat.OpenSong:
539 if not self.field('opensong_file'):505 if not self.field('opensong_file'):
540 critical_error_message_box(UiStrings().NFSs, WizardStrings.YouSpecifyFile % WizardStrings.OS)506 critical_error_message_box(UiStrings().NFSs, WizardStrings.YouSpecifyFile % WizardStrings.OS)
541 self.open_song_file_edit.setFocus()507 self.open_song_path_edit.setFocus()
542 return False508 return False
543 elif self.field('source_format') == BibleFormat.Zefania:509 elif self.field('source_format') == BibleFormat.Zefania:
544 if not self.field('zefania_file'):510 if not self.field('zefania_file'):
545 critical_error_message_box(UiStrings().NFSs, WizardStrings.YouSpecifyFile % WizardStrings.ZEF)511 critical_error_message_box(UiStrings().NFSs, WizardStrings.YouSpecifyFile % WizardStrings.ZEF)
546 self.zefania_file_edit.setFocus()512 self.zefania_path_edit.setFocus()
547 return False513 return False
548 elif self.field('source_format') == BibleFormat.WordProject:514 elif self.field('source_format') == BibleFormat.WordProject:
549 if not self.field('wordproject_file'):515 if not self.field('wordproject_file'):
550 critical_error_message_box(UiStrings().NFSs,516 critical_error_message_box(UiStrings().NFSs,
551 WizardStrings.YouSpecifyFile % WizardStrings.WordProject)517 WizardStrings.YouSpecifyFile % WizardStrings.WordProject)
552 self.wordproject_file_edit.setFocus()518 self.wordproject_path_edit.setFocus()
553 return False519 return False
554 elif self.field('source_format') == BibleFormat.WebDownload:520 elif self.field('source_format') == BibleFormat.WebDownload:
555 # If count is 0 the bible list has not yet been downloaded521 # If count is 0 the bible list has not yet been downloaded
@@ -563,7 +529,7 @@
563 if not self.field('sword_folder_path') and self.sword_bible_combo_box.count() == 0:529 if not self.field('sword_folder_path') and self.sword_bible_combo_box.count() == 0:
564 critical_error_message_box(UiStrings().NFSs,530 critical_error_message_box(UiStrings().NFSs,
565 WizardStrings.YouSpecifyFolder % WizardStrings.SWORD)531 WizardStrings.YouSpecifyFolder % WizardStrings.SWORD)
566 self.sword_folder_edit.setFocus()532 self.sword_folder_path_edit.setFocus()
567 return False533 return False
568 key = self.sword_bible_combo_box.itemData(self.sword_bible_combo_box.currentIndex())534 key = self.sword_bible_combo_box.itemData(self.sword_bible_combo_box.currentIndex())
569 if 'description' in self.pysword_folder_modules_json[key]:535 if 'description' in self.pysword_folder_modules_json[key]:
@@ -575,7 +541,7 @@
575 elif self.sword_tab_widget.currentIndex() == self.sword_tab_widget.indexOf(self.sword_zip_tab):541 elif self.sword_tab_widget.currentIndex() == self.sword_tab_widget.indexOf(self.sword_zip_tab):
576 if not self.field('sword_zip_path'):542 if not self.field('sword_zip_path'):
577 critical_error_message_box(UiStrings().NFSs, WizardStrings.YouSpecifyFile % WizardStrings.SWORD)543 critical_error_message_box(UiStrings().NFSs, WizardStrings.YouSpecifyFile % WizardStrings.SWORD)
578 self.sword_zipfile_edit.setFocus()544 self.sword_zipfile_path_edit.setFocus()
579 return False545 return False
580 key = self.sword_zipbible_combo_box.itemData(self.sword_zipbible_combo_box.currentIndex())546 key = self.sword_zipbible_combo_box.itemData(self.sword_zipbible_combo_box.currentIndex())
581 if 'description' in self.pysword_zip_modules_json[key]:547 if 'description' in self.pysword_zip_modules_json[key]:
@@ -586,7 +552,6 @@
586 elif self.currentPage() == self.license_details_page:552 elif self.currentPage() == self.license_details_page:
587 license_version = self.field('license_version')553 license_version = self.field('license_version')
588 license_copyright = self.field('license_copyright')554 license_copyright = self.field('license_copyright')
589 path = str(AppLocation.get_section_data_path('bibles'))
590 if not license_version:555 if not license_version:
591 critical_error_message_box(556 critical_error_message_box(
592 UiStrings().EmptyField,557 UiStrings().EmptyField,
@@ -608,7 +573,7 @@
608 'existing one.'))573 'existing one.'))
609 self.version_name_edit.setFocus()574 self.version_name_edit.setFocus()
610 return False575 return False
611 elif os.path.exists(os.path.join(path, clean_filename(license_version))):576 elif (AppLocation.get_section_data_path('bibles') / clean_filename(license_version)).exists():
612 critical_error_message_box(577 critical_error_message_box(
613 translate('BiblesPlugin.ImportWizardForm', 'Bible Exists'),578 translate('BiblesPlugin.ImportWizardForm', 'Bible Exists'),
614 translate('BiblesPlugin.ImportWizardForm', 'This Bible already exists. Please import '579 translate('BiblesPlugin.ImportWizardForm', 'This Bible already exists. Please import '
@@ -631,57 +596,6 @@
631 bibles.sort(key=get_locale_key)596 bibles.sort(key=get_locale_key)
632 self.web_translation_combo_box.addItems(bibles)597 self.web_translation_combo_box.addItems(bibles)
633598
634 def on_osis_browse_button_clicked(self):
635 """
636 Show the file open dialog for the OSIS file.
637 """
638 self.get_file_name(WizardStrings.OpenTypeFile % WizardStrings.OSIS, self.osis_file_edit,
639 'last directory import')
640
641 def on_csv_books_browse_button_clicked(self):
642 """
643 Show the file open dialog for the books CSV file.
644 """
645 # TODO: Verify format() with varible template
646 self.get_file_name(
647 WizardStrings.OpenTypeFile % WizardStrings.CSV,
648 self.csv_books_edit,
649 'last directory import',
650 '{name} (*.csv)'.format(name=translate('BiblesPlugin.ImportWizardForm', 'CSV File')))
651
652 def on_csv_verses_browse_button_clicked(self):
653 """
654 Show the file open dialog for the verses CSV file.
655 """
656 # TODO: Verify format() with variable template
657 self.get_file_name(WizardStrings.OpenTypeFile % WizardStrings.CSV, self.csv_verses_edit,
658 'last directory import',
659 '{name} (*.csv)'.format(name=translate('BiblesPlugin.ImportWizardForm', 'CSV File')))
660
661 def on_open_song_browse_button_clicked(self):
662 """
663 Show the file open dialog for the OpenSong file.
664 """
665 # TODO: Verify format() with variable template
666 self.get_file_name(WizardStrings.OpenTypeFile % WizardStrings.OS, self.open_song_file_edit,
667 'last directory import')
668
669 def on_zefania_browse_button_clicked(self):
670 """
671 Show the file open dialog for the Zefania file.
672 """
673 # TODO: Verify format() with variable template
674 self.get_file_name(WizardStrings.OpenTypeFile % WizardStrings.ZEF, self.zefania_file_edit,
675 'last directory import')
676
677 def on_wordproject_browse_button_clicked(self):
678 """
679 Show the file open dialog for the WordProject file.
680 """
681 # TODO: Verify format() with variable template
682 self.get_file_name(WizardStrings.OpenTypeFile % WizardStrings.WordProject, self.wordproject_file_edit,
683 'last directory import')
684
685 def on_web_update_button_clicked(self):599 def on_web_update_button_clicked(self):
686 """600 """
687 Download list of bibles from Crosswalk, BibleServer and BibleGateway.601 Download list of bibles from Crosswalk, BibleServer and BibleGateway.
@@ -718,15 +632,13 @@
718 self.web_update_button.setEnabled(True)632 self.web_update_button.setEnabled(True)
719 self.web_progress_bar.setVisible(False)633 self.web_progress_bar.setVisible(False)
720634
721 def on_sword_browse_button_clicked(self):635 def on_sword_folder_path_edit_path_changed(self, new_path):
722 """636 """
723 Show the file open dialog for the SWORD folder.637 Show the file open dialog for the SWORD folder.
724 """638 """
725 self.get_folder(WizardStrings.OpenTypeFolder % WizardStrings.SWORD, self.sword_folder_edit,639 if new_path:
726 'last directory import')
727 if self.sword_folder_edit.text():
728 try:640 try:
729 self.pysword_folder_modules = modules.SwordModules(self.sword_folder_edit.text())641 self.pysword_folder_modules = modules.SwordModules(str(new_path))
730 self.pysword_folder_modules_json = self.pysword_folder_modules.parse_modules()642 self.pysword_folder_modules_json = self.pysword_folder_modules.parse_modules()
731 bible_keys = self.pysword_folder_modules_json.keys()643 bible_keys = self.pysword_folder_modules_json.keys()
732 self.sword_bible_combo_box.clear()644 self.sword_bible_combo_box.clear()
@@ -735,15 +647,13 @@
735 except:647 except:
736 self.sword_bible_combo_box.clear()648 self.sword_bible_combo_box.clear()
737649
738 def on_sword_zipbrowse_button_clicked(self):650 def on_sword_zipfile_path_edit_path_changed(self, new_path):
739 """651 """
740 Show the file open dialog for a SWORD zip-file.652 Show the file open dialog for a SWORD zip-file.
741 """653 """
742 self.get_file_name(WizardStrings.OpenTypeFile % WizardStrings.SWORD, self.sword_zipfile_edit,654 if new_path:
743 'last directory import')
744 if self.sword_zipfile_edit.text():
745 try:655 try:
746 self.pysword_zip_modules = modules.SwordModules(self.sword_zipfile_edit.text())656 self.pysword_zip_modules = modules.SwordModules(str(new_path))
747 self.pysword_zip_modules_json = self.pysword_zip_modules.parse_modules()657 self.pysword_zip_modules_json = self.pysword_zip_modules.parse_modules()
748 bible_keys = self.pysword_zip_modules_json.keys()658 bible_keys = self.pysword_zip_modules_json.keys()
749 self.sword_zipbible_combo_box.clear()659 self.sword_zipbible_combo_box.clear()
@@ -757,16 +667,16 @@
757 Register the bible import wizard fields.667 Register the bible import wizard fields.
758 """668 """
759 self.select_page.registerField('source_format', self.format_combo_box)669 self.select_page.registerField('source_format', self.format_combo_box)
760 self.select_page.registerField('osis_location', self.osis_file_edit)670 self.select_page.registerField('osis_location', self.osis_path_edit, 'path', PathEdit.pathChanged)
761 self.select_page.registerField('csv_booksfile', self.csv_books_edit)671 self.select_page.registerField('csv_booksfile', self.csv_books_path_edit, 'path', PathEdit.pathChanged)
762 self.select_page.registerField('csv_versefile', self.csv_verses_edit)672 self.select_page.registerField('csv_versefile', self.csv_verses_path_edit, 'path', PathEdit.pathChanged)
763 self.select_page.registerField('opensong_file', self.open_song_file_edit)673 self.select_page.registerField('opensong_file', self.open_song_path_edit, 'path', PathEdit.pathChanged)
764 self.select_page.registerField('zefania_file', self.zefania_file_edit)674 self.select_page.registerField('zefania_file', self.zefania_path_edit, 'path', PathEdit.pathChanged)
765 self.select_page.registerField('wordproject_file', self.wordproject_file_edit)675 self.select_page.registerField('wordproject_file', self.wordproject_path_edit, 'path', PathEdit.pathChanged)
766 self.select_page.registerField('web_location', self.web_source_combo_box)676 self.select_page.registerField('web_location', self.web_source_combo_box)
767 self.select_page.registerField('web_biblename', self.web_translation_combo_box)677 self.select_page.registerField('web_biblename', self.web_translation_combo_box)
768 self.select_page.registerField('sword_folder_path', self.sword_folder_edit)678 self.select_page.registerField('sword_folder_path', self.sword_folder_path_edit, 'path', PathEdit.pathChanged)
769 self.select_page.registerField('sword_zip_path', self.sword_zipfile_edit)679 self.select_page.registerField('sword_zip_path', self.sword_zipfile_path_edit, 'path', PathEdit.pathChanged)
770 self.select_page.registerField('proxy_server', self.web_server_edit)680 self.select_page.registerField('proxy_server', self.web_server_edit)
771 self.select_page.registerField('proxy_username', self.web_user_edit)681 self.select_page.registerField('proxy_username', self.web_user_edit)
772 self.select_page.registerField('proxy_password', self.web_password_edit)682 self.select_page.registerField('proxy_password', self.web_password_edit)
@@ -785,13 +695,13 @@
785 self.finish_button.setVisible(False)695 self.finish_button.setVisible(False)
786 self.cancel_button.setVisible(True)696 self.cancel_button.setVisible(True)
787 self.setField('source_format', 0)697 self.setField('source_format', 0)
788 self.setField('osis_location', '')698 self.setField('osis_location', None)
789 self.setField('csv_booksfile', '')699 self.setField('csv_booksfile', None)
790 self.setField('csv_versefile', '')700 self.setField('csv_versefile', None)
791 self.setField('opensong_file', '')701 self.setField('opensong_file', None)
792 self.setField('zefania_file', '')702 self.setField('zefania_file', None)
793 self.setField('sword_folder_path', '')703 self.setField('sword_folder_path', None)
794 self.setField('sword_zip_path', '')704 self.setField('sword_zip_path', None)
795 self.setField('web_location', WebDownload.Crosswalk)705 self.setField('web_location', WebDownload.Crosswalk)
796 self.setField('web_biblename', self.web_translation_combo_box.currentIndex())706 self.setField('web_biblename', self.web_translation_combo_box.currentIndex())
797 self.setField('proxy_server', settings.value('proxy address'))707 self.setField('proxy_server', settings.value('proxy address'))
@@ -833,16 +743,16 @@
833 if bible_type == BibleFormat.OSIS:743 if bible_type == BibleFormat.OSIS:
834 # Import an OSIS bible.744 # Import an OSIS bible.
835 importer = self.manager.import_bible(BibleFormat.OSIS, name=license_version,745 importer = self.manager.import_bible(BibleFormat.OSIS, name=license_version,
836 filename=self.field('osis_location'))746 file_path=self.field('osis_location'))
837 elif bible_type == BibleFormat.CSV:747 elif bible_type == BibleFormat.CSV:
838 # Import a CSV bible.748 # Import a CSV bible.
839 importer = self.manager.import_bible(BibleFormat.CSV, name=license_version,749 importer = self.manager.import_bible(BibleFormat.CSV, name=license_version,
840 booksfile=self.field('csv_booksfile'),750 books_path=self.field('csv_booksfile'),
841 versefile=self.field('csv_versefile'))751 verse_path=self.field('csv_versefile'))
842 elif bible_type == BibleFormat.OpenSong:752 elif bible_type == BibleFormat.OpenSong:
843 # Import an OpenSong bible.753 # Import an OpenSong bible.
844 importer = self.manager.import_bible(BibleFormat.OpenSong, name=license_version,754 importer = self.manager.import_bible(BibleFormat.OpenSong, name=license_version,
845 filename=self.field('opensong_file'))755 file_path=self.field('opensong_file'))
846 elif bible_type == BibleFormat.WebDownload:756 elif bible_type == BibleFormat.WebDownload:
847 # Import a bible from the web.757 # Import a bible from the web.
848 self.progress_bar.setMaximum(1)758 self.progress_bar.setMaximum(1)
@@ -861,11 +771,11 @@
861 elif bible_type == BibleFormat.Zefania:771 elif bible_type == BibleFormat.Zefania:
862 # Import a Zefania bible.772 # Import a Zefania bible.
863 importer = self.manager.import_bible(BibleFormat.Zefania, name=license_version,773 importer = self.manager.import_bible(BibleFormat.Zefania, name=license_version,
864 filename=self.field('zefania_file'))774 file_path=self.field('zefania_file'))
865 elif bible_type == BibleFormat.WordProject:775 elif bible_type == BibleFormat.WordProject:
866 # Import a WordProject bible.776 # Import a WordProject bible.
867 importer = self.manager.import_bible(BibleFormat.WordProject, name=license_version,777 importer = self.manager.import_bible(BibleFormat.WordProject, name=license_version,
868 filename=self.field('wordproject_file'))778 file_path=self.field('wordproject_file'))
869 elif bible_type == BibleFormat.SWORD:779 elif bible_type == BibleFormat.SWORD:
870 # Import a SWORD bible.780 # Import a SWORD bible.
871 if self.sword_tab_widget.currentIndex() == self.sword_tab_widget.indexOf(self.sword_folder_tab):781 if self.sword_tab_widget.currentIndex() == self.sword_tab_widget.indexOf(self.sword_folder_tab):
872782
=== modified file 'openlp/plugins/bibles/lib/bibleimport.py'
--- openlp/plugins/bibles/lib/bibleimport.py 2017-10-29 06:01:25 +0000
+++ openlp/plugins/bibles/lib/bibleimport.py 2017-11-14 23:03:10 +0000
@@ -37,23 +37,23 @@
37 """37 """
38 def __init__(self, *args, **kwargs):38 def __init__(self, *args, **kwargs):
39 super().__init__(*args, **kwargs)39 super().__init__(*args, **kwargs)
40 self.filename = kwargs['filename'] if 'filename' in kwargs else None40 self.file_path = kwargs.get('file_path')
41 self.wizard = None41 self.wizard = None
42 self.stop_import_flag = False42 self.stop_import_flag = False
43 Registry().register_function('openlp_stop_wizard', self.stop_import)43 Registry().register_function('openlp_stop_wizard', self.stop_import)
4444
45 @staticmethod45 @staticmethod
46 def is_compressed(file):46 def is_compressed(file_path):
47 """47 """
48 Check if the supplied file is compressed48 Check if the supplied file is compressed
4949
50 :param file: A path to the file to check50 :param file_path: A path to the file to check
51 """51 """
52 if is_zipfile(file):52 if is_zipfile(str(file_path)):
53 critical_error_message_box(53 critical_error_message_box(
54 message=translate('BiblesPlugin.BibleImport',54 message=translate('BiblesPlugin.BibleImport',
55 'The file "{file}" you supplied is compressed. You must decompress it before import.'55 'The file "{file}" you supplied is compressed. You must decompress it before import.'
56 ).format(file=file))56 ).format(file=file_path))
57 return True57 return True
58 return False58 return False
5959
@@ -143,24 +143,24 @@
143 self.log_debug('No book name supplied. Falling back to guess_id')143 self.log_debug('No book name supplied. Falling back to guess_id')
144 book_ref_id = guess_id144 book_ref_id = guess_id
145 if not book_ref_id:145 if not book_ref_id:
146 raise ValidationError(msg='Could not resolve book_ref_id in "{}"'.format(self.filename))146 raise ValidationError(msg='Could not resolve book_ref_id in "{}"'.format(self.file_path))
147 book_details = BiblesResourcesDB.get_book_by_id(book_ref_id)147 book_details = BiblesResourcesDB.get_book_by_id(book_ref_id)
148 if book_details is None:148 if book_details is None:
149 raise ValidationError(msg='book_ref_id: {book_ref} Could not be found in the BibleResourcesDB while '149 raise ValidationError(msg='book_ref_id: {book_ref} Could not be found in the BibleResourcesDB while '
150 'importing {file}'.format(book_ref=book_ref_id, file=self.filename))150 'importing {file}'.format(book_ref=book_ref_id, file=self.file_path))
151 return self.create_book(name, book_ref_id, book_details['testament_id'])151 return self.create_book(name, book_ref_id, book_details['testament_id'])
152152
153 def parse_xml(self, filename, use_objectify=False, elements=None, tags=None):153 def parse_xml(self, file_path, use_objectify=False, elements=None, tags=None):
154 """154 """
155 Parse and clean the supplied file by removing any elements or tags we don't use.155 Parse and clean the supplied file by removing any elements or tags we don't use.
156 :param filename: The filename of the xml file to parse. Str156 :param file_path: The filename of the xml file to parse. Str
157 :param use_objectify: Use the objectify parser rather than the etree parser. (Bool)157 :param use_objectify: Use the objectify parser rather than the etree parser. (Bool)
158 :param elements: A tuple of element names (Str) to remove along with their content.158 :param elements: A tuple of element names (Str) to remove along with their content.
159 :param tags: A tuple of element names (Str) to remove, preserving their content.159 :param tags: A tuple of element names (Str) to remove, preserving their content.
160 :return: The root element of the xml document160 :return: The root element of the xml document
161 """161 """
162 try:162 try:
163 with open(filename, 'rb') as import_file:163 with file_path.open('rb') as import_file:
164 # NOTE: We don't need to do any of the normal encoding detection here, because lxml does it's own164 # NOTE: We don't need to do any of the normal encoding detection here, because lxml does it's own
165 # encoding detection, and the two mechanisms together interfere with each other.165 # encoding detection, and the two mechanisms together interfere with each other.
166 if not use_objectify:166 if not use_objectify:
@@ -207,17 +207,17 @@
207 self.log_debug('Stopping import')207 self.log_debug('Stopping import')
208 self.stop_import_flag = True208 self.stop_import_flag = True
209209
210 def validate_xml_file(self, filename, tag):210 def validate_xml_file(self, file_path, tag):
211 """211 """
212 Validate the supplied file212 Validate the supplied file
213213
214 :param filename: The supplied file214 :param file_path: The supplied file
215 :param tag: The expected root tag type215 :param tag: The expected root tag type
216 :return: True if valid. ValidationError is raised otherwise.216 :return: True if valid. ValidationError is raised otherwise.
217 """217 """
218 if BibleImport.is_compressed(filename):218 if BibleImport.is_compressed(file_path):
219 raise ValidationError(msg='Compressed file')219 raise ValidationError(msg='Compressed file')
220 bible = self.parse_xml(filename, use_objectify=True)220 bible = self.parse_xml(file_path, use_objectify=True)
221 if bible is None:221 if bible is None:
222 raise ValidationError(msg='Error when opening file')222 raise ValidationError(msg='Error when opening file')
223 root_tag = bible.tag.lower()223 root_tag = bible.tag.lower()
224224
=== modified file 'openlp/plugins/bibles/lib/biblestab.py'
--- openlp/plugins/bibles/lib/biblestab.py 2017-10-07 07:05:07 +0000
+++ openlp/plugins/bibles/lib/biblestab.py 2017-11-14 23:03:10 +0000
@@ -41,11 +41,11 @@
41 """41 """
42 log.info('Bible Tab loaded')42 log.info('Bible Tab loaded')
4343
44 def _init_(self, parent, title, visible_title, icon_path):44 def _init_(self, *args, **kwargs):
45 self.paragraph_style = True45 self.paragraph_style = True
46 self.show_new_chapters = False46 self.show_new_chapters = False
47 self.display_style = 047 self.display_style = 0
48 super(BiblesTab, self).__init__(parent, title, visible_title, icon_path)48 super().__init__(*args, **kwargs)
4949
50 def setupUi(self):50 def setupUi(self):
51 self.setObjectName('BiblesTab')51 self.setObjectName('BiblesTab')
5252
=== modified file 'openlp/plugins/bibles/lib/db.py'
--- openlp/plugins/bibles/lib/db.py 2017-10-28 10:04:09 +0000
+++ openlp/plugins/bibles/lib/db.py 2017-11-14 23:03:10 +0000
@@ -35,6 +35,7 @@
35from openlp.core.common import clean_filename35from openlp.core.common import clean_filename
36from openlp.core.common.applocation import AppLocation36from openlp.core.common.applocation import AppLocation
37from openlp.core.common.i18n import translate37from openlp.core.common.i18n import translate
38from openlp.core.common.path import Path
38from openlp.core.lib.db import BaseModel, init_db, Manager39from openlp.core.lib.db import BaseModel, init_db, Manager
39from openlp.core.lib.ui import critical_error_message_box40from openlp.core.lib.ui import critical_error_message_box
40from openlp.plugins.bibles.lib import BibleStrings, LanguageSelection, upgrade41from openlp.plugins.bibles.lib import BibleStrings, LanguageSelection, upgrade
@@ -129,10 +130,15 @@
129 :param parent:130 :param parent:
130 :param kwargs:131 :param kwargs:
131 ``path``132 ``path``
132 The path to the bible database file.133 The path to the bible database file. Type: openlp.core.common.path.Path
133134
134 ``name``135 ``name``
135 The name of the database. This is also used as the file name for SQLite databases.136 The name of the database. This is also used as the file name for SQLite databases.
137
138 ``file``
139 Type: openlp.core.common.path.Path
140
141 :rtype: None
136 """142 """
137 log.info('BibleDB loaded')143 log.info('BibleDB loaded')
138 self._setup(parent, **kwargs)144 self._setup(parent, **kwargs)
@@ -145,20 +151,20 @@
145 self.session = None151 self.session = None
146 if 'path' not in kwargs:152 if 'path' not in kwargs:
147 raise KeyError('Missing keyword argument "path".')153 raise KeyError('Missing keyword argument "path".')
154 self.path = kwargs['path']
148 if 'name' not in kwargs and 'file' not in kwargs:155 if 'name' not in kwargs and 'file' not in kwargs:
149 raise KeyError('Missing keyword argument "name" or "file".')156 raise KeyError('Missing keyword argument "name" or "file".')
150 if 'name' in kwargs:157 if 'name' in kwargs:
151 self.name = kwargs['name']158 self.name = kwargs['name']
152 if not isinstance(self.name, str):159 if not isinstance(self.name, str):
153 self.name = str(self.name, 'utf-8')160 self.name = str(self.name, 'utf-8')
154 self.file = clean_filename(self.name) + '.sqlite'161 # TODO: To path object
162 file_path = Path(clean_filename(self.name) + '.sqlite')
155 if 'file' in kwargs:163 if 'file' in kwargs:
156 self.file = kwargs['file']164 file_path = kwargs['file']
157 Manager.__init__(self, 'bibles', init_schema, self.file, upgrade)165 Manager.__init__(self, 'bibles', init_schema, file_path, upgrade)
158 if self.session and 'file' in kwargs:166 if self.session and 'file' in kwargs:
159 self.get_name()167 self.get_name()
160 if 'path' in kwargs:
161 self.path = kwargs['path']
162 self._is_web_bible = None168 self._is_web_bible = None
163169
164 def get_name(self):170 def get_name(self):
@@ -470,9 +476,9 @@
470 Return the cursor object. Instantiate one if it doesn't exist yet.476 Return the cursor object. Instantiate one if it doesn't exist yet.
471 """477 """
472 if BiblesResourcesDB.cursor is None:478 if BiblesResourcesDB.cursor is None:
473 file_path = os.path.join(str(AppLocation.get_directory(AppLocation.PluginsDir)),479 file_path = \
474 'bibles', 'resources', 'bibles_resources.sqlite')480 AppLocation.get_directory(AppLocation.PluginsDir) / 'bibles' / 'resources' / 'bibles_resources.sqlite'
475 conn = sqlite3.connect(file_path)481 conn = sqlite3.connect(str(file_path))
476 BiblesResourcesDB.cursor = conn.cursor()482 BiblesResourcesDB.cursor = conn.cursor()
477 return BiblesResourcesDB.cursor483 return BiblesResourcesDB.cursor
478484
@@ -758,17 +764,13 @@
758 If necessary loads up the database and creates the tables if the database doesn't exist.764 If necessary loads up the database and creates the tables if the database doesn't exist.
759 """765 """
760 if AlternativeBookNamesDB.cursor is None:766 if AlternativeBookNamesDB.cursor is None:
761 file_path = os.path.join(767 file_path = AppLocation.get_directory(AppLocation.DataDir) / 'bibles' / 'alternative_book_names.sqlite'
762 str(AppLocation.get_directory(AppLocation.DataDir)), 'bibles', 'alternative_book_names.sqlite')768 AlternativeBookNamesDB.conn = sqlite3.connect(str(file_path))
763 if not os.path.exists(file_path):769 if not file_path.exists():
764 # create new DB, create table alternative_book_names770 # create new DB, create table alternative_book_names
765 AlternativeBookNamesDB.conn = sqlite3.connect(file_path)
766 AlternativeBookNamesDB.conn.execute(771 AlternativeBookNamesDB.conn.execute(
767 'CREATE TABLE alternative_book_names(id INTEGER NOT NULL, '772 'CREATE TABLE alternative_book_names(id INTEGER NOT NULL, '
768 'book_reference_id INTEGER, language_id INTEGER, name VARCHAR(50), PRIMARY KEY (id))')773 'book_reference_id INTEGER, language_id INTEGER, name VARCHAR(50), PRIMARY KEY (id))')
769 else:
770 # use existing DB
771 AlternativeBookNamesDB.conn = sqlite3.connect(file_path)
772 AlternativeBookNamesDB.cursor = AlternativeBookNamesDB.conn.cursor()774 AlternativeBookNamesDB.cursor = AlternativeBookNamesDB.conn.cursor()
773 return AlternativeBookNamesDB.cursor775 return AlternativeBookNamesDB.cursor
774776
775777
=== added file 'openlp/plugins/bibles/lib/importers/__init__.py'
--- openlp/plugins/bibles/lib/importers/__init__.py 1970-01-01 00:00:00 +0000
+++ openlp/plugins/bibles/lib/importers/__init__.py 2017-11-14 23:03:10 +0000
@@ -0,0 +1,24 @@
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-2017 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"""
23The :mod:`~openlp.plugins.bibles.lib.importers` module contains importers for the Bibles plugin.
24"""
025
=== removed file 'openlp/plugins/bibles/lib/importers/__init__.py'
--- openlp/plugins/bibles/lib/importers/__init__.py 2017-10-23 22:09:57 +0000
+++ openlp/plugins/bibles/lib/importers/__init__.py 1970-01-01 00:00:00 +0000
@@ -1,21 +0,0 @@
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-2017 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###############################################################################
220
=== modified file 'openlp/plugins/bibles/lib/importers/csvbible.py'
--- openlp/plugins/bibles/lib/importers/csvbible.py 2017-10-07 07:05:07 +0000
+++ openlp/plugins/bibles/lib/importers/csvbible.py 2017-11-14 23:03:10 +0000
@@ -73,8 +73,8 @@
73 """73 """
74 super().__init__(*args, **kwargs)74 super().__init__(*args, **kwargs)
75 self.log_info(self.__class__.__name__)75 self.log_info(self.__class__.__name__)
76 self.books_file = kwargs['booksfile']76 self.books_path = kwargs['books_path']
77 self.verses_file = kwargs['versefile']77 self.verses_path = kwargs['verse_path']
7878
79 @staticmethod79 @staticmethod
80 def get_book_name(name, books):80 def get_book_name(name, books):
@@ -92,21 +92,22 @@
92 return book_name92 return book_name
9393
94 @staticmethod94 @staticmethod
95 def parse_csv_file(filename, results_tuple):95 def parse_csv_file(file_path, results_tuple):
96 """96 """
97 Parse the supplied CSV file.97 Parse the supplied CSV file.
9898
99 :param filename: The name of the file to parse. Str99 :param openlp.core.common.path.Path file_path: The name of the file to parse.
100 :param results_tuple: The namedtuple to use to store the results. namedtuple100 :param namedtuple results_tuple: The namedtuple to use to store the results.
101 :return: An iterable yielding namedtuples of type results_tuple101 :return: An list of namedtuples of type results_tuple
102 :rtype: list[namedtuple]
102 """103 """
103 try:104 try:
104 encoding = get_file_encoding(Path(filename))['encoding']105 encoding = get_file_encoding(file_path)['encoding']
105 with open(filename, 'r', encoding=encoding, newline='') as csv_file:106 with file_path.open('r', encoding=encoding, newline='') as csv_file:
106 csv_reader = csv.reader(csv_file, delimiter=',', quotechar='"')107 csv_reader = csv.reader(csv_file, delimiter=',', quotechar='"')
107 return [results_tuple(*line) for line in csv_reader]108 return [results_tuple(*line) for line in csv_reader]
108 except (OSError, csv.Error):109 except (OSError, csv.Error):
109 raise ValidationError(msg='Parsing "{file}" failed'.format(file=filename))110 raise ValidationError(msg='Parsing "{file}" failed'.format(file=file_path))
110111
111 def process_books(self, books):112 def process_books(self, books):
112 """113 """
@@ -159,12 +160,12 @@
159 self.language_id = self.get_language(bible_name)160 self.language_id = self.get_language(bible_name)
160 if not self.language_id:161 if not self.language_id:
161 return False162 return False
162 books = self.parse_csv_file(self.books_file, Book)163 books = self.parse_csv_file(self.books_path, Book)
163 self.wizard.progress_bar.setValue(0)164 self.wizard.progress_bar.setValue(0)
164 self.wizard.progress_bar.setMinimum(0)165 self.wizard.progress_bar.setMinimum(0)
165 self.wizard.progress_bar.setMaximum(len(books))166 self.wizard.progress_bar.setMaximum(len(books))
166 book_list = self.process_books(books)167 book_list = self.process_books(books)
167 verses = self.parse_csv_file(self.verses_file, Verse)168 verses = self.parse_csv_file(self.verses_path, Verse)
168 self.wizard.progress_bar.setValue(0)169 self.wizard.progress_bar.setValue(0)
169 self.wizard.progress_bar.setMaximum(len(books) + 1)170 self.wizard.progress_bar.setMaximum(len(books) + 1)
170 self.process_verses(verses, book_list)171 self.process_verses(verses, book_list)
171172
=== modified file 'openlp/plugins/bibles/lib/importers/opensong.py'
--- openlp/plugins/bibles/lib/importers/opensong.py 2016-12-31 11:01:36 +0000
+++ openlp/plugins/bibles/lib/importers/opensong.py 2017-11-14 23:03:10 +0000
@@ -46,7 +46,8 @@
4646
47 :param number: The raw data from the xml47 :param number: The raw data from the xml
48 :param previous_number: The previous chapter number48 :param previous_number: The previous chapter number
49 :return: Number of current chapter. (Int)49 :return: Number of current chapter.
50 :rtype: int
50 """51 """
51 if number:52 if number:
52 return int(number.split()[-1])53 return int(number.split()[-1])
@@ -132,13 +133,13 @@
132 :param bible_name: The name of the bible being imported133 :param bible_name: The name of the bible being imported
133 :return: True if import completed, False if import was unsuccessful134 :return: True if import completed, False if import was unsuccessful
134 """135 """
135 self.log_debug('Starting OpenSong import from "{name}"'.format(name=self.filename))136 self.log_debug('Starting OpenSong import from "{name}"'.format(name=self.file_path))
136 self.validate_xml_file(self.filename, 'bible')137 self.validate_xml_file(self.file_path, 'bible')
137 bible = self.parse_xml(self.filename, use_objectify=True)138 bible = self.parse_xml(self.file_path, use_objectify=True)
138 if bible is None:139 if bible is None:
139 return False140 return False
140 # No language info in the opensong format, so ask the user141 # No language info in the opensong format, so ask the user
141 self.language_id = self.get_language_id(bible_name=self.filename)142 self.language_id = self.get_language_id(bible_name=str(self.file_path))
142 if not self.language_id:143 if not self.language_id:
143 return False144 return False
144 self.process_books(bible.b)145 self.process_books(bible.b)
145146
=== modified file 'openlp/plugins/bibles/lib/importers/osis.py'
--- openlp/plugins/bibles/lib/importers/osis.py 2016-12-31 11:01:36 +0000
+++ openlp/plugins/bibles/lib/importers/osis.py 2017-11-14 23:03:10 +0000
@@ -159,14 +159,14 @@
159 """159 """
160 Loads a Bible from file.160 Loads a Bible from file.
161 """161 """
162 self.log_debug('Starting OSIS import from "{name}"'.format(name=self.filename))162 self.log_debug('Starting OSIS import from "{name}"'.format(name=self.file_path))
163 self.validate_xml_file(self.filename, '{http://www.bibletechnologies.net/2003/osis/namespace}osis')163 self.validate_xml_file(self.file_path, '{http://www.bibletechnologies.net/2003/osis/namespace}osis')
164 bible = self.parse_xml(self.filename, elements=REMOVABLE_ELEMENTS, tags=REMOVABLE_TAGS)164 bible = self.parse_xml(self.file_path, elements=REMOVABLE_ELEMENTS, tags=REMOVABLE_TAGS)
165 if bible is None:165 if bible is None:
166 return False166 return False
167 # Find bible language167 # Find bible language
168 language = bible.xpath("//ns:osisText/@xml:lang", namespaces=NS)168 language = bible.xpath("//ns:osisText/@xml:lang", namespaces=NS)
169 self.language_id = self.get_language_id(language[0] if language else None, bible_name=self.filename)169 self.language_id = self.get_language_id(language[0] if language else None, bible_name=str(self.file_path))
170 if not self.language_id:170 if not self.language_id:
171 return False171 return False
172 self.process_books(bible)172 self.process_books(bible)
173173
=== modified file 'openlp/plugins/bibles/lib/importers/sword.py'
--- openlp/plugins/bibles/lib/importers/sword.py 2017-10-07 07:05:07 +0000
+++ openlp/plugins/bibles/lib/importers/sword.py 2017-11-14 23:03:10 +0000
@@ -60,7 +60,7 @@
60 bible = pysword_modules.get_bible_from_module(self.sword_key)60 bible = pysword_modules.get_bible_from_module(self.sword_key)
61 language = pysword_module_json['lang']61 language = pysword_module_json['lang']
62 language = language[language.find('.') + 1:]62 language = language[language.find('.') + 1:]
63 language_id = self.get_language_id(language, bible_name=self.filename)63 language_id = self.get_language_id(language, bible_name=str(self.file_path))
64 if not language_id:64 if not language_id:
65 return False65 return False
66 books = bible.get_structure().get_books()66 books = bible.get_structure().get_books()
6767
=== modified file 'openlp/plugins/bibles/lib/importers/wordproject.py'
--- openlp/plugins/bibles/lib/importers/wordproject.py 2016-12-31 11:01:36 +0000
+++ openlp/plugins/bibles/lib/importers/wordproject.py 2017-11-14 23:03:10 +0000
@@ -19,15 +19,14 @@
19# with this program; if not, write to the Free Software Foundation, Inc., 59 #19# with this program; if not, write to the Free Software Foundation, Inc., 59 #
20# Temple Place, Suite 330, Boston, MA 02111-1307 USA #20# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
21###############################################################################21###############################################################################
22import os22import logging
23import re23import re
24import logging
25from codecs import open as copen
26from tempfile import TemporaryDirectory24from tempfile import TemporaryDirectory
27from zipfile import ZipFile25from zipfile import ZipFile
2826
29from bs4 import BeautifulSoup, Tag, NavigableString27from bs4 import BeautifulSoup, Tag, NavigableString
3028
29from openlp.core.common.path import Path
31from openlp.plugins.bibles.lib.bibleimport import BibleImport30from openlp.plugins.bibles.lib.bibleimport import BibleImport
3231
33BOOK_NUMBER_PATTERN = re.compile(r'\[(\d+)\]')32BOOK_NUMBER_PATTERN = re.compile(r'\[(\d+)\]')
@@ -51,9 +50,9 @@
51 Unzip the file to a temporary directory50 Unzip the file to a temporary directory
52 """51 """
53 self.tmp = TemporaryDirectory()52 self.tmp = TemporaryDirectory()
54 zip_file = ZipFile(os.path.abspath(self.filename))53 with ZipFile(str(self.file_path)) as zip_file:
55 zip_file.extractall(self.tmp.name)54 zip_file.extractall(self.tmp.name)
56 self.base_dir = os.path.join(self.tmp.name, os.path.splitext(os.path.basename(self.filename))[0])55 self.base_path = Path(self.tmp.name, self.file_path.stem)
5756
58 def process_books(self):57 def process_books(self):
59 """58 """
@@ -62,8 +61,7 @@
62 :param bible_data: parsed xml61 :param bible_data: parsed xml
63 :return: None62 :return: None
64 """63 """
65 with copen(os.path.join(self.base_dir, 'index.htm'), encoding='utf-8', errors='ignore') as index_file:64 page = (self.base_path / 'index.htm').read_text(encoding='utf-8', errors='ignore')
66 page = index_file.read()
67 soup = BeautifulSoup(page, 'lxml')65 soup = BeautifulSoup(page, 'lxml')
68 bible_books = soup.find('div', 'textOptions').find_all('li')66 bible_books = soup.find('div', 'textOptions').find_all('li')
69 book_count = len(bible_books)67 book_count = len(bible_books)
@@ -93,9 +91,7 @@
93 :return: None91 :return: None
94 """92 """
95 log.debug(book_link)93 log.debug(book_link)
96 book_file = os.path.join(self.base_dir, os.path.normpath(book_link))94 page = (self.base_path / book_link).read_text(encoding='utf-8', errors='ignore')
97 with copen(book_file, encoding='utf-8', errors='ignore') as f:
98 page = f.read()
99 soup = BeautifulSoup(page, 'lxml')95 soup = BeautifulSoup(page, 'lxml')
100 header_div = soup.find('div', 'textHeader')96 header_div = soup.find('div', 'textHeader')
101 chapters_p = header_div.find('p')97 chapters_p = header_div.find('p')
@@ -114,9 +110,8 @@
114 """110 """
115 Get the verses for a particular book111 Get the verses for a particular book
116 """112 """
117 chapter_file_name = os.path.join(self.base_dir, '{:02d}'.format(book_number), '{}.htm'.format(chapter_number))113 chapter_file_path = self.base_path / '{:02d}'.format(book_number) / '{}.htm'.format(chapter_number)
118 with copen(chapter_file_name, encoding='utf-8', errors='ignore') as chapter_file:114 page = chapter_file_path.read_text(encoding='utf-8', errors='ignore')
119 page = chapter_file.read()
120 soup = BeautifulSoup(page, 'lxml')115 soup = BeautifulSoup(page, 'lxml')
121 text_body = soup.find('div', 'textBody')116 text_body = soup.find('div', 'textBody')
122 if text_body:117 if text_body:
@@ -158,9 +153,9 @@
158 """153 """
159 Loads a Bible from file.154 Loads a Bible from file.
160 """155 """
161 self.log_debug('Starting WordProject import from "{name}"'.format(name=self.filename))156 self.log_debug('Starting WordProject import from "{name}"'.format(name=self.file_path))
162 self._unzip_file()157 self._unzip_file()
163 self.language_id = self.get_language_id(None, bible_name=self.filename)158 self.language_id = self.get_language_id(None, bible_name=str(self.file_path))
164 result = False159 result = False
165 if self.language_id:160 if self.language_id:
166 self.process_books()161 self.process_books()
167162
=== modified file 'openlp/plugins/bibles/lib/importers/zefania.py'
--- openlp/plugins/bibles/lib/importers/zefania.py 2017-10-07 07:05:07 +0000
+++ openlp/plugins/bibles/lib/importers/zefania.py 2017-11-14 23:03:10 +0000
@@ -45,13 +45,13 @@
45 """45 """
46 Loads a Bible from file.46 Loads a Bible from file.
47 """47 """
48 log.debug('Starting Zefania import from "{name}"'.format(name=self.filename))48 log.debug('Starting Zefania import from "{name}"'.format(name=self.file_path))
49 success = True49 success = True
50 try:50 try:
51 xmlbible = self.parse_xml(self.filename, elements=REMOVABLE_ELEMENTS, tags=REMOVABLE_TAGS)51 xmlbible = self.parse_xml(self.file_path, elements=REMOVABLE_ELEMENTS, tags=REMOVABLE_TAGS)
52 # Find bible language52 # Find bible language
53 language = xmlbible.xpath("/XMLBIBLE/INFORMATION/language/text()")53 language = xmlbible.xpath("/XMLBIBLE/INFORMATION/language/text()")
54 language_id = self.get_language_id(language[0] if language else None, bible_name=self.filename)54 language_id = self.get_language_id(language[0] if language else None, bible_name=str(self.file_path))
55 if not language_id:55 if not language_id:
56 return False56 return False
57 no_of_books = int(xmlbible.xpath('count(//BIBLEBOOK)'))57 no_of_books = int(xmlbible.xpath('count(//BIBLEBOOK)'))
@@ -69,7 +69,7 @@
69 log.debug('Could not find a name, will use number, basically a guess.')69 log.debug('Could not find a name, will use number, basically a guess.')
70 book_ref_id = int(bnumber)70 book_ref_id = int(bnumber)
71 if not book_ref_id:71 if not book_ref_id:
72 log.error('Importing books from "{name}" failed'.format(name=self.filename))72 log.error('Importing books from "{name}" failed'.format(name=self.file_path))
73 return False73 return False
74 book_details = BiblesResourcesDB.get_book_by_id(book_ref_id)74 book_details = BiblesResourcesDB.get_book_by_id(book_ref_id)
75 db_book = self.create_book(book_details['name'], book_ref_id, book_details['testament_id'])75 db_book = self.create_book(book_details['name'], book_ref_id, book_details['testament_id'])
7676
=== modified file 'openlp/plugins/bibles/lib/manager.py'
--- openlp/plugins/bibles/lib/manager.py 2017-10-23 22:09:57 +0000
+++ openlp/plugins/bibles/lib/manager.py 2017-11-14 23:03:10 +0000
@@ -19,7 +19,6 @@
19# with this program; if not, write to the Free Software Foundation, Inc., 59 #19# with this program; if not, write to the Free Software Foundation, Inc., 59 #
20# Temple Place, Suite 330, Boston, MA 02111-1307 USA #20# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
21###############################################################################21###############################################################################
22
23import logging22import logging
2423
25from openlp.core.common import delete_file24from openlp.core.common import delete_file
@@ -115,7 +114,7 @@
115 self.settings_section = 'bibles'114 self.settings_section = 'bibles'
116 self.web = 'Web'115 self.web = 'Web'
117 self.db_cache = None116 self.db_cache = None
118 self.path = str(AppLocation.get_section_data_path(self.settings_section))117 self.path = AppLocation.get_section_data_path(self.settings_section)
119 self.proxy_name = Settings().value(self.settings_section + '/proxy name')118 self.proxy_name = Settings().value(self.settings_section + '/proxy name')
120 self.suffix = '.sqlite'119 self.suffix = '.sqlite'
121 self.import_wizard = None120 self.import_wizard = None
@@ -128,20 +127,20 @@
128 of HTTPBible is loaded instead of the BibleDB class.127 of HTTPBible is loaded instead of the BibleDB class.
129 """128 """
130 log.debug('Reload bibles')129 log.debug('Reload bibles')
131 files = [str(file) for file in AppLocation.get_files(self.settings_section, self.suffix)]130 file_paths = AppLocation.get_files(self.settings_section, self.suffix)
132 if 'alternative_book_names.sqlite' in files:131 if Path('alternative_book_names.sqlite') in file_paths:
133 files.remove('alternative_book_names.sqlite')132 file_paths.remove(Path('alternative_book_names.sqlite'))
134 log.debug('Bible Files {text}'.format(text=files))133 log.debug('Bible Files {text}'.format(text=file_paths))
135 self.db_cache = {}134 self.db_cache = {}
136 for filename in files:135 for file_path in file_paths:
137 bible = BibleDB(self.parent, path=self.path, file=filename)136 bible = BibleDB(self.parent, path=self.path, file=file_path)
138 if not bible.session:137 if not bible.session:
139 continue138 continue
140 name = bible.get_name()139 name = bible.get_name()
141 # Remove corrupted files.140 # Remove corrupted files.
142 if name is None:141 if name is None:
143 bible.session.close_all()142 bible.session.close_all()
144 delete_file(Path(self.path, filename))143 delete_file(self.path / file_path)
145 continue144 continue
146 log.debug('Bible Name: "{name}"'.format(name=name))145 log.debug('Bible Name: "{name}"'.format(name=name))
147 self.db_cache[name] = bible146 self.db_cache[name] = bible
@@ -150,7 +149,7 @@
150 source = self.db_cache[name].get_object(BibleMeta, 'download_source')149 source = self.db_cache[name].get_object(BibleMeta, 'download_source')
151 download_name = self.db_cache[name].get_object(BibleMeta, 'download_name').value150 download_name = self.db_cache[name].get_object(BibleMeta, 'download_name').value
152 meta_proxy = self.db_cache[name].get_object(BibleMeta, 'proxy_server')151 meta_proxy = self.db_cache[name].get_object(BibleMeta, 'proxy_server')
153 web_bible = HTTPBible(self.parent, path=self.path, file=filename, download_source=source.value,152 web_bible = HTTPBible(self.parent, path=self.path, file=file_path, download_source=source.value,
154 download_name=download_name)153 download_name=download_name)
155 if meta_proxy:154 if meta_proxy:
156 web_bible.proxy_server = meta_proxy.value155 web_bible.proxy_server = meta_proxy.value
157156
=== modified file 'tests/functional/openlp_plugins/bibles/test_bibleimport.py'
--- tests/functional/openlp_plugins/bibles/test_bibleimport.py 2017-10-29 06:01:25 +0000
+++ tests/functional/openlp_plugins/bibles/test_bibleimport.py 2017-11-14 23:03:10 +0000
@@ -30,6 +30,7 @@
30from PyQt5.QtWidgets import QDialog30from PyQt5.QtWidgets import QDialog
3131
32from openlp.core.common.i18n import Language32from openlp.core.common.i18n import Language
33from openlp.core.common.path import Path
33from openlp.core.lib.exceptions import ValidationError34from openlp.core.lib.exceptions import ValidationError
34from openlp.plugins.bibles.lib.bibleimport import BibleImport35from openlp.plugins.bibles.lib.bibleimport import BibleImport
35from openlp.plugins.bibles.lib.db import BibleDB36from openlp.plugins.bibles.lib.db import BibleDB
@@ -48,7 +49,7 @@
48 b' <data><unsupported>Test<x>data</x><y>to</y>discard</unsupported></data>\n'49 b' <data><unsupported>Test<x>data</x><y>to</y>discard</unsupported></data>\n'
49 b'</root>'50 b'</root>'
50 )51 )
51 self.open_patcher = patch('builtins.open')52 self.open_patcher = patch.object(Path, 'open')
52 self.addCleanup(self.open_patcher.stop)53 self.addCleanup(self.open_patcher.stop)
53 self.mocked_open = self.open_patcher.start()54 self.mocked_open = self.open_patcher.start()
54 self.critical_error_message_box_patcher = \55 self.critical_error_message_box_patcher = \
@@ -74,8 +75,8 @@
74 # WHEN: Creating an instance of BibleImport with no key word arguments75 # WHEN: Creating an instance of BibleImport with no key word arguments
75 instance = BibleImport(MagicMock())76 instance = BibleImport(MagicMock())
7677
77 # THEN: The filename attribute should be None78 # THEN: The file_path attribute should be None
78 assert instance.filename is None79 assert instance.file_path is None
79 assert isinstance(instance, BibleDB)80 assert isinstance(instance, BibleDB)
8081
81 def test_init_kwargs_set(self):82 def test_init_kwargs_set(self):
@@ -84,11 +85,11 @@
84 """85 """
85 # GIVEN: A patched BibleDB._setup, BibleImport class and mocked parent86 # GIVEN: A patched BibleDB._setup, BibleImport class and mocked parent
86 # WHEN: Creating an instance of BibleImport with selected key word arguments87 # WHEN: Creating an instance of BibleImport with selected key word arguments
87 kwargs = {'filename': 'bible.xml'}88 kwargs = {'file_path': 'bible.xml'}
88 instance = BibleImport(MagicMock(), **kwargs)89 instance = BibleImport(MagicMock(), **kwargs)
8990
90 # THEN: The filename keyword should be set to bible.xml91 # THEN: The file_path keyword should be set to bible.xml
91 assert instance.filename == 'bible.xml'92 assert instance.file_path == 'bible.xml'
92 assert isinstance(instance, BibleDB)93 assert isinstance(instance, BibleDB)
9394
94 @patch.object(BibleDB, '_setup')95 @patch.object(BibleDB, '_setup')
@@ -361,7 +362,7 @@
361 instance.wizard = MagicMock()362 instance.wizard = MagicMock()
362363
363 # WHEN: Calling parse_xml364 # WHEN: Calling parse_xml
364 result = instance.parse_xml('file.tst')365 result = instance.parse_xml(Path('file.tst'))
365366
366 # THEN: The result returned should contain the correct data, and should be an instance of eetree_Element367 # THEN: The result returned should contain the correct data, and should be an instance of eetree_Element
367 assert etree.tostring(result) == b'<root>\n <data><div>Test<p>data</p><a>to</a>keep</div></data>\n' \368 assert etree.tostring(result) == b'<root>\n <data><div>Test<p>data</p><a>to</a>keep</div></data>\n' \
@@ -378,7 +379,7 @@
378 instance.wizard = MagicMock()379 instance.wizard = MagicMock()
379380
380 # WHEN: Calling parse_xml381 # WHEN: Calling parse_xml
381 result = instance.parse_xml('file.tst', use_objectify=True)382 result = instance.parse_xml(Path('file.tst'), use_objectify=True)
382383
383 # THEN: The result returned should contain the correct data, and should be an instance of ObjectifiedElement384 # THEN: The result returned should contain the correct data, and should be an instance of ObjectifiedElement
384 assert etree.tostring(result) == b'<root><data><div>Test<p>data</p><a>to</a>keep</div></data>' \385 assert etree.tostring(result) == b'<root><data><div>Test<p>data</p><a>to</a>keep</div></data>' \
@@ -396,7 +397,7 @@
396 instance.wizard = MagicMock()397 instance.wizard = MagicMock()
397398
398 # WHEN: Calling parse_xml, with a test file399 # WHEN: Calling parse_xml, with a test file
399 result = instance.parse_xml('file.tst', elements=elements)400 result = instance.parse_xml(Path('file.tst'), elements=elements)
400401
401 # THEN: The result returned should contain the correct data402 # THEN: The result returned should contain the correct data
402 assert etree.tostring(result) == \403 assert etree.tostring(result) == \
@@ -413,7 +414,7 @@
413 instance.wizard = MagicMock()414 instance.wizard = MagicMock()
414415
415 # WHEN: Calling parse_xml, with a test file416 # WHEN: Calling parse_xml, with a test file
416 result = instance.parse_xml('file.tst', tags=tags)417 result = instance.parse_xml(Path('file.tst'), tags=tags)
417418
418 # THEN: The result returned should contain the correct data419 # THEN: The result returned should contain the correct data
419 assert etree.tostring(result) == b'<root>\n <data>Testdatatokeep</data>\n <data><unsupported>Test' \420 assert etree.tostring(result) == b'<root>\n <data>Testdatatokeep</data>\n <data><unsupported>Test' \
@@ -431,7 +432,7 @@
431 instance.wizard = MagicMock()432 instance.wizard = MagicMock()
432433
433 # WHEN: Calling parse_xml, with a test file434 # WHEN: Calling parse_xml, with a test file
434 result = instance.parse_xml('file.tst', elements=elements, tags=tags)435 result = instance.parse_xml(Path('file.tst'), elements=elements, tags=tags)
435436
436 # THEN: The result returned should contain the correct data437 # THEN: The result returned should contain the correct data
437 assert etree.tostring(result) == b'<root>\n <data>Testdatatokeep</data>\n <data/>\n</root>'438 assert etree.tostring(result) == b'<root>\n <data>Testdatatokeep</data>\n <data/>\n</root>'
@@ -446,10 +447,10 @@
446 exception.filename = 'file.tst'447 exception.filename = 'file.tst'
447 exception.strerror = 'No such file or directory'448 exception.strerror = 'No such file or directory'
448 self.mocked_open.side_effect = exception449 self.mocked_open.side_effect = exception
449 importer = BibleImport(MagicMock(), path='.', name='.', filename='')450 importer = BibleImport(MagicMock(), path='.', name='.', file_path=None)
450451
451 # WHEN: Calling parse_xml452 # WHEN: Calling parse_xml
452 result = importer.parse_xml('file.tst')453 result = importer.parse_xml(Path('file.tst'))
453454
454 # THEN: parse_xml should have caught the error, informed the user and returned None455 # THEN: parse_xml should have caught the error, informed the user and returned None
455 mocked_log_exception.assert_called_once_with('Opening file.tst failed.')456 mocked_log_exception.assert_called_once_with('Opening file.tst failed.')
@@ -468,10 +469,10 @@
468 exception.filename = 'file.tst'469 exception.filename = 'file.tst'
469 exception.strerror = 'Permission denied'470 exception.strerror = 'Permission denied'
470 self.mocked_open.side_effect = exception471 self.mocked_open.side_effect = exception
471 importer = BibleImport(MagicMock(), path='.', name='.', filename='')472 importer = BibleImport(MagicMock(), path='.', name='.', file_path=None)
472473
473 # WHEN: Calling parse_xml474 # WHEN: Calling parse_xml
474 result = importer.parse_xml('file.tst')475 result = importer.parse_xml(Path('file.tst'))
475476
476 # THEN: parse_xml should have caught the error, informed the user and returned None477 # THEN: parse_xml should have caught the error, informed the user and returned None
477 mocked_log_exception.assert_called_once_with('Opening file.tst failed.')478 mocked_log_exception.assert_called_once_with('Opening file.tst failed.')
@@ -485,7 +486,7 @@
485 Test set_current_chapter486 Test set_current_chapter
486 """487 """
487 # GIVEN: An instance of BibleImport and a mocked wizard488 # GIVEN: An instance of BibleImport and a mocked wizard
488 importer = BibleImport(MagicMock(), path='.', name='.', filename='')489 importer = BibleImport(MagicMock(), path='.', name='.', file_path=None)
489 importer.wizard = MagicMock()490 importer.wizard = MagicMock()
490491
491 # WHEN: Calling set_current_chapter492 # WHEN: Calling set_current_chapter
@@ -500,7 +501,7 @@
500 Test that validate_xml_file raises a ValidationError when is_compressed returns True501 Test that validate_xml_file raises a ValidationError when is_compressed returns True
501 """502 """
502 # GIVEN: A mocked parse_xml which returns None503 # GIVEN: A mocked parse_xml which returns None
503 importer = BibleImport(MagicMock(), path='.', name='.', filename='')504 importer = BibleImport(MagicMock(), path='.', name='.', file_path=None)
504505
505 # WHEN: Calling is_compressed506 # WHEN: Calling is_compressed
506 # THEN: ValidationError should be raised, with the message 'Compressed file'507 # THEN: ValidationError should be raised, with the message 'Compressed file'
@@ -515,7 +516,7 @@
515 Test that validate_xml_file raises a ValidationError when parse_xml returns None516 Test that validate_xml_file raises a ValidationError when parse_xml returns None
516 """517 """
517 # GIVEN: A mocked parse_xml which returns None518 # GIVEN: A mocked parse_xml which returns None
518 importer = BibleImport(MagicMock(), path='.', name='.', filename='')519 importer = BibleImport(MagicMock(), path='.', name='.', file_path=None)
519520
520 # WHEN: Calling validate_xml_file521 # WHEN: Calling validate_xml_file
521 # THEN: ValidationError should be raised, with the message 'Error when opening file'522 # THEN: ValidationError should be raised, with the message 'Error when opening file'
@@ -531,7 +532,7 @@
531 Test that validate_xml_file returns True with valid XML532 Test that validate_xml_file returns True with valid XML
532 """533 """
533 # GIVEN: Some test data with an OpenSong Bible "bible" root tag534 # GIVEN: Some test data with an OpenSong Bible "bible" root tag
534 importer = BibleImport(MagicMock(), path='.', name='.', filename='')535 importer = BibleImport(MagicMock(), path='.', name='.', file_path=None)
535536
536 # WHEN: Calling validate_xml_file537 # WHEN: Calling validate_xml_file
537 result = importer.validate_xml_file('file.name', 'bible')538 result = importer.validate_xml_file('file.name', 'bible')
@@ -546,7 +547,7 @@
546 Test that validate_xml_file raises a ValidationError with an OpenSong root tag547 Test that validate_xml_file raises a ValidationError with an OpenSong root tag
547 """548 """
548 # GIVEN: Some test data with an Zefania root tag and an instance of BibleImport549 # GIVEN: Some test data with an Zefania root tag and an instance of BibleImport
549 importer = BibleImport(MagicMock(), path='.', name='.', filename='')550 importer = BibleImport(MagicMock(), path='.', name='.', file_path=None)
550551
551 # WHEN: Calling validate_xml_file552 # WHEN: Calling validate_xml_file
552 # THEN: ValidationError should be raised, and the critical error message box should was called informing553 # THEN: ValidationError should be raised, and the critical error message box should was called informing
@@ -566,7 +567,7 @@
566 # GIVEN: Some test data with an Zefania root tag and an instance of BibleImport567 # GIVEN: Some test data with an Zefania root tag and an instance of BibleImport
567 mocked_parse_xml.return_value = objectify.fromstring(568 mocked_parse_xml.return_value = objectify.fromstring(
568 '<osis xmlns=\'http://www.bibletechnologies.net/2003/OSIS/namespace\'></osis>')569 '<osis xmlns=\'http://www.bibletechnologies.net/2003/OSIS/namespace\'></osis>')
569 importer = BibleImport(MagicMock(), path='.', name='.', filename='')570 importer = BibleImport(MagicMock(), path='.', name='.', file_path=None)
570571
571 # WHEN: Calling validate_xml_file572 # WHEN: Calling validate_xml_file
572 # THEN: ValidationError should be raised, and the critical error message box should was called informing573 # THEN: ValidationError should be raised, and the critical error message box should was called informing
@@ -584,7 +585,7 @@
584 Test that validate_xml_file raises a ValidationError with an Zefania root tag585 Test that validate_xml_file raises a ValidationError with an Zefania root tag
585 """586 """
586 # GIVEN: Some test data with an Zefania root tag and an instance of BibleImport587 # GIVEN: Some test data with an Zefania root tag and an instance of BibleImport
587 importer = BibleImport(MagicMock(), path='.', name='.', filename='')588 importer = BibleImport(MagicMock(), path='.', name='.', file_path=None)
588589
589 # WHEN: Calling validate_xml_file590 # WHEN: Calling validate_xml_file
590 # THEN: ValidationError should be raised, and the critical error message box should was called informing591 # THEN: ValidationError should be raised, and the critical error message box should was called informing
@@ -602,7 +603,7 @@
602 Test that validate_xml_file raises a ValidationError with an unknown root tag603 Test that validate_xml_file raises a ValidationError with an unknown root tag
603 """604 """
604 # GIVEN: Some test data with an unknown root tag and an instance of BibleImport605 # GIVEN: Some test data with an unknown root tag and an instance of BibleImport
605 importer = BibleImport(MagicMock(), path='.', name='.', filename='')606 importer = BibleImport(MagicMock(), path='.', name='.', file_path=None)
606607
607 # WHEN: Calling validate_xml_file608 # WHEN: Calling validate_xml_file
608 # THEN: ValidationError should be raised, and the critical error message box should was called informing609 # THEN: ValidationError should be raised, and the critical error message box should was called informing
609610
=== modified file 'tests/functional/openlp_plugins/bibles/test_csvimport.py'
--- tests/functional/openlp_plugins/bibles/test_csvimport.py 2017-10-29 06:01:25 +0000
+++ tests/functional/openlp_plugins/bibles/test_csvimport.py 2017-11-14 23:03:10 +0000
@@ -29,6 +29,7 @@
29from unittest import TestCase29from unittest import TestCase
30from unittest.mock import ANY, MagicMock, PropertyMock, call, patch30from unittest.mock import ANY, MagicMock, PropertyMock, call, patch
3131
32from openlp.core.common.path import Path
32from openlp.core.lib.exceptions import ValidationError33from openlp.core.lib.exceptions import ValidationError
33from openlp.plugins.bibles.lib.bibleimport import BibleImport34from openlp.plugins.bibles.lib.bibleimport import BibleImport
34from openlp.plugins.bibles.lib.importers.csvbible import Book, CSVBible, Verse35from openlp.plugins.bibles.lib.importers.csvbible import Book, CSVBible, Verse
@@ -59,12 +60,13 @@
59 mocked_manager = MagicMock()60 mocked_manager = MagicMock()
6061
61 # WHEN: An importer object is created62 # WHEN: An importer object is created
62 importer = CSVBible(mocked_manager, path='.', name='.', booksfile='books.csv', versefile='verse.csv')63 importer = \
64 CSVBible(mocked_manager, path='.', name='.', books_path=Path('books.csv'), verse_path=Path('verse.csv'))
6365
64 # THEN: The importer should be an instance of BibleImport66 # THEN: The importer should be an instance of BibleImport
65 self.assertIsInstance(importer, BibleImport)67 self.assertIsInstance(importer, BibleImport)
66 self.assertEqual(importer.books_file, 'books.csv')68 self.assertEqual(importer.books_path, Path('books.csv'))
67 self.assertEqual(importer.verses_file, 'verse.csv')69 self.assertEqual(importer.verses_path, Path('verse.csv'))
6870
69 def test_book_namedtuple(self):71 def test_book_namedtuple(self):
70 """72 """
@@ -134,17 +136,17 @@
134136
135 with patch('openlp.plugins.bibles.lib.importers.csvbible.get_file_encoding',137 with patch('openlp.plugins.bibles.lib.importers.csvbible.get_file_encoding',
136 return_value={'encoding': 'utf-8', 'confidence': 0.99}),\138 return_value={'encoding': 'utf-8', 'confidence': 0.99}),\
137 patch('openlp.plugins.bibles.lib.importers.csvbible.open', create=True) as mocked_open,\139 patch('openlp.plugins.bibles.lib.importers.csvbible.Path.open', create=True) as mocked_open,\
138 patch('openlp.plugins.bibles.lib.importers.csvbible.csv.reader',140 patch('openlp.plugins.bibles.lib.importers.csvbible.csv.reader',
139 return_value=iter(test_data)) as mocked_reader:141 return_value=iter(test_data)) as mocked_reader:
140142
141 # WHEN: Calling the CSVBible parse_csv_file method with a file name and TestTuple143 # WHEN: Calling the CSVBible parse_csv_file method with a file name and TestTuple
142 result = CSVBible.parse_csv_file('file.csv', TestTuple)144 result = CSVBible.parse_csv_file(Path('file.csv'), TestTuple)
143145
144 # THEN: A list of TestTuple instances with the parsed data should be returned146 # THEN: A list of TestTuple instances with the parsed data should be returned
145 self.assertEqual(result, [TestTuple('1', 'Line 1', 'Data 1'), TestTuple('2', 'Line 2', 'Data 2'),147 self.assertEqual(result, [TestTuple('1', 'Line 1', 'Data 1'), TestTuple('2', 'Line 2', 'Data 2'),
146 TestTuple('3', 'Line 3', 'Data 3')])148 TestTuple('3', 'Line 3', 'Data 3')])
147 mocked_open.assert_called_once_with('file.csv', 'r', encoding='utf-8', newline='')149 mocked_open.assert_called_once_with('r', encoding='utf-8', newline='')
148 mocked_reader.assert_called_once_with(ANY, delimiter=',', quotechar='"')150 mocked_reader.assert_called_once_with(ANY, delimiter=',', quotechar='"')
149151
150 def test_parse_csv_file_oserror(self):152 def test_parse_csv_file_oserror(self):
@@ -154,12 +156,12 @@
154 # GIVEN: Mocked a mocked open object which raises an OSError156 # GIVEN: Mocked a mocked open object which raises an OSError
155 with patch('openlp.plugins.bibles.lib.importers.csvbible.get_file_encoding',157 with patch('openlp.plugins.bibles.lib.importers.csvbible.get_file_encoding',
156 return_value={'encoding': 'utf-8', 'confidence': 0.99}),\158 return_value={'encoding': 'utf-8', 'confidence': 0.99}),\
157 patch('openlp.plugins.bibles.lib.importers.csvbible.open', side_effect=OSError, create=True):159 patch('openlp.plugins.bibles.lib.importers.csvbible.Path.open', side_effect=OSError, create=True):
158160
159 # WHEN: Calling CSVBible.parse_csv_file161 # WHEN: Calling CSVBible.parse_csv_file
160 # THEN: A ValidationError should be raised162 # THEN: A ValidationError should be raised
161 with self.assertRaises(ValidationError) as context:163 with self.assertRaises(ValidationError) as context:
162 CSVBible.parse_csv_file('file.csv', None)164 CSVBible.parse_csv_file(Path('file.csv'), None)
163 self.assertEqual(context.exception.msg, 'Parsing "file.csv" failed')165 self.assertEqual(context.exception.msg, 'Parsing "file.csv" failed')
164166
165 def test_parse_csv_file_csverror(self):167 def test_parse_csv_file_csverror(self):
@@ -169,13 +171,13 @@
169 # GIVEN: Mocked a csv.reader which raises an csv.Error171 # GIVEN: Mocked a csv.reader which raises an csv.Error
170 with patch('openlp.plugins.bibles.lib.importers.csvbible.get_file_encoding',172 with patch('openlp.plugins.bibles.lib.importers.csvbible.get_file_encoding',
171 return_value={'encoding': 'utf-8', 'confidence': 0.99}),\173 return_value={'encoding': 'utf-8', 'confidence': 0.99}),\
172 patch('openlp.plugins.bibles.lib.importers.csvbible.open', create=True),\174 patch('openlp.plugins.bibles.lib.importers.csvbible.Path.open', create=True),\
173 patch('openlp.plugins.bibles.lib.importers.csvbible.csv.reader', side_effect=csv.Error):175 patch('openlp.plugins.bibles.lib.importers.csvbible.csv.reader', side_effect=csv.Error):
174176
175 # WHEN: Calling CSVBible.parse_csv_file177 # WHEN: Calling CSVBible.parse_csv_file
176 # THEN: A ValidationError should be raised178 # THEN: A ValidationError should be raised
177 with self.assertRaises(ValidationError) as context:179 with self.assertRaises(ValidationError) as context:
178 CSVBible.parse_csv_file('file.csv', None)180 CSVBible.parse_csv_file(Path('file.csv'), None)
179 self.assertEqual(context.exception.msg, 'Parsing "file.csv" failed')181 self.assertEqual(context.exception.msg, 'Parsing "file.csv" failed')
180182
181 def test_process_books_stopped_import(self):183 def test_process_books_stopped_import(self):
@@ -185,7 +187,8 @@
185 # GIVEN: An instance of CSVBible with the stop_import_flag set to True187 # GIVEN: An instance of CSVBible with the stop_import_flag set to True
186 mocked_manager = MagicMock()188 mocked_manager = MagicMock()
187 with patch('openlp.plugins.bibles.lib.db.BibleDB._setup'):189 with patch('openlp.plugins.bibles.lib.db.BibleDB._setup'):
188 importer = CSVBible(mocked_manager, path='.', name='.', booksfile='books.csv', versefile='verse.csv')190 importer = CSVBible(mocked_manager, path='.', name='.', books_path=Path('books.csv'),
191 verse_path=Path('verse.csv'))
189 type(importer).application = PropertyMock()192 type(importer).application = PropertyMock()
190 importer.stop_import_flag = True193 importer.stop_import_flag = True
191 importer.wizard = MagicMock()194 importer.wizard = MagicMock()
@@ -205,7 +208,8 @@
205 mocked_manager = MagicMock()208 mocked_manager = MagicMock()
206 with patch('openlp.plugins.bibles.lib.db.BibleDB._setup'),\209 with patch('openlp.plugins.bibles.lib.db.BibleDB._setup'),\
207 patch('openlp.plugins.bibles.lib.importers.csvbible.translate'):210 patch('openlp.plugins.bibles.lib.importers.csvbible.translate'):
208 importer = CSVBible(mocked_manager, path='.', name='.', booksfile='books.csv', versefile='verse.csv')211 importer = CSVBible(mocked_manager, path='.', name='.', books_path=Path('books.csv'),
212 verse_path=Path('verse.csv'))
209 importer.find_and_create_book = MagicMock()213 importer.find_and_create_book = MagicMock()
210 importer.language_id = 10214 importer.language_id = 10
211 importer.stop_import_flag = False215 importer.stop_import_flag = False
@@ -229,7 +233,8 @@
229 # GIVEN: An instance of CSVBible with the stop_import_flag set to True233 # GIVEN: An instance of CSVBible with the stop_import_flag set to True
230 mocked_manager = MagicMock()234 mocked_manager = MagicMock()
231 with patch('openlp.plugins.bibles.lib.db.BibleDB._setup'):235 with patch('openlp.plugins.bibles.lib.db.BibleDB._setup'):
232 importer = CSVBible(mocked_manager, path='.', name='.', booksfile='books.csv', versefile='verse.csv')236 importer = CSVBible(mocked_manager, path='.', name='.', books_path=Path('books.csv'),
237 verse_path=Path('verse.csv'))
233 importer.get_book_name = MagicMock()238 importer.get_book_name = MagicMock()
234 importer.session = MagicMock()239 importer.session = MagicMock()
235 importer.stop_import_flag = True240 importer.stop_import_flag = True
@@ -250,7 +255,8 @@
250 mocked_manager = MagicMock()255 mocked_manager = MagicMock()
251 with patch('openlp.plugins.bibles.lib.db.BibleDB._setup'),\256 with patch('openlp.plugins.bibles.lib.db.BibleDB._setup'),\
252 patch('openlp.plugins.bibles.lib.importers.csvbible.translate'):257 patch('openlp.plugins.bibles.lib.importers.csvbible.translate'):
253 importer = CSVBible(mocked_manager, path='.', name='.', booksfile='books.csv', versefile='verse.csv')258 importer = CSVBible(mocked_manager, path='.', name='.', books_path=Path('books.csv'),
259 verse_path=Path('verse.csv'))
254 importer.create_verse = MagicMock()260 importer.create_verse = MagicMock()
255 importer.get_book = MagicMock(return_value=Book('1', '1', '1. Mosebog', '1Mos'))261 importer.get_book = MagicMock(return_value=Book('1', '1', '1. Mosebog', '1Mos'))
256 importer.get_book_name = MagicMock(return_value='1. Mosebog')262 importer.get_book_name = MagicMock(return_value='1. Mosebog')
@@ -281,7 +287,8 @@
281 # GIVEN: An instance of CSVBible and a mocked get_language which simulates the user cancelling the language box287 # GIVEN: An instance of CSVBible and a mocked get_language which simulates the user cancelling the language box
282 mocked_manager = MagicMock()288 mocked_manager = MagicMock()
283 with patch('openlp.plugins.bibles.lib.db.BibleDB._setup'):289 with patch('openlp.plugins.bibles.lib.db.BibleDB._setup'):
284 importer = CSVBible(mocked_manager, path='.', name='.', booksfile='books.csv', versefile='verse.csv')290 importer = CSVBible(mocked_manager, path='.', name='.', books_path=Path('books.csv'),
291 verse_path=Path('verse.csv'))
285 importer.get_language = MagicMock(return_value=None)292 importer.get_language = MagicMock(return_value=None)
286293
287 # WHEN: Calling do_import294 # WHEN: Calling do_import
@@ -298,7 +305,8 @@
298 # GIVEN: An instance of CSVBible305 # GIVEN: An instance of CSVBible
299 mocked_manager = MagicMock()306 mocked_manager = MagicMock()
300 with patch('openlp.plugins.bibles.lib.db.BibleDB._setup'):307 with patch('openlp.plugins.bibles.lib.db.BibleDB._setup'):
301 importer = CSVBible(mocked_manager, path='.', name='.', booksfile='books.csv', versefile='verses.csv')308 importer = CSVBible(mocked_manager, path='.', name='.', books_path=Path('books.csv'),
309 verse_path=Path('verses.csv'))
302 importer.get_language = MagicMock(return_value=10)310 importer.get_language = MagicMock(return_value=10)
303 importer.parse_csv_file = MagicMock(side_effect=[['Book 1'], ['Verse 1']])311 importer.parse_csv_file = MagicMock(side_effect=[['Book 1'], ['Verse 1']])
304 importer.process_books = MagicMock(return_value=['Book 1'])312 importer.process_books = MagicMock(return_value=['Book 1'])
@@ -312,7 +320,8 @@
312320
313 # THEN: parse_csv_file should be called twice,321 # THEN: parse_csv_file should be called twice,
314 # and True should be returned.322 # and True should be returned.
315 self.assertEqual(importer.parse_csv_file.mock_calls, [call('books.csv', Book), call('verses.csv', Verse)])323 self.assertEqual(importer.parse_csv_file.mock_calls,
324 [call(Path('books.csv'), Book), call(Path('verses.csv'), Verse)])
316 importer.process_books.assert_called_once_with(['Book 1'])325 importer.process_books.assert_called_once_with(['Book 1'])
317 importer.process_verses.assert_called_once_with(['Verse 1'], ['Book 1'])326 importer.process_verses.assert_called_once_with(['Verse 1'], ['Book 1'])
318 self.assertTrue(result)327 self.assertTrue(result)
@@ -325,12 +334,12 @@
325 # get_book_ref_id_by_name, create_verse, create_book, session and get_language.334 # get_book_ref_id_by_name, create_verse, create_book, session and get_language.
326 result_file = open(os.path.join(TEST_PATH, 'dk1933.json'), 'rb')335 result_file = open(os.path.join(TEST_PATH, 'dk1933.json'), 'rb')
327 test_data = json.loads(result_file.read().decode())336 test_data = json.loads(result_file.read().decode())
328 books_file = os.path.join(TEST_PATH, 'dk1933-books.csv')337 books_file = Path(TEST_PATH, 'dk1933-books.csv')
329 verses_file = os.path.join(TEST_PATH, 'dk1933-verses.csv')338 verses_file = Path(TEST_PATH, 'dk1933-verses.csv')
330 with patch('openlp.plugins.bibles.lib.importers.csvbible.CSVBible.application'):339 with patch('openlp.plugins.bibles.lib.importers.csvbible.CSVBible.application'):
331 mocked_manager = MagicMock()340 mocked_manager = MagicMock()
332 mocked_import_wizard = MagicMock()341 mocked_import_wizard = MagicMock()
333 importer = CSVBible(mocked_manager, path='.', name='.', booksfile=books_file, versefile=verses_file)342 importer = CSVBible(mocked_manager, path='.', name='.', books_path=books_file, verse_path=verses_file)
334 importer.wizard = mocked_import_wizard343 importer.wizard = mocked_import_wizard
335 importer.get_book_ref_id_by_name = MagicMock()344 importer.get_book_ref_id_by_name = MagicMock()
336 importer.create_verse = MagicMock()345 importer.create_verse = MagicMock()
337346
=== modified file 'tests/functional/openlp_plugins/bibles/test_opensongimport.py'
--- tests/functional/openlp_plugins/bibles/test_opensongimport.py 2017-10-29 06:01:25 +0000
+++ tests/functional/openlp_plugins/bibles/test_opensongimport.py 2017-11-14 23:03:10 +0000
@@ -29,6 +29,7 @@
2929
30from lxml import objectify30from lxml import objectify
3131
32from openlp.core.common.path import Path
32from openlp.core.common.registry import Registry33from openlp.core.common.registry import Registry
33from openlp.plugins.bibles.lib.importers.opensong import OpenSongBible, get_text, parse_chapter_number34from openlp.plugins.bibles.lib.importers.opensong import OpenSongBible, get_text, parse_chapter_number
34from openlp.plugins.bibles.lib.bibleimport import BibleImport35from openlp.plugins.bibles.lib.bibleimport import BibleImport
@@ -64,7 +65,7 @@
64 mocked_manager = MagicMock()65 mocked_manager = MagicMock()
6566
66 # WHEN: An importer object is created67 # WHEN: An importer object is created
67 importer = OpenSongBible(mocked_manager, path='.', name='.', filename='')68 importer = OpenSongBible(mocked_manager, path='.', name='.', file_path=None)
6869
69 # THEN: The importer should be an instance of BibleDB70 # THEN: The importer should be an instance of BibleDB
70 self.assertIsInstance(importer, BibleImport)71 self.assertIsInstance(importer, BibleImport)
@@ -126,7 +127,7 @@
126 Test parse_verse_number when supplied with a valid verse number127 Test parse_verse_number when supplied with a valid verse number
127 """128 """
128 # GIVEN: An instance of OpenSongBible, the number 15 represented as a string and an instance of OpenSongBible129 # GIVEN: An instance of OpenSongBible, the number 15 represented as a string and an instance of OpenSongBible
129 importer = OpenSongBible(MagicMock(), path='.', name='.', filename='')130 importer = OpenSongBible(MagicMock(), path='.', name='.', file_path=None)
130131
131 # WHEN: Calling parse_verse_number132 # WHEN: Calling parse_verse_number
132 result = importer.parse_verse_number('15', 0)133 result = importer.parse_verse_number('15', 0)
@@ -139,7 +140,7 @@
139 Test parse_verse_number when supplied with a verse range140 Test parse_verse_number when supplied with a verse range
140 """141 """
141 # GIVEN: An instance of OpenSongBible, and the range 24-26 represented as a string142 # GIVEN: An instance of OpenSongBible, and the range 24-26 represented as a string
142 importer = OpenSongBible(MagicMock(), path='.', name='.', filename='')143 importer = OpenSongBible(MagicMock(), path='.', name='.', file_path=None)
143144
144 # WHEN: Calling parse_verse_number145 # WHEN: Calling parse_verse_number
145 result = importer.parse_verse_number('24-26', 0)146 result = importer.parse_verse_number('24-26', 0)
@@ -152,7 +153,7 @@
152 Test parse_verse_number when supplied with a invalid verse number153 Test parse_verse_number when supplied with a invalid verse number
153 """154 """
154 # GIVEN: An instance of OpenSongBible, a non numeric string represented as a string155 # GIVEN: An instance of OpenSongBible, a non numeric string represented as a string
155 importer = OpenSongBible(MagicMock(), path='.', name='.', filename='')156 importer = OpenSongBible(MagicMock(), path='.', name='.', file_path=None)
156157
157 # WHEN: Calling parse_verse_number158 # WHEN: Calling parse_verse_number
158 result = importer.parse_verse_number('invalid', 41)159 result = importer.parse_verse_number('invalid', 41)
@@ -165,7 +166,7 @@
165 Test parse_verse_number when the verse number is an empty string. (Bug #1074727)166 Test parse_verse_number when the verse number is an empty string. (Bug #1074727)
166 """167 """
167 # GIVEN: An instance of OpenSongBible, an empty string, and the previous verse number set as 14168 # GIVEN: An instance of OpenSongBible, an empty string, and the previous verse number set as 14
168 importer = OpenSongBible(MagicMock(), path='.', name='.', filename='')169 importer = OpenSongBible(MagicMock(), path='.', name='.', file_path=None)
169 # WHEN: Calling parse_verse_number170 # WHEN: Calling parse_verse_number
170 result = importer.parse_verse_number('', 14)171 result = importer.parse_verse_number('', 14)
171172
@@ -178,7 +179,7 @@
178 """179 """
179 with patch.object(OpenSongBible, 'log_warning')as mocked_log_warning:180 with patch.object(OpenSongBible, 'log_warning')as mocked_log_warning:
180 # GIVEN: An instanceofOpenSongBible, a Tuple, and the previous verse number set as 12181 # GIVEN: An instanceofOpenSongBible, a Tuple, and the previous verse number set as 12
181 importer = OpenSongBible(MagicMock(), path='.', name='.', filename='')182 importer = OpenSongBible(MagicMock(), path='.', name='.', file_path=None)
182183
183 # WHEN: Calling parse_verse_number184 # WHEN: Calling parse_verse_number
184 result = importer.parse_verse_number((1, 2, 3), 12)185 result = importer.parse_verse_number((1, 2, 3), 12)
@@ -193,7 +194,7 @@
193 Test process_books when stop_import is set to True194 Test process_books when stop_import is set to True
194 """195 """
195 # GIVEN: An instance of OpenSongBible196 # GIVEN: An instance of OpenSongBible
196 importer = OpenSongBible(MagicMock(), path='.', name='.', filename='')197 importer = OpenSongBible(MagicMock(), path='.', name='.', file_path=None)
197198
198 # WHEN: stop_import_flag is set to True199 # WHEN: stop_import_flag is set to True
199 importer.stop_import_flag = True200 importer.stop_import_flag = True
@@ -209,7 +210,7 @@
209 # GIVEN: An instance of OpenSongBible Importer and two mocked books210 # GIVEN: An instance of OpenSongBible Importer and two mocked books
210 self.mocked_find_and_create_book.side_effect = ['db_book1', 'db_book2']211 self.mocked_find_and_create_book.side_effect = ['db_book1', 'db_book2']
211 with patch.object(OpenSongBible, 'process_chapters') as mocked_process_chapters:212 with patch.object(OpenSongBible, 'process_chapters') as mocked_process_chapters:
212 importer = OpenSongBible(MagicMock(), path='.', name='.', filename='')213 importer = OpenSongBible(MagicMock(), path='.', name='.', file_path=None)
213214
214 book1 = MagicMock()215 book1 = MagicMock()
215 book1.attrib = {'n': 'Name1'}216 book1.attrib = {'n': 'Name1'}
@@ -236,7 +237,7 @@
236 Test process_chapters when stop_import is set to True237 Test process_chapters when stop_import is set to True
237 """238 """
238 # GIVEN: An isntance of OpenSongBible239 # GIVEN: An isntance of OpenSongBible
239 importer = OpenSongBible(MagicMock(), path='.', name='.', filename='')240 importer = OpenSongBible(MagicMock(), path='.', name='.', file_path=None)
240 importer.parse_chapter_number = MagicMock()241 importer.parse_chapter_number = MagicMock()
241242
242 # WHEN: stop_import_flag is set to True243 # WHEN: stop_import_flag is set to True
@@ -252,7 +253,7 @@
252 Test process_chapters when it completes253 Test process_chapters when it completes
253 """254 """
254 # GIVEN: An instance of OpenSongBible255 # GIVEN: An instance of OpenSongBible
255 importer = OpenSongBible(MagicMock(), path='.', name='.', filename='')256 importer = OpenSongBible(MagicMock(), path='.', name='.', file_path=None)
256 importer.wizard = MagicMock()257 importer.wizard = MagicMock()
257258
258 # WHEN: called with some valid data259 # WHEN: called with some valid data
@@ -284,7 +285,7 @@
284 Test process_verses when stop_import is set to True285 Test process_verses when stop_import is set to True
285 """286 """
286 # GIVEN: An isntance of OpenSongBible287 # GIVEN: An isntance of OpenSongBible
287 importer = OpenSongBible(MagicMock(), path='.', name='.', filename='')288 importer = OpenSongBible(MagicMock(), path='.', name='.', file_path=None)
288 importer.parse_verse_number = MagicMock()289 importer.parse_verse_number = MagicMock()
289290
290 # WHEN: stop_import_flag is set to True291 # WHEN: stop_import_flag is set to True
@@ -303,7 +304,7 @@
303 patch.object(OpenSongBible, 'parse_verse_number',304 patch.object(OpenSongBible, 'parse_verse_number',
304 **{'side_effect': [1, 2]}) as mocked_parse_verse_number:305 **{'side_effect': [1, 2]}) as mocked_parse_verse_number:
305 # GIVEN: An instance of OpenSongBible306 # GIVEN: An instance of OpenSongBible
306 importer = OpenSongBible(MagicMock(), path='.', name='.', filename='')307 importer = OpenSongBible(MagicMock(), path='.', name='.', file_path=None)
307 importer.wizard = MagicMock()308 importer.wizard = MagicMock()
308309
309 # WHEN: called with some valid data310 # WHEN: called with some valid data
@@ -338,7 +339,7 @@
338 patch.object(OpenSongBible, 'validate_xml_file'), \339 patch.object(OpenSongBible, 'validate_xml_file'), \
339 patch.object(OpenSongBible, 'parse_xml', return_value=None), \340 patch.object(OpenSongBible, 'parse_xml', return_value=None), \
340 patch.object(OpenSongBible, 'get_language_id') as mocked_language_id:341 patch.object(OpenSongBible, 'get_language_id') as mocked_language_id:
341 importer = OpenSongBible(MagicMock(), path='.', name='.', filename='')342 importer = OpenSongBible(MagicMock(), path='.', name='.', file_path=None)
342343
343 # WHEN: Calling do_import344 # WHEN: Calling do_import
344 result = importer.do_import()345 result = importer.do_import()
@@ -357,7 +358,7 @@
357 patch.object(OpenSongBible, 'parse_xml'), \358 patch.object(OpenSongBible, 'parse_xml'), \
358 patch.object(OpenSongBible, 'get_language_id', return_value=False), \359 patch.object(OpenSongBible, 'get_language_id', return_value=False), \
359 patch.object(OpenSongBible, 'process_books') as mocked_process_books:360 patch.object(OpenSongBible, 'process_books') as mocked_process_books:
360 importer = OpenSongBible(MagicMock(), path='.', name='.', filename='')361 importer = OpenSongBible(MagicMock(), path='.', name='.', file_path=None)
361362
362 # WHEN: Calling do_import363 # WHEN: Calling do_import
363 result = importer.do_import()364 result = importer.do_import()
@@ -376,7 +377,7 @@
376 patch.object(OpenSongBible, 'parse_xml'), \377 patch.object(OpenSongBible, 'parse_xml'), \
377 patch.object(OpenSongBible, 'get_language_id', return_value=10), \378 patch.object(OpenSongBible, 'get_language_id', return_value=10), \
378 patch.object(OpenSongBible, 'process_books'):379 patch.object(OpenSongBible, 'process_books'):
379 importer = OpenSongBible(MagicMock(), path='.', name='.', filename='')380 importer = OpenSongBible(MagicMock(), path='.', name='.', file_path=None)
380381
381 # WHEN: Calling do_import382 # WHEN: Calling do_import
382 result = importer.do_import()383 result = importer.do_import()
@@ -406,7 +407,7 @@
406 with patch('openlp.plugins.bibles.lib.importers.opensong.OpenSongBible.application'):407 with patch('openlp.plugins.bibles.lib.importers.opensong.OpenSongBible.application'):
407 mocked_manager = MagicMock()408 mocked_manager = MagicMock()
408 mocked_import_wizard = MagicMock()409 mocked_import_wizard = MagicMock()
409 importer = OpenSongBible(mocked_manager, path='.', name='.', filename='')410 importer = OpenSongBible(mocked_manager, path='.', name='.', file_path=None)
410 importer.wizard = mocked_import_wizard411 importer.wizard = mocked_import_wizard
411 importer.get_book_ref_id_by_name = MagicMock()412 importer.get_book_ref_id_by_name = MagicMock()
412 importer.create_verse = MagicMock()413 importer.create_verse = MagicMock()
@@ -416,7 +417,7 @@
416 importer.get_language.return_value = 'Danish'417 importer.get_language.return_value = 'Danish'
417418
418 # WHEN: Importing bible file419 # WHEN: Importing bible file
419 importer.filename = os.path.join(TEST_PATH, bible_file)420 importer.file_path = Path(TEST_PATH, bible_file)
420 importer.do_import()421 importer.do_import()
421422
422 # THEN: The create_verse() method should have been called with each verse in the file.423 # THEN: The create_verse() method should have been called with each verse in the file.
423424
=== modified file 'tests/functional/openlp_plugins/bibles/test_osisimport.py'
--- tests/functional/openlp_plugins/bibles/test_osisimport.py 2017-10-29 06:01:25 +0000
+++ tests/functional/openlp_plugins/bibles/test_osisimport.py 2017-11-14 23:03:10 +0000
@@ -27,6 +27,7 @@
27from unittest import TestCase27from unittest import TestCase
28from unittest.mock import MagicMock, call, patch28from unittest.mock import MagicMock, call, patch
2929
30from openlp.core.common.path import Path
30from openlp.plugins.bibles.lib.bibleimport import BibleImport31from openlp.plugins.bibles.lib.bibleimport import BibleImport
31from openlp.plugins.bibles.lib.db import BibleDB32from openlp.plugins.bibles.lib.db import BibleDB
32from openlp.plugins.bibles.lib.importers.osis import OSISBible33from openlp.plugins.bibles.lib.importers.osis import OSISBible
@@ -63,7 +64,7 @@
63 mocked_manager = MagicMock()64 mocked_manager = MagicMock()
6465
65 # WHEN: An importer object is created66 # WHEN: An importer object is created
66 importer = OSISBible(mocked_manager, path='.', name='.', filename='')67 importer = OSISBible(mocked_manager, path='.', name='.', file_path=None)
6768
68 # THEN: The importer should be an instance of BibleDB69 # THEN: The importer should be an instance of BibleDB
69 self.assertIsInstance(importer, BibleDB)70 self.assertIsInstance(importer, BibleDB)
@@ -73,7 +74,7 @@
73 Test process_books when stop_import is set to True74 Test process_books when stop_import is set to True
74 """75 """
75 # GIVEN: An instance of OSISBible adn some mocked data76 # GIVEN: An instance of OSISBible adn some mocked data
76 importer = OSISBible(MagicMock(), path='.', name='.', filename='')77 importer = OSISBible(MagicMock(), path='.', name='.', file_path=None)
77 mocked_data = MagicMock(**{'xpath.return_value': ['Book']})78 mocked_data = MagicMock(**{'xpath.return_value': ['Book']})
7879
79 # WHEN: stop_import_flag is set to True and process_books is called80 # WHEN: stop_import_flag is set to True and process_books is called
@@ -90,7 +91,7 @@
90 # GIVEN: An instance of OSISBible Importer and two mocked books91 # GIVEN: An instance of OSISBible Importer and two mocked books
91 self.mocked_find_and_create_book.side_effect = ['db_book1', 'db_book2']92 self.mocked_find_and_create_book.side_effect = ['db_book1', 'db_book2']
92 with patch.object(OSISBible, 'process_chapters') as mocked_process_chapters:93 with patch.object(OSISBible, 'process_chapters') as mocked_process_chapters:
93 importer = OSISBible(MagicMock(), path='.', name='.', filename='')94 importer = OSISBible(MagicMock(), path='.', name='.', file_path=None)
9495
95 book1 = MagicMock()96 book1 = MagicMock()
96 book1.get.return_value = 'Name1'97 book1.get.return_value = 'Name1'
@@ -128,7 +129,7 @@
128 test_chapter = MagicMock()129 test_chapter = MagicMock()
129 test_chapter.__iter__.return_value = [test_verse]130 test_chapter.__iter__.return_value = [test_verse]
130 test_chapter.get.side_effect = lambda x: {'osisID': '1.2.4', 'sID': '999'}.get(x)131 test_chapter.get.side_effect = lambda x: {'osisID': '1.2.4', 'sID': '999'}.get(x)
131 importer = OSISBible(MagicMock(), path='.', name='.', filename='')132 importer = OSISBible(MagicMock(), path='.', name='.', file_path=None)
132133
133 # WHEN: Calling process_chapters134 # WHEN: Calling process_chapters
134 importer.process_chapters(test_book, [test_chapter])135 importer.process_chapters(test_book, [test_chapter])
@@ -155,7 +156,7 @@
155 test_chapter = MagicMock()156 test_chapter = MagicMock()
156 test_chapter.__iter__.return_value = [test_verse]157 test_chapter.__iter__.return_value = [test_verse]
157 test_chapter.get.side_effect = lambda x: {'osisID': '1.2.4', 'sID': '999'}.get(x)158 test_chapter.get.side_effect = lambda x: {'osisID': '1.2.4', 'sID': '999'}.get(x)
158 importer = OSISBible(MagicMock(), path='.', name='.', filename='')159 importer = OSISBible(MagicMock(), path='.', name='.', file_path=None)
159160
160 # WHEN: Calling process_chapters161 # WHEN: Calling process_chapters
161 importer.process_chapters(test_book, [test_chapter])162 importer.process_chapters(test_book, [test_chapter])
@@ -180,7 +181,7 @@
180 test_chapter.get.side_effect = lambda x: {'osisID': '1.2.4'}.get(x)181 test_chapter.get.side_effect = lambda x: {'osisID': '1.2.4'}.get(x)
181182
182 # WHEN: Calling process_chapters183 # WHEN: Calling process_chapters
183 importer = OSISBible(MagicMock(), path='.', name='.', filename='')184 importer = OSISBible(MagicMock(), path='.', name='.', file_path=None)
184 importer.process_chapters(test_book, [test_chapter])185 importer.process_chapters(test_book, [test_chapter])
185186
186 # THEN: neither set_current_chapter or process_verse should have been called187 # THEN: neither set_current_chapter or process_verse should have been called
@@ -201,7 +202,7 @@
201 test_chapter = MagicMock()202 test_chapter = MagicMock()
202 test_chapter.tag = '{http://www.bibletechnologies.net/2003/OSIS/namespace}chapter'203 test_chapter.tag = '{http://www.bibletechnologies.net/2003/OSIS/namespace}chapter'
203 test_chapter.get.side_effect = lambda x: {'osisID': '1.2.4', 'sID': '999'}.get(x)204 test_chapter.get.side_effect = lambda x: {'osisID': '1.2.4', 'sID': '999'}.get(x)
204 importer = OSISBible(MagicMock(), path='.', name='.', filename='')205 importer = OSISBible(MagicMock(), path='.', name='.', file_path=None)
205206
206 # WHEN: Calling process_chapters207 # WHEN: Calling process_chapters
207 importer.process_chapters(test_book, [test_chapter])208 importer.process_chapters(test_book, [test_chapter])
@@ -228,7 +229,7 @@
228 test_verse.text = 'Verse Text'229 test_verse.text = 'Verse Text'
229230
230 # WHEN: Calling process_chapters231 # WHEN: Calling process_chapters
231 importer = OSISBible(MagicMock(), path='.', name='.', filename='')232 importer = OSISBible(MagicMock(), path='.', name='.', file_path=None)
232 importer.process_chapters(test_book, [test_verse])233 importer.process_chapters(test_book, [test_verse])
233234
234 # THEN: process_verse should have been called with the test data235 # THEN: process_verse should have been called with the test data
@@ -245,7 +246,7 @@
245 test_verse.get.side_effect = lambda x: {}.get(x)246 test_verse.get.side_effect = lambda x: {}.get(x)
246 test_verse.tail = 'Verse Text'247 test_verse.tail = 'Verse Text'
247 test_verse.text = None248 test_verse.text = None
248 importer = OSISBible(MagicMock(), path='.', name='.', filename='')249 importer = OSISBible(MagicMock(), path='.', name='.', file_path=None)
249250
250 # WHEN: Calling process_verse with the test data251 # WHEN: Calling process_verse with the test data
251 importer.process_verse(test_book, 2, test_verse)252 importer.process_verse(test_book, 2, test_verse)
@@ -264,7 +265,7 @@
264 test_verse.get.side_effect = lambda x: {}.get(x)265 test_verse.get.side_effect = lambda x: {}.get(x)
265 test_verse.tail = 'Verse Text'266 test_verse.tail = 'Verse Text'
266 test_verse.text = None267 test_verse.text = None
267 importer = OSISBible(MagicMock(), path='.', name='.', filename='')268 importer = OSISBible(MagicMock(), path='.', name='.', file_path=None)
268269
269 # WHEN: Calling process_verse with the test data270 # WHEN: Calling process_verse with the test data
270 importer.process_verse(test_book, 2, test_verse)271 importer.process_verse(test_book, 2, test_verse)
@@ -282,7 +283,7 @@
282 test_verse.tail = None283 test_verse.tail = None
283 test_verse.text = None284 test_verse.text = None
284 test_verse.get.side_effect = lambda x: {'osisID': '1.2.4', 'sID': '999'}.get(x)285 test_verse.get.side_effect = lambda x: {'osisID': '1.2.4', 'sID': '999'}.get(x)
285 importer = OSISBible(MagicMock(), path='.', name='.', filename='')286 importer = OSISBible(MagicMock(), path='.', name='.', file_path=None)
286287
287 # WHEN: Calling process_verse with the test data288 # WHEN: Calling process_verse with the test data
288 importer.process_verse(test_book, 2, test_verse, use_milestones=True)289 importer.process_verse(test_book, 2, test_verse, use_milestones=True)
@@ -301,7 +302,7 @@
301 test_verse.tail = 'Verse Text'302 test_verse.tail = 'Verse Text'
302 test_verse.text = None303 test_verse.text = None
303 test_verse.get.side_effect = lambda x: {'osisID': '1.2.4', 'sID': '999'}.get(x)304 test_verse.get.side_effect = lambda x: {'osisID': '1.2.4', 'sID': '999'}.get(x)
304 importer = OSISBible(MagicMock(), path='.', name='.', filename='')305 importer = OSISBible(MagicMock(), path='.', name='.', file_path=None)
305306
306 # WHEN: Calling process_verse with the test data307 # WHEN: Calling process_verse with the test data
307 importer.process_verse(test_book, 2, test_verse, use_milestones=True)308 importer.process_verse(test_book, 2, test_verse, use_milestones=True)
@@ -320,7 +321,7 @@
320 test_verse.tail = '\n ' # Whitespace321 test_verse.tail = '\n ' # Whitespace
321 test_verse.text = None322 test_verse.text = None
322 test_verse.get.side_effect = lambda x: {'osisID': '1.2.4', 'sID': '999'}.get(x)323 test_verse.get.side_effect = lambda x: {'osisID': '1.2.4', 'sID': '999'}.get(x)
323 importer = OSISBible(MagicMock(), path='.', name='.', filename='')324 importer = OSISBible(MagicMock(), path='.', name='.', file_path=None)
324325
325 # WHEN: Calling process_verse with the test data326 # WHEN: Calling process_verse with the test data
326 importer.process_verse(test_book, 2, test_verse)327 importer.process_verse(test_book, 2, test_verse)
@@ -339,7 +340,7 @@
339 test_verse.tail = '\n ' # Whitespace340 test_verse.tail = '\n ' # Whitespace
340 test_verse.text = 'Verse Text'341 test_verse.text = 'Verse Text'
341 test_verse.get.side_effect = lambda x: {'osisID': '1.2.4', 'sID': '999'}.get(x)342 test_verse.get.side_effect = lambda x: {'osisID': '1.2.4', 'sID': '999'}.get(x)
342 importer = OSISBible(MagicMock(), path='.', name='.', filename='')343 importer = OSISBible(MagicMock(), path='.', name='.', file_path=None)
343344
344 # WHEN: Calling process_verse with the test data345 # WHEN: Calling process_verse with the test data
345 importer.process_verse(test_book, 2, test_verse)346 importer.process_verse(test_book, 2, test_verse)
@@ -356,7 +357,7 @@
356 patch.object(OSISBible, 'validate_xml_file'), \357 patch.object(OSISBible, 'validate_xml_file'), \
357 patch.object(OSISBible, 'parse_xml', return_value=None), \358 patch.object(OSISBible, 'parse_xml', return_value=None), \
358 patch.object(OSISBible, 'get_language_id') as mocked_language_id:359 patch.object(OSISBible, 'get_language_id') as mocked_language_id:
359 importer = OSISBible(MagicMock(), path='.', name='.', filename='')360 importer = OSISBible(MagicMock(), path='.', name='.', file_path=None)
360361
361 # WHEN: Calling do_import362 # WHEN: Calling do_import
362 result = importer.do_import()363 result = importer.do_import()
@@ -375,7 +376,7 @@
375 patch.object(OSISBible, 'parse_xml'), \376 patch.object(OSISBible, 'parse_xml'), \
376 patch.object(OSISBible, 'get_language_id', **{'return_value': False}), \377 patch.object(OSISBible, 'get_language_id', **{'return_value': False}), \
377 patch.object(OSISBible, 'process_books') as mocked_process_books:378 patch.object(OSISBible, 'process_books') as mocked_process_books:
378 importer = OSISBible(MagicMock(), path='.', name='.', filename='')379 importer = OSISBible(MagicMock(), path='.', name='.', file_path=None)
379380
380 # WHEN: Calling do_import381 # WHEN: Calling do_import
381 result = importer.do_import()382 result = importer.do_import()
@@ -394,7 +395,7 @@
394 patch.object(OSISBible, 'parse_xml'), \395 patch.object(OSISBible, 'parse_xml'), \
395 patch.object(OSISBible, 'get_language_id', **{'return_value': 10}), \396 patch.object(OSISBible, 'get_language_id', **{'return_value': 10}), \
396 patch.object(OSISBible, 'process_books'):397 patch.object(OSISBible, 'process_books'):
397 importer = OSISBible(MagicMock(), path='.', name='.', filename='')398 importer = OSISBible(MagicMock(), path='.', name='.', file_path=None)
398399
399 # WHEN: Calling do_import400 # WHEN: Calling do_import
400 result = importer.do_import()401 result = importer.do_import()
@@ -427,7 +428,7 @@
427 with patch('openlp.plugins.bibles.lib.importers.osis.OSISBible.application'):428 with patch('openlp.plugins.bibles.lib.importers.osis.OSISBible.application'):
428 mocked_manager = MagicMock()429 mocked_manager = MagicMock()
429 mocked_import_wizard = MagicMock()430 mocked_import_wizard = MagicMock()
430 importer = OSISBible(mocked_manager, path='.', name='.', filename='')431 importer = OSISBible(mocked_manager, path='.', name='.', file_path=None)
431 importer.wizard = mocked_import_wizard432 importer.wizard = mocked_import_wizard
432 importer.get_book_ref_id_by_name = MagicMock()433 importer.get_book_ref_id_by_name = MagicMock()
433 importer.create_verse = MagicMock()434 importer.create_verse = MagicMock()
@@ -437,7 +438,7 @@
437 importer.get_language.return_value = 'Danish'438 importer.get_language.return_value = 'Danish'
438439
439 # WHEN: Importing bible file440 # WHEN: Importing bible file
440 importer.filename = os.path.join(TEST_PATH, bible_file)441 importer.file_path = Path(TEST_PATH, bible_file)
441 importer.do_import()442 importer.do_import()
442443
443 # THEN: The create_verse() method should have been called with each verse in the file.444 # THEN: The create_verse() method should have been called with each verse in the file.
@@ -457,7 +458,7 @@
457 with patch('openlp.plugins.bibles.lib.importers.osis.OSISBible.application'):458 with patch('openlp.plugins.bibles.lib.importers.osis.OSISBible.application'):
458 mocked_manager = MagicMock()459 mocked_manager = MagicMock()
459 mocked_import_wizard = MagicMock()460 mocked_import_wizard = MagicMock()
460 importer = OSISBible(mocked_manager, path='.', name='.', filename='')461 importer = OSISBible(mocked_manager, path='.', name='.', file_path=None)
461 importer.wizard = mocked_import_wizard462 importer.wizard = mocked_import_wizard
462 importer.get_book_ref_id_by_name = MagicMock()463 importer.get_book_ref_id_by_name = MagicMock()
463 importer.create_verse = MagicMock()464 importer.create_verse = MagicMock()
@@ -467,7 +468,7 @@
467 importer.get_language.return_value = 'English'468 importer.get_language.return_value = 'English'
468469
469 # WHEN: Importing bible file470 # WHEN: Importing bible file
470 importer.filename = os.path.join(TEST_PATH, bible_file)471 importer.file_path = Path(TEST_PATH, bible_file)
471 importer.do_import()472 importer.do_import()
472473
473 # THEN: The create_verse() method should have been called with each verse in the file.474 # THEN: The create_verse() method should have been called with each verse in the file.
@@ -487,7 +488,7 @@
487 with patch('openlp.plugins.bibles.lib.importers.osis.OSISBible.application'):488 with patch('openlp.plugins.bibles.lib.importers.osis.OSISBible.application'):
488 mocked_manager = MagicMock()489 mocked_manager = MagicMock()
489 mocked_import_wizard = MagicMock()490 mocked_import_wizard = MagicMock()
490 importer = OSISBible(mocked_manager, path='.', name='.', filename='')491 importer = OSISBible(mocked_manager, path='.', name='.', file_path=None)
491 importer.wizard = mocked_import_wizard492 importer.wizard = mocked_import_wizard
492 importer.get_book_ref_id_by_name = MagicMock()493 importer.get_book_ref_id_by_name = MagicMock()
493 importer.create_verse = MagicMock()494 importer.create_verse = MagicMock()
@@ -497,7 +498,7 @@
497 importer.get_language.return_value = 'English'498 importer.get_language.return_value = 'English'
498499
499 # WHEN: Importing bible file500 # WHEN: Importing bible file
500 importer.filename = os.path.join(TEST_PATH, bible_file)501 importer.file_path = Path(TEST_PATH, bible_file)
501 importer.do_import()502 importer.do_import()
502503
503 # THEN: The create_verse() method should have been called with each verse in the file.504 # THEN: The create_verse() method should have been called with each verse in the file.
@@ -517,7 +518,7 @@
517 with patch('openlp.plugins.bibles.lib.importers.osis.OSISBible.application'):518 with patch('openlp.plugins.bibles.lib.importers.osis.OSISBible.application'):
518 mocked_manager = MagicMock()519 mocked_manager = MagicMock()
519 mocked_import_wizard = MagicMock()520 mocked_import_wizard = MagicMock()
520 importer = OSISBible(mocked_manager, path='.', name='.', filename='')521 importer = OSISBible(mocked_manager, path='.', name='.', file_path=None)
521 importer.wizard = mocked_import_wizard522 importer.wizard = mocked_import_wizard
522 importer.get_book_ref_id_by_name = MagicMock()523 importer.get_book_ref_id_by_name = MagicMock()
523 importer.create_verse = MagicMock()524 importer.create_verse = MagicMock()
@@ -527,7 +528,7 @@
527 importer.get_language.return_value = 'Danish'528 importer.get_language.return_value = 'Danish'
528529
529 # WHEN: Importing bible file530 # WHEN: Importing bible file
530 importer.filename = os.path.join(TEST_PATH, bible_file)531 importer.file_path = Path(TEST_PATH, bible_file)
531 importer.do_import()532 importer.do_import()
532533
533 # THEN: The create_verse() method should have been called with each verse in the file.534 # THEN: The create_verse() method should have been called with each verse in the file.
534535
=== modified file 'tests/functional/openlp_plugins/bibles/test_swordimport.py'
--- tests/functional/openlp_plugins/bibles/test_swordimport.py 2017-04-24 05:17:55 +0000
+++ tests/functional/openlp_plugins/bibles/test_swordimport.py 2017-11-14 23:03:10 +0000
@@ -64,7 +64,7 @@
64 mocked_manager = MagicMock()64 mocked_manager = MagicMock()
6565
66 # WHEN: An importer object is created66 # WHEN: An importer object is created
67 importer = SwordBible(mocked_manager, path='.', name='.', filename='', sword_key='', sword_path='')67 importer = SwordBible(mocked_manager, path='.', name='.', file_path=None, sword_key='', sword_path='')
6868
69 # THEN: The importer should be an instance of BibleDB69 # THEN: The importer should be an instance of BibleDB
70 self.assertIsInstance(importer, BibleDB)70 self.assertIsInstance(importer, BibleDB)
@@ -80,7 +80,7 @@
80 # Also mocked pysword structures80 # Also mocked pysword structures
81 mocked_manager = MagicMock()81 mocked_manager = MagicMock()
82 mocked_import_wizard = MagicMock()82 mocked_import_wizard = MagicMock()
83 importer = SwordBible(mocked_manager, path='.', name='.', filename='', sword_key='', sword_path='')83 importer = SwordBible(mocked_manager, path='.', name='.', file_path=None, sword_key='', sword_path='')
84 result_file = open(os.path.join(TEST_PATH, 'dk1933.json'), 'rb')84 result_file = open(os.path.join(TEST_PATH, 'dk1933.json'), 'rb')
85 test_data = json.loads(result_file.read().decode())85 test_data = json.loads(result_file.read().decode())
86 importer.wizard = mocked_import_wizard86 importer.wizard = mocked_import_wizard
8787
=== modified file 'tests/functional/openlp_plugins/bibles/test_wordprojectimport.py'
--- tests/functional/openlp_plugins/bibles/test_wordprojectimport.py 2017-04-24 05:17:55 +0000
+++ tests/functional/openlp_plugins/bibles/test_wordprojectimport.py 2017-11-14 23:03:10 +0000
@@ -26,6 +26,7 @@
26from unittest import TestCase26from unittest import TestCase
27from unittest.mock import MagicMock, patch, call27from unittest.mock import MagicMock, patch, call
2828
29from openlp.core.common.path import Path
29from openlp.plugins.bibles.lib.importers.wordproject import WordProjectBible30from openlp.plugins.bibles.lib.importers.wordproject import WordProjectBible
3031
3132
@@ -48,19 +49,17 @@
48 self.addCleanup(self.manager_patcher.stop)49 self.addCleanup(self.manager_patcher.stop)
49 self.manager_patcher.start()50 self.manager_patcher.start()
5051
51 @patch('openlp.plugins.bibles.lib.importers.wordproject.os')52 @patch.object(Path, 'read_text')
52 @patch('openlp.plugins.bibles.lib.importers.wordproject.copen')53 def test_process_books(self, mocked_read_text):
53 def test_process_books(self, mocked_open, mocked_os):
54 """54 """
55 Test the process_books() method55 Test the process_books() method
56 """56 """
57 # GIVEN: A WordProject importer and a bunch of mocked things57 # GIVEN: A WordProject importer and a bunch of mocked things
58 importer = WordProjectBible(MagicMock(), path='.', name='.', filename='kj.zip')58 importer = WordProjectBible(MagicMock(), path='.', name='.', file_path=Path('kj.zip'))
59 importer.base_dir = ''59 importer.base_path = Path()
60 importer.stop_import_flag = False60 importer.stop_import_flag = False
61 importer.language_id = 'en'61 importer.language_id = 'en'
62 mocked_open.return_value.__enter__.return_value.read.return_value = INDEX_PAGE62 mocked_read_text.return_value = INDEX_PAGE
63 mocked_os.path.join.side_effect = lambda *x: ''.join(x)
6463
65 # WHEN: process_books() is called64 # WHEN: process_books() is called
66 with patch.object(importer, 'find_and_create_book') as mocked_find_and_create_book, \65 with patch.object(importer, 'find_and_create_book') as mocked_find_and_create_book, \
@@ -69,26 +68,22 @@
69 importer.process_books()68 importer.process_books()
7069
71 # THEN: The right methods should have been called70 # THEN: The right methods should have been called
72 mocked_os.path.join.assert_called_once_with('', 'index.htm')71 mocked_read_text.assert_called_once_with(encoding='utf-8', errors='ignore')
73 mocked_open.assert_called_once_with('index.htm', encoding='utf-8', errors='ignore')
74 assert mocked_find_and_create_book.call_count == 66, 'There should be 66 books'72 assert mocked_find_and_create_book.call_count == 66, 'There should be 66 books'
75 assert mocked_process_chapters.call_count == 66, 'There should be 66 books'73 assert mocked_process_chapters.call_count == 66, 'There should be 66 books'
76 assert mocked_session.commit.call_count == 66, 'There should be 66 books'74 assert mocked_session.commit.call_count == 66, 'There should be 66 books'
7775
78 @patch('openlp.plugins.bibles.lib.importers.wordproject.os')76 @patch.object(Path, 'read_text')
79 @patch('openlp.plugins.bibles.lib.importers.wordproject.copen')77 def test_process_chapters(self, mocked_read_text):
80 def test_process_chapters(self, mocked_open, mocked_os):
81 """78 """
82 Test the process_chapters() method79 Test the process_chapters() method
83 """80 """
84 # GIVEN: A WordProject importer and a bunch of mocked things81 # GIVEN: A WordProject importer and a bunch of mocked things
85 importer = WordProjectBible(MagicMock(), path='.', name='.', filename='kj.zip')82 importer = WordProjectBible(MagicMock(), path='.', name='.', file_path=Path('kj.zip'))
86 importer.base_dir = ''83 importer.base_path = Path()
87 importer.stop_import_flag = False84 importer.stop_import_flag = False
88 importer.language_id = 'en'85 importer.language_id = 'en'
89 mocked_open.return_value.__enter__.return_value.read.return_value = CHAPTER_PAGE86 mocked_read_text.return_value = CHAPTER_PAGE
90 mocked_os.path.join.side_effect = lambda *x: ''.join(x)
91 mocked_os.path.normpath.side_effect = lambda x: x
92 mocked_db_book = MagicMock()87 mocked_db_book = MagicMock()
93 mocked_db_book.name = 'Genesis'88 mocked_db_book.name = 'Genesis'
94 book_id = 189 book_id = 1
@@ -102,24 +97,21 @@
102 # THEN: The right methods should have been called97 # THEN: The right methods should have been called
103 expected_set_current_chapter_calls = [call('Genesis', ch) for ch in range(1, 51)]98 expected_set_current_chapter_calls = [call('Genesis', ch) for ch in range(1, 51)]
104 expected_process_verses_calls = [call(mocked_db_book, 1, ch) for ch in range(1, 51)]99 expected_process_verses_calls = [call(mocked_db_book, 1, ch) for ch in range(1, 51)]
105 mocked_os.path.join.assert_called_once_with('', '01/1.htm')100 mocked_read_text.assert_called_once_with(encoding='utf-8', errors='ignore')
106 mocked_open.assert_called_once_with('01/1.htm', encoding='utf-8', errors='ignore')
107 assert mocked_set_current_chapter.call_args_list == expected_set_current_chapter_calls101 assert mocked_set_current_chapter.call_args_list == expected_set_current_chapter_calls
108 assert mocked_process_verses.call_args_list == expected_process_verses_calls102 assert mocked_process_verses.call_args_list == expected_process_verses_calls
109103
110 @patch('openlp.plugins.bibles.lib.importers.wordproject.os')104 @patch.object(Path, 'read_text')
111 @patch('openlp.plugins.bibles.lib.importers.wordproject.copen')105 def test_process_verses(self, mocked_read_text):
112 def test_process_verses(self, mocked_open, mocked_os):
113 """106 """
114 Test the process_verses() method107 Test the process_verses() method
115 """108 """
116 # GIVEN: A WordProject importer and a bunch of mocked things109 # GIVEN: A WordProject importer and a bunch of mocked things
117 importer = WordProjectBible(MagicMock(), path='.', name='.', filename='kj.zip')110 importer = WordProjectBible(MagicMock(), path='.', name='.', file_path=Path('kj.zip'))
118 importer.base_dir = ''111 importer.base_path = Path()
119 importer.stop_import_flag = False112 importer.stop_import_flag = False
120 importer.language_id = 'en'113 importer.language_id = 'en'
121 mocked_open.return_value.__enter__.return_value.read.return_value = CHAPTER_PAGE114 mocked_read_text.return_value = CHAPTER_PAGE
122 mocked_os.path.join.side_effect = lambda *x: '/'.join(x)
123 mocked_db_book = MagicMock()115 mocked_db_book = MagicMock()
124 mocked_db_book.name = 'Genesis'116 mocked_db_book.name = 'Genesis'
125 book_number = 1117 book_number = 1
@@ -130,8 +122,7 @@
130 importer.process_verses(mocked_db_book, book_number, chapter_number)122 importer.process_verses(mocked_db_book, book_number, chapter_number)
131123
132 # THEN: All the right methods should have been called124 # THEN: All the right methods should have been called
133 mocked_os.path.join.assert_called_once_with('', '01', '1.htm')125 mocked_read_text.assert_called_once_with(encoding='utf-8', errors='ignore')
134 mocked_open.assert_called_once_with('/01/1.htm', encoding='utf-8', errors='ignore')
135 assert mocked_process_verse.call_count == 31126 assert mocked_process_verse.call_count == 31
136127
137 def test_process_verse(self):128 def test_process_verse(self):
@@ -139,7 +130,7 @@
139 Test the process_verse() method130 Test the process_verse() method
140 """131 """
141 # GIVEN: An importer and a mocked method132 # GIVEN: An importer and a mocked method
142 importer = WordProjectBible(MagicMock(), path='.', name='.', filename='kj.zip')133 importer = WordProjectBible(MagicMock(), path='.', name='.', file_path=Path('kj.zip'))
143 mocked_db_book = MagicMock()134 mocked_db_book = MagicMock()
144 mocked_db_book.id = 1135 mocked_db_book.id = 1
145 chapter_number = 1136 chapter_number = 1
@@ -158,7 +149,7 @@
158 Test the process_verse() method when there's no text149 Test the process_verse() method when there's no text
159 """150 """
160 # GIVEN: An importer and a mocked method151 # GIVEN: An importer and a mocked method
161 importer = WordProjectBible(MagicMock(), path='.', name='.', filename='kj.zip')152 importer = WordProjectBible(MagicMock(), path='.', name='.', file_path=Path('kj.zip'))
162 mocked_db_book = MagicMock()153 mocked_db_book = MagicMock()
163 mocked_db_book.id = 1154 mocked_db_book.id = 1
164 chapter_number = 1155 chapter_number = 1
@@ -177,7 +168,7 @@
177 Test the do_import() method168 Test the do_import() method
178 """169 """
179 # GIVEN: An importer and mocked methods170 # GIVEN: An importer and mocked methods
180 importer = WordProjectBible(MagicMock(), path='.', name='.', filename='kj.zip')171 importer = WordProjectBible(MagicMock(), path='.', name='.', file_path='kj.zip')
181172
182 # WHEN: do_import() is called173 # WHEN: do_import() is called
183 with patch.object(importer, '_unzip_file') as mocked_unzip_file, \174 with patch.object(importer, '_unzip_file') as mocked_unzip_file, \
@@ -199,7 +190,7 @@
199 Test the do_import() method when the language is not available190 Test the do_import() method when the language is not available
200 """191 """
201 # GIVEN: An importer and mocked methods192 # GIVEN: An importer and mocked methods
202 importer = WordProjectBible(MagicMock(), path='.', name='.', filename='kj.zip')193 importer = WordProjectBible(MagicMock(), path='.', name='.', file_path='kj.zip')
203194
204 # WHEN: do_import() is called195 # WHEN: do_import() is called
205 with patch.object(importer, '_unzip_file') as mocked_unzip_file, \196 with patch.object(importer, '_unzip_file') as mocked_unzip_file, \
206197
=== modified file 'tests/functional/openlp_plugins/bibles/test_zefaniaimport.py'
--- tests/functional/openlp_plugins/bibles/test_zefaniaimport.py 2017-04-24 05:17:55 +0000
+++ tests/functional/openlp_plugins/bibles/test_zefaniaimport.py 2017-11-14 23:03:10 +0000
@@ -27,6 +27,7 @@
27from unittest import TestCase27from unittest import TestCase
28from unittest.mock import MagicMock, patch28from unittest.mock import MagicMock, patch
2929
30from openlp.core.common.path import Path
30from openlp.plugins.bibles.lib.importers.zefania import ZefaniaBible31from openlp.plugins.bibles.lib.importers.zefania import ZefaniaBible
31from openlp.plugins.bibles.lib.db import BibleDB32from openlp.plugins.bibles.lib.db import BibleDB
3233
@@ -55,7 +56,7 @@
55 mocked_manager = MagicMock()56 mocked_manager = MagicMock()
5657
57 # WHEN: An importer object is created58 # WHEN: An importer object is created
58 importer = ZefaniaBible(mocked_manager, path='.', name='.', filename='')59 importer = ZefaniaBible(mocked_manager, path='.', name='.', file_path=None)
5960
60 # THEN: The importer should be an instance of BibleDB61 # THEN: The importer should be an instance of BibleDB
61 self.assertIsInstance(importer, BibleDB)62 self.assertIsInstance(importer, BibleDB)
@@ -72,7 +73,7 @@
72 with patch('openlp.plugins.bibles.lib.importers.zefania.ZefaniaBible.application'):73 with patch('openlp.plugins.bibles.lib.importers.zefania.ZefaniaBible.application'):
73 mocked_manager = MagicMock()74 mocked_manager = MagicMock()
74 mocked_import_wizard = MagicMock()75 mocked_import_wizard = MagicMock()
75 importer = ZefaniaBible(mocked_manager, path='.', name='.', filename='')76 importer = ZefaniaBible(mocked_manager, path='.', name='.', file_path=None)
76 importer.wizard = mocked_import_wizard77 importer.wizard = mocked_import_wizard
77 importer.create_verse = MagicMock()78 importer.create_verse = MagicMock()
78 importer.create_book = MagicMock()79 importer.create_book = MagicMock()
@@ -81,7 +82,7 @@
81 importer.get_language.return_value = 'Danish'82 importer.get_language.return_value = 'Danish'
8283
83 # WHEN: Importing bible file84 # WHEN: Importing bible file
84 importer.filename = os.path.join(TEST_PATH, bible_file)85 importer.file_path = Path(TEST_PATH, bible_file)
85 importer.do_import()86 importer.do_import()
8687
87 # THEN: The create_verse() method should have been called with each verse in the file.88 # THEN: The create_verse() method should have been called with each verse in the file.
@@ -102,7 +103,7 @@
102 with patch('openlp.plugins.bibles.lib.importers.zefania.ZefaniaBible.application'):103 with patch('openlp.plugins.bibles.lib.importers.zefania.ZefaniaBible.application'):
103 mocked_manager = MagicMock()104 mocked_manager = MagicMock()
104 mocked_import_wizard = MagicMock()105 mocked_import_wizard = MagicMock()
105 importer = ZefaniaBible(mocked_manager, path='.', name='.', filename='')106 importer = ZefaniaBible(mocked_manager, path='.', name='.', file_path=None)
106 importer.wizard = mocked_import_wizard107 importer.wizard = mocked_import_wizard
107 importer.create_verse = MagicMock()108 importer.create_verse = MagicMock()
108 importer.create_book = MagicMock()109 importer.create_book = MagicMock()
@@ -111,7 +112,7 @@
111 importer.get_language.return_value = 'Russian'112 importer.get_language.return_value = 'Russian'
112113
113 # WHEN: Importing bible file114 # WHEN: Importing bible file
114 importer.filename = os.path.join(TEST_PATH, bible_file)115 importer.file_path = Path(TEST_PATH, bible_file)
115 importer.do_import()116 importer.do_import()
116117
117 # THEN: The create_verse() method should have been called with each verse in the file.118 # THEN: The create_verse() method should have been called with each verse in the file.