Migrate bibles to use the centeral proxy settings. Upgrade settings and bible meta data accordingly.

bzr-revno: 2837
This commit is contained in:
Phill 2018-10-24 20:35:22 +01:00 committed by Philip Ridout
commit 891f1dc397
11 changed files with 304 additions and 101 deletions

View File

@ -275,7 +275,11 @@ class Settings(QtCore.QSettings):
('songuasge/db password', 'songusage/db password', []),
('songuasge/db hostname', 'songusage/db hostname', []),
('songuasge/db database', 'songusage/db database', []),
('presentations / Powerpoint Viewer', '', [])
('presentations / Powerpoint Viewer', '', []),
('bibles/proxy name', '', []), # Just remove these bible proxy settings. They weren't used in 2.4!
('bibles/proxy address', '', []),
('bibles/proxy username', '', []),
('bibles/proxy password', '', [])
]
@staticmethod

View File

@ -52,10 +52,6 @@ __default_settings__ = {
'bibles/display new chapter': False,
'bibles/second bibles': True,
'bibles/primary bible': '',
'bibles/proxy name': '',
'bibles/proxy address': '',
'bibles/proxy username': '',
'bibles/proxy password': '',
'bibles/bible theme': '',
'bibles/verse separator': '',
'bibles/range separator': '',

View File

@ -210,22 +210,22 @@ class BibleImportForm(OpenLPWizard):
self.open_song_layout.addRow(self.open_song_file_label, self.open_song_path_edit)
self.open_song_layout.setItem(1, QtWidgets.QFormLayout.LabelRole, self.spacer)
self.select_stack.addWidget(self.open_song_widget)
self.web_tab_widget = QtWidgets.QTabWidget(self.select_page)
self.web_tab_widget.setObjectName('WebTabWidget')
self.web_widget = QtWidgets.QWidget(self.select_page)
self.web_widget.setObjectName('WebWidget')
self.web_bible_tab = QtWidgets.QWidget()
self.web_bible_tab.setObjectName('WebBibleTab')
self.web_bible_layout = QtWidgets.QFormLayout(self.web_bible_tab)
self.web_bible_layout = QtWidgets.QFormLayout(self.web_widget)
self.web_bible_layout.setObjectName('WebBibleLayout')
self.web_update_label = QtWidgets.QLabel(self.web_bible_tab)
self.web_update_label = QtWidgets.QLabel(self.web_widget)
self.web_update_label.setObjectName('WebUpdateLabel')
self.web_bible_layout.setWidget(0, QtWidgets.QFormLayout.LabelRole, self.web_update_label)
self.web_update_button = QtWidgets.QPushButton(self.web_bible_tab)
self.web_update_button = QtWidgets.QPushButton(self.web_widget)
self.web_update_button.setObjectName('WebUpdateButton')
self.web_bible_layout.setWidget(0, QtWidgets.QFormLayout.FieldRole, self.web_update_button)
self.web_source_label = QtWidgets.QLabel(self.web_bible_tab)
self.web_source_label = QtWidgets.QLabel(self.web_widget)
self.web_source_label.setObjectName('WebSourceLabel')
self.web_bible_layout.setWidget(1, QtWidgets.QFormLayout.LabelRole, self.web_source_label)
self.web_source_combo_box = QtWidgets.QComboBox(self.web_bible_tab)
self.web_source_combo_box = QtWidgets.QComboBox(self.web_widget)
self.web_source_combo_box.setObjectName('WebSourceComboBox')
self.web_source_combo_box.addItems(['', '', ''])
self.web_source_combo_box.setEnabled(False)
@ -243,31 +243,7 @@ class BibleImportForm(OpenLPWizard):
self.web_progress_bar.setObjectName('WebTranslationProgressBar')
self.web_progress_bar.setVisible(False)
self.web_bible_layout.setWidget(3, QtWidgets.QFormLayout.SpanningRole, self.web_progress_bar)
self.web_tab_widget.addTab(self.web_bible_tab, '')
self.web_proxy_tab = QtWidgets.QWidget()
self.web_proxy_tab.setObjectName('WebProxyTab')
self.web_proxy_layout = QtWidgets.QFormLayout(self.web_proxy_tab)
self.web_proxy_layout.setObjectName('WebProxyLayout')
self.web_server_label = QtWidgets.QLabel(self.web_proxy_tab)
self.web_server_label.setObjectName('WebServerLabel')
self.web_proxy_layout.setWidget(0, QtWidgets.QFormLayout.LabelRole, self.web_server_label)
self.web_server_edit = QtWidgets.QLineEdit(self.web_proxy_tab)
self.web_server_edit.setObjectName('WebServerEdit')
self.web_proxy_layout.setWidget(0, QtWidgets.QFormLayout.FieldRole, self.web_server_edit)
self.web_user_label = QtWidgets.QLabel(self.web_proxy_tab)
self.web_user_label.setObjectName('WebUserLabel')
self.web_proxy_layout.setWidget(1, QtWidgets.QFormLayout.LabelRole, self.web_user_label)
self.web_user_edit = QtWidgets.QLineEdit(self.web_proxy_tab)
self.web_user_edit.setObjectName('WebUserEdit')
self.web_proxy_layout.setWidget(1, QtWidgets.QFormLayout.FieldRole, self.web_user_edit)
self.web_password_label = QtWidgets.QLabel(self.web_proxy_tab)
self.web_password_label.setObjectName('WebPasswordLabel')
self.web_proxy_layout.setWidget(2, QtWidgets.QFormLayout.LabelRole, self.web_password_label)
self.web_password_edit = QtWidgets.QLineEdit(self.web_proxy_tab)
self.web_password_edit.setObjectName('WebPasswordEdit')
self.web_proxy_layout.setWidget(2, QtWidgets.QFormLayout.FieldRole, self.web_password_edit)
self.web_tab_widget.addTab(self.web_proxy_tab, '')
self.select_stack.addWidget(self.web_tab_widget)
self.select_stack.addWidget(self.web_widget)
self.zefania_widget = QtWidgets.QWidget(self.select_page)
self.zefania_widget.setObjectName('ZefaniaWidget')
self.zefania_layout = QtWidgets.QFormLayout(self.zefania_widget)
@ -427,14 +403,6 @@ class BibleImportForm(OpenLPWizard):
self.web_source_combo_box.setItemText(WebDownload.Bibleserver, translate('BiblesPlugin.ImportWizardForm',
'Bibleserver'))
self.web_translation_label.setText(translate('BiblesPlugin.ImportWizardForm', 'Bible:'))
self.web_tab_widget.setTabText(self.web_tab_widget.indexOf(self.web_bible_tab),
translate('BiblesPlugin.ImportWizardForm', 'Download Options'))
self.web_server_label.setText(translate('BiblesPlugin.ImportWizardForm', 'Server:'))
self.web_user_label.setText(translate('BiblesPlugin.ImportWizardForm', 'Username:'))
self.web_password_label.setText(translate('BiblesPlugin.ImportWizardForm', 'Password:'))
self.web_tab_widget.setTabText(
self.web_tab_widget.indexOf(self.web_proxy_tab), translate('BiblesPlugin.ImportWizardForm',
'Proxy Server (Optional)'))
self.sword_bible_label.setText(translate('BiblesPlugin.ImportWizardForm', 'Bibles:'))
self.sword_folder_label.setText(translate('BiblesPlugin.ImportWizardForm', 'SWORD data folder:'))
self.sword_zipfile_label.setText(translate('BiblesPlugin.ImportWizardForm', 'SWORD zip-file:'))
@ -609,11 +577,10 @@ class BibleImportForm(OpenLPWizard):
self.web_update_button.setEnabled(False)
self.web_progress_bar.setVisible(True)
self.web_progress_bar.setValue(0)
proxy_server = self.field('proxy_server')
# TODO: Where does critical_error_message_box get %s string from?
for (download_type, extractor) in ((WebDownload.Crosswalk, CWExtract(proxy_server)),
(WebDownload.BibleGateway, BGExtract(proxy_server)),
(WebDownload.Bibleserver, BSExtract(proxy_server))):
for (download_type, extractor) in ((WebDownload.Crosswalk, CWExtract()),
(WebDownload.BibleGateway, BGExtract()),
(WebDownload.Bibleserver, BSExtract())):
try:
bibles = extractor.get_bibles_from_http()
except (urllib.error.URLError, ConnectionError) as err:
@ -679,9 +646,6 @@ class BibleImportForm(OpenLPWizard):
self.select_page.registerField('web_biblename', self.web_translation_combo_box)
self.select_page.registerField('sword_folder_path', self.sword_folder_path_edit, 'path', PathEdit.pathChanged)
self.select_page.registerField('sword_zip_path', self.sword_zipfile_path_edit, 'path', PathEdit.pathChanged)
self.select_page.registerField('proxy_server', self.web_server_edit)
self.select_page.registerField('proxy_username', self.web_user_edit)
self.select_page.registerField('proxy_password', self.web_password_edit)
self.license_details_page.registerField('license_version', self.version_name_edit)
self.license_details_page.registerField('license_copyright', self.copyright_edit)
self.license_details_page.registerField('license_permissions', self.permissions_edit)
@ -706,9 +670,6 @@ class BibleImportForm(OpenLPWizard):
self.setField('sword_zip_path', None)
self.setField('web_location', WebDownload.Crosswalk)
self.setField('web_biblename', self.web_translation_combo_box.currentIndex())
self.setField('proxy_server', settings.value('proxy address'))
self.setField('proxy_username', settings.value('proxy username'))
self.setField('proxy_password', settings.value('proxy password'))
self.setField('license_version', self.version_name_edit.text())
self.version_name_edit.setPlaceholderText(UiStrings().RequiredShowInFooter)
self.setField('license_copyright', self.copyright_edit.text())
@ -765,9 +726,6 @@ class BibleImportForm(OpenLPWizard):
BibleFormat.WebDownload, name=license_version,
download_source=WebDownload.Names[download_location],
download_name=bible,
proxy_server=self.field('proxy_server'),
proxy_username=self.field('proxy_username'),
proxy_password=self.field('proxy_password'),
language_id=language_id
)
elif bible_type == BibleFormat.Zefania:

View File

@ -82,20 +82,19 @@ def init_schema(url):
meta_table = Table('metadata', metadata,
Column('key', types.Unicode(255), primary_key=True, index=True),
Column('value', types.Unicode(255)),)
Column('value', types.Unicode(255)))
book_table = Table('book', metadata,
Column('id', types.Integer, primary_key=True),
Column('book_reference_id', types.Integer, index=True),
Column('testament_reference_id', types.Integer),
Column('name', types.Unicode(50), index=True),)
Column('name', types.Unicode(50), index=True))
verse_table = Table('verse', metadata,
Column('id', types.Integer, primary_key=True, index=True),
Column('book_id', types.Integer, ForeignKey(
'book.id'), index=True),
Column('book_id', types.Integer, ForeignKey('book.id'), index=True),
Column('chapter', types.Integer, index=True),
Column('verse', types.Integer, index=True),
Column('text', types.UnicodeText, index=True),)
Column('text', types.UnicodeText, index=True))
try:
class_mapper(BibleMeta)

View File

@ -94,9 +94,8 @@ class BGExtract(RegistryProperties):
"""
NAME = 'BibleGateway'
def __init__(self, proxy_url=None):
log.debug('BGExtract.init(proxy_url="{url}")'.format(url=proxy_url))
self.proxy_url = proxy_url
def __init__(self):
log.debug('BGExtract.__init__()')
socket.setdefaulttimeout(30)
def _remove_elements(self, parent, tag, class_=None):
@ -358,9 +357,8 @@ class BSExtract(RegistryProperties):
"""
NAME = 'BibleServer'
def __init__(self, proxy_url=None):
log.debug('BSExtract.init("{url}")'.format(url=proxy_url))
self.proxy_url = proxy_url
def __init__(self):
log.debug('BSExtract.__init__()')
socket.setdefaulttimeout(30)
def get_bible_chapter(self, version, book_name, chapter):
@ -461,9 +459,8 @@ class CWExtract(RegistryProperties):
"""
NAME = 'Crosswalk'
def __init__(self, proxy_url=None):
log.debug('CWExtract.init("{url}")'.format(url=proxy_url))
self.proxy_url = proxy_url
def __init__(self):
log.debug('CWExtract.__init__()')
socket.setdefaulttimeout(30)
def get_bible_chapter(self, version, book_name, chapter):
@ -595,19 +592,9 @@ class HTTPBible(BibleImport, RegistryProperties):
super().__init__(*args, **kwargs)
self.download_source = kwargs['download_source']
self.download_name = kwargs['download_name']
# TODO: Clean up proxy stuff. We probably want one global proxy per connection type (HTTP and HTTPS) at most.
self.proxy_server = None
self.proxy_username = None
self.proxy_password = None
self.language_id = None
if 'path' in kwargs:
self.path = kwargs['path']
if 'proxy_server' in kwargs:
self.proxy_server = kwargs['proxy_server']
if 'proxy_username' in kwargs:
self.proxy_username = kwargs['proxy_username']
if 'proxy_password' in kwargs:
self.proxy_password = kwargs['proxy_password']
if 'language_id' in kwargs:
self.language_id = kwargs['language_id']
@ -621,20 +608,12 @@ class HTTPBible(BibleImport, RegistryProperties):
'Registering Bible and loading books...'))
self.save_meta('download_source', self.download_source)
self.save_meta('download_name', self.download_name)
if self.proxy_server:
self.save_meta('proxy_server', self.proxy_server)
if self.proxy_username:
# Store the proxy userid.
self.save_meta('proxy_username', self.proxy_username)
if self.proxy_password:
# Store the proxy password.
self.save_meta('proxy_password', self.proxy_password)
if self.download_source.lower() == 'crosswalk':
handler = CWExtract(self.proxy_server)
handler = CWExtract()
elif self.download_source.lower() == 'biblegateway':
handler = BGExtract(self.proxy_server)
handler = BGExtract()
elif self.download_source.lower() == 'bibleserver':
handler = BSExtract(self.proxy_server)
handler = BSExtract()
books = handler.get_books_from_http(self.download_name)
if not books:
log.error('Importing books from {source} - download name: "{name}" '
@ -722,11 +701,11 @@ class HTTPBible(BibleImport, RegistryProperties):
log.debug('HTTPBible.get_chapter("{book}", "{chapter}")'.format(book=book, chapter=chapter))
log.debug('source = {source}'.format(source=self.download_source))
if self.download_source.lower() == 'crosswalk':
handler = CWExtract(self.proxy_server)
handler = CWExtract()
elif self.download_source.lower() == 'biblegateway':
handler = BGExtract(self.proxy_server)
handler = BGExtract()
elif self.download_source.lower() == 'bibleserver':
handler = BSExtract(self.proxy_server)
handler = BSExtract()
return handler.get_bible_chapter(self.download_name, book, chapter)
def get_books(self):

View File

@ -116,7 +116,6 @@ class BibleManager(LogMixin, RegistryProperties):
self.web = 'Web'
self.db_cache = None
self.path = AppLocation.get_section_data_path(self.settings_section)
self.proxy_name = Settings().value(self.settings_section + '/proxy name')
self.suffix = '.sqlite'
self.import_wizard = None
self.reload_bibles()
@ -149,11 +148,8 @@ class BibleManager(LogMixin, RegistryProperties):
if self.db_cache[name].is_web_bible:
source = self.db_cache[name].get_object(BibleMeta, 'download_source')
download_name = self.db_cache[name].get_object(BibleMeta, 'download_name').value
meta_proxy = self.db_cache[name].get_object(BibleMeta, 'proxy_server')
web_bible = HTTPBible(self.parent, path=self.path, file=file_path, download_source=source.value,
download_name=download_name)
if meta_proxy:
web_bible.proxy_server = meta_proxy.value
self.db_cache[name] = web_bible
log.debug('Bibles reloaded')

View File

@ -24,8 +24,16 @@ The :mod:`upgrade` module provides a way for the database and schema that is the
"""
import logging
from PyQt5 import QtWidgets
from sqlalchemy import Table
from sqlalchemy.sql.expression import delete, select
from openlp.core.common.i18n import translate
from openlp.core.common.settings import ProxyMode, Settings
from openlp.core.lib.db import get_upgrade_op
log = logging.getLogger(__name__)
__version__ = 1
__version__ = 2
# TODO: When removing an upgrade path the ftw-data needs updating to the minimum supported version
@ -36,3 +44,48 @@ def upgrade_1(session, metadata):
This upgrade renamed a number of keys to a single naming convention.
"""
log.info('No upgrades to perform')
def upgrade_2(session, metadata):
"""
Remove the individual proxy settings, after the implementation of central proxy settings.
Added in 2.5 (3.0 development)
"""
settings = Settings()
op = get_upgrade_op(session)
metadata_table = Table('metadata', metadata, autoload=True)
proxy, = session.execute(select([metadata_table.c.value], metadata_table.c.key == 'proxy_server')).first() or ('', )
if proxy and not \
(proxy == settings.value('advanced/proxy http') or proxy == settings.value('advanced/proxy https')):
http_proxy = ''
https_proxy = ''
name, = session.execute(select([metadata_table.c.value], metadata_table.c.key == 'name')).first()
msg_box = QtWidgets.QMessageBox()
msg_box.setText(translate('BiblesPlugin', f'The proxy server {proxy} was found in the bible {name}.<br>'
f'Would you like to set it as the proxy for OpenLP?'))
msg_box.setIcon(QtWidgets.QMessageBox.Question)
msg_box.addButton(QtWidgets.QMessageBox.No)
http_button = msg_box.addButton('http', QtWidgets.QMessageBox.ActionRole)
both_button = msg_box.addButton(translate('BiblesPlugin', 'both'), QtWidgets.QMessageBox.ActionRole)
https_button = msg_box.addButton('https', QtWidgets.QMessageBox.ActionRole)
msg_box.setDefaultButton(both_button)
msg_box.exec()
clicked_button = msg_box.clickedButton()
if clicked_button in [http_button, both_button]:
http_proxy = proxy
settings.setValue('advanced/proxy http', proxy)
if clicked_button in [https_button, both_button]:
https_proxy = proxy
settings.setValue('advanced/proxy https', proxy)
if http_proxy or https_proxy:
username, = session.execute(
select([metadata_table.c.value], metadata_table.c.key == 'proxy_username')).first()
proxy, = session.execute(select([metadata_table.c.value], metadata_table.c.key == 'proxy_password')).first()
settings.setValue('advanced/proxy username', username)
settings.setValue('advanced/proxy password', proxy)
settings.setValue('advanced/proxy mode', ProxyMode.MANUAL_PROXY)
op.execute(delete(metadata_table, metadata_table.c.key == 'proxy_server'))
op.execute(delete(metadata_table, metadata_table.c.key == 'proxy_username'))
op.execute(delete(metadata_table, metadata_table.c.key == 'proxy_password'))

View File

@ -0,0 +1,218 @@
# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
# Copyright (c) 2008-2018 OpenLP Developers #
# --------------------------------------------------------------------------- #
# This program is free software; you can redistribute it and/or modify it #
# under the terms of the GNU General Public License as published by the Free #
# Software Foundation; version 2 of the License. #
# #
# This program is distributed in the hope that it will be useful, but WITHOUT #
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
# more details. #
# #
# You should have received a copy of the GNU General Public License along #
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
###############################################################################
"""
This module contains tests for the upgrade submodule of the Bibles plugin.
"""
import os
import shutil
from pathlib import Path
from tempfile import mkdtemp
from unittest import TestCase
from unittest.mock import MagicMock, call, patch
from PyQt5 import QtWidgets
from sqlalchemy import create_engine
from openlp.core.common.settings import ProxyMode
from openlp.core.lib.db import upgrade_db
from openlp.plugins.bibles.lib import upgrade
from tests.helpers.testmixin import TestMixin
from tests.utils.constants import RESOURCE_PATH
class TestUpgrade(TestCase, TestMixin):
"""
Test the `upgrade_2` function in the :mod:`upgrade` module when the db does not contains proxy metadata
"""
def setUp(self):
"""
Setup for tests
"""
self.tmp_path = Path(mkdtemp())
db_path = RESOURCE_PATH / 'bibles' / 'web-bible-2.4.6-v1.sqlite'
db_tmp_path = self.tmp_path / 'web-bible-2.4.6-v1.sqlite'
shutil.copyfile(db_path, db_tmp_path)
self.db_url = 'sqlite:///' + str(db_tmp_path)
patched_settings = patch('openlp.plugins.bibles.lib.upgrade.Settings')
self.mocked_settings = patched_settings.start()
self.addCleanup(patched_settings.stop)
self.mocked_settings_instance = MagicMock()
self.mocked_settings.return_value = self.mocked_settings_instance
patched_message_box = patch('openlp.plugins.bibles.lib.upgrade.QtWidgets.QMessageBox')
self.mocked_message_box = patched_message_box.start()
self.addCleanup(patched_message_box.stop)
def tearDown(self):
"""
Clean up after tests
"""
# Ignore errors since windows can have problems with locked files
shutil.rmtree(self.tmp_path, ignore_errors=True)
def test_upgrade_2_none_selected(self):
"""
Test that upgrade 2 completes properly when the user chooses not to use a proxy ('No')
"""
# GIVEN: An version 1 web bible with proxy settings
# WHEN: Calling upgrade_db and the user has 'clicked' the 'No' button
upgrade_db(self.db_url, upgrade)
# THEN: The proxy meta data should have been removed, and the version should have been changed to version 2
self.mocked_message_box.assert_not_called()
engine = create_engine(self.db_url)
conn = engine.connect()
assert conn.execute('SELECT * FROM metadata WHERE key = "version"').first().value == '2'
class TestProxyMetaUpgrade(TestCase, TestMixin):
"""
Test the `upgrade_2` function in the :mod:`upgrade` module when the db contains proxy metadata
"""
def setUp(self):
"""
Setup for tests
"""
self.tmp_path = Path(mkdtemp())
db_path = RESOURCE_PATH / 'bibles' / 'web-bible-2.4.6-proxy-meta-v1.sqlite'
db_tmp_path = self.tmp_path / 'web-bible-2.4.6-proxy-meta-v1.sqlite'
shutil.copyfile(db_path, db_tmp_path)
self.db_url = 'sqlite:///' + str(db_tmp_path)
patched_settings = patch('openlp.plugins.bibles.lib.upgrade.Settings')
self.mocked_settings = patched_settings.start()
self.addCleanup(patched_settings.stop)
self.mocked_settings_instance = MagicMock()
self.mocked_settings.return_value = self.mocked_settings_instance
patched_message_box = patch('openlp.plugins.bibles.lib.upgrade.QtWidgets.QMessageBox')
mocked_message_box = patched_message_box.start()
self.addCleanup(patched_message_box.stop)
self.mocked_no_button = MagicMock()
self.mocked_http_button = MagicMock()
self.mocked_both_button = MagicMock()
self.mocked_https_button = MagicMock()
self.mocked_message_box_instance = MagicMock(
**{'addButton.side_effect': [self.mocked_no_button, self.mocked_http_button,
self.mocked_both_button, self.mocked_https_button]})
mocked_message_box.return_value = self.mocked_message_box_instance
def tearDown(self):
"""
Clean up after tests
"""
# Ignore errors since windows can have problems with locked files
shutil.rmtree(self.tmp_path, ignore_errors=True)
def test_upgrade_2_none_selected(self):
"""
Test that upgrade 2 completes properly when the user chooses not to use a proxy ('No')
"""
# GIVEN: An version 1 web bible with proxy settings
# WHEN: Calling upgrade_db and the user has 'clicked' the 'No' button
self.mocked_message_box_instance.clickedButton.return_value = self.mocked_no_button
upgrade_db(self.db_url, upgrade)
# THEN: The proxy meta data should have been removed, and the version should have been changed to version 2
engine = create_engine(self.db_url)
conn = engine.connect()
assert len(conn.execute('SELECT * FROM metadata WHERE key = "proxy_server"').fetchall()) == 0
assert len(conn.execute('SELECT * FROM metadata WHERE key = "proxy_username"').fetchall()) == 0
assert len(conn.execute('SELECT * FROM metadata WHERE key = "proxy_password"').fetchall()) == 0
assert conn.execute('SELECT * FROM metadata WHERE key = "version"').first().value == '2'
self.mocked_settings_instance.setValue.assert_not_called()
def test_upgrade_2_http_selected(self):
"""
Test that upgrade 2 completes properly when the user chooses to use a HTTP proxy
"""
# GIVEN: An version 1 web bible with proxy settings
# WHEN: Calling upgrade_db and the user has 'clicked' the 'HTTP' button
self.mocked_message_box_instance.clickedButton.return_value = self.mocked_http_button
upgrade_db(self.db_url, upgrade)
# THEN: The proxy meta data should have been removed, the version should have been changed to version 2, and the
# proxy server saved to the settings
engine = create_engine(self.db_url)
conn = engine.connect()
assert len(conn.execute('SELECT * FROM metadata WHERE key = "proxy_server"').fetchall()) == 0
assert len(conn.execute('SELECT * FROM metadata WHERE key = "proxy_username"').fetchall()) == 0
assert len(conn.execute('SELECT * FROM metadata WHERE key = "proxy_password"').fetchall()) == 0
assert conn.execute('SELECT * FROM metadata WHERE key = "version"').first().value == '2'
assert self.mocked_settings_instance.setValue.call_args_list == [
call('advanced/proxy http', 'proxy_server'), call('advanced/proxy username', 'proxy_username'),
call('advanced/proxy password', 'proxy_password'), call('advanced/proxy mode', ProxyMode.MANUAL_PROXY)]
def test_upgrade_2_https_selected(self):
"""
Tcest that upgrade 2 completes properly when the user chooses to use a HTTPS proxy
"""
# GIVEN: An version 1 web bible with proxy settings
# WHEN: Calling upgrade_db and the user has 'clicked' the 'HTTPS' button
self.mocked_message_box_instance.clickedButton.return_value = self.mocked_https_button
upgrade_db(self.db_url, upgrade)
# THEN: The proxy settings should have been removed, the version should have been changed to version 2, and the
# proxy server saved to the settings
engine = create_engine(self.db_url)
conn = engine.connect()
assert len(conn.execute('SELECT * FROM metadata WHERE key = "proxy_server"').fetchall()) == 0
assert len(conn.execute('SELECT * FROM metadata WHERE key = "proxy_username"').fetchall()) == 0
assert len(conn.execute('SELECT * FROM metadata WHERE key = "proxy_password"').fetchall()) == 0
assert conn.execute('SELECT * FROM metadata WHERE key = "version"').first().value == '2'
assert self.mocked_settings_instance.setValue.call_args_list == [
call('advanced/proxy https', 'proxy_server'), call('advanced/proxy username', 'proxy_username'),
call('advanced/proxy password', 'proxy_password'), call('advanced/proxy mode', ProxyMode.MANUAL_PROXY)]
def test_upgrade_2_both_selected(self):
"""
Tcest that upgrade 2 completes properly when the user chooses to use a both HTTP and HTTPS proxies
"""
# GIVEN: An version 1 web bible with proxy settings
# WHEN: Calling upgrade_db
self.mocked_message_box_instance.clickedButton.return_value = self.mocked_both_button
upgrade_db(self.db_url, upgrade)
# THEN: The proxy settings should have been removed, the version should have been changed to version 2, and the
# proxy server saved to the settings
engine = create_engine(self.db_url)
conn = engine.connect()
assert len(conn.execute('SELECT * FROM metadata WHERE key = "proxy_server"').fetchall()) == 0
assert len(conn.execute('SELECT * FROM metadata WHERE key = "proxy_username"').fetchall()) == 0
assert len(conn.execute('SELECT * FROM metadata WHERE key = "proxy_password"').fetchall()) == 0
assert conn.execute('SELECT * FROM metadata WHERE key = "version"').first().value == '2'
assert self.mocked_settings_instance.setValue.call_args_list == [
call('advanced/proxy http', 'proxy_server'), call('advanced/proxy https', 'proxy_server'),
call('advanced/proxy username', 'proxy_username'), call('advanced/proxy password', 'proxy_password'),
call('advanced/proxy mode', ProxyMode.MANUAL_PROXY)]

Binary file not shown.

Binary file not shown.