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 |
Related bugs: |
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.
Commit message
Description of the change
Add this to your merge proposal:
-------
lp:~phill-ridout/openlp/pathlib9 (revision 2783)
https:/
[RUNNING]
[SUCCESS]
https:/
[RUNNING]
[SUCCESS]
https:/
[RUNNING]
[SUCCESS]
https:/
[RUNNING]
[SUCCESS]
https:/
[RUNNING]
[SUCCESS]
https:/
[RUNNING]
[SUCCESS]
https:/
[RUNNING]
[FAILURE]
Stopping after failure, see https:/
Phill (phill-ridout) wrote : Posted in a previous version of this proposal | # |
Tim Bentley (trb143) wrote : Posted in a previous version of this proposal | # |
Looks good but subject answers from superfly.
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.
Raoul Snyman (raoul-snyman) : | # |
Tim Bentley (trb143) : | # |
Preview Diff
1 | === modified file 'openlp/plugins/bibles/forms/bibleimportform.py' | |||
2 | --- openlp/plugins/bibles/forms/bibleimportform.py 2017-10-23 22:09:57 +0000 | |||
3 | +++ openlp/plugins/bibles/forms/bibleimportform.py 2017-11-14 23:03:10 +0000 | |||
4 | @@ -23,7 +23,6 @@ | |||
5 | 23 | The bible import functions for OpenLP | 23 | The bible import functions for OpenLP |
6 | 24 | """ | 24 | """ |
7 | 25 | import logging | 25 | import logging |
8 | 26 | import os | ||
9 | 27 | import urllib.error | 26 | import urllib.error |
10 | 28 | from lxml import etree | 27 | from lxml import etree |
11 | 29 | 28 | ||
12 | @@ -41,6 +40,7 @@ | |||
13 | 41 | from openlp.core.lib.db import delete_database | 40 | from openlp.core.lib.db import delete_database |
14 | 42 | from openlp.core.lib.exceptions import ValidationError | 41 | from openlp.core.lib.exceptions import ValidationError |
15 | 43 | from openlp.core.lib.ui import critical_error_message_box | 42 | from openlp.core.lib.ui import critical_error_message_box |
16 | 43 | from openlp.core.widgets.edits import PathEdit | ||
17 | 44 | from openlp.core.widgets.wizard import OpenLPWizard, WizardStrings | 44 | from openlp.core.widgets.wizard import OpenLPWizard, WizardStrings |
18 | 45 | from openlp.plugins.bibles.lib.db import clean_filename | 45 | from openlp.plugins.bibles.lib.db import clean_filename |
19 | 46 | from openlp.plugins.bibles.lib.importers.http import CWExtract, BGExtract, BSExtract | 46 | from openlp.plugins.bibles.lib.importers.http import CWExtract, BGExtract, BSExtract |
20 | @@ -122,15 +122,9 @@ | |||
21 | 122 | Set up the signals used in the bible importer. | 122 | Set up the signals used in the bible importer. |
22 | 123 | """ | 123 | """ |
23 | 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) |
24 | 125 | self.osis_browse_button.clicked.connect(self.on_osis_browse_button_clicked) | ||
25 | 126 | self.csv_books_button.clicked.connect(self.on_csv_books_browse_button_clicked) | ||
26 | 127 | self.csv_verses_button.clicked.connect(self.on_csv_verses_browse_button_clicked) | ||
27 | 128 | self.open_song_browse_button.clicked.connect(self.on_open_song_browse_button_clicked) | ||
28 | 129 | self.zefania_browse_button.clicked.connect(self.on_zefania_browse_button_clicked) | ||
29 | 130 | self.wordproject_browse_button.clicked.connect(self.on_wordproject_browse_button_clicked) | ||
30 | 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) |
33 | 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) |
34 | 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) |
35 | 134 | 128 | ||
36 | 135 | def add_custom_pages(self): | 129 | def add_custom_pages(self): |
37 | 136 | """ | 130 | """ |
38 | @@ -161,17 +155,12 @@ | |||
39 | 161 | self.osis_layout.setObjectName('OsisLayout') | 155 | self.osis_layout.setObjectName('OsisLayout') |
40 | 162 | self.osis_file_label = QtWidgets.QLabel(self.osis_widget) | 156 | self.osis_file_label = QtWidgets.QLabel(self.osis_widget) |
41 | 163 | self.osis_file_label.setObjectName('OsisFileLabel') | 157 | self.osis_file_label.setObjectName('OsisFileLabel') |
53 | 164 | self.osis_file_layout = QtWidgets.QHBoxLayout() | 158 | self.osis_path_edit = PathEdit( |
54 | 165 | self.osis_file_layout.setObjectName('OsisFileLayout') | 159 | self.osis_widget, |
55 | 166 | self.osis_file_edit = QtWidgets.QLineEdit(self.osis_widget) | 160 | default_path=Settings().value('bibles/last directory import'), |
56 | 167 | self.osis_file_edit.setSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Preferred) | 161 | dialog_caption=WizardStrings.OpenTypeFile.format(file_type=WizardStrings.OSIS), |
57 | 168 | self.osis_file_edit.setObjectName('OsisFileEdit') | 162 | show_revert=False) |
58 | 169 | self.osis_file_layout.addWidget(self.osis_file_edit) | 163 | self.osis_layout.addRow(self.osis_file_label, self.osis_path_edit) |
48 | 170 | self.osis_browse_button = QtWidgets.QToolButton(self.osis_widget) | ||
49 | 171 | self.osis_browse_button.setIcon(self.open_icon) | ||
50 | 172 | self.osis_browse_button.setObjectName('OsisBrowseButton') | ||
51 | 173 | self.osis_file_layout.addWidget(self.osis_browse_button) | ||
52 | 174 | self.osis_layout.addRow(self.osis_file_label, self.osis_file_layout) | ||
59 | 175 | self.osis_layout.setItem(1, QtWidgets.QFormLayout.LabelRole, self.spacer) | 164 | self.osis_layout.setItem(1, QtWidgets.QFormLayout.LabelRole, self.spacer) |
60 | 176 | self.select_stack.addWidget(self.osis_widget) | 165 | self.select_stack.addWidget(self.osis_widget) |
61 | 177 | self.csv_widget = QtWidgets.QWidget(self.select_page) | 166 | self.csv_widget = QtWidgets.QWidget(self.select_page) |
62 | @@ -181,30 +170,27 @@ | |||
63 | 181 | self.csv_layout.setObjectName('CsvLayout') | 170 | self.csv_layout.setObjectName('CsvLayout') |
64 | 182 | self.csv_books_label = QtWidgets.QLabel(self.csv_widget) | 171 | self.csv_books_label = QtWidgets.QLabel(self.csv_widget) |
65 | 183 | self.csv_books_label.setObjectName('CsvBooksLabel') | 172 | self.csv_books_label.setObjectName('CsvBooksLabel') |
77 | 184 | self.csv_books_layout = QtWidgets.QHBoxLayout() | 173 | self.csv_books_path_edit = PathEdit( |
78 | 185 | self.csv_books_layout.setObjectName('CsvBooksLayout') | 174 | self.csv_widget, |
79 | 186 | self.csv_books_edit = QtWidgets.QLineEdit(self.csv_widget) | 175 | default_path=Settings().value('bibles/last directory import'), |
80 | 187 | self.csv_books_edit.setSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Preferred) | 176 | dialog_caption=WizardStrings.OpenTypeFile.format(file_type=WizardStrings.CSV), |
81 | 188 | self.csv_books_edit.setObjectName('CsvBooksEdit') | 177 | show_revert=False, |
82 | 189 | self.csv_books_layout.addWidget(self.csv_books_edit) | 178 | ) |
83 | 190 | self.csv_books_button = QtWidgets.QToolButton(self.csv_widget) | 179 | self.csv_books_path_edit.filters = \ |
84 | 191 | self.csv_books_button.setIcon(self.open_icon) | 180 | '{name} (*.csv)'.format(name=translate('BiblesPlugin.ImportWizardForm', 'CSV File')) |
85 | 192 | self.csv_books_button.setObjectName('CsvBooksButton') | 181 | self.csv_layout.addRow(self.csv_books_label, self.csv_books_path_edit) |
75 | 193 | self.csv_books_layout.addWidget(self.csv_books_button) | ||
76 | 194 | self.csv_layout.addRow(self.csv_books_label, self.csv_books_layout) | ||
86 | 195 | self.csv_verses_label = QtWidgets.QLabel(self.csv_widget) | 182 | self.csv_verses_label = QtWidgets.QLabel(self.csv_widget) |
87 | 196 | self.csv_verses_label.setObjectName('CsvVersesLabel') | 183 | self.csv_verses_label.setObjectName('CsvVersesLabel') |
99 | 197 | self.csv_verses_layout = QtWidgets.QHBoxLayout() | 184 | self.csv_verses_path_edit = PathEdit( |
100 | 198 | self.csv_verses_layout.setObjectName('CsvVersesLayout') | 185 | self.csv_widget, |
101 | 199 | self.csv_verses_edit = QtWidgets.QLineEdit(self.csv_widget) | 186 | default_path=Settings().value('bibles/last directory import'), |
102 | 200 | self.csv_verses_edit.setSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Preferred) | 187 | dialog_caption=WizardStrings.OpenTypeFile.format(file_type=WizardStrings.CSV), |
103 | 201 | self.csv_verses_edit.setObjectName('CsvVersesEdit') | 188 | show_revert=False, |
104 | 202 | self.csv_verses_layout.addWidget(self.csv_verses_edit) | 189 | ) |
105 | 203 | self.csv_verses_button = QtWidgets.QToolButton(self.csv_widget) | 190 | self.csv_verses_path_edit.filters = \ |
106 | 204 | self.csv_verses_button.setIcon(self.open_icon) | 191 | '{name} (*.csv)'.format(name=translate('BiblesPlugin.ImportWizardForm', 'CSV File')) |
107 | 205 | self.csv_verses_button.setObjectName('CsvVersesButton') | 192 | self.csv_layout.addRow(self.csv_books_label, self.csv_books_path_edit) |
108 | 206 | self.csv_verses_layout.addWidget(self.csv_verses_button) | 193 | self.csv_layout.addRow(self.csv_verses_label, self.csv_verses_path_edit) |
98 | 207 | self.csv_layout.addRow(self.csv_verses_label, self.csv_verses_layout) | ||
109 | 208 | self.csv_layout.setItem(3, QtWidgets.QFormLayout.LabelRole, self.spacer) | 194 | self.csv_layout.setItem(3, QtWidgets.QFormLayout.LabelRole, self.spacer) |
110 | 209 | self.select_stack.addWidget(self.csv_widget) | 195 | self.select_stack.addWidget(self.csv_widget) |
111 | 210 | self.open_song_widget = QtWidgets.QWidget(self.select_page) | 196 | self.open_song_widget = QtWidgets.QWidget(self.select_page) |
112 | @@ -214,17 +200,13 @@ | |||
113 | 214 | self.open_song_layout.setObjectName('OpenSongLayout') | 200 | self.open_song_layout.setObjectName('OpenSongLayout') |
114 | 215 | self.open_song_file_label = QtWidgets.QLabel(self.open_song_widget) | 201 | self.open_song_file_label = QtWidgets.QLabel(self.open_song_widget) |
115 | 216 | self.open_song_file_label.setObjectName('OpenSongFileLabel') | 202 | self.open_song_file_label.setObjectName('OpenSongFileLabel') |
127 | 217 | self.open_song_file_layout = QtWidgets.QHBoxLayout() | 203 | self.open_song_path_edit = PathEdit( |
128 | 218 | self.open_song_file_layout.setObjectName('OpenSongFileLayout') | 204 | self.open_song_widget, |
129 | 219 | self.open_song_file_edit = QtWidgets.QLineEdit(self.open_song_widget) | 205 | default_path=Settings().value('bibles/last directory import'), |
130 | 220 | self.open_song_file_edit.setSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Preferred) | 206 | dialog_caption=WizardStrings.OpenTypeFile.format(file_type=WizardStrings.OS), |
131 | 221 | self.open_song_file_edit.setObjectName('OpenSongFileEdit') | 207 | show_revert=False, |
132 | 222 | self.open_song_file_layout.addWidget(self.open_song_file_edit) | 208 | ) |
133 | 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) |
123 | 224 | self.open_song_browse_button.setIcon(self.open_icon) | ||
124 | 225 | self.open_song_browse_button.setObjectName('OpenSongBrowseButton') | ||
125 | 226 | self.open_song_file_layout.addWidget(self.open_song_browse_button) | ||
126 | 227 | self.open_song_layout.addRow(self.open_song_file_label, self.open_song_file_layout) | ||
134 | 228 | self.open_song_layout.setItem(1, QtWidgets.QFormLayout.LabelRole, self.spacer) | 210 | self.open_song_layout.setItem(1, QtWidgets.QFormLayout.LabelRole, self.spacer) |
135 | 229 | self.select_stack.addWidget(self.open_song_widget) | 211 | self.select_stack.addWidget(self.open_song_widget) |
136 | 230 | self.web_tab_widget = QtWidgets.QTabWidget(self.select_page) | 212 | self.web_tab_widget = QtWidgets.QTabWidget(self.select_page) |
137 | @@ -292,17 +274,14 @@ | |||
138 | 292 | self.zefania_layout.setObjectName('ZefaniaLayout') | 274 | self.zefania_layout.setObjectName('ZefaniaLayout') |
139 | 293 | self.zefania_file_label = QtWidgets.QLabel(self.zefania_widget) | 275 | self.zefania_file_label = QtWidgets.QLabel(self.zefania_widget) |
140 | 294 | self.zefania_file_label.setObjectName('ZefaniaFileLabel') | 276 | self.zefania_file_label.setObjectName('ZefaniaFileLabel') |
152 | 295 | self.zefania_file_layout = QtWidgets.QHBoxLayout() | 277 | self.zefania_path_edit = PathEdit( |
153 | 296 | self.zefania_file_layout.setObjectName('ZefaniaFileLayout') | 278 | self.zefania_widget, |
154 | 297 | self.zefania_file_edit = QtWidgets.QLineEdit(self.zefania_widget) | 279 | default_path=Settings().value('bibles/last directory import'), |
155 | 298 | self.zefania_file_edit.setObjectName('ZefaniaFileEdit') | 280 | dialog_caption=WizardStrings.OpenTypeFile.format(file_type=WizardStrings.ZEF), |
156 | 299 | self.zefania_file_layout.addWidget(self.zefania_file_edit) | 281 | show_revert=False, |
157 | 300 | self.zefania_browse_button = QtWidgets.QToolButton(self.zefania_widget) | 282 | ) |
158 | 301 | self.zefania_browse_button.setIcon(self.open_icon) | 283 | self.zefania_layout.addRow(self.zefania_file_label, self.zefania_path_edit) |
159 | 302 | self.zefania_browse_button.setObjectName('ZefaniaBrowseButton') | 284 | self.zefania_layout.setItem(2, QtWidgets.QFormLayout.LabelRole, self.spacer) |
149 | 303 | self.zefania_file_layout.addWidget(self.zefania_browse_button) | ||
150 | 304 | self.zefania_layout.addRow(self.zefania_file_label, self.zefania_file_layout) | ||
151 | 305 | self.zefania_layout.setItem(5, QtWidgets.QFormLayout.LabelRole, self.spacer) | ||
160 | 306 | self.select_stack.addWidget(self.zefania_widget) | 285 | self.select_stack.addWidget(self.zefania_widget) |
161 | 307 | self.sword_widget = QtWidgets.QWidget(self.select_page) | 286 | self.sword_widget = QtWidgets.QWidget(self.select_page) |
162 | 308 | self.sword_widget.setObjectName('SwordWidget') | 287 | self.sword_widget.setObjectName('SwordWidget') |
163 | @@ -318,16 +297,13 @@ | |||
164 | 318 | self.sword_folder_label = QtWidgets.QLabel(self.sword_folder_tab) | 297 | self.sword_folder_label = QtWidgets.QLabel(self.sword_folder_tab) |
165 | 319 | self.sword_folder_label.setObjectName('SwordSourceLabel') | 298 | self.sword_folder_label.setObjectName('SwordSourceLabel') |
166 | 320 | self.sword_folder_label.setObjectName('SwordFolderLabel') | 299 | self.sword_folder_label.setObjectName('SwordFolderLabel') |
177 | 321 | self.sword_folder_edit = QtWidgets.QLineEdit(self.sword_folder_tab) | 300 | self.sword_folder_path_edit = PathEdit( |
178 | 322 | self.sword_folder_edit.setSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Preferred) | 301 | self.sword_folder_tab, |
179 | 323 | self.sword_folder_edit.setObjectName('SwordFolderEdit') | 302 | default_path=Settings().value('bibles/last directory import'), |
180 | 324 | self.sword_browse_button = QtWidgets.QToolButton(self.sword_folder_tab) | 303 | dialog_caption=WizardStrings.OpenTypeFile.format(file_type=WizardStrings.SWORD), |
181 | 325 | self.sword_browse_button.setIcon(self.open_icon) | 304 | show_revert=False, |
182 | 326 | self.sword_browse_button.setObjectName('SwordBrowseButton') | 305 | ) |
183 | 327 | self.sword_folder_layout = QtWidgets.QHBoxLayout() | 306 | self.sword_folder_tab_layout.addRow(self.sword_folder_label, self.sword_folder_path_edit) |
174 | 328 | self.sword_folder_layout.addWidget(self.sword_folder_edit) | ||
175 | 329 | self.sword_folder_layout.addWidget(self.sword_browse_button) | ||
176 | 330 | self.sword_folder_tab_layout.addRow(self.sword_folder_label, self.sword_folder_layout) | ||
184 | 331 | self.sword_bible_label = QtWidgets.QLabel(self.sword_folder_tab) | 307 | self.sword_bible_label = QtWidgets.QLabel(self.sword_folder_tab) |
185 | 332 | self.sword_bible_label.setObjectName('SwordBibleLabel') | 308 | self.sword_bible_label.setObjectName('SwordBibleLabel') |
186 | 333 | self.sword_bible_combo_box = QtWidgets.QComboBox(self.sword_folder_tab) | 309 | self.sword_bible_combo_box = QtWidgets.QComboBox(self.sword_folder_tab) |
187 | @@ -342,16 +318,13 @@ | |||
188 | 342 | self.sword_zip_layout.setObjectName('SwordZipLayout') | 318 | self.sword_zip_layout.setObjectName('SwordZipLayout') |
189 | 343 | self.sword_zipfile_label = QtWidgets.QLabel(self.sword_zip_tab) | 319 | self.sword_zipfile_label = QtWidgets.QLabel(self.sword_zip_tab) |
190 | 344 | self.sword_zipfile_label.setObjectName('SwordZipFileLabel') | 320 | self.sword_zipfile_label.setObjectName('SwordZipFileLabel') |
201 | 345 | self.sword_zipfile_edit = QtWidgets.QLineEdit(self.sword_zip_tab) | 321 | self.sword_zipfile_path_edit = PathEdit( |
202 | 346 | self.sword_zipfile_edit.setSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Preferred) | 322 | self.sword_zip_tab, |
203 | 347 | self.sword_zipfile_edit.setObjectName('SwordZipFileEdit') | 323 | default_path=Settings().value('bibles/last directory import'), |
204 | 348 | self.sword_zipbrowse_button = QtWidgets.QToolButton(self.sword_zip_tab) | 324 | dialog_caption=WizardStrings.OpenTypeFile.format(file_type=WizardStrings.SWORD), |
205 | 349 | self.sword_zipbrowse_button.setIcon(self.open_icon) | 325 | show_revert=False, |
206 | 350 | self.sword_zipbrowse_button.setObjectName('SwordZipBrowseButton') | 326 | ) |
207 | 351 | self.sword_zipfile_layout = QtWidgets.QHBoxLayout() | 327 | self.sword_zip_layout.addRow(self.sword_zipfile_label, self.sword_zipfile_path_edit) |
198 | 352 | self.sword_zipfile_layout.addWidget(self.sword_zipfile_edit) | ||
199 | 353 | self.sword_zipfile_layout.addWidget(self.sword_zipbrowse_button) | ||
200 | 354 | self.sword_zip_layout.addRow(self.sword_zipfile_label, self.sword_zipfile_layout) | ||
208 | 355 | self.sword_zipbible_label = QtWidgets.QLabel(self.sword_folder_tab) | 328 | self.sword_zipbible_label = QtWidgets.QLabel(self.sword_folder_tab) |
209 | 356 | self.sword_zipbible_label.setObjectName('SwordZipBibleLabel') | 329 | self.sword_zipbible_label.setObjectName('SwordZipBibleLabel') |
210 | 357 | self.sword_zipbible_combo_box = QtWidgets.QComboBox(self.sword_zip_tab) | 330 | self.sword_zipbible_combo_box = QtWidgets.QComboBox(self.sword_zip_tab) |
211 | @@ -372,18 +345,13 @@ | |||
212 | 372 | self.wordproject_layout.setObjectName('WordProjectLayout') | 345 | self.wordproject_layout.setObjectName('WordProjectLayout') |
213 | 373 | self.wordproject_file_label = QtWidgets.QLabel(self.wordproject_widget) | 346 | self.wordproject_file_label = QtWidgets.QLabel(self.wordproject_widget) |
214 | 374 | self.wordproject_file_label.setObjectName('WordProjectFileLabel') | 347 | self.wordproject_file_label.setObjectName('WordProjectFileLabel') |
227 | 375 | self.wordproject_file_layout = QtWidgets.QHBoxLayout() | 348 | self.wordproject_path_edit = PathEdit( |
228 | 376 | self.wordproject_file_layout.setObjectName('WordProjectFileLayout') | 349 | self.wordproject_widget, |
229 | 377 | self.wordproject_file_edit = QtWidgets.QLineEdit(self.wordproject_widget) | 350 | default_path=Settings().value('bibles/last directory import'), |
230 | 378 | self.wordproject_file_edit.setSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Preferred) | 351 | dialog_caption=WizardStrings.OpenTypeFile.format(file_type=WizardStrings.WordProject), |
231 | 379 | self.wordproject_file_edit.setObjectName('WordProjectFileEdit') | 352 | show_revert=False) |
232 | 380 | self.wordproject_file_layout.addWidget(self.wordproject_file_edit) | 353 | self.wordproject_layout.addRow(self.wordproject_file_label, self.wordproject_path_edit) |
233 | 381 | self.wordproject_browse_button = QtWidgets.QToolButton(self.wordproject_widget) | 354 | self.wordproject_layout.setItem(1, QtWidgets.QFormLayout.LabelRole, self.spacer) |
222 | 382 | self.wordproject_browse_button.setIcon(self.open_icon) | ||
223 | 383 | self.wordproject_browse_button.setObjectName('WordProjectBrowseButton') | ||
224 | 384 | self.wordproject_file_layout.addWidget(self.wordproject_browse_button) | ||
225 | 385 | self.wordproject_layout.addRow(self.wordproject_file_label, self.wordproject_file_layout) | ||
226 | 386 | self.wordproject_layout.setItem(5, QtWidgets.QFormLayout.LabelRole, self.spacer) | ||
234 | 387 | self.select_stack.addWidget(self.wordproject_widget) | 355 | self.select_stack.addWidget(self.wordproject_widget) |
235 | 388 | self.select_page_layout.addLayout(self.select_stack) | 356 | self.select_page_layout.addLayout(self.select_stack) |
236 | 389 | self.addPage(self.select_page) | 357 | self.addPage(self.select_page) |
237 | @@ -468,8 +436,6 @@ | |||
238 | 468 | self.sword_bible_label.setText(translate('BiblesPlugin.ImportWizardForm', 'Bibles:')) | 436 | self.sword_bible_label.setText(translate('BiblesPlugin.ImportWizardForm', 'Bibles:')) |
239 | 469 | self.sword_folder_label.setText(translate('BiblesPlugin.ImportWizardForm', 'SWORD data folder:')) | 437 | self.sword_folder_label.setText(translate('BiblesPlugin.ImportWizardForm', 'SWORD data folder:')) |
240 | 470 | self.sword_zipfile_label.setText(translate('BiblesPlugin.ImportWizardForm', 'SWORD zip-file:')) | 438 | self.sword_zipfile_label.setText(translate('BiblesPlugin.ImportWizardForm', 'SWORD zip-file:')) |
241 | 471 | self.sword_folder_edit.setPlaceholderText(translate('BiblesPlugin.ImportWizardForm', | ||
242 | 472 | 'Defaults to the standard SWORD data folder')) | ||
243 | 473 | self.sword_zipbible_label.setText(translate('BiblesPlugin.ImportWizardForm', 'Bibles:')) | 439 | self.sword_zipbible_label.setText(translate('BiblesPlugin.ImportWizardForm', 'Bibles:')) |
244 | 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), |
245 | 475 | translate('BiblesPlugin.ImportWizardForm', 'Import from folder')) | 441 | translate('BiblesPlugin.ImportWizardForm', 'Import from folder')) |
246 | @@ -518,7 +484,7 @@ | |||
247 | 518 | if self.field('source_format') == BibleFormat.OSIS: | 484 | if self.field('source_format') == BibleFormat.OSIS: |
248 | 519 | if not self.field('osis_location'): | 485 | if not self.field('osis_location'): |
249 | 520 | critical_error_message_box(UiStrings().NFSs, WizardStrings.YouSpecifyFile % WizardStrings.OSIS) | 486 | critical_error_message_box(UiStrings().NFSs, WizardStrings.YouSpecifyFile % WizardStrings.OSIS) |
251 | 521 | self.osis_file_edit.setFocus() | 487 | self.osis_path_edit.setFocus() |
252 | 522 | return False | 488 | return False |
253 | 523 | elif self.field('source_format') == BibleFormat.CSV: | 489 | elif self.field('source_format') == BibleFormat.CSV: |
254 | 524 | if not self.field('csv_booksfile'): | 490 | if not self.field('csv_booksfile'): |
255 | @@ -538,18 +504,18 @@ | |||
256 | 538 | elif self.field('source_format') == BibleFormat.OpenSong: | 504 | elif self.field('source_format') == BibleFormat.OpenSong: |
257 | 539 | if not self.field('opensong_file'): | 505 | if not self.field('opensong_file'): |
258 | 540 | critical_error_message_box(UiStrings().NFSs, WizardStrings.YouSpecifyFile % WizardStrings.OS) | 506 | critical_error_message_box(UiStrings().NFSs, WizardStrings.YouSpecifyFile % WizardStrings.OS) |
260 | 541 | self.open_song_file_edit.setFocus() | 507 | self.open_song_path_edit.setFocus() |
261 | 542 | return False | 508 | return False |
262 | 543 | elif self.field('source_format') == BibleFormat.Zefania: | 509 | elif self.field('source_format') == BibleFormat.Zefania: |
263 | 544 | if not self.field('zefania_file'): | 510 | if not self.field('zefania_file'): |
264 | 545 | critical_error_message_box(UiStrings().NFSs, WizardStrings.YouSpecifyFile % WizardStrings.ZEF) | 511 | critical_error_message_box(UiStrings().NFSs, WizardStrings.YouSpecifyFile % WizardStrings.ZEF) |
266 | 546 | self.zefania_file_edit.setFocus() | 512 | self.zefania_path_edit.setFocus() |
267 | 547 | return False | 513 | return False |
268 | 548 | elif self.field('source_format') == BibleFormat.WordProject: | 514 | elif self.field('source_format') == BibleFormat.WordProject: |
269 | 549 | if not self.field('wordproject_file'): | 515 | if not self.field('wordproject_file'): |
270 | 550 | critical_error_message_box(UiStrings().NFSs, | 516 | critical_error_message_box(UiStrings().NFSs, |
271 | 551 | WizardStrings.YouSpecifyFile % WizardStrings.WordProject) | 517 | WizardStrings.YouSpecifyFile % WizardStrings.WordProject) |
273 | 552 | self.wordproject_file_edit.setFocus() | 518 | self.wordproject_path_edit.setFocus() |
274 | 553 | return False | 519 | return False |
275 | 554 | elif self.field('source_format') == BibleFormat.WebDownload: | 520 | elif self.field('source_format') == BibleFormat.WebDownload: |
276 | 555 | # If count is 0 the bible list has not yet been downloaded | 521 | # If count is 0 the bible list has not yet been downloaded |
277 | @@ -563,7 +529,7 @@ | |||
278 | 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: |
279 | 564 | critical_error_message_box(UiStrings().NFSs, | 530 | critical_error_message_box(UiStrings().NFSs, |
280 | 565 | WizardStrings.YouSpecifyFolder % WizardStrings.SWORD) | 531 | WizardStrings.YouSpecifyFolder % WizardStrings.SWORD) |
282 | 566 | self.sword_folder_edit.setFocus() | 532 | self.sword_folder_path_edit.setFocus() |
283 | 567 | return False | 533 | return False |
284 | 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()) |
285 | 569 | if 'description' in self.pysword_folder_modules_json[key]: | 535 | if 'description' in self.pysword_folder_modules_json[key]: |
286 | @@ -575,7 +541,7 @@ | |||
287 | 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): |
288 | 576 | if not self.field('sword_zip_path'): | 542 | if not self.field('sword_zip_path'): |
289 | 577 | critical_error_message_box(UiStrings().NFSs, WizardStrings.YouSpecifyFile % WizardStrings.SWORD) | 543 | critical_error_message_box(UiStrings().NFSs, WizardStrings.YouSpecifyFile % WizardStrings.SWORD) |
291 | 578 | self.sword_zipfile_edit.setFocus() | 544 | self.sword_zipfile_path_edit.setFocus() |
292 | 579 | return False | 545 | return False |
293 | 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()) |
294 | 581 | if 'description' in self.pysword_zip_modules_json[key]: | 547 | if 'description' in self.pysword_zip_modules_json[key]: |
295 | @@ -586,7 +552,6 @@ | |||
296 | 586 | elif self.currentPage() == self.license_details_page: | 552 | elif self.currentPage() == self.license_details_page: |
297 | 587 | license_version = self.field('license_version') | 553 | license_version = self.field('license_version') |
298 | 588 | license_copyright = self.field('license_copyright') | 554 | license_copyright = self.field('license_copyright') |
299 | 589 | path = str(AppLocation.get_section_data_path('bibles')) | ||
300 | 590 | if not license_version: | 555 | if not license_version: |
301 | 591 | critical_error_message_box( | 556 | critical_error_message_box( |
302 | 592 | UiStrings().EmptyField, | 557 | UiStrings().EmptyField, |
303 | @@ -608,7 +573,7 @@ | |||
304 | 608 | 'existing one.')) | 573 | 'existing one.')) |
305 | 609 | self.version_name_edit.setFocus() | 574 | self.version_name_edit.setFocus() |
306 | 610 | return False | 575 | return False |
308 | 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(): |
309 | 612 | critical_error_message_box( | 577 | critical_error_message_box( |
310 | 613 | translate('BiblesPlugin.ImportWizardForm', 'Bible Exists'), | 578 | translate('BiblesPlugin.ImportWizardForm', 'Bible Exists'), |
311 | 614 | translate('BiblesPlugin.ImportWizardForm', 'This Bible already exists. Please import ' | 579 | translate('BiblesPlugin.ImportWizardForm', 'This Bible already exists. Please import ' |
312 | @@ -631,57 +596,6 @@ | |||
313 | 631 | bibles.sort(key=get_locale_key) | 596 | bibles.sort(key=get_locale_key) |
314 | 632 | self.web_translation_combo_box.addItems(bibles) | 597 | self.web_translation_combo_box.addItems(bibles) |
315 | 633 | 598 | ||
316 | 634 | def on_osis_browse_button_clicked(self): | ||
317 | 635 | """ | ||
318 | 636 | Show the file open dialog for the OSIS file. | ||
319 | 637 | """ | ||
320 | 638 | self.get_file_name(WizardStrings.OpenTypeFile % WizardStrings.OSIS, self.osis_file_edit, | ||
321 | 639 | 'last directory import') | ||
322 | 640 | |||
323 | 641 | def on_csv_books_browse_button_clicked(self): | ||
324 | 642 | """ | ||
325 | 643 | Show the file open dialog for the books CSV file. | ||
326 | 644 | """ | ||
327 | 645 | # TODO: Verify format() with varible template | ||
328 | 646 | self.get_file_name( | ||
329 | 647 | WizardStrings.OpenTypeFile % WizardStrings.CSV, | ||
330 | 648 | self.csv_books_edit, | ||
331 | 649 | 'last directory import', | ||
332 | 650 | '{name} (*.csv)'.format(name=translate('BiblesPlugin.ImportWizardForm', 'CSV File'))) | ||
333 | 651 | |||
334 | 652 | def on_csv_verses_browse_button_clicked(self): | ||
335 | 653 | """ | ||
336 | 654 | Show the file open dialog for the verses CSV file. | ||
337 | 655 | """ | ||
338 | 656 | # TODO: Verify format() with variable template | ||
339 | 657 | self.get_file_name(WizardStrings.OpenTypeFile % WizardStrings.CSV, self.csv_verses_edit, | ||
340 | 658 | 'last directory import', | ||
341 | 659 | '{name} (*.csv)'.format(name=translate('BiblesPlugin.ImportWizardForm', 'CSV File'))) | ||
342 | 660 | |||
343 | 661 | def on_open_song_browse_button_clicked(self): | ||
344 | 662 | """ | ||
345 | 663 | Show the file open dialog for the OpenSong file. | ||
346 | 664 | """ | ||
347 | 665 | # TODO: Verify format() with variable template | ||
348 | 666 | self.get_file_name(WizardStrings.OpenTypeFile % WizardStrings.OS, self.open_song_file_edit, | ||
349 | 667 | 'last directory import') | ||
350 | 668 | |||
351 | 669 | def on_zefania_browse_button_clicked(self): | ||
352 | 670 | """ | ||
353 | 671 | Show the file open dialog for the Zefania file. | ||
354 | 672 | """ | ||
355 | 673 | # TODO: Verify format() with variable template | ||
356 | 674 | self.get_file_name(WizardStrings.OpenTypeFile % WizardStrings.ZEF, self.zefania_file_edit, | ||
357 | 675 | 'last directory import') | ||
358 | 676 | |||
359 | 677 | def on_wordproject_browse_button_clicked(self): | ||
360 | 678 | """ | ||
361 | 679 | Show the file open dialog for the WordProject file. | ||
362 | 680 | """ | ||
363 | 681 | # TODO: Verify format() with variable template | ||
364 | 682 | self.get_file_name(WizardStrings.OpenTypeFile % WizardStrings.WordProject, self.wordproject_file_edit, | ||
365 | 683 | 'last directory import') | ||
366 | 684 | |||
367 | 685 | def on_web_update_button_clicked(self): | 599 | def on_web_update_button_clicked(self): |
368 | 686 | """ | 600 | """ |
369 | 687 | Download list of bibles from Crosswalk, BibleServer and BibleGateway. | 601 | Download list of bibles from Crosswalk, BibleServer and BibleGateway. |
370 | @@ -718,15 +632,13 @@ | |||
371 | 718 | self.web_update_button.setEnabled(True) | 632 | self.web_update_button.setEnabled(True) |
372 | 719 | self.web_progress_bar.setVisible(False) | 633 | self.web_progress_bar.setVisible(False) |
373 | 720 | 634 | ||
375 | 721 | def on_sword_browse_button_clicked(self): | 635 | def on_sword_folder_path_edit_path_changed(self, new_path): |
376 | 722 | """ | 636 | """ |
377 | 723 | Show the file open dialog for the SWORD folder. | 637 | Show the file open dialog for the SWORD folder. |
378 | 724 | """ | 638 | """ |
382 | 725 | self.get_folder(WizardStrings.OpenTypeFolder % WizardStrings.SWORD, self.sword_folder_edit, | 639 | if new_path: |
380 | 726 | 'last directory import') | ||
381 | 727 | if self.sword_folder_edit.text(): | ||
383 | 728 | try: | 640 | try: |
385 | 729 | self.pysword_folder_modules = modules.SwordModules(self.sword_folder_edit.text()) | 641 | self.pysword_folder_modules = modules.SwordModules(str(new_path)) |
386 | 730 | self.pysword_folder_modules_json = self.pysword_folder_modules.parse_modules() | 642 | self.pysword_folder_modules_json = self.pysword_folder_modules.parse_modules() |
387 | 731 | bible_keys = self.pysword_folder_modules_json.keys() | 643 | bible_keys = self.pysword_folder_modules_json.keys() |
388 | 732 | self.sword_bible_combo_box.clear() | 644 | self.sword_bible_combo_box.clear() |
389 | @@ -735,15 +647,13 @@ | |||
390 | 735 | except: | 647 | except: |
391 | 736 | self.sword_bible_combo_box.clear() | 648 | self.sword_bible_combo_box.clear() |
392 | 737 | 649 | ||
394 | 738 | def on_sword_zipbrowse_button_clicked(self): | 650 | def on_sword_zipfile_path_edit_path_changed(self, new_path): |
395 | 739 | """ | 651 | """ |
396 | 740 | Show the file open dialog for a SWORD zip-file. | 652 | Show the file open dialog for a SWORD zip-file. |
397 | 741 | """ | 653 | """ |
401 | 742 | self.get_file_name(WizardStrings.OpenTypeFile % WizardStrings.SWORD, self.sword_zipfile_edit, | 654 | if new_path: |
399 | 743 | 'last directory import') | ||
400 | 744 | if self.sword_zipfile_edit.text(): | ||
402 | 745 | try: | 655 | try: |
404 | 746 | self.pysword_zip_modules = modules.SwordModules(self.sword_zipfile_edit.text()) | 656 | self.pysword_zip_modules = modules.SwordModules(str(new_path)) |
405 | 747 | self.pysword_zip_modules_json = self.pysword_zip_modules.parse_modules() | 657 | self.pysword_zip_modules_json = self.pysword_zip_modules.parse_modules() |
406 | 748 | bible_keys = self.pysword_zip_modules_json.keys() | 658 | bible_keys = self.pysword_zip_modules_json.keys() |
407 | 749 | self.sword_zipbible_combo_box.clear() | 659 | self.sword_zipbible_combo_box.clear() |
408 | @@ -757,16 +667,16 @@ | |||
409 | 757 | Register the bible import wizard fields. | 667 | Register the bible import wizard fields. |
410 | 758 | """ | 668 | """ |
411 | 759 | self.select_page.registerField('source_format', self.format_combo_box) | 669 | self.select_page.registerField('source_format', self.format_combo_box) |
418 | 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) |
419 | 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) |
420 | 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) |
421 | 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) |
422 | 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) |
423 | 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) |
424 | 766 | self.select_page.registerField('web_location', self.web_source_combo_box) | 676 | self.select_page.registerField('web_location', self.web_source_combo_box) |
425 | 767 | self.select_page.registerField('web_biblename', self.web_translation_combo_box) | 677 | self.select_page.registerField('web_biblename', self.web_translation_combo_box) |
428 | 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) |
429 | 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) |
430 | 770 | self.select_page.registerField('proxy_server', self.web_server_edit) | 680 | self.select_page.registerField('proxy_server', self.web_server_edit) |
431 | 771 | self.select_page.registerField('proxy_username', self.web_user_edit) | 681 | self.select_page.registerField('proxy_username', self.web_user_edit) |
432 | 772 | self.select_page.registerField('proxy_password', self.web_password_edit) | 682 | self.select_page.registerField('proxy_password', self.web_password_edit) |
433 | @@ -785,13 +695,13 @@ | |||
434 | 785 | self.finish_button.setVisible(False) | 695 | self.finish_button.setVisible(False) |
435 | 786 | self.cancel_button.setVisible(True) | 696 | self.cancel_button.setVisible(True) |
436 | 787 | self.setField('source_format', 0) | 697 | self.setField('source_format', 0) |
444 | 788 | self.setField('osis_location', '') | 698 | self.setField('osis_location', None) |
445 | 789 | self.setField('csv_booksfile', '') | 699 | self.setField('csv_booksfile', None) |
446 | 790 | self.setField('csv_versefile', '') | 700 | self.setField('csv_versefile', None) |
447 | 791 | self.setField('opensong_file', '') | 701 | self.setField('opensong_file', None) |
448 | 792 | self.setField('zefania_file', '') | 702 | self.setField('zefania_file', None) |
449 | 793 | self.setField('sword_folder_path', '') | 703 | self.setField('sword_folder_path', None) |
450 | 794 | self.setField('sword_zip_path', '') | 704 | self.setField('sword_zip_path', None) |
451 | 795 | self.setField('web_location', WebDownload.Crosswalk) | 705 | self.setField('web_location', WebDownload.Crosswalk) |
452 | 796 | self.setField('web_biblename', self.web_translation_combo_box.currentIndex()) | 706 | self.setField('web_biblename', self.web_translation_combo_box.currentIndex()) |
453 | 797 | self.setField('proxy_server', settings.value('proxy address')) | 707 | self.setField('proxy_server', settings.value('proxy address')) |
454 | @@ -833,16 +743,16 @@ | |||
455 | 833 | if bible_type == BibleFormat.OSIS: | 743 | if bible_type == BibleFormat.OSIS: |
456 | 834 | # Import an OSIS bible. | 744 | # Import an OSIS bible. |
457 | 835 | importer = self.manager.import_bible(BibleFormat.OSIS, name=license_version, | 745 | importer = self.manager.import_bible(BibleFormat.OSIS, name=license_version, |
459 | 836 | filename=self.field('osis_location')) | 746 | file_path=self.field('osis_location')) |
460 | 837 | elif bible_type == BibleFormat.CSV: | 747 | elif bible_type == BibleFormat.CSV: |
461 | 838 | # Import a CSV bible. | 748 | # Import a CSV bible. |
462 | 839 | importer = self.manager.import_bible(BibleFormat.CSV, name=license_version, | 749 | importer = self.manager.import_bible(BibleFormat.CSV, name=license_version, |
465 | 840 | booksfile=self.field('csv_booksfile'), | 750 | books_path=self.field('csv_booksfile'), |
466 | 841 | versefile=self.field('csv_versefile')) | 751 | verse_path=self.field('csv_versefile')) |
467 | 842 | elif bible_type == BibleFormat.OpenSong: | 752 | elif bible_type == BibleFormat.OpenSong: |
468 | 843 | # Import an OpenSong bible. | 753 | # Import an OpenSong bible. |
469 | 844 | importer = self.manager.import_bible(BibleFormat.OpenSong, name=license_version, | 754 | importer = self.manager.import_bible(BibleFormat.OpenSong, name=license_version, |
471 | 845 | filename=self.field('opensong_file')) | 755 | file_path=self.field('opensong_file')) |
472 | 846 | elif bible_type == BibleFormat.WebDownload: | 756 | elif bible_type == BibleFormat.WebDownload: |
473 | 847 | # Import a bible from the web. | 757 | # Import a bible from the web. |
474 | 848 | self.progress_bar.setMaximum(1) | 758 | self.progress_bar.setMaximum(1) |
475 | @@ -861,11 +771,11 @@ | |||
476 | 861 | elif bible_type == BibleFormat.Zefania: | 771 | elif bible_type == BibleFormat.Zefania: |
477 | 862 | # Import a Zefania bible. | 772 | # Import a Zefania bible. |
478 | 863 | importer = self.manager.import_bible(BibleFormat.Zefania, name=license_version, | 773 | importer = self.manager.import_bible(BibleFormat.Zefania, name=license_version, |
480 | 864 | filename=self.field('zefania_file')) | 774 | file_path=self.field('zefania_file')) |
481 | 865 | elif bible_type == BibleFormat.WordProject: | 775 | elif bible_type == BibleFormat.WordProject: |
482 | 866 | # Import a WordProject bible. | 776 | # Import a WordProject bible. |
483 | 867 | importer = self.manager.import_bible(BibleFormat.WordProject, name=license_version, | 777 | importer = self.manager.import_bible(BibleFormat.WordProject, name=license_version, |
485 | 868 | filename=self.field('wordproject_file')) | 778 | file_path=self.field('wordproject_file')) |
486 | 869 | elif bible_type == BibleFormat.SWORD: | 779 | elif bible_type == BibleFormat.SWORD: |
487 | 870 | # Import a SWORD bible. | 780 | # Import a SWORD bible. |
488 | 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): |
489 | 872 | 782 | ||
490 | === modified file 'openlp/plugins/bibles/lib/bibleimport.py' | |||
491 | --- openlp/plugins/bibles/lib/bibleimport.py 2017-10-29 06:01:25 +0000 | |||
492 | +++ openlp/plugins/bibles/lib/bibleimport.py 2017-11-14 23:03:10 +0000 | |||
493 | @@ -37,23 +37,23 @@ | |||
494 | 37 | """ | 37 | """ |
495 | 38 | def __init__(self, *args, **kwargs): | 38 | def __init__(self, *args, **kwargs): |
496 | 39 | super().__init__(*args, **kwargs) | 39 | super().__init__(*args, **kwargs) |
498 | 40 | self.filename = kwargs['filename'] if 'filename' in kwargs else None | 40 | self.file_path = kwargs.get('file_path') |
499 | 41 | self.wizard = None | 41 | self.wizard = None |
500 | 42 | self.stop_import_flag = False | 42 | self.stop_import_flag = False |
501 | 43 | Registry().register_function('openlp_stop_wizard', self.stop_import) | 43 | Registry().register_function('openlp_stop_wizard', self.stop_import) |
502 | 44 | 44 | ||
503 | 45 | @staticmethod | 45 | @staticmethod |
505 | 46 | def is_compressed(file): | 46 | def is_compressed(file_path): |
506 | 47 | """ | 47 | """ |
507 | 48 | Check if the supplied file is compressed | 48 | Check if the supplied file is compressed |
508 | 49 | 49 | ||
510 | 50 | :param file: A path to the file to check | 50 | :param file_path: A path to the file to check |
511 | 51 | """ | 51 | """ |
513 | 52 | if is_zipfile(file): | 52 | if is_zipfile(str(file_path)): |
514 | 53 | critical_error_message_box( | 53 | critical_error_message_box( |
515 | 54 | message=translate('BiblesPlugin.BibleImport', | 54 | message=translate('BiblesPlugin.BibleImport', |
516 | 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.' |
518 | 56 | ).format(file=file)) | 56 | ).format(file=file_path)) |
519 | 57 | return True | 57 | return True |
520 | 58 | return False | 58 | return False |
521 | 59 | 59 | ||
522 | @@ -143,24 +143,24 @@ | |||
523 | 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') |
524 | 144 | book_ref_id = guess_id | 144 | book_ref_id = guess_id |
525 | 145 | if not book_ref_id: | 145 | if not book_ref_id: |
527 | 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)) |
528 | 147 | book_details = BiblesResourcesDB.get_book_by_id(book_ref_id) | 147 | book_details = BiblesResourcesDB.get_book_by_id(book_ref_id) |
529 | 148 | if book_details is None: | 148 | if book_details is None: |
530 | 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 ' |
532 | 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)) |
533 | 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']) |
534 | 152 | 152 | ||
536 | 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): |
537 | 154 | """ | 154 | """ |
538 | 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. |
540 | 156 | :param filename: The filename of the xml file to parse. Str | 156 | :param file_path: The filename of the xml file to parse. Str |
541 | 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) |
542 | 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. |
543 | 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. |
544 | 160 | :return: The root element of the xml document | 160 | :return: The root element of the xml document |
545 | 161 | """ | 161 | """ |
546 | 162 | try: | 162 | try: |
548 | 163 | with open(filename, 'rb') as import_file: | 163 | with file_path.open('rb') as import_file: |
549 | 164 | # NOTE: We don't need to do any of the normal encoding detection here, because lxml does it's own | 164 | # NOTE: We don't need to do any of the normal encoding detection here, because lxml does it's own |
550 | 165 | # encoding detection, and the two mechanisms together interfere with each other. | 165 | # encoding detection, and the two mechanisms together interfere with each other. |
551 | 166 | if not use_objectify: | 166 | if not use_objectify: |
552 | @@ -207,17 +207,17 @@ | |||
553 | 207 | self.log_debug('Stopping import') | 207 | self.log_debug('Stopping import') |
554 | 208 | self.stop_import_flag = True | 208 | self.stop_import_flag = True |
555 | 209 | 209 | ||
557 | 210 | def validate_xml_file(self, filename, tag): | 210 | def validate_xml_file(self, file_path, tag): |
558 | 211 | """ | 211 | """ |
559 | 212 | Validate the supplied file | 212 | Validate the supplied file |
560 | 213 | 213 | ||
562 | 214 | :param filename: The supplied file | 214 | :param file_path: The supplied file |
563 | 215 | :param tag: The expected root tag type | 215 | :param tag: The expected root tag type |
564 | 216 | :return: True if valid. ValidationError is raised otherwise. | 216 | :return: True if valid. ValidationError is raised otherwise. |
565 | 217 | """ | 217 | """ |
567 | 218 | if BibleImport.is_compressed(filename): | 218 | if BibleImport.is_compressed(file_path): |
568 | 219 | raise ValidationError(msg='Compressed file') | 219 | raise ValidationError(msg='Compressed file') |
570 | 220 | bible = self.parse_xml(filename, use_objectify=True) | 220 | bible = self.parse_xml(file_path, use_objectify=True) |
571 | 221 | if bible is None: | 221 | if bible is None: |
572 | 222 | raise ValidationError(msg='Error when opening file') | 222 | raise ValidationError(msg='Error when opening file') |
573 | 223 | root_tag = bible.tag.lower() | 223 | root_tag = bible.tag.lower() |
574 | 224 | 224 | ||
575 | === modified file 'openlp/plugins/bibles/lib/biblestab.py' | |||
576 | --- openlp/plugins/bibles/lib/biblestab.py 2017-10-07 07:05:07 +0000 | |||
577 | +++ openlp/plugins/bibles/lib/biblestab.py 2017-11-14 23:03:10 +0000 | |||
578 | @@ -41,11 +41,11 @@ | |||
579 | 41 | """ | 41 | """ |
580 | 42 | log.info('Bible Tab loaded') | 42 | log.info('Bible Tab loaded') |
581 | 43 | 43 | ||
583 | 44 | def _init_(self, parent, title, visible_title, icon_path): | 44 | def _init_(self, *args, **kwargs): |
584 | 45 | self.paragraph_style = True | 45 | self.paragraph_style = True |
585 | 46 | self.show_new_chapters = False | 46 | self.show_new_chapters = False |
586 | 47 | self.display_style = 0 | 47 | self.display_style = 0 |
588 | 48 | super(BiblesTab, self).__init__(parent, title, visible_title, icon_path) | 48 | super().__init__(*args, **kwargs) |
589 | 49 | 49 | ||
590 | 50 | def setupUi(self): | 50 | def setupUi(self): |
591 | 51 | self.setObjectName('BiblesTab') | 51 | self.setObjectName('BiblesTab') |
592 | 52 | 52 | ||
593 | === modified file 'openlp/plugins/bibles/lib/db.py' | |||
594 | --- openlp/plugins/bibles/lib/db.py 2017-10-28 10:04:09 +0000 | |||
595 | +++ openlp/plugins/bibles/lib/db.py 2017-11-14 23:03:10 +0000 | |||
596 | @@ -35,6 +35,7 @@ | |||
597 | 35 | from openlp.core.common import clean_filename | 35 | from openlp.core.common import clean_filename |
598 | 36 | from openlp.core.common.applocation import AppLocation | 36 | from openlp.core.common.applocation import AppLocation |
599 | 37 | from openlp.core.common.i18n import translate | 37 | from openlp.core.common.i18n import translate |
600 | 38 | from openlp.core.common.path import Path | ||
601 | 38 | from openlp.core.lib.db import BaseModel, init_db, Manager | 39 | from openlp.core.lib.db import BaseModel, init_db, Manager |
602 | 39 | from openlp.core.lib.ui import critical_error_message_box | 40 | from openlp.core.lib.ui import critical_error_message_box |
603 | 40 | from openlp.plugins.bibles.lib import BibleStrings, LanguageSelection, upgrade | 41 | from openlp.plugins.bibles.lib import BibleStrings, LanguageSelection, upgrade |
604 | @@ -129,10 +130,15 @@ | |||
605 | 129 | :param parent: | 130 | :param parent: |
606 | 130 | :param kwargs: | 131 | :param kwargs: |
607 | 131 | ``path`` | 132 | ``path`` |
609 | 132 | The path to the bible database file. | 133 | The path to the bible database file. Type: openlp.core.common.path.Path |
610 | 133 | 134 | ||
611 | 134 | ``name`` | 135 | ``name`` |
612 | 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. |
613 | 137 | |||
614 | 138 | ``file`` | ||
615 | 139 | Type: openlp.core.common.path.Path | ||
616 | 140 | |||
617 | 141 | :rtype: None | ||
618 | 136 | """ | 142 | """ |
619 | 137 | log.info('BibleDB loaded') | 143 | log.info('BibleDB loaded') |
620 | 138 | self._setup(parent, **kwargs) | 144 | self._setup(parent, **kwargs) |
621 | @@ -145,20 +151,20 @@ | |||
622 | 145 | self.session = None | 151 | self.session = None |
623 | 146 | if 'path' not in kwargs: | 152 | if 'path' not in kwargs: |
624 | 147 | raise KeyError('Missing keyword argument "path".') | 153 | raise KeyError('Missing keyword argument "path".') |
625 | 154 | self.path = kwargs['path'] | ||
626 | 148 | if 'name' not in kwargs and 'file' not in kwargs: | 155 | if 'name' not in kwargs and 'file' not in kwargs: |
627 | 149 | raise KeyError('Missing keyword argument "name" or "file".') | 156 | raise KeyError('Missing keyword argument "name" or "file".') |
628 | 150 | if 'name' in kwargs: | 157 | if 'name' in kwargs: |
629 | 151 | self.name = kwargs['name'] | 158 | self.name = kwargs['name'] |
630 | 152 | if not isinstance(self.name, str): | 159 | if not isinstance(self.name, str): |
631 | 153 | self.name = str(self.name, 'utf-8') | 160 | self.name = str(self.name, 'utf-8') |
633 | 154 | self.file = clean_filename(self.name) + '.sqlite' | 161 | # TODO: To path object |
634 | 162 | file_path = Path(clean_filename(self.name) + '.sqlite') | ||
635 | 155 | if 'file' in kwargs: | 163 | if 'file' in kwargs: |
638 | 156 | self.file = kwargs['file'] | 164 | file_path = kwargs['file'] |
639 | 157 | Manager.__init__(self, 'bibles', init_schema, self.file, upgrade) | 165 | Manager.__init__(self, 'bibles', init_schema, file_path, upgrade) |
640 | 158 | if self.session and 'file' in kwargs: | 166 | if self.session and 'file' in kwargs: |
641 | 159 | self.get_name() | 167 | self.get_name() |
642 | 160 | if 'path' in kwargs: | ||
643 | 161 | self.path = kwargs['path'] | ||
644 | 162 | self._is_web_bible = None | 168 | self._is_web_bible = None |
645 | 163 | 169 | ||
646 | 164 | def get_name(self): | 170 | def get_name(self): |
647 | @@ -470,9 +476,9 @@ | |||
648 | 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. |
649 | 471 | """ | 477 | """ |
650 | 472 | if BiblesResourcesDB.cursor is None: | 478 | if BiblesResourcesDB.cursor is None: |
654 | 473 | file_path = os.path.join(str(AppLocation.get_directory(AppLocation.PluginsDir)), | 479 | file_path = \ |
655 | 474 | 'bibles', 'resources', 'bibles_resources.sqlite') | 480 | AppLocation.get_directory(AppLocation.PluginsDir) / 'bibles' / 'resources' / 'bibles_resources.sqlite' |
656 | 475 | conn = sqlite3.connect(file_path) | 481 | conn = sqlite3.connect(str(file_path)) |
657 | 476 | BiblesResourcesDB.cursor = conn.cursor() | 482 | BiblesResourcesDB.cursor = conn.cursor() |
658 | 477 | return BiblesResourcesDB.cursor | 483 | return BiblesResourcesDB.cursor |
659 | 478 | 484 | ||
660 | @@ -758,17 +764,13 @@ | |||
661 | 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. |
662 | 759 | """ | 765 | """ |
663 | 760 | if AlternativeBookNamesDB.cursor is None: | 766 | if AlternativeBookNamesDB.cursor is None: |
667 | 761 | file_path = os.path.join( | 767 | file_path = AppLocation.get_directory(AppLocation.DataDir) / 'bibles' / 'alternative_book_names.sqlite' |
668 | 762 | str(AppLocation.get_directory(AppLocation.DataDir)), 'bibles', 'alternative_book_names.sqlite') | 768 | AlternativeBookNamesDB.conn = sqlite3.connect(str(file_path)) |
669 | 763 | if not os.path.exists(file_path): | 769 | if not file_path.exists(): |
670 | 764 | # create new DB, create table alternative_book_names | 770 | # create new DB, create table alternative_book_names |
671 | 765 | AlternativeBookNamesDB.conn = sqlite3.connect(file_path) | ||
672 | 766 | AlternativeBookNamesDB.conn.execute( | 771 | AlternativeBookNamesDB.conn.execute( |
673 | 767 | 'CREATE TABLE alternative_book_names(id INTEGER NOT NULL, ' | 772 | 'CREATE TABLE alternative_book_names(id INTEGER NOT NULL, ' |
674 | 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))') |
675 | 769 | else: | ||
676 | 770 | # use existing DB | ||
677 | 771 | AlternativeBookNamesDB.conn = sqlite3.connect(file_path) | ||
678 | 772 | AlternativeBookNamesDB.cursor = AlternativeBookNamesDB.conn.cursor() | 774 | AlternativeBookNamesDB.cursor = AlternativeBookNamesDB.conn.cursor() |
679 | 773 | return AlternativeBookNamesDB.cursor | 775 | return AlternativeBookNamesDB.cursor |
680 | 774 | 776 | ||
681 | 775 | 777 | ||
682 | === added file 'openlp/plugins/bibles/lib/importers/__init__.py' | |||
683 | --- openlp/plugins/bibles/lib/importers/__init__.py 1970-01-01 00:00:00 +0000 | |||
684 | +++ openlp/plugins/bibles/lib/importers/__init__.py 2017-11-14 23:03:10 +0000 | |||
685 | @@ -0,0 +1,24 @@ | |||
686 | 1 | # -*- coding: utf-8 -*- | ||
687 | 2 | # vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 | ||
688 | 3 | |||
689 | 4 | ############################################################################### | ||
690 | 5 | # OpenLP - Open Source Lyrics Projection # | ||
691 | 6 | # --------------------------------------------------------------------------- # | ||
692 | 7 | # Copyright (c) 2008-2017 OpenLP Developers # | ||
693 | 8 | # --------------------------------------------------------------------------- # | ||
694 | 9 | # This program is free software; you can redistribute it and/or modify it # | ||
695 | 10 | # under the terms of the GNU General Public License as published by the Free # | ||
696 | 11 | # Software Foundation; version 2 of the License. # | ||
697 | 12 | # # | ||
698 | 13 | # This program is distributed in the hope that it will be useful, but WITHOUT # | ||
699 | 14 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # | ||
700 | 15 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # | ||
701 | 16 | # more details. # | ||
702 | 17 | # # | ||
703 | 18 | # You should have received a copy of the GNU General Public License along # | ||
704 | 19 | # with this program; if not, write to the Free Software Foundation, Inc., 59 # | ||
705 | 20 | # Temple Place, Suite 330, Boston, MA 02111-1307 USA # | ||
706 | 21 | ############################################################################### | ||
707 | 22 | """ | ||
708 | 23 | The :mod:`~openlp.plugins.bibles.lib.importers` module contains importers for the Bibles plugin. | ||
709 | 24 | """ | ||
710 | 0 | 25 | ||
711 | === removed file 'openlp/plugins/bibles/lib/importers/__init__.py' | |||
712 | --- openlp/plugins/bibles/lib/importers/__init__.py 2017-10-23 22:09:57 +0000 | |||
713 | +++ openlp/plugins/bibles/lib/importers/__init__.py 1970-01-01 00:00:00 +0000 | |||
714 | @@ -1,21 +0,0 @@ | |||
715 | 1 | # -*- coding: utf-8 -*- | ||
716 | 2 | # vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 | ||
717 | 3 | |||
718 | 4 | ############################################################################### | ||
719 | 5 | # OpenLP - Open Source Lyrics Projection # | ||
720 | 6 | # --------------------------------------------------------------------------- # | ||
721 | 7 | # Copyright (c) 2008-2017 OpenLP Developers # | ||
722 | 8 | # --------------------------------------------------------------------------- # | ||
723 | 9 | # This program is free software; you can redistribute it and/or modify it # | ||
724 | 10 | # under the terms of the GNU General Public License as published by the Free # | ||
725 | 11 | # Software Foundation; version 2 of the License. # | ||
726 | 12 | # # | ||
727 | 13 | # This program is distributed in the hope that it will be useful, but WITHOUT # | ||
728 | 14 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # | ||
729 | 15 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # | ||
730 | 16 | # more details. # | ||
731 | 17 | # # | ||
732 | 18 | # You should have received a copy of the GNU General Public License along # | ||
733 | 19 | # with this program; if not, write to the Free Software Foundation, Inc., 59 # | ||
734 | 20 | # Temple Place, Suite 330, Boston, MA 02111-1307 USA # | ||
735 | 21 | ############################################################################### | ||
736 | 22 | 0 | ||
737 | === modified file 'openlp/plugins/bibles/lib/importers/csvbible.py' | |||
738 | --- openlp/plugins/bibles/lib/importers/csvbible.py 2017-10-07 07:05:07 +0000 | |||
739 | +++ openlp/plugins/bibles/lib/importers/csvbible.py 2017-11-14 23:03:10 +0000 | |||
740 | @@ -73,8 +73,8 @@ | |||
741 | 73 | """ | 73 | """ |
742 | 74 | super().__init__(*args, **kwargs) | 74 | super().__init__(*args, **kwargs) |
743 | 75 | self.log_info(self.__class__.__name__) | 75 | self.log_info(self.__class__.__name__) |
746 | 76 | self.books_file = kwargs['booksfile'] | 76 | self.books_path = kwargs['books_path'] |
747 | 77 | self.verses_file = kwargs['versefile'] | 77 | self.verses_path = kwargs['verse_path'] |
748 | 78 | 78 | ||
749 | 79 | @staticmethod | 79 | @staticmethod |
750 | 80 | def get_book_name(name, books): | 80 | def get_book_name(name, books): |
751 | @@ -92,21 +92,22 @@ | |||
752 | 92 | return book_name | 92 | return book_name |
753 | 93 | 93 | ||
754 | 94 | @staticmethod | 94 | @staticmethod |
756 | 95 | def parse_csv_file(filename, results_tuple): | 95 | def parse_csv_file(file_path, results_tuple): |
757 | 96 | """ | 96 | """ |
758 | 97 | Parse the supplied CSV file. | 97 | Parse the supplied CSV file. |
759 | 98 | 98 | ||
763 | 99 | :param filename: The name of the file to parse. Str | 99 | :param openlp.core.common.path.Path file_path: The name of the file to parse. |
764 | 100 | :param results_tuple: The namedtuple to use to store the results. namedtuple | 100 | :param namedtuple results_tuple: The namedtuple to use to store the results. |
765 | 101 | :return: An iterable yielding namedtuples of type results_tuple | 101 | :return: An list of namedtuples of type results_tuple |
766 | 102 | :rtype: list[namedtuple] | ||
767 | 102 | """ | 103 | """ |
768 | 103 | try: | 104 | try: |
771 | 104 | encoding = get_file_encoding(Path(filename))['encoding'] | 105 | encoding = get_file_encoding(file_path)['encoding'] |
772 | 105 | with open(filename, 'r', encoding=encoding, newline='') as csv_file: | 106 | with file_path.open('r', encoding=encoding, newline='') as csv_file: |
773 | 106 | csv_reader = csv.reader(csv_file, delimiter=',', quotechar='"') | 107 | csv_reader = csv.reader(csv_file, delimiter=',', quotechar='"') |
774 | 107 | return [results_tuple(*line) for line in csv_reader] | 108 | return [results_tuple(*line) for line in csv_reader] |
775 | 108 | except (OSError, csv.Error): | 109 | except (OSError, csv.Error): |
777 | 109 | raise ValidationError(msg='Parsing "{file}" failed'.format(file=filename)) | 110 | raise ValidationError(msg='Parsing "{file}" failed'.format(file=file_path)) |
778 | 110 | 111 | ||
779 | 111 | def process_books(self, books): | 112 | def process_books(self, books): |
780 | 112 | """ | 113 | """ |
781 | @@ -159,12 +160,12 @@ | |||
782 | 159 | self.language_id = self.get_language(bible_name) | 160 | self.language_id = self.get_language(bible_name) |
783 | 160 | if not self.language_id: | 161 | if not self.language_id: |
784 | 161 | return False | 162 | return False |
786 | 162 | books = self.parse_csv_file(self.books_file, Book) | 163 | books = self.parse_csv_file(self.books_path, Book) |
787 | 163 | self.wizard.progress_bar.setValue(0) | 164 | self.wizard.progress_bar.setValue(0) |
788 | 164 | self.wizard.progress_bar.setMinimum(0) | 165 | self.wizard.progress_bar.setMinimum(0) |
789 | 165 | self.wizard.progress_bar.setMaximum(len(books)) | 166 | self.wizard.progress_bar.setMaximum(len(books)) |
790 | 166 | book_list = self.process_books(books) | 167 | book_list = self.process_books(books) |
792 | 167 | verses = self.parse_csv_file(self.verses_file, Verse) | 168 | verses = self.parse_csv_file(self.verses_path, Verse) |
793 | 168 | self.wizard.progress_bar.setValue(0) | 169 | self.wizard.progress_bar.setValue(0) |
794 | 169 | self.wizard.progress_bar.setMaximum(len(books) + 1) | 170 | self.wizard.progress_bar.setMaximum(len(books) + 1) |
795 | 170 | self.process_verses(verses, book_list) | 171 | self.process_verses(verses, book_list) |
796 | 171 | 172 | ||
797 | === modified file 'openlp/plugins/bibles/lib/importers/opensong.py' | |||
798 | --- openlp/plugins/bibles/lib/importers/opensong.py 2016-12-31 11:01:36 +0000 | |||
799 | +++ openlp/plugins/bibles/lib/importers/opensong.py 2017-11-14 23:03:10 +0000 | |||
800 | @@ -46,7 +46,8 @@ | |||
801 | 46 | 46 | ||
802 | 47 | :param number: The raw data from the xml | 47 | :param number: The raw data from the xml |
803 | 48 | :param previous_number: The previous chapter number | 48 | :param previous_number: The previous chapter number |
805 | 49 | :return: Number of current chapter. (Int) | 49 | :return: Number of current chapter. |
806 | 50 | :rtype: int | ||
807 | 50 | """ | 51 | """ |
808 | 51 | if number: | 52 | if number: |
809 | 52 | return int(number.split()[-1]) | 53 | return int(number.split()[-1]) |
810 | @@ -132,13 +133,13 @@ | |||
811 | 132 | :param bible_name: The name of the bible being imported | 133 | :param bible_name: The name of the bible being imported |
812 | 133 | :return: True if import completed, False if import was unsuccessful | 134 | :return: True if import completed, False if import was unsuccessful |
813 | 134 | """ | 135 | """ |
817 | 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)) |
818 | 136 | self.validate_xml_file(self.filename, 'bible') | 137 | self.validate_xml_file(self.file_path, 'bible') |
819 | 137 | bible = self.parse_xml(self.filename, use_objectify=True) | 138 | bible = self.parse_xml(self.file_path, use_objectify=True) |
820 | 138 | if bible is None: | 139 | if bible is None: |
821 | 139 | return False | 140 | return False |
822 | 140 | # No language info in the opensong format, so ask the user | 141 | # No language info in the opensong format, so ask the user |
824 | 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)) |
825 | 142 | if not self.language_id: | 143 | if not self.language_id: |
826 | 143 | return False | 144 | return False |
827 | 144 | self.process_books(bible.b) | 145 | self.process_books(bible.b) |
828 | 145 | 146 | ||
829 | === modified file 'openlp/plugins/bibles/lib/importers/osis.py' | |||
830 | --- openlp/plugins/bibles/lib/importers/osis.py 2016-12-31 11:01:36 +0000 | |||
831 | +++ openlp/plugins/bibles/lib/importers/osis.py 2017-11-14 23:03:10 +0000 | |||
832 | @@ -159,14 +159,14 @@ | |||
833 | 159 | """ | 159 | """ |
834 | 160 | Loads a Bible from file. | 160 | Loads a Bible from file. |
835 | 161 | """ | 161 | """ |
839 | 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)) |
840 | 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') |
841 | 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) |
842 | 165 | if bible is None: | 165 | if bible is None: |
843 | 166 | return False | 166 | return False |
844 | 167 | # Find bible language | 167 | # Find bible language |
845 | 168 | language = bible.xpath("//ns:osisText/@xml:lang", namespaces=NS) | 168 | language = bible.xpath("//ns:osisText/@xml:lang", namespaces=NS) |
847 | 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)) |
848 | 170 | if not self.language_id: | 170 | if not self.language_id: |
849 | 171 | return False | 171 | return False |
850 | 172 | self.process_books(bible) | 172 | self.process_books(bible) |
851 | 173 | 173 | ||
852 | === modified file 'openlp/plugins/bibles/lib/importers/sword.py' | |||
853 | --- openlp/plugins/bibles/lib/importers/sword.py 2017-10-07 07:05:07 +0000 | |||
854 | +++ openlp/plugins/bibles/lib/importers/sword.py 2017-11-14 23:03:10 +0000 | |||
855 | @@ -60,7 +60,7 @@ | |||
856 | 60 | bible = pysword_modules.get_bible_from_module(self.sword_key) | 60 | bible = pysword_modules.get_bible_from_module(self.sword_key) |
857 | 61 | language = pysword_module_json['lang'] | 61 | language = pysword_module_json['lang'] |
858 | 62 | language = language[language.find('.') + 1:] | 62 | language = language[language.find('.') + 1:] |
860 | 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)) |
861 | 64 | if not language_id: | 64 | if not language_id: |
862 | 65 | return False | 65 | return False |
863 | 66 | books = bible.get_structure().get_books() | 66 | books = bible.get_structure().get_books() |
864 | 67 | 67 | ||
865 | === modified file 'openlp/plugins/bibles/lib/importers/wordproject.py' | |||
866 | --- openlp/plugins/bibles/lib/importers/wordproject.py 2016-12-31 11:01:36 +0000 | |||
867 | +++ openlp/plugins/bibles/lib/importers/wordproject.py 2017-11-14 23:03:10 +0000 | |||
868 | @@ -19,15 +19,14 @@ | |||
869 | 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 # |
870 | 20 | # Temple Place, Suite 330, Boston, MA 02111-1307 USA # | 20 | # Temple Place, Suite 330, Boston, MA 02111-1307 USA # |
871 | 21 | ############################################################################### | 21 | ############################################################################### |
873 | 22 | import os | 22 | import logging |
874 | 23 | import re | 23 | import re |
875 | 24 | import logging | ||
876 | 25 | from codecs import open as copen | ||
877 | 26 | from tempfile import TemporaryDirectory | 24 | from tempfile import TemporaryDirectory |
878 | 27 | from zipfile import ZipFile | 25 | from zipfile import ZipFile |
879 | 28 | 26 | ||
880 | 29 | from bs4 import BeautifulSoup, Tag, NavigableString | 27 | from bs4 import BeautifulSoup, Tag, NavigableString |
881 | 30 | 28 | ||
882 | 29 | from openlp.core.common.path import Path | ||
883 | 31 | from openlp.plugins.bibles.lib.bibleimport import BibleImport | 30 | from openlp.plugins.bibles.lib.bibleimport import BibleImport |
884 | 32 | 31 | ||
885 | 33 | BOOK_NUMBER_PATTERN = re.compile(r'\[(\d+)\]') | 32 | BOOK_NUMBER_PATTERN = re.compile(r'\[(\d+)\]') |
886 | @@ -51,9 +50,9 @@ | |||
887 | 51 | Unzip the file to a temporary directory | 50 | Unzip the file to a temporary directory |
888 | 52 | """ | 51 | """ |
889 | 53 | self.tmp = TemporaryDirectory() | 52 | self.tmp = TemporaryDirectory() |
893 | 54 | zip_file = ZipFile(os.path.abspath(self.filename)) | 53 | with ZipFile(str(self.file_path)) as zip_file: |
894 | 55 | zip_file.extractall(self.tmp.name) | 54 | zip_file.extractall(self.tmp.name) |
895 | 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) |
896 | 57 | 56 | ||
897 | 58 | def process_books(self): | 57 | def process_books(self): |
898 | 59 | """ | 58 | """ |
899 | @@ -62,8 +61,7 @@ | |||
900 | 62 | :param bible_data: parsed xml | 61 | :param bible_data: parsed xml |
901 | 63 | :return: None | 62 | :return: None |
902 | 64 | """ | 63 | """ |
905 | 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') |
904 | 66 | page = index_file.read() | ||
906 | 67 | soup = BeautifulSoup(page, 'lxml') | 65 | soup = BeautifulSoup(page, 'lxml') |
907 | 68 | bible_books = soup.find('div', 'textOptions').find_all('li') | 66 | bible_books = soup.find('div', 'textOptions').find_all('li') |
908 | 69 | book_count = len(bible_books) | 67 | book_count = len(bible_books) |
909 | @@ -93,9 +91,7 @@ | |||
910 | 93 | :return: None | 91 | :return: None |
911 | 94 | """ | 92 | """ |
912 | 95 | log.debug(book_link) | 93 | log.debug(book_link) |
916 | 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') |
914 | 97 | with copen(book_file, encoding='utf-8', errors='ignore') as f: | ||
915 | 98 | page = f.read() | ||
917 | 99 | soup = BeautifulSoup(page, 'lxml') | 95 | soup = BeautifulSoup(page, 'lxml') |
918 | 100 | header_div = soup.find('div', 'textHeader') | 96 | header_div = soup.find('div', 'textHeader') |
919 | 101 | chapters_p = header_div.find('p') | 97 | chapters_p = header_div.find('p') |
920 | @@ -114,9 +110,8 @@ | |||
921 | 114 | """ | 110 | """ |
922 | 115 | Get the verses for a particular book | 111 | Get the verses for a particular book |
923 | 116 | """ | 112 | """ |
927 | 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) |
928 | 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') |
926 | 119 | page = chapter_file.read() | ||
929 | 120 | soup = BeautifulSoup(page, 'lxml') | 115 | soup = BeautifulSoup(page, 'lxml') |
930 | 121 | text_body = soup.find('div', 'textBody') | 116 | text_body = soup.find('div', 'textBody') |
931 | 122 | if text_body: | 117 | if text_body: |
932 | @@ -158,9 +153,9 @@ | |||
933 | 158 | """ | 153 | """ |
934 | 159 | Loads a Bible from file. | 154 | Loads a Bible from file. |
935 | 160 | """ | 155 | """ |
937 | 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)) |
938 | 162 | self._unzip_file() | 157 | self._unzip_file() |
940 | 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)) |
941 | 164 | result = False | 159 | result = False |
942 | 165 | if self.language_id: | 160 | if self.language_id: |
943 | 166 | self.process_books() | 161 | self.process_books() |
944 | 167 | 162 | ||
945 | === modified file 'openlp/plugins/bibles/lib/importers/zefania.py' | |||
946 | --- openlp/plugins/bibles/lib/importers/zefania.py 2017-10-07 07:05:07 +0000 | |||
947 | +++ openlp/plugins/bibles/lib/importers/zefania.py 2017-11-14 23:03:10 +0000 | |||
948 | @@ -45,13 +45,13 @@ | |||
949 | 45 | """ | 45 | """ |
950 | 46 | Loads a Bible from file. | 46 | Loads a Bible from file. |
951 | 47 | """ | 47 | """ |
953 | 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)) |
954 | 49 | success = True | 49 | success = True |
955 | 50 | try: | 50 | try: |
957 | 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) |
958 | 52 | # Find bible language | 52 | # Find bible language |
959 | 53 | language = xmlbible.xpath("/XMLBIBLE/INFORMATION/language/text()") | 53 | language = xmlbible.xpath("/XMLBIBLE/INFORMATION/language/text()") |
961 | 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)) |
962 | 55 | if not language_id: | 55 | if not language_id: |
963 | 56 | return False | 56 | return False |
964 | 57 | no_of_books = int(xmlbible.xpath('count(//BIBLEBOOK)')) | 57 | no_of_books = int(xmlbible.xpath('count(//BIBLEBOOK)')) |
965 | @@ -69,7 +69,7 @@ | |||
966 | 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.') |
967 | 70 | book_ref_id = int(bnumber) | 70 | book_ref_id = int(bnumber) |
968 | 71 | if not book_ref_id: | 71 | if not book_ref_id: |
970 | 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)) |
971 | 73 | return False | 73 | return False |
972 | 74 | book_details = BiblesResourcesDB.get_book_by_id(book_ref_id) | 74 | book_details = BiblesResourcesDB.get_book_by_id(book_ref_id) |
973 | 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']) |
974 | 76 | 76 | ||
975 | === modified file 'openlp/plugins/bibles/lib/manager.py' | |||
976 | --- openlp/plugins/bibles/lib/manager.py 2017-10-23 22:09:57 +0000 | |||
977 | +++ openlp/plugins/bibles/lib/manager.py 2017-11-14 23:03:10 +0000 | |||
978 | @@ -19,7 +19,6 @@ | |||
979 | 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 # |
980 | 20 | # Temple Place, Suite 330, Boston, MA 02111-1307 USA # | 20 | # Temple Place, Suite 330, Boston, MA 02111-1307 USA # |
981 | 21 | ############################################################################### | 21 | ############################################################################### |
982 | 22 | |||
983 | 23 | import logging | 22 | import logging |
984 | 24 | 23 | ||
985 | 25 | from openlp.core.common import delete_file | 24 | from openlp.core.common import delete_file |
986 | @@ -115,7 +114,7 @@ | |||
987 | 115 | self.settings_section = 'bibles' | 114 | self.settings_section = 'bibles' |
988 | 116 | self.web = 'Web' | 115 | self.web = 'Web' |
989 | 117 | self.db_cache = None | 116 | self.db_cache = None |
991 | 118 | self.path = str(AppLocation.get_section_data_path(self.settings_section)) | 117 | self.path = AppLocation.get_section_data_path(self.settings_section) |
992 | 119 | self.proxy_name = Settings().value(self.settings_section + '/proxy name') | 118 | self.proxy_name = Settings().value(self.settings_section + '/proxy name') |
993 | 120 | self.suffix = '.sqlite' | 119 | self.suffix = '.sqlite' |
994 | 121 | self.import_wizard = None | 120 | self.import_wizard = None |
995 | @@ -128,20 +127,20 @@ | |||
996 | 128 | of HTTPBible is loaded instead of the BibleDB class. | 127 | of HTTPBible is loaded instead of the BibleDB class. |
997 | 129 | """ | 128 | """ |
998 | 130 | log.debug('Reload bibles') | 129 | log.debug('Reload bibles') |
1003 | 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) |
1004 | 132 | if 'alternative_book_names.sqlite' in files: | 131 | if Path('alternative_book_names.sqlite') in file_paths: |
1005 | 133 | files.remove('alternative_book_names.sqlite') | 132 | file_paths.remove(Path('alternative_book_names.sqlite')) |
1006 | 134 | log.debug('Bible Files {text}'.format(text=files)) | 133 | log.debug('Bible Files {text}'.format(text=file_paths)) |
1007 | 135 | self.db_cache = {} | 134 | self.db_cache = {} |
1010 | 136 | for filename in files: | 135 | for file_path in file_paths: |
1011 | 137 | bible = BibleDB(self.parent, path=self.path, file=filename) | 136 | bible = BibleDB(self.parent, path=self.path, file=file_path) |
1012 | 138 | if not bible.session: | 137 | if not bible.session: |
1013 | 139 | continue | 138 | continue |
1014 | 140 | name = bible.get_name() | 139 | name = bible.get_name() |
1015 | 141 | # Remove corrupted files. | 140 | # Remove corrupted files. |
1016 | 142 | if name is None: | 141 | if name is None: |
1017 | 143 | bible.session.close_all() | 142 | bible.session.close_all() |
1019 | 144 | delete_file(Path(self.path, filename)) | 143 | delete_file(self.path / file_path) |
1020 | 145 | continue | 144 | continue |
1021 | 146 | log.debug('Bible Name: "{name}"'.format(name=name)) | 145 | log.debug('Bible Name: "{name}"'.format(name=name)) |
1022 | 147 | self.db_cache[name] = bible | 146 | self.db_cache[name] = bible |
1023 | @@ -150,7 +149,7 @@ | |||
1024 | 150 | source = self.db_cache[name].get_object(BibleMeta, 'download_source') | 149 | source = self.db_cache[name].get_object(BibleMeta, 'download_source') |
1025 | 151 | download_name = self.db_cache[name].get_object(BibleMeta, 'download_name').value | 150 | download_name = self.db_cache[name].get_object(BibleMeta, 'download_name').value |
1026 | 152 | meta_proxy = self.db_cache[name].get_object(BibleMeta, 'proxy_server') | 151 | meta_proxy = self.db_cache[name].get_object(BibleMeta, 'proxy_server') |
1028 | 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, |
1029 | 154 | download_name=download_name) | 153 | download_name=download_name) |
1030 | 155 | if meta_proxy: | 154 | if meta_proxy: |
1031 | 156 | web_bible.proxy_server = meta_proxy.value | 155 | web_bible.proxy_server = meta_proxy.value |
1032 | 157 | 156 | ||
1033 | === modified file 'tests/functional/openlp_plugins/bibles/test_bibleimport.py' | |||
1034 | --- tests/functional/openlp_plugins/bibles/test_bibleimport.py 2017-10-29 06:01:25 +0000 | |||
1035 | +++ tests/functional/openlp_plugins/bibles/test_bibleimport.py 2017-11-14 23:03:10 +0000 | |||
1036 | @@ -30,6 +30,7 @@ | |||
1037 | 30 | from PyQt5.QtWidgets import QDialog | 30 | from PyQt5.QtWidgets import QDialog |
1038 | 31 | 31 | ||
1039 | 32 | from openlp.core.common.i18n import Language | 32 | from openlp.core.common.i18n import Language |
1040 | 33 | from openlp.core.common.path import Path | ||
1041 | 33 | from openlp.core.lib.exceptions import ValidationError | 34 | from openlp.core.lib.exceptions import ValidationError |
1042 | 34 | from openlp.plugins.bibles.lib.bibleimport import BibleImport | 35 | from openlp.plugins.bibles.lib.bibleimport import BibleImport |
1043 | 35 | from openlp.plugins.bibles.lib.db import BibleDB | 36 | from openlp.plugins.bibles.lib.db import BibleDB |
1044 | @@ -48,7 +49,7 @@ | |||
1045 | 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' |
1046 | 49 | b'</root>' | 50 | b'</root>' |
1047 | 50 | ) | 51 | ) |
1049 | 51 | self.open_patcher = patch('builtins.open') | 52 | self.open_patcher = patch.object(Path, 'open') |
1050 | 52 | self.addCleanup(self.open_patcher.stop) | 53 | self.addCleanup(self.open_patcher.stop) |
1051 | 53 | self.mocked_open = self.open_patcher.start() | 54 | self.mocked_open = self.open_patcher.start() |
1052 | 54 | self.critical_error_message_box_patcher = \ | 55 | self.critical_error_message_box_patcher = \ |
1053 | @@ -74,8 +75,8 @@ | |||
1054 | 74 | # WHEN: Creating an instance of BibleImport with no key word arguments | 75 | # WHEN: Creating an instance of BibleImport with no key word arguments |
1055 | 75 | instance = BibleImport(MagicMock()) | 76 | instance = BibleImport(MagicMock()) |
1056 | 76 | 77 | ||
1059 | 77 | # THEN: The filename attribute should be None | 78 | # THEN: The file_path attribute should be None |
1060 | 78 | assert instance.filename is None | 79 | assert instance.file_path is None |
1061 | 79 | assert isinstance(instance, BibleDB) | 80 | assert isinstance(instance, BibleDB) |
1062 | 80 | 81 | ||
1063 | 81 | def test_init_kwargs_set(self): | 82 | def test_init_kwargs_set(self): |
1064 | @@ -84,11 +85,11 @@ | |||
1065 | 84 | """ | 85 | """ |
1066 | 85 | # GIVEN: A patched BibleDB._setup, BibleImport class and mocked parent | 86 | # GIVEN: A patched BibleDB._setup, BibleImport class and mocked parent |
1067 | 86 | # WHEN: Creating an instance of BibleImport with selected key word arguments | 87 | # WHEN: Creating an instance of BibleImport with selected key word arguments |
1069 | 87 | kwargs = {'filename': 'bible.xml'} | 88 | kwargs = {'file_path': 'bible.xml'} |
1070 | 88 | instance = BibleImport(MagicMock(), **kwargs) | 89 | instance = BibleImport(MagicMock(), **kwargs) |
1071 | 89 | 90 | ||
1074 | 90 | # THEN: The filename keyword should be set to bible.xml | 91 | # THEN: The file_path keyword should be set to bible.xml |
1075 | 91 | assert instance.filename == 'bible.xml' | 92 | assert instance.file_path == 'bible.xml' |
1076 | 92 | assert isinstance(instance, BibleDB) | 93 | assert isinstance(instance, BibleDB) |
1077 | 93 | 94 | ||
1078 | 94 | @patch.object(BibleDB, '_setup') | 95 | @patch.object(BibleDB, '_setup') |
1079 | @@ -361,7 +362,7 @@ | |||
1080 | 361 | instance.wizard = MagicMock() | 362 | instance.wizard = MagicMock() |
1081 | 362 | 363 | ||
1082 | 363 | # WHEN: Calling parse_xml | 364 | # WHEN: Calling parse_xml |
1084 | 364 | result = instance.parse_xml('file.tst') | 365 | result = instance.parse_xml(Path('file.tst')) |
1085 | 365 | 366 | ||
1086 | 366 | # THEN: The result returned should contain the correct data, and should be an instance of eetree_Element | 367 | # THEN: The result returned should contain the correct data, and should be an instance of eetree_Element |
1087 | 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' \ |
1088 | @@ -378,7 +379,7 @@ | |||
1089 | 378 | instance.wizard = MagicMock() | 379 | instance.wizard = MagicMock() |
1090 | 379 | 380 | ||
1091 | 380 | # WHEN: Calling parse_xml | 381 | # WHEN: Calling parse_xml |
1093 | 381 | result = instance.parse_xml('file.tst', use_objectify=True) | 382 | result = instance.parse_xml(Path('file.tst'), use_objectify=True) |
1094 | 382 | 383 | ||
1095 | 383 | # THEN: The result returned should contain the correct data, and should be an instance of ObjectifiedElement | 384 | # THEN: The result returned should contain the correct data, and should be an instance of ObjectifiedElement |
1096 | 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>' \ |
1097 | @@ -396,7 +397,7 @@ | |||
1098 | 396 | instance.wizard = MagicMock() | 397 | instance.wizard = MagicMock() |
1099 | 397 | 398 | ||
1100 | 398 | # WHEN: Calling parse_xml, with a test file | 399 | # WHEN: Calling parse_xml, with a test file |
1102 | 399 | result = instance.parse_xml('file.tst', elements=elements) | 400 | result = instance.parse_xml(Path('file.tst'), elements=elements) |
1103 | 400 | 401 | ||
1104 | 401 | # THEN: The result returned should contain the correct data | 402 | # THEN: The result returned should contain the correct data |
1105 | 402 | assert etree.tostring(result) == \ | 403 | assert etree.tostring(result) == \ |
1106 | @@ -413,7 +414,7 @@ | |||
1107 | 413 | instance.wizard = MagicMock() | 414 | instance.wizard = MagicMock() |
1108 | 414 | 415 | ||
1109 | 415 | # WHEN: Calling parse_xml, with a test file | 416 | # WHEN: Calling parse_xml, with a test file |
1111 | 416 | result = instance.parse_xml('file.tst', tags=tags) | 417 | result = instance.parse_xml(Path('file.tst'), tags=tags) |
1112 | 417 | 418 | ||
1113 | 418 | # THEN: The result returned should contain the correct data | 419 | # THEN: The result returned should contain the correct data |
1114 | 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' \ |
1115 | @@ -431,7 +432,7 @@ | |||
1116 | 431 | instance.wizard = MagicMock() | 432 | instance.wizard = MagicMock() |
1117 | 432 | 433 | ||
1118 | 433 | # WHEN: Calling parse_xml, with a test file | 434 | # WHEN: Calling parse_xml, with a test file |
1120 | 434 | result = instance.parse_xml('file.tst', elements=elements, tags=tags) | 435 | result = instance.parse_xml(Path('file.tst'), elements=elements, tags=tags) |
1121 | 435 | 436 | ||
1122 | 436 | # THEN: The result returned should contain the correct data | 437 | # THEN: The result returned should contain the correct data |
1123 | 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>' |
1124 | @@ -446,10 +447,10 @@ | |||
1125 | 446 | exception.filename = 'file.tst' | 447 | exception.filename = 'file.tst' |
1126 | 447 | exception.strerror = 'No such file or directory' | 448 | exception.strerror = 'No such file or directory' |
1127 | 448 | self.mocked_open.side_effect = exception | 449 | self.mocked_open.side_effect = exception |
1129 | 449 | importer = BibleImport(MagicMock(), path='.', name='.', filename='') | 450 | importer = BibleImport(MagicMock(), path='.', name='.', file_path=None) |
1130 | 450 | 451 | ||
1131 | 451 | # WHEN: Calling parse_xml | 452 | # WHEN: Calling parse_xml |
1133 | 452 | result = importer.parse_xml('file.tst') | 453 | result = importer.parse_xml(Path('file.tst')) |
1134 | 453 | 454 | ||
1135 | 454 | # THEN: parse_xml should have caught the error, informed the user and returned None | 455 | # THEN: parse_xml should have caught the error, informed the user and returned None |
1136 | 455 | mocked_log_exception.assert_called_once_with('Opening file.tst failed.') | 456 | mocked_log_exception.assert_called_once_with('Opening file.tst failed.') |
1137 | @@ -468,10 +469,10 @@ | |||
1138 | 468 | exception.filename = 'file.tst' | 469 | exception.filename = 'file.tst' |
1139 | 469 | exception.strerror = 'Permission denied' | 470 | exception.strerror = 'Permission denied' |
1140 | 470 | self.mocked_open.side_effect = exception | 471 | self.mocked_open.side_effect = exception |
1142 | 471 | importer = BibleImport(MagicMock(), path='.', name='.', filename='') | 472 | importer = BibleImport(MagicMock(), path='.', name='.', file_path=None) |
1143 | 472 | 473 | ||
1144 | 473 | # WHEN: Calling parse_xml | 474 | # WHEN: Calling parse_xml |
1146 | 474 | result = importer.parse_xml('file.tst') | 475 | result = importer.parse_xml(Path('file.tst')) |
1147 | 475 | 476 | ||
1148 | 476 | # THEN: parse_xml should have caught the error, informed the user and returned None | 477 | # THEN: parse_xml should have caught the error, informed the user and returned None |
1149 | 477 | mocked_log_exception.assert_called_once_with('Opening file.tst failed.') | 478 | mocked_log_exception.assert_called_once_with('Opening file.tst failed.') |
1150 | @@ -485,7 +486,7 @@ | |||
1151 | 485 | Test set_current_chapter | 486 | Test set_current_chapter |
1152 | 486 | """ | 487 | """ |
1153 | 487 | # GIVEN: An instance of BibleImport and a mocked wizard | 488 | # GIVEN: An instance of BibleImport and a mocked wizard |
1155 | 488 | importer = BibleImport(MagicMock(), path='.', name='.', filename='') | 489 | importer = BibleImport(MagicMock(), path='.', name='.', file_path=None) |
1156 | 489 | importer.wizard = MagicMock() | 490 | importer.wizard = MagicMock() |
1157 | 490 | 491 | ||
1158 | 491 | # WHEN: Calling set_current_chapter | 492 | # WHEN: Calling set_current_chapter |
1159 | @@ -500,7 +501,7 @@ | |||
1160 | 500 | Test that validate_xml_file raises a ValidationError when is_compressed returns True | 501 | Test that validate_xml_file raises a ValidationError when is_compressed returns True |
1161 | 501 | """ | 502 | """ |
1162 | 502 | # GIVEN: A mocked parse_xml which returns None | 503 | # GIVEN: A mocked parse_xml which returns None |
1164 | 503 | importer = BibleImport(MagicMock(), path='.', name='.', filename='') | 504 | importer = BibleImport(MagicMock(), path='.', name='.', file_path=None) |
1165 | 504 | 505 | ||
1166 | 505 | # WHEN: Calling is_compressed | 506 | # WHEN: Calling is_compressed |
1167 | 506 | # THEN: ValidationError should be raised, with the message 'Compressed file' | 507 | # THEN: ValidationError should be raised, with the message 'Compressed file' |
1168 | @@ -515,7 +516,7 @@ | |||
1169 | 515 | Test that validate_xml_file raises a ValidationError when parse_xml returns None | 516 | Test that validate_xml_file raises a ValidationError when parse_xml returns None |
1170 | 516 | """ | 517 | """ |
1171 | 517 | # GIVEN: A mocked parse_xml which returns None | 518 | # GIVEN: A mocked parse_xml which returns None |
1173 | 518 | importer = BibleImport(MagicMock(), path='.', name='.', filename='') | 519 | importer = BibleImport(MagicMock(), path='.', name='.', file_path=None) |
1174 | 519 | 520 | ||
1175 | 520 | # WHEN: Calling validate_xml_file | 521 | # WHEN: Calling validate_xml_file |
1176 | 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' |
1177 | @@ -531,7 +532,7 @@ | |||
1178 | 531 | Test that validate_xml_file returns True with valid XML | 532 | Test that validate_xml_file returns True with valid XML |
1179 | 532 | """ | 533 | """ |
1180 | 533 | # GIVEN: Some test data with an OpenSong Bible "bible" root tag | 534 | # GIVEN: Some test data with an OpenSong Bible "bible" root tag |
1182 | 534 | importer = BibleImport(MagicMock(), path='.', name='.', filename='') | 535 | importer = BibleImport(MagicMock(), path='.', name='.', file_path=None) |
1183 | 535 | 536 | ||
1184 | 536 | # WHEN: Calling validate_xml_file | 537 | # WHEN: Calling validate_xml_file |
1185 | 537 | result = importer.validate_xml_file('file.name', 'bible') | 538 | result = importer.validate_xml_file('file.name', 'bible') |
1186 | @@ -546,7 +547,7 @@ | |||
1187 | 546 | Test that validate_xml_file raises a ValidationError with an OpenSong root tag | 547 | Test that validate_xml_file raises a ValidationError with an OpenSong root tag |
1188 | 547 | """ | 548 | """ |
1189 | 548 | # GIVEN: Some test data with an Zefania root tag and an instance of BibleImport | 549 | # GIVEN: Some test data with an Zefania root tag and an instance of BibleImport |
1191 | 549 | importer = BibleImport(MagicMock(), path='.', name='.', filename='') | 550 | importer = BibleImport(MagicMock(), path='.', name='.', file_path=None) |
1192 | 550 | 551 | ||
1193 | 551 | # WHEN: Calling validate_xml_file | 552 | # WHEN: Calling validate_xml_file |
1194 | 552 | # THEN: ValidationError should be raised, and the critical error message box should was called informing | 553 | # THEN: ValidationError should be raised, and the critical error message box should was called informing |
1195 | @@ -566,7 +567,7 @@ | |||
1196 | 566 | # GIVEN: Some test data with an Zefania root tag and an instance of BibleImport | 567 | # GIVEN: Some test data with an Zefania root tag and an instance of BibleImport |
1197 | 567 | mocked_parse_xml.return_value = objectify.fromstring( | 568 | mocked_parse_xml.return_value = objectify.fromstring( |
1198 | 568 | '<osis xmlns=\'http://www.bibletechnologies.net/2003/OSIS/namespace\'></osis>') | 569 | '<osis xmlns=\'http://www.bibletechnologies.net/2003/OSIS/namespace\'></osis>') |
1200 | 569 | importer = BibleImport(MagicMock(), path='.', name='.', filename='') | 570 | importer = BibleImport(MagicMock(), path='.', name='.', file_path=None) |
1201 | 570 | 571 | ||
1202 | 571 | # WHEN: Calling validate_xml_file | 572 | # WHEN: Calling validate_xml_file |
1203 | 572 | # THEN: ValidationError should be raised, and the critical error message box should was called informing | 573 | # THEN: ValidationError should be raised, and the critical error message box should was called informing |
1204 | @@ -584,7 +585,7 @@ | |||
1205 | 584 | Test that validate_xml_file raises a ValidationError with an Zefania root tag | 585 | Test that validate_xml_file raises a ValidationError with an Zefania root tag |
1206 | 585 | """ | 586 | """ |
1207 | 586 | # GIVEN: Some test data with an Zefania root tag and an instance of BibleImport | 587 | # GIVEN: Some test data with an Zefania root tag and an instance of BibleImport |
1209 | 587 | importer = BibleImport(MagicMock(), path='.', name='.', filename='') | 588 | importer = BibleImport(MagicMock(), path='.', name='.', file_path=None) |
1210 | 588 | 589 | ||
1211 | 589 | # WHEN: Calling validate_xml_file | 590 | # WHEN: Calling validate_xml_file |
1212 | 590 | # THEN: ValidationError should be raised, and the critical error message box should was called informing | 591 | # THEN: ValidationError should be raised, and the critical error message box should was called informing |
1213 | @@ -602,7 +603,7 @@ | |||
1214 | 602 | Test that validate_xml_file raises a ValidationError with an unknown root tag | 603 | Test that validate_xml_file raises a ValidationError with an unknown root tag |
1215 | 603 | """ | 604 | """ |
1216 | 604 | # GIVEN: Some test data with an unknown root tag and an instance of BibleImport | 605 | # GIVEN: Some test data with an unknown root tag and an instance of BibleImport |
1218 | 605 | importer = BibleImport(MagicMock(), path='.', name='.', filename='') | 606 | importer = BibleImport(MagicMock(), path='.', name='.', file_path=None) |
1219 | 606 | 607 | ||
1220 | 607 | # WHEN: Calling validate_xml_file | 608 | # WHEN: Calling validate_xml_file |
1221 | 608 | # THEN: ValidationError should be raised, and the critical error message box should was called informing | 609 | # THEN: ValidationError should be raised, and the critical error message box should was called informing |
1222 | 609 | 610 | ||
1223 | === modified file 'tests/functional/openlp_plugins/bibles/test_csvimport.py' | |||
1224 | --- tests/functional/openlp_plugins/bibles/test_csvimport.py 2017-10-29 06:01:25 +0000 | |||
1225 | +++ tests/functional/openlp_plugins/bibles/test_csvimport.py 2017-11-14 23:03:10 +0000 | |||
1226 | @@ -29,6 +29,7 @@ | |||
1227 | 29 | from unittest import TestCase | 29 | from unittest import TestCase |
1228 | 30 | from unittest.mock import ANY, MagicMock, PropertyMock, call, patch | 30 | from unittest.mock import ANY, MagicMock, PropertyMock, call, patch |
1229 | 31 | 31 | ||
1230 | 32 | from openlp.core.common.path import Path | ||
1231 | 32 | from openlp.core.lib.exceptions import ValidationError | 33 | from openlp.core.lib.exceptions import ValidationError |
1232 | 33 | from openlp.plugins.bibles.lib.bibleimport import BibleImport | 34 | from openlp.plugins.bibles.lib.bibleimport import BibleImport |
1233 | 34 | from openlp.plugins.bibles.lib.importers.csvbible import Book, CSVBible, Verse | 35 | from openlp.plugins.bibles.lib.importers.csvbible import Book, CSVBible, Verse |
1234 | @@ -59,12 +60,13 @@ | |||
1235 | 59 | mocked_manager = MagicMock() | 60 | mocked_manager = MagicMock() |
1236 | 60 | 61 | ||
1237 | 61 | # WHEN: An importer object is created | 62 | # WHEN: An importer object is created |
1239 | 62 | importer = CSVBible(mocked_manager, path='.', name='.', booksfile='books.csv', versefile='verse.csv') | 63 | importer = \ |
1240 | 64 | CSVBible(mocked_manager, path='.', name='.', books_path=Path('books.csv'), verse_path=Path('verse.csv')) | ||
1241 | 63 | 65 | ||
1242 | 64 | # THEN: The importer should be an instance of BibleImport | 66 | # THEN: The importer should be an instance of BibleImport |
1243 | 65 | self.assertIsInstance(importer, BibleImport) | 67 | self.assertIsInstance(importer, BibleImport) |
1246 | 66 | self.assertEqual(importer.books_file, 'books.csv') | 68 | self.assertEqual(importer.books_path, Path('books.csv')) |
1247 | 67 | self.assertEqual(importer.verses_file, 'verse.csv') | 69 | self.assertEqual(importer.verses_path, Path('verse.csv')) |
1248 | 68 | 70 | ||
1249 | 69 | def test_book_namedtuple(self): | 71 | def test_book_namedtuple(self): |
1250 | 70 | """ | 72 | """ |
1251 | @@ -134,17 +136,17 @@ | |||
1252 | 134 | 136 | ||
1253 | 135 | with patch('openlp.plugins.bibles.lib.importers.csvbible.get_file_encoding', | 137 | with patch('openlp.plugins.bibles.lib.importers.csvbible.get_file_encoding', |
1254 | 136 | return_value={'encoding': 'utf-8', 'confidence': 0.99}),\ | 138 | return_value={'encoding': 'utf-8', 'confidence': 0.99}),\ |
1256 | 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,\ |
1257 | 138 | patch('openlp.plugins.bibles.lib.importers.csvbible.csv.reader', | 140 | patch('openlp.plugins.bibles.lib.importers.csvbible.csv.reader', |
1258 | 139 | return_value=iter(test_data)) as mocked_reader: | 141 | return_value=iter(test_data)) as mocked_reader: |
1259 | 140 | 142 | ||
1260 | 141 | # WHEN: Calling the CSVBible parse_csv_file method with a file name and TestTuple | 143 | # WHEN: Calling the CSVBible parse_csv_file method with a file name and TestTuple |
1262 | 142 | result = CSVBible.parse_csv_file('file.csv', TestTuple) | 144 | result = CSVBible.parse_csv_file(Path('file.csv'), TestTuple) |
1263 | 143 | 145 | ||
1264 | 144 | # THEN: A list of TestTuple instances with the parsed data should be returned | 146 | # THEN: A list of TestTuple instances with the parsed data should be returned |
1265 | 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'), |
1266 | 146 | TestTuple('3', 'Line 3', 'Data 3')]) | 148 | TestTuple('3', 'Line 3', 'Data 3')]) |
1268 | 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='') |
1269 | 148 | mocked_reader.assert_called_once_with(ANY, delimiter=',', quotechar='"') | 150 | mocked_reader.assert_called_once_with(ANY, delimiter=',', quotechar='"') |
1270 | 149 | 151 | ||
1271 | 150 | def test_parse_csv_file_oserror(self): | 152 | def test_parse_csv_file_oserror(self): |
1272 | @@ -154,12 +156,12 @@ | |||
1273 | 154 | # GIVEN: Mocked a mocked open object which raises an OSError | 156 | # GIVEN: Mocked a mocked open object which raises an OSError |
1274 | 155 | with patch('openlp.plugins.bibles.lib.importers.csvbible.get_file_encoding', | 157 | with patch('openlp.plugins.bibles.lib.importers.csvbible.get_file_encoding', |
1275 | 156 | return_value={'encoding': 'utf-8', 'confidence': 0.99}),\ | 158 | return_value={'encoding': 'utf-8', 'confidence': 0.99}),\ |
1277 | 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): |
1278 | 158 | 160 | ||
1279 | 159 | # WHEN: Calling CSVBible.parse_csv_file | 161 | # WHEN: Calling CSVBible.parse_csv_file |
1280 | 160 | # THEN: A ValidationError should be raised | 162 | # THEN: A ValidationError should be raised |
1281 | 161 | with self.assertRaises(ValidationError) as context: | 163 | with self.assertRaises(ValidationError) as context: |
1283 | 162 | CSVBible.parse_csv_file('file.csv', None) | 164 | CSVBible.parse_csv_file(Path('file.csv'), None) |
1284 | 163 | self.assertEqual(context.exception.msg, 'Parsing "file.csv" failed') | 165 | self.assertEqual(context.exception.msg, 'Parsing "file.csv" failed') |
1285 | 164 | 166 | ||
1286 | 165 | def test_parse_csv_file_csverror(self): | 167 | def test_parse_csv_file_csverror(self): |
1287 | @@ -169,13 +171,13 @@ | |||
1288 | 169 | # GIVEN: Mocked a csv.reader which raises an csv.Error | 171 | # GIVEN: Mocked a csv.reader which raises an csv.Error |
1289 | 170 | with patch('openlp.plugins.bibles.lib.importers.csvbible.get_file_encoding', | 172 | with patch('openlp.plugins.bibles.lib.importers.csvbible.get_file_encoding', |
1290 | 171 | return_value={'encoding': 'utf-8', 'confidence': 0.99}),\ | 173 | return_value={'encoding': 'utf-8', 'confidence': 0.99}),\ |
1292 | 172 | patch('openlp.plugins.bibles.lib.importers.csvbible.open', create=True),\ | 174 | patch('openlp.plugins.bibles.lib.importers.csvbible.Path.open', create=True),\ |
1293 | 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): |
1294 | 174 | 176 | ||
1295 | 175 | # WHEN: Calling CSVBible.parse_csv_file | 177 | # WHEN: Calling CSVBible.parse_csv_file |
1296 | 176 | # THEN: A ValidationError should be raised | 178 | # THEN: A ValidationError should be raised |
1297 | 177 | with self.assertRaises(ValidationError) as context: | 179 | with self.assertRaises(ValidationError) as context: |
1299 | 178 | CSVBible.parse_csv_file('file.csv', None) | 180 | CSVBible.parse_csv_file(Path('file.csv'), None) |
1300 | 179 | self.assertEqual(context.exception.msg, 'Parsing "file.csv" failed') | 181 | self.assertEqual(context.exception.msg, 'Parsing "file.csv" failed') |
1301 | 180 | 182 | ||
1302 | 181 | def test_process_books_stopped_import(self): | 183 | def test_process_books_stopped_import(self): |
1303 | @@ -185,7 +187,8 @@ | |||
1304 | 185 | # GIVEN: An instance of CSVBible with the stop_import_flag set to True | 187 | # GIVEN: An instance of CSVBible with the stop_import_flag set to True |
1305 | 186 | mocked_manager = MagicMock() | 188 | mocked_manager = MagicMock() |
1306 | 187 | with patch('openlp.plugins.bibles.lib.db.BibleDB._setup'): | 189 | with patch('openlp.plugins.bibles.lib.db.BibleDB._setup'): |
1308 | 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'), |
1309 | 191 | verse_path=Path('verse.csv')) | ||
1310 | 189 | type(importer).application = PropertyMock() | 192 | type(importer).application = PropertyMock() |
1311 | 190 | importer.stop_import_flag = True | 193 | importer.stop_import_flag = True |
1312 | 191 | importer.wizard = MagicMock() | 194 | importer.wizard = MagicMock() |
1313 | @@ -205,7 +208,8 @@ | |||
1314 | 205 | mocked_manager = MagicMock() | 208 | mocked_manager = MagicMock() |
1315 | 206 | with patch('openlp.plugins.bibles.lib.db.BibleDB._setup'),\ | 209 | with patch('openlp.plugins.bibles.lib.db.BibleDB._setup'),\ |
1316 | 207 | patch('openlp.plugins.bibles.lib.importers.csvbible.translate'): | 210 | patch('openlp.plugins.bibles.lib.importers.csvbible.translate'): |
1318 | 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'), |
1319 | 212 | verse_path=Path('verse.csv')) | ||
1320 | 209 | importer.find_and_create_book = MagicMock() | 213 | importer.find_and_create_book = MagicMock() |
1321 | 210 | importer.language_id = 10 | 214 | importer.language_id = 10 |
1322 | 211 | importer.stop_import_flag = False | 215 | importer.stop_import_flag = False |
1323 | @@ -229,7 +233,8 @@ | |||
1324 | 229 | # GIVEN: An instance of CSVBible with the stop_import_flag set to True | 233 | # GIVEN: An instance of CSVBible with the stop_import_flag set to True |
1325 | 230 | mocked_manager = MagicMock() | 234 | mocked_manager = MagicMock() |
1326 | 231 | with patch('openlp.plugins.bibles.lib.db.BibleDB._setup'): | 235 | with patch('openlp.plugins.bibles.lib.db.BibleDB._setup'): |
1328 | 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'), |
1329 | 237 | verse_path=Path('verse.csv')) | ||
1330 | 233 | importer.get_book_name = MagicMock() | 238 | importer.get_book_name = MagicMock() |
1331 | 234 | importer.session = MagicMock() | 239 | importer.session = MagicMock() |
1332 | 235 | importer.stop_import_flag = True | 240 | importer.stop_import_flag = True |
1333 | @@ -250,7 +255,8 @@ | |||
1334 | 250 | mocked_manager = MagicMock() | 255 | mocked_manager = MagicMock() |
1335 | 251 | with patch('openlp.plugins.bibles.lib.db.BibleDB._setup'),\ | 256 | with patch('openlp.plugins.bibles.lib.db.BibleDB._setup'),\ |
1336 | 252 | patch('openlp.plugins.bibles.lib.importers.csvbible.translate'): | 257 | patch('openlp.plugins.bibles.lib.importers.csvbible.translate'): |
1338 | 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'), |
1339 | 259 | verse_path=Path('verse.csv')) | ||
1340 | 254 | importer.create_verse = MagicMock() | 260 | importer.create_verse = MagicMock() |
1341 | 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')) |
1342 | 256 | importer.get_book_name = MagicMock(return_value='1. Mosebog') | 262 | importer.get_book_name = MagicMock(return_value='1. Mosebog') |
1343 | @@ -281,7 +287,8 @@ | |||
1344 | 281 | # GIVEN: An instance of CSVBible and a mocked get_language which simulates the user cancelling the language box | 287 | # GIVEN: An instance of CSVBible and a mocked get_language which simulates the user cancelling the language box |
1345 | 282 | mocked_manager = MagicMock() | 288 | mocked_manager = MagicMock() |
1346 | 283 | with patch('openlp.plugins.bibles.lib.db.BibleDB._setup'): | 289 | with patch('openlp.plugins.bibles.lib.db.BibleDB._setup'): |
1348 | 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'), |
1349 | 291 | verse_path=Path('verse.csv')) | ||
1350 | 285 | importer.get_language = MagicMock(return_value=None) | 292 | importer.get_language = MagicMock(return_value=None) |
1351 | 286 | 293 | ||
1352 | 287 | # WHEN: Calling do_import | 294 | # WHEN: Calling do_import |
1353 | @@ -298,7 +305,8 @@ | |||
1354 | 298 | # GIVEN: An instance of CSVBible | 305 | # GIVEN: An instance of CSVBible |
1355 | 299 | mocked_manager = MagicMock() | 306 | mocked_manager = MagicMock() |
1356 | 300 | with patch('openlp.plugins.bibles.lib.db.BibleDB._setup'): | 307 | with patch('openlp.plugins.bibles.lib.db.BibleDB._setup'): |
1358 | 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'), |
1359 | 309 | verse_path=Path('verses.csv')) | ||
1360 | 302 | importer.get_language = MagicMock(return_value=10) | 310 | importer.get_language = MagicMock(return_value=10) |
1361 | 303 | importer.parse_csv_file = MagicMock(side_effect=[['Book 1'], ['Verse 1']]) | 311 | importer.parse_csv_file = MagicMock(side_effect=[['Book 1'], ['Verse 1']]) |
1362 | 304 | importer.process_books = MagicMock(return_value=['Book 1']) | 312 | importer.process_books = MagicMock(return_value=['Book 1']) |
1363 | @@ -312,7 +320,8 @@ | |||
1364 | 312 | 320 | ||
1365 | 313 | # THEN: parse_csv_file should be called twice, | 321 | # THEN: parse_csv_file should be called twice, |
1366 | 314 | # and True should be returned. | 322 | # and True should be returned. |
1368 | 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, |
1369 | 324 | [call(Path('books.csv'), Book), call(Path('verses.csv'), Verse)]) | ||
1370 | 316 | importer.process_books.assert_called_once_with(['Book 1']) | 325 | importer.process_books.assert_called_once_with(['Book 1']) |
1371 | 317 | importer.process_verses.assert_called_once_with(['Verse 1'], ['Book 1']) | 326 | importer.process_verses.assert_called_once_with(['Verse 1'], ['Book 1']) |
1372 | 318 | self.assertTrue(result) | 327 | self.assertTrue(result) |
1373 | @@ -325,12 +334,12 @@ | |||
1374 | 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. |
1375 | 326 | result_file = open(os.path.join(TEST_PATH, 'dk1933.json'), 'rb') | 335 | result_file = open(os.path.join(TEST_PATH, 'dk1933.json'), 'rb') |
1376 | 327 | test_data = json.loads(result_file.read().decode()) | 336 | test_data = json.loads(result_file.read().decode()) |
1379 | 328 | books_file = os.path.join(TEST_PATH, 'dk1933-books.csv') | 337 | books_file = Path(TEST_PATH, 'dk1933-books.csv') |
1380 | 329 | verses_file = os.path.join(TEST_PATH, 'dk1933-verses.csv') | 338 | verses_file = Path(TEST_PATH, 'dk1933-verses.csv') |
1381 | 330 | with patch('openlp.plugins.bibles.lib.importers.csvbible.CSVBible.application'): | 339 | with patch('openlp.plugins.bibles.lib.importers.csvbible.CSVBible.application'): |
1382 | 331 | mocked_manager = MagicMock() | 340 | mocked_manager = MagicMock() |
1383 | 332 | mocked_import_wizard = MagicMock() | 341 | mocked_import_wizard = MagicMock() |
1385 | 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) |
1386 | 334 | importer.wizard = mocked_import_wizard | 343 | importer.wizard = mocked_import_wizard |
1387 | 335 | importer.get_book_ref_id_by_name = MagicMock() | 344 | importer.get_book_ref_id_by_name = MagicMock() |
1388 | 336 | importer.create_verse = MagicMock() | 345 | importer.create_verse = MagicMock() |
1389 | 337 | 346 | ||
1390 | === modified file 'tests/functional/openlp_plugins/bibles/test_opensongimport.py' | |||
1391 | --- tests/functional/openlp_plugins/bibles/test_opensongimport.py 2017-10-29 06:01:25 +0000 | |||
1392 | +++ tests/functional/openlp_plugins/bibles/test_opensongimport.py 2017-11-14 23:03:10 +0000 | |||
1393 | @@ -29,6 +29,7 @@ | |||
1394 | 29 | 29 | ||
1395 | 30 | from lxml import objectify | 30 | from lxml import objectify |
1396 | 31 | 31 | ||
1397 | 32 | from openlp.core.common.path import Path | ||
1398 | 32 | from openlp.core.common.registry import Registry | 33 | from openlp.core.common.registry import Registry |
1399 | 33 | from openlp.plugins.bibles.lib.importers.opensong import OpenSongBible, get_text, parse_chapter_number | 34 | from openlp.plugins.bibles.lib.importers.opensong import OpenSongBible, get_text, parse_chapter_number |
1400 | 34 | from openlp.plugins.bibles.lib.bibleimport import BibleImport | 35 | from openlp.plugins.bibles.lib.bibleimport import BibleImport |
1401 | @@ -64,7 +65,7 @@ | |||
1402 | 64 | mocked_manager = MagicMock() | 65 | mocked_manager = MagicMock() |
1403 | 65 | 66 | ||
1404 | 66 | # WHEN: An importer object is created | 67 | # WHEN: An importer object is created |
1406 | 67 | importer = OpenSongBible(mocked_manager, path='.', name='.', filename='') | 68 | importer = OpenSongBible(mocked_manager, path='.', name='.', file_path=None) |
1407 | 68 | 69 | ||
1408 | 69 | # THEN: The importer should be an instance of BibleDB | 70 | # THEN: The importer should be an instance of BibleDB |
1409 | 70 | self.assertIsInstance(importer, BibleImport) | 71 | self.assertIsInstance(importer, BibleImport) |
1410 | @@ -126,7 +127,7 @@ | |||
1411 | 126 | Test parse_verse_number when supplied with a valid verse number | 127 | Test parse_verse_number when supplied with a valid verse number |
1412 | 127 | """ | 128 | """ |
1413 | 128 | # GIVEN: An instance of OpenSongBible, the number 15 represented as a string and an instance of OpenSongBible | 129 | # GIVEN: An instance of OpenSongBible, the number 15 represented as a string and an instance of OpenSongBible |
1415 | 129 | importer = OpenSongBible(MagicMock(), path='.', name='.', filename='') | 130 | importer = OpenSongBible(MagicMock(), path='.', name='.', file_path=None) |
1416 | 130 | 131 | ||
1417 | 131 | # WHEN: Calling parse_verse_number | 132 | # WHEN: Calling parse_verse_number |
1418 | 132 | result = importer.parse_verse_number('15', 0) | 133 | result = importer.parse_verse_number('15', 0) |
1419 | @@ -139,7 +140,7 @@ | |||
1420 | 139 | Test parse_verse_number when supplied with a verse range | 140 | Test parse_verse_number when supplied with a verse range |
1421 | 140 | """ | 141 | """ |
1422 | 141 | # GIVEN: An instance of OpenSongBible, and the range 24-26 represented as a string | 142 | # GIVEN: An instance of OpenSongBible, and the range 24-26 represented as a string |
1424 | 142 | importer = OpenSongBible(MagicMock(), path='.', name='.', filename='') | 143 | importer = OpenSongBible(MagicMock(), path='.', name='.', file_path=None) |
1425 | 143 | 144 | ||
1426 | 144 | # WHEN: Calling parse_verse_number | 145 | # WHEN: Calling parse_verse_number |
1427 | 145 | result = importer.parse_verse_number('24-26', 0) | 146 | result = importer.parse_verse_number('24-26', 0) |
1428 | @@ -152,7 +153,7 @@ | |||
1429 | 152 | Test parse_verse_number when supplied with a invalid verse number | 153 | Test parse_verse_number when supplied with a invalid verse number |
1430 | 153 | """ | 154 | """ |
1431 | 154 | # GIVEN: An instance of OpenSongBible, a non numeric string represented as a string | 155 | # GIVEN: An instance of OpenSongBible, a non numeric string represented as a string |
1433 | 155 | importer = OpenSongBible(MagicMock(), path='.', name='.', filename='') | 156 | importer = OpenSongBible(MagicMock(), path='.', name='.', file_path=None) |
1434 | 156 | 157 | ||
1435 | 157 | # WHEN: Calling parse_verse_number | 158 | # WHEN: Calling parse_verse_number |
1436 | 158 | result = importer.parse_verse_number('invalid', 41) | 159 | result = importer.parse_verse_number('invalid', 41) |
1437 | @@ -165,7 +166,7 @@ | |||
1438 | 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) |
1439 | 166 | """ | 167 | """ |
1440 | 167 | # GIVEN: An instance of OpenSongBible, an empty string, and the previous verse number set as 14 | 168 | # GIVEN: An instance of OpenSongBible, an empty string, and the previous verse number set as 14 |
1442 | 168 | importer = OpenSongBible(MagicMock(), path='.', name='.', filename='') | 169 | importer = OpenSongBible(MagicMock(), path='.', name='.', file_path=None) |
1443 | 169 | # WHEN: Calling parse_verse_number | 170 | # WHEN: Calling parse_verse_number |
1444 | 170 | result = importer.parse_verse_number('', 14) | 171 | result = importer.parse_verse_number('', 14) |
1445 | 171 | 172 | ||
1446 | @@ -178,7 +179,7 @@ | |||
1447 | 178 | """ | 179 | """ |
1448 | 179 | with patch.object(OpenSongBible, 'log_warning')as mocked_log_warning: | 180 | with patch.object(OpenSongBible, 'log_warning')as mocked_log_warning: |
1449 | 180 | # GIVEN: An instanceofOpenSongBible, a Tuple, and the previous verse number set as 12 | 181 | # GIVEN: An instanceofOpenSongBible, a Tuple, and the previous verse number set as 12 |
1451 | 181 | importer = OpenSongBible(MagicMock(), path='.', name='.', filename='') | 182 | importer = OpenSongBible(MagicMock(), path='.', name='.', file_path=None) |
1452 | 182 | 183 | ||
1453 | 183 | # WHEN: Calling parse_verse_number | 184 | # WHEN: Calling parse_verse_number |
1454 | 184 | result = importer.parse_verse_number((1, 2, 3), 12) | 185 | result = importer.parse_verse_number((1, 2, 3), 12) |
1455 | @@ -193,7 +194,7 @@ | |||
1456 | 193 | Test process_books when stop_import is set to True | 194 | Test process_books when stop_import is set to True |
1457 | 194 | """ | 195 | """ |
1458 | 195 | # GIVEN: An instance of OpenSongBible | 196 | # GIVEN: An instance of OpenSongBible |
1460 | 196 | importer = OpenSongBible(MagicMock(), path='.', name='.', filename='') | 197 | importer = OpenSongBible(MagicMock(), path='.', name='.', file_path=None) |
1461 | 197 | 198 | ||
1462 | 198 | # WHEN: stop_import_flag is set to True | 199 | # WHEN: stop_import_flag is set to True |
1463 | 199 | importer.stop_import_flag = True | 200 | importer.stop_import_flag = True |
1464 | @@ -209,7 +210,7 @@ | |||
1465 | 209 | # GIVEN: An instance of OpenSongBible Importer and two mocked books | 210 | # GIVEN: An instance of OpenSongBible Importer and two mocked books |
1466 | 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'] |
1467 | 211 | with patch.object(OpenSongBible, 'process_chapters') as mocked_process_chapters: | 212 | with patch.object(OpenSongBible, 'process_chapters') as mocked_process_chapters: |
1469 | 212 | importer = OpenSongBible(MagicMock(), path='.', name='.', filename='') | 213 | importer = OpenSongBible(MagicMock(), path='.', name='.', file_path=None) |
1470 | 213 | 214 | ||
1471 | 214 | book1 = MagicMock() | 215 | book1 = MagicMock() |
1472 | 215 | book1.attrib = {'n': 'Name1'} | 216 | book1.attrib = {'n': 'Name1'} |
1473 | @@ -236,7 +237,7 @@ | |||
1474 | 236 | Test process_chapters when stop_import is set to True | 237 | Test process_chapters when stop_import is set to True |
1475 | 237 | """ | 238 | """ |
1476 | 238 | # GIVEN: An isntance of OpenSongBible | 239 | # GIVEN: An isntance of OpenSongBible |
1478 | 239 | importer = OpenSongBible(MagicMock(), path='.', name='.', filename='') | 240 | importer = OpenSongBible(MagicMock(), path='.', name='.', file_path=None) |
1479 | 240 | importer.parse_chapter_number = MagicMock() | 241 | importer.parse_chapter_number = MagicMock() |
1480 | 241 | 242 | ||
1481 | 242 | # WHEN: stop_import_flag is set to True | 243 | # WHEN: stop_import_flag is set to True |
1482 | @@ -252,7 +253,7 @@ | |||
1483 | 252 | Test process_chapters when it completes | 253 | Test process_chapters when it completes |
1484 | 253 | """ | 254 | """ |
1485 | 254 | # GIVEN: An instance of OpenSongBible | 255 | # GIVEN: An instance of OpenSongBible |
1487 | 255 | importer = OpenSongBible(MagicMock(), path='.', name='.', filename='') | 256 | importer = OpenSongBible(MagicMock(), path='.', name='.', file_path=None) |
1488 | 256 | importer.wizard = MagicMock() | 257 | importer.wizard = MagicMock() |
1489 | 257 | 258 | ||
1490 | 258 | # WHEN: called with some valid data | 259 | # WHEN: called with some valid data |
1491 | @@ -284,7 +285,7 @@ | |||
1492 | 284 | Test process_verses when stop_import is set to True | 285 | Test process_verses when stop_import is set to True |
1493 | 285 | """ | 286 | """ |
1494 | 286 | # GIVEN: An isntance of OpenSongBible | 287 | # GIVEN: An isntance of OpenSongBible |
1496 | 287 | importer = OpenSongBible(MagicMock(), path='.', name='.', filename='') | 288 | importer = OpenSongBible(MagicMock(), path='.', name='.', file_path=None) |
1497 | 288 | importer.parse_verse_number = MagicMock() | 289 | importer.parse_verse_number = MagicMock() |
1498 | 289 | 290 | ||
1499 | 290 | # WHEN: stop_import_flag is set to True | 291 | # WHEN: stop_import_flag is set to True |
1500 | @@ -303,7 +304,7 @@ | |||
1501 | 303 | patch.object(OpenSongBible, 'parse_verse_number', | 304 | patch.object(OpenSongBible, 'parse_verse_number', |
1502 | 304 | **{'side_effect': [1, 2]}) as mocked_parse_verse_number: | 305 | **{'side_effect': [1, 2]}) as mocked_parse_verse_number: |
1503 | 305 | # GIVEN: An instance of OpenSongBible | 306 | # GIVEN: An instance of OpenSongBible |
1505 | 306 | importer = OpenSongBible(MagicMock(), path='.', name='.', filename='') | 307 | importer = OpenSongBible(MagicMock(), path='.', name='.', file_path=None) |
1506 | 307 | importer.wizard = MagicMock() | 308 | importer.wizard = MagicMock() |
1507 | 308 | 309 | ||
1508 | 309 | # WHEN: called with some valid data | 310 | # WHEN: called with some valid data |
1509 | @@ -338,7 +339,7 @@ | |||
1510 | 338 | patch.object(OpenSongBible, 'validate_xml_file'), \ | 339 | patch.object(OpenSongBible, 'validate_xml_file'), \ |
1511 | 339 | patch.object(OpenSongBible, 'parse_xml', return_value=None), \ | 340 | patch.object(OpenSongBible, 'parse_xml', return_value=None), \ |
1512 | 340 | patch.object(OpenSongBible, 'get_language_id') as mocked_language_id: | 341 | patch.object(OpenSongBible, 'get_language_id') as mocked_language_id: |
1514 | 341 | importer = OpenSongBible(MagicMock(), path='.', name='.', filename='') | 342 | importer = OpenSongBible(MagicMock(), path='.', name='.', file_path=None) |
1515 | 342 | 343 | ||
1516 | 343 | # WHEN: Calling do_import | 344 | # WHEN: Calling do_import |
1517 | 344 | result = importer.do_import() | 345 | result = importer.do_import() |
1518 | @@ -357,7 +358,7 @@ | |||
1519 | 357 | patch.object(OpenSongBible, 'parse_xml'), \ | 358 | patch.object(OpenSongBible, 'parse_xml'), \ |
1520 | 358 | patch.object(OpenSongBible, 'get_language_id', return_value=False), \ | 359 | patch.object(OpenSongBible, 'get_language_id', return_value=False), \ |
1521 | 359 | patch.object(OpenSongBible, 'process_books') as mocked_process_books: | 360 | patch.object(OpenSongBible, 'process_books') as mocked_process_books: |
1523 | 360 | importer = OpenSongBible(MagicMock(), path='.', name='.', filename='') | 361 | importer = OpenSongBible(MagicMock(), path='.', name='.', file_path=None) |
1524 | 361 | 362 | ||
1525 | 362 | # WHEN: Calling do_import | 363 | # WHEN: Calling do_import |
1526 | 363 | result = importer.do_import() | 364 | result = importer.do_import() |
1527 | @@ -376,7 +377,7 @@ | |||
1528 | 376 | patch.object(OpenSongBible, 'parse_xml'), \ | 377 | patch.object(OpenSongBible, 'parse_xml'), \ |
1529 | 377 | patch.object(OpenSongBible, 'get_language_id', return_value=10), \ | 378 | patch.object(OpenSongBible, 'get_language_id', return_value=10), \ |
1530 | 378 | patch.object(OpenSongBible, 'process_books'): | 379 | patch.object(OpenSongBible, 'process_books'): |
1532 | 379 | importer = OpenSongBible(MagicMock(), path='.', name='.', filename='') | 380 | importer = OpenSongBible(MagicMock(), path='.', name='.', file_path=None) |
1533 | 380 | 381 | ||
1534 | 381 | # WHEN: Calling do_import | 382 | # WHEN: Calling do_import |
1535 | 382 | result = importer.do_import() | 383 | result = importer.do_import() |
1536 | @@ -406,7 +407,7 @@ | |||
1537 | 406 | with patch('openlp.plugins.bibles.lib.importers.opensong.OpenSongBible.application'): | 407 | with patch('openlp.plugins.bibles.lib.importers.opensong.OpenSongBible.application'): |
1538 | 407 | mocked_manager = MagicMock() | 408 | mocked_manager = MagicMock() |
1539 | 408 | mocked_import_wizard = MagicMock() | 409 | mocked_import_wizard = MagicMock() |
1541 | 409 | importer = OpenSongBible(mocked_manager, path='.', name='.', filename='') | 410 | importer = OpenSongBible(mocked_manager, path='.', name='.', file_path=None) |
1542 | 410 | importer.wizard = mocked_import_wizard | 411 | importer.wizard = mocked_import_wizard |
1543 | 411 | importer.get_book_ref_id_by_name = MagicMock() | 412 | importer.get_book_ref_id_by_name = MagicMock() |
1544 | 412 | importer.create_verse = MagicMock() | 413 | importer.create_verse = MagicMock() |
1545 | @@ -416,7 +417,7 @@ | |||
1546 | 416 | importer.get_language.return_value = 'Danish' | 417 | importer.get_language.return_value = 'Danish' |
1547 | 417 | 418 | ||
1548 | 418 | # WHEN: Importing bible file | 419 | # WHEN: Importing bible file |
1550 | 419 | importer.filename = os.path.join(TEST_PATH, bible_file) | 420 | importer.file_path = Path(TEST_PATH, bible_file) |
1551 | 420 | importer.do_import() | 421 | importer.do_import() |
1552 | 421 | 422 | ||
1553 | 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. |
1554 | 423 | 424 | ||
1555 | === modified file 'tests/functional/openlp_plugins/bibles/test_osisimport.py' | |||
1556 | --- tests/functional/openlp_plugins/bibles/test_osisimport.py 2017-10-29 06:01:25 +0000 | |||
1557 | +++ tests/functional/openlp_plugins/bibles/test_osisimport.py 2017-11-14 23:03:10 +0000 | |||
1558 | @@ -27,6 +27,7 @@ | |||
1559 | 27 | from unittest import TestCase | 27 | from unittest import TestCase |
1560 | 28 | from unittest.mock import MagicMock, call, patch | 28 | from unittest.mock import MagicMock, call, patch |
1561 | 29 | 29 | ||
1562 | 30 | from openlp.core.common.path import Path | ||
1563 | 30 | from openlp.plugins.bibles.lib.bibleimport import BibleImport | 31 | from openlp.plugins.bibles.lib.bibleimport import BibleImport |
1564 | 31 | from openlp.plugins.bibles.lib.db import BibleDB | 32 | from openlp.plugins.bibles.lib.db import BibleDB |
1565 | 32 | from openlp.plugins.bibles.lib.importers.osis import OSISBible | 33 | from openlp.plugins.bibles.lib.importers.osis import OSISBible |
1566 | @@ -63,7 +64,7 @@ | |||
1567 | 63 | mocked_manager = MagicMock() | 64 | mocked_manager = MagicMock() |
1568 | 64 | 65 | ||
1569 | 65 | # WHEN: An importer object is created | 66 | # WHEN: An importer object is created |
1571 | 66 | importer = OSISBible(mocked_manager, path='.', name='.', filename='') | 67 | importer = OSISBible(mocked_manager, path='.', name='.', file_path=None) |
1572 | 67 | 68 | ||
1573 | 68 | # THEN: The importer should be an instance of BibleDB | 69 | # THEN: The importer should be an instance of BibleDB |
1574 | 69 | self.assertIsInstance(importer, BibleDB) | 70 | self.assertIsInstance(importer, BibleDB) |
1575 | @@ -73,7 +74,7 @@ | |||
1576 | 73 | Test process_books when stop_import is set to True | 74 | Test process_books when stop_import is set to True |
1577 | 74 | """ | 75 | """ |
1578 | 75 | # GIVEN: An instance of OSISBible adn some mocked data | 76 | # GIVEN: An instance of OSISBible adn some mocked data |
1580 | 76 | importer = OSISBible(MagicMock(), path='.', name='.', filename='') | 77 | importer = OSISBible(MagicMock(), path='.', name='.', file_path=None) |
1581 | 77 | mocked_data = MagicMock(**{'xpath.return_value': ['Book']}) | 78 | mocked_data = MagicMock(**{'xpath.return_value': ['Book']}) |
1582 | 78 | 79 | ||
1583 | 79 | # WHEN: stop_import_flag is set to True and process_books is called | 80 | # WHEN: stop_import_flag is set to True and process_books is called |
1584 | @@ -90,7 +91,7 @@ | |||
1585 | 90 | # GIVEN: An instance of OSISBible Importer and two mocked books | 91 | # GIVEN: An instance of OSISBible Importer and two mocked books |
1586 | 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'] |
1587 | 92 | with patch.object(OSISBible, 'process_chapters') as mocked_process_chapters: | 93 | with patch.object(OSISBible, 'process_chapters') as mocked_process_chapters: |
1589 | 93 | importer = OSISBible(MagicMock(), path='.', name='.', filename='') | 94 | importer = OSISBible(MagicMock(), path='.', name='.', file_path=None) |
1590 | 94 | 95 | ||
1591 | 95 | book1 = MagicMock() | 96 | book1 = MagicMock() |
1592 | 96 | book1.get.return_value = 'Name1' | 97 | book1.get.return_value = 'Name1' |
1593 | @@ -128,7 +129,7 @@ | |||
1594 | 128 | test_chapter = MagicMock() | 129 | test_chapter = MagicMock() |
1595 | 129 | test_chapter.__iter__.return_value = [test_verse] | 130 | test_chapter.__iter__.return_value = [test_verse] |
1596 | 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) |
1598 | 131 | importer = OSISBible(MagicMock(), path='.', name='.', filename='') | 132 | importer = OSISBible(MagicMock(), path='.', name='.', file_path=None) |
1599 | 132 | 133 | ||
1600 | 133 | # WHEN: Calling process_chapters | 134 | # WHEN: Calling process_chapters |
1601 | 134 | importer.process_chapters(test_book, [test_chapter]) | 135 | importer.process_chapters(test_book, [test_chapter]) |
1602 | @@ -155,7 +156,7 @@ | |||
1603 | 155 | test_chapter = MagicMock() | 156 | test_chapter = MagicMock() |
1604 | 156 | test_chapter.__iter__.return_value = [test_verse] | 157 | test_chapter.__iter__.return_value = [test_verse] |
1605 | 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) |
1607 | 158 | importer = OSISBible(MagicMock(), path='.', name='.', filename='') | 159 | importer = OSISBible(MagicMock(), path='.', name='.', file_path=None) |
1608 | 159 | 160 | ||
1609 | 160 | # WHEN: Calling process_chapters | 161 | # WHEN: Calling process_chapters |
1610 | 161 | importer.process_chapters(test_book, [test_chapter]) | 162 | importer.process_chapters(test_book, [test_chapter]) |
1611 | @@ -180,7 +181,7 @@ | |||
1612 | 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) |
1613 | 181 | 182 | ||
1614 | 182 | # WHEN: Calling process_chapters | 183 | # WHEN: Calling process_chapters |
1616 | 183 | importer = OSISBible(MagicMock(), path='.', name='.', filename='') | 184 | importer = OSISBible(MagicMock(), path='.', name='.', file_path=None) |
1617 | 184 | importer.process_chapters(test_book, [test_chapter]) | 185 | importer.process_chapters(test_book, [test_chapter]) |
1618 | 185 | 186 | ||
1619 | 186 | # THEN: neither set_current_chapter or process_verse should have been called | 187 | # THEN: neither set_current_chapter or process_verse should have been called |
1620 | @@ -201,7 +202,7 @@ | |||
1621 | 201 | test_chapter = MagicMock() | 202 | test_chapter = MagicMock() |
1622 | 202 | test_chapter.tag = '{http://www.bibletechnologies.net/2003/OSIS/namespace}chapter' | 203 | test_chapter.tag = '{http://www.bibletechnologies.net/2003/OSIS/namespace}chapter' |
1623 | 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) |
1625 | 204 | importer = OSISBible(MagicMock(), path='.', name='.', filename='') | 205 | importer = OSISBible(MagicMock(), path='.', name='.', file_path=None) |
1626 | 205 | 206 | ||
1627 | 206 | # WHEN: Calling process_chapters | 207 | # WHEN: Calling process_chapters |
1628 | 207 | importer.process_chapters(test_book, [test_chapter]) | 208 | importer.process_chapters(test_book, [test_chapter]) |
1629 | @@ -228,7 +229,7 @@ | |||
1630 | 228 | test_verse.text = 'Verse Text' | 229 | test_verse.text = 'Verse Text' |
1631 | 229 | 230 | ||
1632 | 230 | # WHEN: Calling process_chapters | 231 | # WHEN: Calling process_chapters |
1634 | 231 | importer = OSISBible(MagicMock(), path='.', name='.', filename='') | 232 | importer = OSISBible(MagicMock(), path='.', name='.', file_path=None) |
1635 | 232 | importer.process_chapters(test_book, [test_verse]) | 233 | importer.process_chapters(test_book, [test_verse]) |
1636 | 233 | 234 | ||
1637 | 234 | # THEN: process_verse should have been called with the test data | 235 | # THEN: process_verse should have been called with the test data |
1638 | @@ -245,7 +246,7 @@ | |||
1639 | 245 | test_verse.get.side_effect = lambda x: {}.get(x) | 246 | test_verse.get.side_effect = lambda x: {}.get(x) |
1640 | 246 | test_verse.tail = 'Verse Text' | 247 | test_verse.tail = 'Verse Text' |
1641 | 247 | test_verse.text = None | 248 | test_verse.text = None |
1643 | 248 | importer = OSISBible(MagicMock(), path='.', name='.', filename='') | 249 | importer = OSISBible(MagicMock(), path='.', name='.', file_path=None) |
1644 | 249 | 250 | ||
1645 | 250 | # WHEN: Calling process_verse with the test data | 251 | # WHEN: Calling process_verse with the test data |
1646 | 251 | importer.process_verse(test_book, 2, test_verse) | 252 | importer.process_verse(test_book, 2, test_verse) |
1647 | @@ -264,7 +265,7 @@ | |||
1648 | 264 | test_verse.get.side_effect = lambda x: {}.get(x) | 265 | test_verse.get.side_effect = lambda x: {}.get(x) |
1649 | 265 | test_verse.tail = 'Verse Text' | 266 | test_verse.tail = 'Verse Text' |
1650 | 266 | test_verse.text = None | 267 | test_verse.text = None |
1652 | 267 | importer = OSISBible(MagicMock(), path='.', name='.', filename='') | 268 | importer = OSISBible(MagicMock(), path='.', name='.', file_path=None) |
1653 | 268 | 269 | ||
1654 | 269 | # WHEN: Calling process_verse with the test data | 270 | # WHEN: Calling process_verse with the test data |
1655 | 270 | importer.process_verse(test_book, 2, test_verse) | 271 | importer.process_verse(test_book, 2, test_verse) |
1656 | @@ -282,7 +283,7 @@ | |||
1657 | 282 | test_verse.tail = None | 283 | test_verse.tail = None |
1658 | 283 | test_verse.text = None | 284 | test_verse.text = None |
1659 | 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) |
1661 | 285 | importer = OSISBible(MagicMock(), path='.', name='.', filename='') | 286 | importer = OSISBible(MagicMock(), path='.', name='.', file_path=None) |
1662 | 286 | 287 | ||
1663 | 287 | # WHEN: Calling process_verse with the test data | 288 | # WHEN: Calling process_verse with the test data |
1664 | 288 | importer.process_verse(test_book, 2, test_verse, use_milestones=True) | 289 | importer.process_verse(test_book, 2, test_verse, use_milestones=True) |
1665 | @@ -301,7 +302,7 @@ | |||
1666 | 301 | test_verse.tail = 'Verse Text' | 302 | test_verse.tail = 'Verse Text' |
1667 | 302 | test_verse.text = None | 303 | test_verse.text = None |
1668 | 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) |
1670 | 304 | importer = OSISBible(MagicMock(), path='.', name='.', filename='') | 305 | importer = OSISBible(MagicMock(), path='.', name='.', file_path=None) |
1671 | 305 | 306 | ||
1672 | 306 | # WHEN: Calling process_verse with the test data | 307 | # WHEN: Calling process_verse with the test data |
1673 | 307 | importer.process_verse(test_book, 2, test_verse, use_milestones=True) | 308 | importer.process_verse(test_book, 2, test_verse, use_milestones=True) |
1674 | @@ -320,7 +321,7 @@ | |||
1675 | 320 | test_verse.tail = '\n ' # Whitespace | 321 | test_verse.tail = '\n ' # Whitespace |
1676 | 321 | test_verse.text = None | 322 | test_verse.text = None |
1677 | 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) |
1679 | 323 | importer = OSISBible(MagicMock(), path='.', name='.', filename='') | 324 | importer = OSISBible(MagicMock(), path='.', name='.', file_path=None) |
1680 | 324 | 325 | ||
1681 | 325 | # WHEN: Calling process_verse with the test data | 326 | # WHEN: Calling process_verse with the test data |
1682 | 326 | importer.process_verse(test_book, 2, test_verse) | 327 | importer.process_verse(test_book, 2, test_verse) |
1683 | @@ -339,7 +340,7 @@ | |||
1684 | 339 | test_verse.tail = '\n ' # Whitespace | 340 | test_verse.tail = '\n ' # Whitespace |
1685 | 340 | test_verse.text = 'Verse Text' | 341 | test_verse.text = 'Verse Text' |
1686 | 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) |
1688 | 342 | importer = OSISBible(MagicMock(), path='.', name='.', filename='') | 343 | importer = OSISBible(MagicMock(), path='.', name='.', file_path=None) |
1689 | 343 | 344 | ||
1690 | 344 | # WHEN: Calling process_verse with the test data | 345 | # WHEN: Calling process_verse with the test data |
1691 | 345 | importer.process_verse(test_book, 2, test_verse) | 346 | importer.process_verse(test_book, 2, test_verse) |
1692 | @@ -356,7 +357,7 @@ | |||
1693 | 356 | patch.object(OSISBible, 'validate_xml_file'), \ | 357 | patch.object(OSISBible, 'validate_xml_file'), \ |
1694 | 357 | patch.object(OSISBible, 'parse_xml', return_value=None), \ | 358 | patch.object(OSISBible, 'parse_xml', return_value=None), \ |
1695 | 358 | patch.object(OSISBible, 'get_language_id') as mocked_language_id: | 359 | patch.object(OSISBible, 'get_language_id') as mocked_language_id: |
1697 | 359 | importer = OSISBible(MagicMock(), path='.', name='.', filename='') | 360 | importer = OSISBible(MagicMock(), path='.', name='.', file_path=None) |
1698 | 360 | 361 | ||
1699 | 361 | # WHEN: Calling do_import | 362 | # WHEN: Calling do_import |
1700 | 362 | result = importer.do_import() | 363 | result = importer.do_import() |
1701 | @@ -375,7 +376,7 @@ | |||
1702 | 375 | patch.object(OSISBible, 'parse_xml'), \ | 376 | patch.object(OSISBible, 'parse_xml'), \ |
1703 | 376 | patch.object(OSISBible, 'get_language_id', **{'return_value': False}), \ | 377 | patch.object(OSISBible, 'get_language_id', **{'return_value': False}), \ |
1704 | 377 | patch.object(OSISBible, 'process_books') as mocked_process_books: | 378 | patch.object(OSISBible, 'process_books') as mocked_process_books: |
1706 | 378 | importer = OSISBible(MagicMock(), path='.', name='.', filename='') | 379 | importer = OSISBible(MagicMock(), path='.', name='.', file_path=None) |
1707 | 379 | 380 | ||
1708 | 380 | # WHEN: Calling do_import | 381 | # WHEN: Calling do_import |
1709 | 381 | result = importer.do_import() | 382 | result = importer.do_import() |
1710 | @@ -394,7 +395,7 @@ | |||
1711 | 394 | patch.object(OSISBible, 'parse_xml'), \ | 395 | patch.object(OSISBible, 'parse_xml'), \ |
1712 | 395 | patch.object(OSISBible, 'get_language_id', **{'return_value': 10}), \ | 396 | patch.object(OSISBible, 'get_language_id', **{'return_value': 10}), \ |
1713 | 396 | patch.object(OSISBible, 'process_books'): | 397 | patch.object(OSISBible, 'process_books'): |
1715 | 397 | importer = OSISBible(MagicMock(), path='.', name='.', filename='') | 398 | importer = OSISBible(MagicMock(), path='.', name='.', file_path=None) |
1716 | 398 | 399 | ||
1717 | 399 | # WHEN: Calling do_import | 400 | # WHEN: Calling do_import |
1718 | 400 | result = importer.do_import() | 401 | result = importer.do_import() |
1719 | @@ -427,7 +428,7 @@ | |||
1720 | 427 | with patch('openlp.plugins.bibles.lib.importers.osis.OSISBible.application'): | 428 | with patch('openlp.plugins.bibles.lib.importers.osis.OSISBible.application'): |
1721 | 428 | mocked_manager = MagicMock() | 429 | mocked_manager = MagicMock() |
1722 | 429 | mocked_import_wizard = MagicMock() | 430 | mocked_import_wizard = MagicMock() |
1724 | 430 | importer = OSISBible(mocked_manager, path='.', name='.', filename='') | 431 | importer = OSISBible(mocked_manager, path='.', name='.', file_path=None) |
1725 | 431 | importer.wizard = mocked_import_wizard | 432 | importer.wizard = mocked_import_wizard |
1726 | 432 | importer.get_book_ref_id_by_name = MagicMock() | 433 | importer.get_book_ref_id_by_name = MagicMock() |
1727 | 433 | importer.create_verse = MagicMock() | 434 | importer.create_verse = MagicMock() |
1728 | @@ -437,7 +438,7 @@ | |||
1729 | 437 | importer.get_language.return_value = 'Danish' | 438 | importer.get_language.return_value = 'Danish' |
1730 | 438 | 439 | ||
1731 | 439 | # WHEN: Importing bible file | 440 | # WHEN: Importing bible file |
1733 | 440 | importer.filename = os.path.join(TEST_PATH, bible_file) | 441 | importer.file_path = Path(TEST_PATH, bible_file) |
1734 | 441 | importer.do_import() | 442 | importer.do_import() |
1735 | 442 | 443 | ||
1736 | 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. |
1737 | @@ -457,7 +458,7 @@ | |||
1738 | 457 | with patch('openlp.plugins.bibles.lib.importers.osis.OSISBible.application'): | 458 | with patch('openlp.plugins.bibles.lib.importers.osis.OSISBible.application'): |
1739 | 458 | mocked_manager = MagicMock() | 459 | mocked_manager = MagicMock() |
1740 | 459 | mocked_import_wizard = MagicMock() | 460 | mocked_import_wizard = MagicMock() |
1742 | 460 | importer = OSISBible(mocked_manager, path='.', name='.', filename='') | 461 | importer = OSISBible(mocked_manager, path='.', name='.', file_path=None) |
1743 | 461 | importer.wizard = mocked_import_wizard | 462 | importer.wizard = mocked_import_wizard |
1744 | 462 | importer.get_book_ref_id_by_name = MagicMock() | 463 | importer.get_book_ref_id_by_name = MagicMock() |
1745 | 463 | importer.create_verse = MagicMock() | 464 | importer.create_verse = MagicMock() |
1746 | @@ -467,7 +468,7 @@ | |||
1747 | 467 | importer.get_language.return_value = 'English' | 468 | importer.get_language.return_value = 'English' |
1748 | 468 | 469 | ||
1749 | 469 | # WHEN: Importing bible file | 470 | # WHEN: Importing bible file |
1751 | 470 | importer.filename = os.path.join(TEST_PATH, bible_file) | 471 | importer.file_path = Path(TEST_PATH, bible_file) |
1752 | 471 | importer.do_import() | 472 | importer.do_import() |
1753 | 472 | 473 | ||
1754 | 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. |
1755 | @@ -487,7 +488,7 @@ | |||
1756 | 487 | with patch('openlp.plugins.bibles.lib.importers.osis.OSISBible.application'): | 488 | with patch('openlp.plugins.bibles.lib.importers.osis.OSISBible.application'): |
1757 | 488 | mocked_manager = MagicMock() | 489 | mocked_manager = MagicMock() |
1758 | 489 | mocked_import_wizard = MagicMock() | 490 | mocked_import_wizard = MagicMock() |
1760 | 490 | importer = OSISBible(mocked_manager, path='.', name='.', filename='') | 491 | importer = OSISBible(mocked_manager, path='.', name='.', file_path=None) |
1761 | 491 | importer.wizard = mocked_import_wizard | 492 | importer.wizard = mocked_import_wizard |
1762 | 492 | importer.get_book_ref_id_by_name = MagicMock() | 493 | importer.get_book_ref_id_by_name = MagicMock() |
1763 | 493 | importer.create_verse = MagicMock() | 494 | importer.create_verse = MagicMock() |
1764 | @@ -497,7 +498,7 @@ | |||
1765 | 497 | importer.get_language.return_value = 'English' | 498 | importer.get_language.return_value = 'English' |
1766 | 498 | 499 | ||
1767 | 499 | # WHEN: Importing bible file | 500 | # WHEN: Importing bible file |
1769 | 500 | importer.filename = os.path.join(TEST_PATH, bible_file) | 501 | importer.file_path = Path(TEST_PATH, bible_file) |
1770 | 501 | importer.do_import() | 502 | importer.do_import() |
1771 | 502 | 503 | ||
1772 | 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. |
1773 | @@ -517,7 +518,7 @@ | |||
1774 | 517 | with patch('openlp.plugins.bibles.lib.importers.osis.OSISBible.application'): | 518 | with patch('openlp.plugins.bibles.lib.importers.osis.OSISBible.application'): |
1775 | 518 | mocked_manager = MagicMock() | 519 | mocked_manager = MagicMock() |
1776 | 519 | mocked_import_wizard = MagicMock() | 520 | mocked_import_wizard = MagicMock() |
1778 | 520 | importer = OSISBible(mocked_manager, path='.', name='.', filename='') | 521 | importer = OSISBible(mocked_manager, path='.', name='.', file_path=None) |
1779 | 521 | importer.wizard = mocked_import_wizard | 522 | importer.wizard = mocked_import_wizard |
1780 | 522 | importer.get_book_ref_id_by_name = MagicMock() | 523 | importer.get_book_ref_id_by_name = MagicMock() |
1781 | 523 | importer.create_verse = MagicMock() | 524 | importer.create_verse = MagicMock() |
1782 | @@ -527,7 +528,7 @@ | |||
1783 | 527 | importer.get_language.return_value = 'Danish' | 528 | importer.get_language.return_value = 'Danish' |
1784 | 528 | 529 | ||
1785 | 529 | # WHEN: Importing bible file | 530 | # WHEN: Importing bible file |
1787 | 530 | importer.filename = os.path.join(TEST_PATH, bible_file) | 531 | importer.file_path = Path(TEST_PATH, bible_file) |
1788 | 531 | importer.do_import() | 532 | importer.do_import() |
1789 | 532 | 533 | ||
1790 | 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. |
1791 | 534 | 535 | ||
1792 | === modified file 'tests/functional/openlp_plugins/bibles/test_swordimport.py' | |||
1793 | --- tests/functional/openlp_plugins/bibles/test_swordimport.py 2017-04-24 05:17:55 +0000 | |||
1794 | +++ tests/functional/openlp_plugins/bibles/test_swordimport.py 2017-11-14 23:03:10 +0000 | |||
1795 | @@ -64,7 +64,7 @@ | |||
1796 | 64 | mocked_manager = MagicMock() | 64 | mocked_manager = MagicMock() |
1797 | 65 | 65 | ||
1798 | 66 | # WHEN: An importer object is created | 66 | # WHEN: An importer object is created |
1800 | 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='') |
1801 | 68 | 68 | ||
1802 | 69 | # THEN: The importer should be an instance of BibleDB | 69 | # THEN: The importer should be an instance of BibleDB |
1803 | 70 | self.assertIsInstance(importer, BibleDB) | 70 | self.assertIsInstance(importer, BibleDB) |
1804 | @@ -80,7 +80,7 @@ | |||
1805 | 80 | # Also mocked pysword structures | 80 | # Also mocked pysword structures |
1806 | 81 | mocked_manager = MagicMock() | 81 | mocked_manager = MagicMock() |
1807 | 82 | mocked_import_wizard = MagicMock() | 82 | mocked_import_wizard = MagicMock() |
1809 | 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='') |
1810 | 84 | result_file = open(os.path.join(TEST_PATH, 'dk1933.json'), 'rb') | 84 | result_file = open(os.path.join(TEST_PATH, 'dk1933.json'), 'rb') |
1811 | 85 | test_data = json.loads(result_file.read().decode()) | 85 | test_data = json.loads(result_file.read().decode()) |
1812 | 86 | importer.wizard = mocked_import_wizard | 86 | importer.wizard = mocked_import_wizard |
1813 | 87 | 87 | ||
1814 | === modified file 'tests/functional/openlp_plugins/bibles/test_wordprojectimport.py' | |||
1815 | --- tests/functional/openlp_plugins/bibles/test_wordprojectimport.py 2017-04-24 05:17:55 +0000 | |||
1816 | +++ tests/functional/openlp_plugins/bibles/test_wordprojectimport.py 2017-11-14 23:03:10 +0000 | |||
1817 | @@ -26,6 +26,7 @@ | |||
1818 | 26 | from unittest import TestCase | 26 | from unittest import TestCase |
1819 | 27 | from unittest.mock import MagicMock, patch, call | 27 | from unittest.mock import MagicMock, patch, call |
1820 | 28 | 28 | ||
1821 | 29 | from openlp.core.common.path import Path | ||
1822 | 29 | from openlp.plugins.bibles.lib.importers.wordproject import WordProjectBible | 30 | from openlp.plugins.bibles.lib.importers.wordproject import WordProjectBible |
1823 | 30 | 31 | ||
1824 | 31 | 32 | ||
1825 | @@ -48,19 +49,17 @@ | |||
1826 | 48 | self.addCleanup(self.manager_patcher.stop) | 49 | self.addCleanup(self.manager_patcher.stop) |
1827 | 49 | self.manager_patcher.start() | 50 | self.manager_patcher.start() |
1828 | 50 | 51 | ||
1832 | 51 | @patch('openlp.plugins.bibles.lib.importers.wordproject.os') | 52 | @patch.object(Path, 'read_text') |
1833 | 52 | @patch('openlp.plugins.bibles.lib.importers.wordproject.copen') | 53 | def test_process_books(self, mocked_read_text): |
1831 | 53 | def test_process_books(self, mocked_open, mocked_os): | ||
1834 | 54 | """ | 54 | """ |
1835 | 55 | Test the process_books() method | 55 | Test the process_books() method |
1836 | 56 | """ | 56 | """ |
1837 | 57 | # GIVEN: A WordProject importer and a bunch of mocked things | 57 | # GIVEN: A WordProject importer and a bunch of mocked things |
1840 | 58 | importer = WordProjectBible(MagicMock(), path='.', name='.', filename='kj.zip') | 58 | importer = WordProjectBible(MagicMock(), path='.', name='.', file_path=Path('kj.zip')) |
1841 | 59 | importer.base_dir = '' | 59 | importer.base_path = Path() |
1842 | 60 | importer.stop_import_flag = False | 60 | importer.stop_import_flag = False |
1843 | 61 | importer.language_id = 'en' | 61 | importer.language_id = 'en' |
1846 | 62 | mocked_open.return_value.__enter__.return_value.read.return_value = INDEX_PAGE | 62 | mocked_read_text.return_value = INDEX_PAGE |
1845 | 63 | mocked_os.path.join.side_effect = lambda *x: ''.join(x) | ||
1847 | 64 | 63 | ||
1848 | 65 | # WHEN: process_books() is called | 64 | # WHEN: process_books() is called |
1849 | 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, \ |
1850 | @@ -69,26 +68,22 @@ | |||
1851 | 69 | importer.process_books() | 68 | importer.process_books() |
1852 | 70 | 69 | ||
1853 | 71 | # THEN: The right methods should have been called | 70 | # THEN: The right methods should have been called |
1856 | 72 | mocked_os.path.join.assert_called_once_with('', 'index.htm') | 71 | mocked_read_text.assert_called_once_with(encoding='utf-8', errors='ignore') |
1855 | 73 | mocked_open.assert_called_once_with('index.htm', encoding='utf-8', errors='ignore') | ||
1857 | 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' |
1858 | 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' |
1859 | 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' |
1860 | 77 | 75 | ||
1864 | 78 | @patch('openlp.plugins.bibles.lib.importers.wordproject.os') | 76 | @patch.object(Path, 'read_text') |
1865 | 79 | @patch('openlp.plugins.bibles.lib.importers.wordproject.copen') | 77 | def test_process_chapters(self, mocked_read_text): |
1863 | 80 | def test_process_chapters(self, mocked_open, mocked_os): | ||
1866 | 81 | """ | 78 | """ |
1867 | 82 | Test the process_chapters() method | 79 | Test the process_chapters() method |
1868 | 83 | """ | 80 | """ |
1869 | 84 | # GIVEN: A WordProject importer and a bunch of mocked things | 81 | # GIVEN: A WordProject importer and a bunch of mocked things |
1872 | 85 | importer = WordProjectBible(MagicMock(), path='.', name='.', filename='kj.zip') | 82 | importer = WordProjectBible(MagicMock(), path='.', name='.', file_path=Path('kj.zip')) |
1873 | 86 | importer.base_dir = '' | 83 | importer.base_path = Path() |
1874 | 87 | importer.stop_import_flag = False | 84 | importer.stop_import_flag = False |
1875 | 88 | importer.language_id = 'en' | 85 | importer.language_id = 'en' |
1879 | 89 | mocked_open.return_value.__enter__.return_value.read.return_value = CHAPTER_PAGE | 86 | mocked_read_text.return_value = CHAPTER_PAGE |
1877 | 90 | mocked_os.path.join.side_effect = lambda *x: ''.join(x) | ||
1878 | 91 | mocked_os.path.normpath.side_effect = lambda x: x | ||
1880 | 92 | mocked_db_book = MagicMock() | 87 | mocked_db_book = MagicMock() |
1881 | 93 | mocked_db_book.name = 'Genesis' | 88 | mocked_db_book.name = 'Genesis' |
1882 | 94 | book_id = 1 | 89 | book_id = 1 |
1883 | @@ -102,24 +97,21 @@ | |||
1884 | 102 | # THEN: The right methods should have been called | 97 | # THEN: The right methods should have been called |
1885 | 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)] |
1886 | 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)] |
1889 | 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') |
1888 | 106 | mocked_open.assert_called_once_with('01/1.htm', encoding='utf-8', errors='ignore') | ||
1890 | 107 | assert mocked_set_current_chapter.call_args_list == expected_set_current_chapter_calls | 101 | assert mocked_set_current_chapter.call_args_list == expected_set_current_chapter_calls |
1891 | 108 | assert mocked_process_verses.call_args_list == expected_process_verses_calls | 102 | assert mocked_process_verses.call_args_list == expected_process_verses_calls |
1892 | 109 | 103 | ||
1896 | 110 | @patch('openlp.plugins.bibles.lib.importers.wordproject.os') | 104 | @patch.object(Path, 'read_text') |
1897 | 111 | @patch('openlp.plugins.bibles.lib.importers.wordproject.copen') | 105 | def test_process_verses(self, mocked_read_text): |
1895 | 112 | def test_process_verses(self, mocked_open, mocked_os): | ||
1898 | 113 | """ | 106 | """ |
1899 | 114 | Test the process_verses() method | 107 | Test the process_verses() method |
1900 | 115 | """ | 108 | """ |
1901 | 116 | # GIVEN: A WordProject importer and a bunch of mocked things | 109 | # GIVEN: A WordProject importer and a bunch of mocked things |
1904 | 117 | importer = WordProjectBible(MagicMock(), path='.', name='.', filename='kj.zip') | 110 | importer = WordProjectBible(MagicMock(), path='.', name='.', file_path=Path('kj.zip')) |
1905 | 118 | importer.base_dir = '' | 111 | importer.base_path = Path() |
1906 | 119 | importer.stop_import_flag = False | 112 | importer.stop_import_flag = False |
1907 | 120 | importer.language_id = 'en' | 113 | importer.language_id = 'en' |
1910 | 121 | mocked_open.return_value.__enter__.return_value.read.return_value = CHAPTER_PAGE | 114 | mocked_read_text.return_value = CHAPTER_PAGE |
1909 | 122 | mocked_os.path.join.side_effect = lambda *x: '/'.join(x) | ||
1911 | 123 | mocked_db_book = MagicMock() | 115 | mocked_db_book = MagicMock() |
1912 | 124 | mocked_db_book.name = 'Genesis' | 116 | mocked_db_book.name = 'Genesis' |
1913 | 125 | book_number = 1 | 117 | book_number = 1 |
1914 | @@ -130,8 +122,7 @@ | |||
1915 | 130 | importer.process_verses(mocked_db_book, book_number, chapter_number) | 122 | importer.process_verses(mocked_db_book, book_number, chapter_number) |
1916 | 131 | 123 | ||
1917 | 132 | # THEN: All the right methods should have been called | 124 | # THEN: All the right methods should have been called |
1920 | 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') |
1919 | 134 | mocked_open.assert_called_once_with('/01/1.htm', encoding='utf-8', errors='ignore') | ||
1921 | 135 | assert mocked_process_verse.call_count == 31 | 126 | assert mocked_process_verse.call_count == 31 |
1922 | 136 | 127 | ||
1923 | 137 | def test_process_verse(self): | 128 | def test_process_verse(self): |
1924 | @@ -139,7 +130,7 @@ | |||
1925 | 139 | Test the process_verse() method | 130 | Test the process_verse() method |
1926 | 140 | """ | 131 | """ |
1927 | 141 | # GIVEN: An importer and a mocked method | 132 | # GIVEN: An importer and a mocked method |
1929 | 142 | importer = WordProjectBible(MagicMock(), path='.', name='.', filename='kj.zip') | 133 | importer = WordProjectBible(MagicMock(), path='.', name='.', file_path=Path('kj.zip')) |
1930 | 143 | mocked_db_book = MagicMock() | 134 | mocked_db_book = MagicMock() |
1931 | 144 | mocked_db_book.id = 1 | 135 | mocked_db_book.id = 1 |
1932 | 145 | chapter_number = 1 | 136 | chapter_number = 1 |
1933 | @@ -158,7 +149,7 @@ | |||
1934 | 158 | Test the process_verse() method when there's no text | 149 | Test the process_verse() method when there's no text |
1935 | 159 | """ | 150 | """ |
1936 | 160 | # GIVEN: An importer and a mocked method | 151 | # GIVEN: An importer and a mocked method |
1938 | 161 | importer = WordProjectBible(MagicMock(), path='.', name='.', filename='kj.zip') | 152 | importer = WordProjectBible(MagicMock(), path='.', name='.', file_path=Path('kj.zip')) |
1939 | 162 | mocked_db_book = MagicMock() | 153 | mocked_db_book = MagicMock() |
1940 | 163 | mocked_db_book.id = 1 | 154 | mocked_db_book.id = 1 |
1941 | 164 | chapter_number = 1 | 155 | chapter_number = 1 |
1942 | @@ -177,7 +168,7 @@ | |||
1943 | 177 | Test the do_import() method | 168 | Test the do_import() method |
1944 | 178 | """ | 169 | """ |
1945 | 179 | # GIVEN: An importer and mocked methods | 170 | # GIVEN: An importer and mocked methods |
1947 | 180 | importer = WordProjectBible(MagicMock(), path='.', name='.', filename='kj.zip') | 171 | importer = WordProjectBible(MagicMock(), path='.', name='.', file_path='kj.zip') |
1948 | 181 | 172 | ||
1949 | 182 | # WHEN: do_import() is called | 173 | # WHEN: do_import() is called |
1950 | 183 | with patch.object(importer, '_unzip_file') as mocked_unzip_file, \ | 174 | with patch.object(importer, '_unzip_file') as mocked_unzip_file, \ |
1951 | @@ -199,7 +190,7 @@ | |||
1952 | 199 | Test the do_import() method when the language is not available | 190 | Test the do_import() method when the language is not available |
1953 | 200 | """ | 191 | """ |
1954 | 201 | # GIVEN: An importer and mocked methods | 192 | # GIVEN: An importer and mocked methods |
1956 | 202 | importer = WordProjectBible(MagicMock(), path='.', name='.', filename='kj.zip') | 193 | importer = WordProjectBible(MagicMock(), path='.', name='.', file_path='kj.zip') |
1957 | 203 | 194 | ||
1958 | 204 | # WHEN: do_import() is called | 195 | # WHEN: do_import() is called |
1959 | 205 | with patch.object(importer, '_unzip_file') as mocked_unzip_file, \ | 196 | with patch.object(importer, '_unzip_file') as mocked_unzip_file, \ |
1960 | 206 | 197 | ||
1961 | === modified file 'tests/functional/openlp_plugins/bibles/test_zefaniaimport.py' | |||
1962 | --- tests/functional/openlp_plugins/bibles/test_zefaniaimport.py 2017-04-24 05:17:55 +0000 | |||
1963 | +++ tests/functional/openlp_plugins/bibles/test_zefaniaimport.py 2017-11-14 23:03:10 +0000 | |||
1964 | @@ -27,6 +27,7 @@ | |||
1965 | 27 | from unittest import TestCase | 27 | from unittest import TestCase |
1966 | 28 | from unittest.mock import MagicMock, patch | 28 | from unittest.mock import MagicMock, patch |
1967 | 29 | 29 | ||
1968 | 30 | from openlp.core.common.path import Path | ||
1969 | 30 | from openlp.plugins.bibles.lib.importers.zefania import ZefaniaBible | 31 | from openlp.plugins.bibles.lib.importers.zefania import ZefaniaBible |
1970 | 31 | from openlp.plugins.bibles.lib.db import BibleDB | 32 | from openlp.plugins.bibles.lib.db import BibleDB |
1971 | 32 | 33 | ||
1972 | @@ -55,7 +56,7 @@ | |||
1973 | 55 | mocked_manager = MagicMock() | 56 | mocked_manager = MagicMock() |
1974 | 56 | 57 | ||
1975 | 57 | # WHEN: An importer object is created | 58 | # WHEN: An importer object is created |
1977 | 58 | importer = ZefaniaBible(mocked_manager, path='.', name='.', filename='') | 59 | importer = ZefaniaBible(mocked_manager, path='.', name='.', file_path=None) |
1978 | 59 | 60 | ||
1979 | 60 | # THEN: The importer should be an instance of BibleDB | 61 | # THEN: The importer should be an instance of BibleDB |
1980 | 61 | self.assertIsInstance(importer, BibleDB) | 62 | self.assertIsInstance(importer, BibleDB) |
1981 | @@ -72,7 +73,7 @@ | |||
1982 | 72 | with patch('openlp.plugins.bibles.lib.importers.zefania.ZefaniaBible.application'): | 73 | with patch('openlp.plugins.bibles.lib.importers.zefania.ZefaniaBible.application'): |
1983 | 73 | mocked_manager = MagicMock() | 74 | mocked_manager = MagicMock() |
1984 | 74 | mocked_import_wizard = MagicMock() | 75 | mocked_import_wizard = MagicMock() |
1986 | 75 | importer = ZefaniaBible(mocked_manager, path='.', name='.', filename='') | 76 | importer = ZefaniaBible(mocked_manager, path='.', name='.', file_path=None) |
1987 | 76 | importer.wizard = mocked_import_wizard | 77 | importer.wizard = mocked_import_wizard |
1988 | 77 | importer.create_verse = MagicMock() | 78 | importer.create_verse = MagicMock() |
1989 | 78 | importer.create_book = MagicMock() | 79 | importer.create_book = MagicMock() |
1990 | @@ -81,7 +82,7 @@ | |||
1991 | 81 | importer.get_language.return_value = 'Danish' | 82 | importer.get_language.return_value = 'Danish' |
1992 | 82 | 83 | ||
1993 | 83 | # WHEN: Importing bible file | 84 | # WHEN: Importing bible file |
1995 | 84 | importer.filename = os.path.join(TEST_PATH, bible_file) | 85 | importer.file_path = Path(TEST_PATH, bible_file) |
1996 | 85 | importer.do_import() | 86 | importer.do_import() |
1997 | 86 | 87 | ||
1998 | 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. |
1999 | @@ -102,7 +103,7 @@ | |||
2000 | 102 | with patch('openlp.plugins.bibles.lib.importers.zefania.ZefaniaBible.application'): | 103 | with patch('openlp.plugins.bibles.lib.importers.zefania.ZefaniaBible.application'): |
2001 | 103 | mocked_manager = MagicMock() | 104 | mocked_manager = MagicMock() |
2002 | 104 | mocked_import_wizard = MagicMock() | 105 | mocked_import_wizard = MagicMock() |
2004 | 105 | importer = ZefaniaBible(mocked_manager, path='.', name='.', filename='') | 106 | importer = ZefaniaBible(mocked_manager, path='.', name='.', file_path=None) |
2005 | 106 | importer.wizard = mocked_import_wizard | 107 | importer.wizard = mocked_import_wizard |
2006 | 107 | importer.create_verse = MagicMock() | 108 | importer.create_verse = MagicMock() |
2007 | 108 | importer.create_book = MagicMock() | 109 | importer.create_book = MagicMock() |
2008 | @@ -111,7 +112,7 @@ | |||
2009 | 111 | importer.get_language.return_value = 'Russian' | 112 | importer.get_language.return_value = 'Russian' |
2010 | 112 | 113 | ||
2011 | 113 | # WHEN: Importing bible file | 114 | # WHEN: Importing bible file |
2013 | 114 | importer.filename = os.path.join(TEST_PATH, bible_file) | 115 | importer.file_path = Path(TEST_PATH, bible_file) |
2014 | 115 | importer.do_import() | 116 | importer.do_import() |
2015 | 116 | 117 | ||
2016 | 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. |
Superfly, when you get a mo, could you tell me if 1048, 1828, 1860, 1892 are acceptable, or if I've got it wrong?