Merge lp:~phill-ridout/openlp/bible_proxies into lp:openlp
- bible_proxies
- Merge into trunk
Status: | Merged |
---|---|
Merged at revision: | 2837 |
Proposed branch: | lp:~phill-ridout/openlp/bible_proxies |
Merge into: | lp:openlp |
Diff against target: |
611 lines (+304/-101) 8 files modified
openlp/core/common/settings.py (+5/-1) openlp/plugins/bibles/bibleplugin.py (+0/-4) openlp/plugins/bibles/forms/bibleimportform.py (+11/-53) openlp/plugins/bibles/lib/db.py (+4/-5) openlp/plugins/bibles/lib/importers/http.py (+12/-33) openlp/plugins/bibles/lib/manager.py (+0/-4) openlp/plugins/bibles/lib/upgrade.py (+54/-1) tests/functional/openlp_plugins/bibles/test_upgrade.py (+218/-0) |
To merge this branch: | bzr merge lp:~phill-ridout/openlp/bible_proxies |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Tomas Groth | Approve | ||
Review via email: mp+357662@code.launchpad.net |
Commit message
Migrate bibles to use the centeral proxy settings. Upgrade settings and bible meta data accordingly.
Add this to your merge proposal:
-------
lp:~phill-ridout/openlp/bible_proxies (revision 2835)
https:/
[RUNNING]
[SUCCESS]
https:/
[RUNNING]
[SUCCESS]
https:/
[SUCCESS]
https:/
[SUCCESS]
https:/
[FAILURE]
https:/
[RUNNING]
[SUCCESS]
https:/
[RUNNING]
[SUCCESS]
https:/
[RUNNING]
[FAILURE]
Failed builds:
- Branch-
- Branch-
Description of the change
Raoul Snyman (raoul-snyman) wrote : | # |
Raoul Snyman (raoul-snyman) wrote : | # |
Linting passed!
Tomas Groth (tomasgroth) wrote : | # |
Looks, though I haven't actually tested...
Preview Diff
1 | === modified file 'openlp/core/common/settings.py' |
2 | --- openlp/core/common/settings.py 2018-06-07 17:44:35 +0000 |
3 | +++ openlp/core/common/settings.py 2018-10-22 20:55:00 +0000 |
4 | @@ -274,7 +274,11 @@ |
5 | ('songuasge/db password', 'songusage/db password', []), |
6 | ('songuasge/db hostname', 'songusage/db hostname', []), |
7 | ('songuasge/db database', 'songusage/db database', []), |
8 | - ('presentations / Powerpoint Viewer', '', []) |
9 | + ('presentations / Powerpoint Viewer', '', []), |
10 | + ('bibles/proxy name', '', []), # Just remove these bible proxy settings. They weren't used in 2.4! |
11 | + ('bibles/proxy address', '', []), |
12 | + ('bibles/proxy username', '', []), |
13 | + ('bibles/proxy password', '', []) |
14 | ] |
15 | |
16 | @staticmethod |
17 | |
18 | === modified file 'openlp/plugins/bibles/bibleplugin.py' |
19 | --- openlp/plugins/bibles/bibleplugin.py 2018-08-25 14:08:19 +0000 |
20 | +++ openlp/plugins/bibles/bibleplugin.py 2018-10-22 20:55:00 +0000 |
21 | @@ -52,10 +52,6 @@ |
22 | 'bibles/display new chapter': False, |
23 | 'bibles/second bibles': True, |
24 | 'bibles/primary bible': '', |
25 | - 'bibles/proxy name': '', |
26 | - 'bibles/proxy address': '', |
27 | - 'bibles/proxy username': '', |
28 | - 'bibles/proxy password': '', |
29 | 'bibles/bible theme': '', |
30 | 'bibles/verse separator': '', |
31 | 'bibles/range separator': '', |
32 | |
33 | === modified file 'openlp/plugins/bibles/forms/bibleimportform.py' |
34 | --- openlp/plugins/bibles/forms/bibleimportform.py 2017-12-29 09:15:48 +0000 |
35 | +++ openlp/plugins/bibles/forms/bibleimportform.py 2018-10-22 20:55:00 +0000 |
36 | @@ -210,22 +210,22 @@ |
37 | self.open_song_layout.addRow(self.open_song_file_label, self.open_song_path_edit) |
38 | self.open_song_layout.setItem(1, QtWidgets.QFormLayout.LabelRole, self.spacer) |
39 | self.select_stack.addWidget(self.open_song_widget) |
40 | - self.web_tab_widget = QtWidgets.QTabWidget(self.select_page) |
41 | - self.web_tab_widget.setObjectName('WebTabWidget') |
42 | + self.web_widget = QtWidgets.QWidget(self.select_page) |
43 | + self.web_widget.setObjectName('WebWidget') |
44 | self.web_bible_tab = QtWidgets.QWidget() |
45 | self.web_bible_tab.setObjectName('WebBibleTab') |
46 | - self.web_bible_layout = QtWidgets.QFormLayout(self.web_bible_tab) |
47 | + self.web_bible_layout = QtWidgets.QFormLayout(self.web_widget) |
48 | self.web_bible_layout.setObjectName('WebBibleLayout') |
49 | - self.web_update_label = QtWidgets.QLabel(self.web_bible_tab) |
50 | + self.web_update_label = QtWidgets.QLabel(self.web_widget) |
51 | self.web_update_label.setObjectName('WebUpdateLabel') |
52 | self.web_bible_layout.setWidget(0, QtWidgets.QFormLayout.LabelRole, self.web_update_label) |
53 | - self.web_update_button = QtWidgets.QPushButton(self.web_bible_tab) |
54 | + self.web_update_button = QtWidgets.QPushButton(self.web_widget) |
55 | self.web_update_button.setObjectName('WebUpdateButton') |
56 | self.web_bible_layout.setWidget(0, QtWidgets.QFormLayout.FieldRole, self.web_update_button) |
57 | - self.web_source_label = QtWidgets.QLabel(self.web_bible_tab) |
58 | + self.web_source_label = QtWidgets.QLabel(self.web_widget) |
59 | self.web_source_label.setObjectName('WebSourceLabel') |
60 | self.web_bible_layout.setWidget(1, QtWidgets.QFormLayout.LabelRole, self.web_source_label) |
61 | - self.web_source_combo_box = QtWidgets.QComboBox(self.web_bible_tab) |
62 | + self.web_source_combo_box = QtWidgets.QComboBox(self.web_widget) |
63 | self.web_source_combo_box.setObjectName('WebSourceComboBox') |
64 | self.web_source_combo_box.addItems(['', '', '']) |
65 | self.web_source_combo_box.setEnabled(False) |
66 | @@ -243,31 +243,7 @@ |
67 | self.web_progress_bar.setObjectName('WebTranslationProgressBar') |
68 | self.web_progress_bar.setVisible(False) |
69 | self.web_bible_layout.setWidget(3, QtWidgets.QFormLayout.SpanningRole, self.web_progress_bar) |
70 | - self.web_tab_widget.addTab(self.web_bible_tab, '') |
71 | - self.web_proxy_tab = QtWidgets.QWidget() |
72 | - self.web_proxy_tab.setObjectName('WebProxyTab') |
73 | - self.web_proxy_layout = QtWidgets.QFormLayout(self.web_proxy_tab) |
74 | - self.web_proxy_layout.setObjectName('WebProxyLayout') |
75 | - self.web_server_label = QtWidgets.QLabel(self.web_proxy_tab) |
76 | - self.web_server_label.setObjectName('WebServerLabel') |
77 | - self.web_proxy_layout.setWidget(0, QtWidgets.QFormLayout.LabelRole, self.web_server_label) |
78 | - self.web_server_edit = QtWidgets.QLineEdit(self.web_proxy_tab) |
79 | - self.web_server_edit.setObjectName('WebServerEdit') |
80 | - self.web_proxy_layout.setWidget(0, QtWidgets.QFormLayout.FieldRole, self.web_server_edit) |
81 | - self.web_user_label = QtWidgets.QLabel(self.web_proxy_tab) |
82 | - self.web_user_label.setObjectName('WebUserLabel') |
83 | - self.web_proxy_layout.setWidget(1, QtWidgets.QFormLayout.LabelRole, self.web_user_label) |
84 | - self.web_user_edit = QtWidgets.QLineEdit(self.web_proxy_tab) |
85 | - self.web_user_edit.setObjectName('WebUserEdit') |
86 | - self.web_proxy_layout.setWidget(1, QtWidgets.QFormLayout.FieldRole, self.web_user_edit) |
87 | - self.web_password_label = QtWidgets.QLabel(self.web_proxy_tab) |
88 | - self.web_password_label.setObjectName('WebPasswordLabel') |
89 | - self.web_proxy_layout.setWidget(2, QtWidgets.QFormLayout.LabelRole, self.web_password_label) |
90 | - self.web_password_edit = QtWidgets.QLineEdit(self.web_proxy_tab) |
91 | - self.web_password_edit.setObjectName('WebPasswordEdit') |
92 | - self.web_proxy_layout.setWidget(2, QtWidgets.QFormLayout.FieldRole, self.web_password_edit) |
93 | - self.web_tab_widget.addTab(self.web_proxy_tab, '') |
94 | - self.select_stack.addWidget(self.web_tab_widget) |
95 | + self.select_stack.addWidget(self.web_widget) |
96 | self.zefania_widget = QtWidgets.QWidget(self.select_page) |
97 | self.zefania_widget.setObjectName('ZefaniaWidget') |
98 | self.zefania_layout = QtWidgets.QFormLayout(self.zefania_widget) |
99 | @@ -427,14 +403,6 @@ |
100 | self.web_source_combo_box.setItemText(WebDownload.Bibleserver, translate('BiblesPlugin.ImportWizardForm', |
101 | 'Bibleserver')) |
102 | self.web_translation_label.setText(translate('BiblesPlugin.ImportWizardForm', 'Bible:')) |
103 | - self.web_tab_widget.setTabText(self.web_tab_widget.indexOf(self.web_bible_tab), |
104 | - translate('BiblesPlugin.ImportWizardForm', 'Download Options')) |
105 | - self.web_server_label.setText(translate('BiblesPlugin.ImportWizardForm', 'Server:')) |
106 | - self.web_user_label.setText(translate('BiblesPlugin.ImportWizardForm', 'Username:')) |
107 | - self.web_password_label.setText(translate('BiblesPlugin.ImportWizardForm', 'Password:')) |
108 | - self.web_tab_widget.setTabText( |
109 | - self.web_tab_widget.indexOf(self.web_proxy_tab), translate('BiblesPlugin.ImportWizardForm', |
110 | - 'Proxy Server (Optional)')) |
111 | self.sword_bible_label.setText(translate('BiblesPlugin.ImportWizardForm', 'Bibles:')) |
112 | self.sword_folder_label.setText(translate('BiblesPlugin.ImportWizardForm', 'SWORD data folder:')) |
113 | self.sword_zipfile_label.setText(translate('BiblesPlugin.ImportWizardForm', 'SWORD zip-file:')) |
114 | @@ -609,11 +577,10 @@ |
115 | self.web_update_button.setEnabled(False) |
116 | self.web_progress_bar.setVisible(True) |
117 | self.web_progress_bar.setValue(0) |
118 | - proxy_server = self.field('proxy_server') |
119 | # TODO: Where does critical_error_message_box get %s string from? |
120 | - for (download_type, extractor) in ((WebDownload.Crosswalk, CWExtract(proxy_server)), |
121 | - (WebDownload.BibleGateway, BGExtract(proxy_server)), |
122 | - (WebDownload.Bibleserver, BSExtract(proxy_server))): |
123 | + for (download_type, extractor) in ((WebDownload.Crosswalk, CWExtract()), |
124 | + (WebDownload.BibleGateway, BGExtract()), |
125 | + (WebDownload.Bibleserver, BSExtract())): |
126 | try: |
127 | bibles = extractor.get_bibles_from_http() |
128 | except (urllib.error.URLError, ConnectionError) as err: |
129 | @@ -679,9 +646,6 @@ |
130 | self.select_page.registerField('web_biblename', self.web_translation_combo_box) |
131 | self.select_page.registerField('sword_folder_path', self.sword_folder_path_edit, 'path', PathEdit.pathChanged) |
132 | self.select_page.registerField('sword_zip_path', self.sword_zipfile_path_edit, 'path', PathEdit.pathChanged) |
133 | - self.select_page.registerField('proxy_server', self.web_server_edit) |
134 | - self.select_page.registerField('proxy_username', self.web_user_edit) |
135 | - self.select_page.registerField('proxy_password', self.web_password_edit) |
136 | self.license_details_page.registerField('license_version', self.version_name_edit) |
137 | self.license_details_page.registerField('license_copyright', self.copyright_edit) |
138 | self.license_details_page.registerField('license_permissions', self.permissions_edit) |
139 | @@ -706,9 +670,6 @@ |
140 | self.setField('sword_zip_path', None) |
141 | self.setField('web_location', WebDownload.Crosswalk) |
142 | self.setField('web_biblename', self.web_translation_combo_box.currentIndex()) |
143 | - self.setField('proxy_server', settings.value('proxy address')) |
144 | - self.setField('proxy_username', settings.value('proxy username')) |
145 | - self.setField('proxy_password', settings.value('proxy password')) |
146 | self.setField('license_version', self.version_name_edit.text()) |
147 | self.version_name_edit.setPlaceholderText(UiStrings().RequiredShowInFooter) |
148 | self.setField('license_copyright', self.copyright_edit.text()) |
149 | @@ -765,9 +726,6 @@ |
150 | BibleFormat.WebDownload, name=license_version, |
151 | download_source=WebDownload.Names[download_location], |
152 | download_name=bible, |
153 | - proxy_server=self.field('proxy_server'), |
154 | - proxy_username=self.field('proxy_username'), |
155 | - proxy_password=self.field('proxy_password'), |
156 | language_id=language_id |
157 | ) |
158 | elif bible_type == BibleFormat.Zefania: |
159 | |
160 | === modified file 'openlp/plugins/bibles/lib/db.py' |
161 | --- openlp/plugins/bibles/lib/db.py 2017-12-29 09:15:48 +0000 |
162 | +++ openlp/plugins/bibles/lib/db.py 2018-10-22 20:55:00 +0000 |
163 | @@ -82,20 +82,19 @@ |
164 | |
165 | meta_table = Table('metadata', metadata, |
166 | Column('key', types.Unicode(255), primary_key=True, index=True), |
167 | - Column('value', types.Unicode(255)),) |
168 | + Column('value', types.Unicode(255))) |
169 | |
170 | book_table = Table('book', metadata, |
171 | Column('id', types.Integer, primary_key=True), |
172 | Column('book_reference_id', types.Integer, index=True), |
173 | Column('testament_reference_id', types.Integer), |
174 | - Column('name', types.Unicode(50), index=True),) |
175 | + Column('name', types.Unicode(50), index=True)) |
176 | verse_table = Table('verse', metadata, |
177 | Column('id', types.Integer, primary_key=True, index=True), |
178 | - Column('book_id', types.Integer, ForeignKey( |
179 | - 'book.id'), index=True), |
180 | + Column('book_id', types.Integer, ForeignKey('book.id'), index=True), |
181 | Column('chapter', types.Integer, index=True), |
182 | Column('verse', types.Integer, index=True), |
183 | - Column('text', types.UnicodeText, index=True),) |
184 | + Column('text', types.UnicodeText, index=True)) |
185 | |
186 | try: |
187 | class_mapper(BibleMeta) |
188 | |
189 | === modified file 'openlp/plugins/bibles/lib/importers/http.py' |
190 | --- openlp/plugins/bibles/lib/importers/http.py 2017-12-29 09:15:48 +0000 |
191 | +++ openlp/plugins/bibles/lib/importers/http.py 2018-10-22 20:55:00 +0000 |
192 | @@ -94,9 +94,8 @@ |
193 | """ |
194 | NAME = 'BibleGateway' |
195 | |
196 | - def __init__(self, proxy_url=None): |
197 | - log.debug('BGExtract.init(proxy_url="{url}")'.format(url=proxy_url)) |
198 | - self.proxy_url = proxy_url |
199 | + def __init__(self): |
200 | + log.debug('BGExtract.__init__()') |
201 | socket.setdefaulttimeout(30) |
202 | |
203 | def _remove_elements(self, parent, tag, class_=None): |
204 | @@ -358,9 +357,8 @@ |
205 | """ |
206 | NAME = 'BibleServer' |
207 | |
208 | - def __init__(self, proxy_url=None): |
209 | - log.debug('BSExtract.init("{url}")'.format(url=proxy_url)) |
210 | - self.proxy_url = proxy_url |
211 | + def __init__(self): |
212 | + log.debug('BSExtract.__init__()') |
213 | socket.setdefaulttimeout(30) |
214 | |
215 | def get_bible_chapter(self, version, book_name, chapter): |
216 | @@ -461,9 +459,8 @@ |
217 | """ |
218 | NAME = 'Crosswalk' |
219 | |
220 | - def __init__(self, proxy_url=None): |
221 | - log.debug('CWExtract.init("{url}")'.format(url=proxy_url)) |
222 | - self.proxy_url = proxy_url |
223 | + def __init__(self): |
224 | + log.debug('CWExtract.__init__()') |
225 | socket.setdefaulttimeout(30) |
226 | |
227 | def get_bible_chapter(self, version, book_name, chapter): |
228 | @@ -595,19 +592,9 @@ |
229 | super().__init__(*args, **kwargs) |
230 | self.download_source = kwargs['download_source'] |
231 | self.download_name = kwargs['download_name'] |
232 | - # TODO: Clean up proxy stuff. We probably want one global proxy per connection type (HTTP and HTTPS) at most. |
233 | - self.proxy_server = None |
234 | - self.proxy_username = None |
235 | - self.proxy_password = None |
236 | self.language_id = None |
237 | if 'path' in kwargs: |
238 | self.path = kwargs['path'] |
239 | - if 'proxy_server' in kwargs: |
240 | - self.proxy_server = kwargs['proxy_server'] |
241 | - if 'proxy_username' in kwargs: |
242 | - self.proxy_username = kwargs['proxy_username'] |
243 | - if 'proxy_password' in kwargs: |
244 | - self.proxy_password = kwargs['proxy_password'] |
245 | if 'language_id' in kwargs: |
246 | self.language_id = kwargs['language_id'] |
247 | |
248 | @@ -621,20 +608,12 @@ |
249 | 'Registering Bible and loading books...')) |
250 | self.save_meta('download_source', self.download_source) |
251 | self.save_meta('download_name', self.download_name) |
252 | - if self.proxy_server: |
253 | - self.save_meta('proxy_server', self.proxy_server) |
254 | - if self.proxy_username: |
255 | - # Store the proxy userid. |
256 | - self.save_meta('proxy_username', self.proxy_username) |
257 | - if self.proxy_password: |
258 | - # Store the proxy password. |
259 | - self.save_meta('proxy_password', self.proxy_password) |
260 | if self.download_source.lower() == 'crosswalk': |
261 | - handler = CWExtract(self.proxy_server) |
262 | + handler = CWExtract() |
263 | elif self.download_source.lower() == 'biblegateway': |
264 | - handler = BGExtract(self.proxy_server) |
265 | + handler = BGExtract() |
266 | elif self.download_source.lower() == 'bibleserver': |
267 | - handler = BSExtract(self.proxy_server) |
268 | + handler = BSExtract() |
269 | books = handler.get_books_from_http(self.download_name) |
270 | if not books: |
271 | log.error('Importing books from {source} - download name: "{name}" ' |
272 | @@ -722,11 +701,11 @@ |
273 | log.debug('HTTPBible.get_chapter("{book}", "{chapter}")'.format(book=book, chapter=chapter)) |
274 | log.debug('source = {source}'.format(source=self.download_source)) |
275 | if self.download_source.lower() == 'crosswalk': |
276 | - handler = CWExtract(self.proxy_server) |
277 | + handler = CWExtract() |
278 | elif self.download_source.lower() == 'biblegateway': |
279 | - handler = BGExtract(self.proxy_server) |
280 | + handler = BGExtract() |
281 | elif self.download_source.lower() == 'bibleserver': |
282 | - handler = BSExtract(self.proxy_server) |
283 | + handler = BSExtract() |
284 | return handler.get_bible_chapter(self.download_name, book, chapter) |
285 | |
286 | def get_books(self): |
287 | |
288 | === modified file 'openlp/plugins/bibles/lib/manager.py' |
289 | --- openlp/plugins/bibles/lib/manager.py 2017-12-29 09:15:48 +0000 |
290 | +++ openlp/plugins/bibles/lib/manager.py 2018-10-22 20:55:00 +0000 |
291 | @@ -116,7 +116,6 @@ |
292 | self.web = 'Web' |
293 | self.db_cache = None |
294 | self.path = AppLocation.get_section_data_path(self.settings_section) |
295 | - self.proxy_name = Settings().value(self.settings_section + '/proxy name') |
296 | self.suffix = '.sqlite' |
297 | self.import_wizard = None |
298 | self.reload_bibles() |
299 | @@ -149,11 +148,8 @@ |
300 | if self.db_cache[name].is_web_bible: |
301 | source = self.db_cache[name].get_object(BibleMeta, 'download_source') |
302 | download_name = self.db_cache[name].get_object(BibleMeta, 'download_name').value |
303 | - meta_proxy = self.db_cache[name].get_object(BibleMeta, 'proxy_server') |
304 | web_bible = HTTPBible(self.parent, path=self.path, file=file_path, download_source=source.value, |
305 | download_name=download_name) |
306 | - if meta_proxy: |
307 | - web_bible.proxy_server = meta_proxy.value |
308 | self.db_cache[name] = web_bible |
309 | log.debug('Bibles reloaded') |
310 | |
311 | |
312 | === modified file 'openlp/plugins/bibles/lib/upgrade.py' |
313 | --- openlp/plugins/bibles/lib/upgrade.py 2017-12-29 09:15:48 +0000 |
314 | +++ openlp/plugins/bibles/lib/upgrade.py 2018-10-22 20:55:00 +0000 |
315 | @@ -24,8 +24,16 @@ |
316 | """ |
317 | import logging |
318 | |
319 | +from PyQt5 import QtWidgets |
320 | +from sqlalchemy import Table |
321 | +from sqlalchemy.sql.expression import delete, select |
322 | + |
323 | +from openlp.core.common.i18n import translate |
324 | +from openlp.core.common.settings import ProxyMode, Settings |
325 | +from openlp.core.lib.db import get_upgrade_op |
326 | + |
327 | log = logging.getLogger(__name__) |
328 | -__version__ = 1 |
329 | +__version__ = 2 |
330 | |
331 | |
332 | # TODO: When removing an upgrade path the ftw-data needs updating to the minimum supported version |
333 | @@ -36,3 +44,48 @@ |
334 | This upgrade renamed a number of keys to a single naming convention. |
335 | """ |
336 | log.info('No upgrades to perform') |
337 | + |
338 | + |
339 | +def upgrade_2(session, metadata): |
340 | + """ |
341 | + Remove the individual proxy settings, after the implementation of central proxy settings. |
342 | + Added in 2.5 (3.0 development) |
343 | + """ |
344 | + settings = Settings() |
345 | + op = get_upgrade_op(session) |
346 | + metadata_table = Table('metadata', metadata, autoload=True) |
347 | + proxy, = session.execute(select([metadata_table.c.value], metadata_table.c.key == 'proxy_server')).first() or ('', ) |
348 | + if proxy and not \ |
349 | + (proxy == settings.value('advanced/proxy http') or proxy == settings.value('advanced/proxy https')): |
350 | + http_proxy = '' |
351 | + https_proxy = '' |
352 | + name, = session.execute(select([metadata_table.c.value], metadata_table.c.key == 'name')).first() |
353 | + msg_box = QtWidgets.QMessageBox() |
354 | + msg_box.setText(translate('BiblesPlugin', f'The proxy server {proxy} was found in the bible {name}.<br>' |
355 | + f'Would you like to set it as the proxy for OpenLP?')) |
356 | + msg_box.setIcon(QtWidgets.QMessageBox.Question) |
357 | + msg_box.addButton(QtWidgets.QMessageBox.No) |
358 | + http_button = msg_box.addButton('http', QtWidgets.QMessageBox.ActionRole) |
359 | + both_button = msg_box.addButton(translate('BiblesPlugin', 'both'), QtWidgets.QMessageBox.ActionRole) |
360 | + https_button = msg_box.addButton('https', QtWidgets.QMessageBox.ActionRole) |
361 | + msg_box.setDefaultButton(both_button) |
362 | + msg_box.exec() |
363 | + |
364 | + clicked_button = msg_box.clickedButton() |
365 | + if clicked_button in [http_button, both_button]: |
366 | + http_proxy = proxy |
367 | + settings.setValue('advanced/proxy http', proxy) |
368 | + if clicked_button in [https_button, both_button]: |
369 | + https_proxy = proxy |
370 | + settings.setValue('advanced/proxy https', proxy) |
371 | + if http_proxy or https_proxy: |
372 | + username, = session.execute( |
373 | + select([metadata_table.c.value], metadata_table.c.key == 'proxy_username')).first() |
374 | + proxy, = session.execute(select([metadata_table.c.value], metadata_table.c.key == 'proxy_password')).first() |
375 | + settings.setValue('advanced/proxy username', username) |
376 | + settings.setValue('advanced/proxy password', proxy) |
377 | + settings.setValue('advanced/proxy mode', ProxyMode.MANUAL_PROXY) |
378 | + |
379 | + op.execute(delete(metadata_table, metadata_table.c.key == 'proxy_server')) |
380 | + op.execute(delete(metadata_table, metadata_table.c.key == 'proxy_username')) |
381 | + op.execute(delete(metadata_table, metadata_table.c.key == 'proxy_password')) |
382 | |
383 | === added file 'tests/functional/openlp_plugins/bibles/test_upgrade.py' |
384 | --- tests/functional/openlp_plugins/bibles/test_upgrade.py 1970-01-01 00:00:00 +0000 |
385 | +++ tests/functional/openlp_plugins/bibles/test_upgrade.py 2018-10-22 20:55:00 +0000 |
386 | @@ -0,0 +1,218 @@ |
387 | +# -*- coding: utf-8 -*- |
388 | +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 |
389 | + |
390 | +############################################################################### |
391 | +# OpenLP - Open Source Lyrics Projection # |
392 | +# --------------------------------------------------------------------------- # |
393 | +# Copyright (c) 2008-2018 OpenLP Developers # |
394 | +# --------------------------------------------------------------------------- # |
395 | +# This program is free software; you can redistribute it and/or modify it # |
396 | +# under the terms of the GNU General Public License as published by the Free # |
397 | +# Software Foundation; version 2 of the License. # |
398 | +# # |
399 | +# This program is distributed in the hope that it will be useful, but WITHOUT # |
400 | +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # |
401 | +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # |
402 | +# more details. # |
403 | +# # |
404 | +# You should have received a copy of the GNU General Public License along # |
405 | +# with this program; if not, write to the Free Software Foundation, Inc., 59 # |
406 | +# Temple Place, Suite 330, Boston, MA 02111-1307 USA # |
407 | +############################################################################### |
408 | +""" |
409 | +This module contains tests for the upgrade submodule of the Bibles plugin. |
410 | +""" |
411 | +import os |
412 | +import shutil |
413 | +from pathlib import Path |
414 | +from tempfile import mkdtemp |
415 | +from unittest import TestCase |
416 | +from unittest.mock import MagicMock, call, patch |
417 | + |
418 | +from PyQt5 import QtWidgets |
419 | +from sqlalchemy import create_engine |
420 | + |
421 | +from openlp.core.common.settings import ProxyMode |
422 | +from openlp.core.lib.db import upgrade_db |
423 | +from openlp.plugins.bibles.lib import upgrade |
424 | +from tests.helpers.testmixin import TestMixin |
425 | +from tests.utils.constants import RESOURCE_PATH |
426 | + |
427 | + |
428 | +class TestUpgrade(TestCase, TestMixin): |
429 | + """ |
430 | + Test the `upgrade_2` function in the :mod:`upgrade` module when the db does not contains proxy metadata |
431 | + """ |
432 | + |
433 | + def setUp(self): |
434 | + """ |
435 | + Setup for tests |
436 | + """ |
437 | + self.tmp_path = Path(mkdtemp()) |
438 | + db_path = RESOURCE_PATH / 'bibles' / 'web-bible-2.4.6-v1.sqlite' |
439 | + db_tmp_path = self.tmp_path / 'web-bible-2.4.6-v1.sqlite' |
440 | + shutil.copyfile(db_path, db_tmp_path) |
441 | + self.db_url = 'sqlite:///' + str(db_tmp_path) |
442 | + |
443 | + patched_settings = patch('openlp.plugins.bibles.lib.upgrade.Settings') |
444 | + self.mocked_settings = patched_settings.start() |
445 | + self.addCleanup(patched_settings.stop) |
446 | + self.mocked_settings_instance = MagicMock() |
447 | + self.mocked_settings.return_value = self.mocked_settings_instance |
448 | + |
449 | + patched_message_box = patch('openlp.plugins.bibles.lib.upgrade.QtWidgets.QMessageBox') |
450 | + self.mocked_message_box = patched_message_box.start() |
451 | + self.addCleanup(patched_message_box.stop) |
452 | + |
453 | + def tearDown(self): |
454 | + """ |
455 | + Clean up after tests |
456 | + """ |
457 | + # Ignore errors since windows can have problems with locked files |
458 | + shutil.rmtree(self.tmp_path, ignore_errors=True) |
459 | + |
460 | + def test_upgrade_2_none_selected(self): |
461 | + """ |
462 | + Test that upgrade 2 completes properly when the user chooses not to use a proxy ('No') |
463 | + """ |
464 | + # GIVEN: An version 1 web bible with proxy settings |
465 | + |
466 | + # WHEN: Calling upgrade_db and the user has 'clicked' the 'No' button |
467 | + upgrade_db(self.db_url, upgrade) |
468 | + |
469 | + # THEN: The proxy meta data should have been removed, and the version should have been changed to version 2 |
470 | + self.mocked_message_box.assert_not_called() |
471 | + engine = create_engine(self.db_url) |
472 | + conn = engine.connect() |
473 | + assert conn.execute('SELECT * FROM metadata WHERE key = "version"').first().value == '2' |
474 | + |
475 | + |
476 | +class TestProxyMetaUpgrade(TestCase, TestMixin): |
477 | + """ |
478 | + Test the `upgrade_2` function in the :mod:`upgrade` module when the db contains proxy metadata |
479 | + """ |
480 | + |
481 | + def setUp(self): |
482 | + """ |
483 | + Setup for tests |
484 | + """ |
485 | + self.tmp_path = Path(mkdtemp()) |
486 | + db_path = RESOURCE_PATH / 'bibles' / 'web-bible-2.4.6-proxy-meta-v1.sqlite' |
487 | + db_tmp_path = self.tmp_path / 'web-bible-2.4.6-proxy-meta-v1.sqlite' |
488 | + shutil.copyfile(db_path, db_tmp_path) |
489 | + self.db_url = 'sqlite:///' + str(db_tmp_path) |
490 | + |
491 | + patched_settings = patch('openlp.plugins.bibles.lib.upgrade.Settings') |
492 | + self.mocked_settings = patched_settings.start() |
493 | + self.addCleanup(patched_settings.stop) |
494 | + self.mocked_settings_instance = MagicMock() |
495 | + self.mocked_settings.return_value = self.mocked_settings_instance |
496 | + |
497 | + patched_message_box = patch('openlp.plugins.bibles.lib.upgrade.QtWidgets.QMessageBox') |
498 | + mocked_message_box = patched_message_box.start() |
499 | + self.addCleanup(patched_message_box.stop) |
500 | + self.mocked_no_button = MagicMock() |
501 | + self.mocked_http_button = MagicMock() |
502 | + self.mocked_both_button = MagicMock() |
503 | + self.mocked_https_button = MagicMock() |
504 | + self.mocked_message_box_instance = MagicMock( |
505 | + **{'addButton.side_effect': [self.mocked_no_button, self.mocked_http_button, |
506 | + self.mocked_both_button, self.mocked_https_button]}) |
507 | + mocked_message_box.return_value = self.mocked_message_box_instance |
508 | + |
509 | + def tearDown(self): |
510 | + """ |
511 | + Clean up after tests |
512 | + """ |
513 | + # Ignore errors since windows can have problems with locked files |
514 | + shutil.rmtree(self.tmp_path, ignore_errors=True) |
515 | + |
516 | + def test_upgrade_2_none_selected(self): |
517 | + """ |
518 | + Test that upgrade 2 completes properly when the user chooses not to use a proxy ('No') |
519 | + """ |
520 | + # GIVEN: An version 1 web bible with proxy settings |
521 | + |
522 | + # WHEN: Calling upgrade_db and the user has 'clicked' the 'No' button |
523 | + self.mocked_message_box_instance.clickedButton.return_value = self.mocked_no_button |
524 | + upgrade_db(self.db_url, upgrade) |
525 | + |
526 | + # THEN: The proxy meta data should have been removed, and the version should have been changed to version 2 |
527 | + engine = create_engine(self.db_url) |
528 | + conn = engine.connect() |
529 | + assert len(conn.execute('SELECT * FROM metadata WHERE key = "proxy_server"').fetchall()) == 0 |
530 | + assert len(conn.execute('SELECT * FROM metadata WHERE key = "proxy_username"').fetchall()) == 0 |
531 | + assert len(conn.execute('SELECT * FROM metadata WHERE key = "proxy_password"').fetchall()) == 0 |
532 | + assert conn.execute('SELECT * FROM metadata WHERE key = "version"').first().value == '2' |
533 | + self.mocked_settings_instance.setValue.assert_not_called() |
534 | + |
535 | + def test_upgrade_2_http_selected(self): |
536 | + """ |
537 | + Test that upgrade 2 completes properly when the user chooses to use a HTTP proxy |
538 | + """ |
539 | + # GIVEN: An version 1 web bible with proxy settings |
540 | + |
541 | + # WHEN: Calling upgrade_db and the user has 'clicked' the 'HTTP' button |
542 | + self.mocked_message_box_instance.clickedButton.return_value = self.mocked_http_button |
543 | + upgrade_db(self.db_url, upgrade) |
544 | + |
545 | + # THEN: The proxy meta data should have been removed, the version should have been changed to version 2, and the |
546 | + # proxy server saved to the settings |
547 | + engine = create_engine(self.db_url) |
548 | + conn = engine.connect() |
549 | + assert len(conn.execute('SELECT * FROM metadata WHERE key = "proxy_server"').fetchall()) == 0 |
550 | + assert len(conn.execute('SELECT * FROM metadata WHERE key = "proxy_username"').fetchall()) == 0 |
551 | + assert len(conn.execute('SELECT * FROM metadata WHERE key = "proxy_password"').fetchall()) == 0 |
552 | + assert conn.execute('SELECT * FROM metadata WHERE key = "version"').first().value == '2' |
553 | + |
554 | + assert self.mocked_settings_instance.setValue.call_args_list == [ |
555 | + call('advanced/proxy http', 'proxy_server'), call('advanced/proxy username', 'proxy_username'), |
556 | + call('advanced/proxy password', 'proxy_password'), call('advanced/proxy mode', ProxyMode.MANUAL_PROXY)] |
557 | + |
558 | + def test_upgrade_2_https_selected(self): |
559 | + """ |
560 | + Tcest that upgrade 2 completes properly when the user chooses to use a HTTPS proxy |
561 | + """ |
562 | + # GIVEN: An version 1 web bible with proxy settings |
563 | + |
564 | + # WHEN: Calling upgrade_db and the user has 'clicked' the 'HTTPS' button |
565 | + self.mocked_message_box_instance.clickedButton.return_value = self.mocked_https_button |
566 | + upgrade_db(self.db_url, upgrade) |
567 | + |
568 | + # THEN: The proxy settings should have been removed, the version should have been changed to version 2, and the |
569 | + # proxy server saved to the settings |
570 | + engine = create_engine(self.db_url) |
571 | + conn = engine.connect() |
572 | + assert len(conn.execute('SELECT * FROM metadata WHERE key = "proxy_server"').fetchall()) == 0 |
573 | + assert len(conn.execute('SELECT * FROM metadata WHERE key = "proxy_username"').fetchall()) == 0 |
574 | + assert len(conn.execute('SELECT * FROM metadata WHERE key = "proxy_password"').fetchall()) == 0 |
575 | + assert conn.execute('SELECT * FROM metadata WHERE key = "version"').first().value == '2' |
576 | + |
577 | + assert self.mocked_settings_instance.setValue.call_args_list == [ |
578 | + call('advanced/proxy https', 'proxy_server'), call('advanced/proxy username', 'proxy_username'), |
579 | + call('advanced/proxy password', 'proxy_password'), call('advanced/proxy mode', ProxyMode.MANUAL_PROXY)] |
580 | + |
581 | + def test_upgrade_2_both_selected(self): |
582 | + """ |
583 | + Tcest that upgrade 2 completes properly when the user chooses to use a both HTTP and HTTPS proxies |
584 | + """ |
585 | + |
586 | + # GIVEN: An version 1 web bible with proxy settings |
587 | + |
588 | + # WHEN: Calling upgrade_db |
589 | + self.mocked_message_box_instance.clickedButton.return_value = self.mocked_both_button |
590 | + upgrade_db(self.db_url, upgrade) |
591 | + |
592 | + # THEN: The proxy settings should have been removed, the version should have been changed to version 2, and the |
593 | + # proxy server saved to the settings |
594 | + engine = create_engine(self.db_url) |
595 | + conn = engine.connect() |
596 | + assert len(conn.execute('SELECT * FROM metadata WHERE key = "proxy_server"').fetchall()) == 0 |
597 | + assert len(conn.execute('SELECT * FROM metadata WHERE key = "proxy_username"').fetchall()) == 0 |
598 | + assert len(conn.execute('SELECT * FROM metadata WHERE key = "proxy_password"').fetchall()) == 0 |
599 | + assert conn.execute('SELECT * FROM metadata WHERE key = "version"').first().value == '2' |
600 | + |
601 | + assert self.mocked_settings_instance.setValue.call_args_list == [ |
602 | + call('advanced/proxy http', 'proxy_server'), call('advanced/proxy https', 'proxy_server'), |
603 | + call('advanced/proxy username', 'proxy_username'), call('advanced/proxy password', 'proxy_password'), |
604 | + call('advanced/proxy mode', ProxyMode.MANUAL_PROXY)] |
605 | |
606 | === modified file 'tests/resources/bibles/tests.sqlite' |
607 | Binary files tests/resources/bibles/tests.sqlite 2014-03-11 19:01:09 +0000 and tests/resources/bibles/tests.sqlite 2018-10-22 20:55:00 +0000 differ |
608 | === added file 'tests/resources/bibles/web-bible-2.4.6-proxy-meta-v1.sqlite' |
609 | Binary files tests/resources/bibles/web-bible-2.4.6-proxy-meta-v1.sqlite 1970-01-01 00:00:00 +0000 and tests/resources/bibles/web-bible-2.4.6-proxy-meta-v1.sqlite 2018-10-22 20:55:00 +0000 differ |
610 | === added file 'tests/resources/bibles/web-bible-2.4.6-v1.sqlite' |
611 | Binary files tests/resources/bibles/web-bible-2.4.6-v1.sqlite 1970-01-01 00:00:00 +0000 and tests/resources/bibles/web-bible-2.4.6-v1.sqlite 2018-10-22 20:55:00 +0000 differ |
Linux tests passed!