Merge branch 'beta_fixes_4' into 'master'

Fix first run issues

Closes #683 and #682

See merge request openlp/openlp!262
This commit is contained in:
Tim Bentley 2020-10-20 11:32:48 +00:00
commit f47a168733
7 changed files with 41 additions and 40 deletions

View File

@ -75,8 +75,6 @@ class RemoteVersionWorker(ThreadWorker):
self.no_internet.emit()
if version_info and (QtCore.QVersionNumber.fromString(version_info['latest']['version']) >
QtCore.QVersionNumber.fromString(self.current_version)):
Registry().get('settings').setValue('api/last version test', date.today().strftime('%Y-%m-%d'))
Registry().get('settings_form').api_tab.master_version = version_info['latest']['version']
self.new_version.emit(version_info['latest']['version'])
self.quit.emit()

View File

@ -280,6 +280,7 @@ class DownloadWorker(ThreadWorker):
log.exception('Unable to download %s', url)
self.download_failed.emit()
finally:
time.sleep(1)
self.quit.emit()
@QtCore.pyqtSlot()

View File

@ -358,6 +358,13 @@ class Manager(object):
self.db_url = init_url(plugin_name, str(db_file_path)) # TOdO :PATHLIB
else:
self.db_url = init_url(plugin_name)
if not session:
try:
self.session = init_schema(self.db_url)
except (SQLAlchemyError, DBAPIError):
handle_db_error(plugin_name, db_file_path)
else:
self.session = session
if upgrade_mod:
try:
db_ver, up_ver = upgrade_db(self.db_url, upgrade_mod)
@ -373,13 +380,6 @@ class Manager(object):
db_up=up_ver,
db_name=self.db_url))
return
if not session:
try:
self.session = init_schema(self.db_url)
except (SQLAlchemyError, DBAPIError):
handle_db_error(plugin_name, db_file_path)
else:
self.session = session
def save_object(self, object_instance, commit=True):
"""

View File

@ -186,7 +186,6 @@ class FirstTimeForm(QtWidgets.QWizard, UiFirstTimeWizard, RegistryProperties):
self.has_web_access = True
self.application.process_events()
self.downloading = translate('OpenLP.FirstTimeWizard', 'Downloading {name}...')
self.application.set_normal_cursor()
self.is_index_downloaded = True
def _parse_config(self, web_config):
@ -330,6 +329,7 @@ class FirstTimeForm(QtWidgets.QWizard, UiFirstTimeWizard, RegistryProperties):
# Was the thread created.
if self.thumbnail_download_threads:
while any([not is_thread_finished(thread_name) for thread_name in self.thumbnail_download_threads]):
self.application.process_events()
time.sleep(0.1)
self.application.set_normal_cursor()
Registry().remove_function('config_screen_changed', self.screen_selection_widget.load)

View File

@ -23,7 +23,7 @@ This is the main window, where all the action happens.
"""
import os
import shutil
from datetime import datetime
from datetime import datetime, date
from pathlib import Path
from tempfile import gettempdir
@ -626,6 +626,8 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow, LogMixin, RegistryPropert
:param version: The Version to be displayed.
"""
Registry().get('settings').setValue('api/last version test', date.today().strftime('%Y-%m-%d'))
Registry().get('settings_form').api_tab.master_version = version
version_text = translate('OpenLP.MainWindow', 'Version {version} of the web remote is now available for '
'download.\nTo download this version, go to the Remote settings and click the Upgrade '
'button.').format(version=version)

View File

@ -27,10 +27,10 @@ import sys
from collections import OrderedDict
from datetime import date
import requests
from PyQt5 import QtCore
from openlp.core.common.applocation import AppLocation
from openlp.core.common.httputils import get_web_page
from openlp.core.common.registry import Registry
from openlp.core.threading import ThreadWorker, run_thread
@ -104,9 +104,9 @@ class VersionWorker(ThreadWorker):
retries = 0
while retries < 3:
try:
response = requests.get(download_url, headers=headers)
if response.status_code == 200:
remote_version = response.text.strip()
response = get_web_page(download_url, headers=headers)
if response:
remote_version = response.strip()
log.debug('New version found: %s', remote_version)
break
except OSError:

View File

@ -47,8 +47,8 @@ def test_worker_init():
@patch('openlp.core.version.platform')
@patch('openlp.core.version.requests')
def test_worker_start(mock_requests, mock_platform):
@patch('openlp.core.version.get_web_page')
def test_worker_start(mock_get_web_page, mock_platform):
"""
Test the VersionWorkder.start() method
"""
@ -57,7 +57,7 @@ def test_worker_start(mock_requests, mock_platform):
current_version = {'full': '2.0', 'version': '2.0', 'build': None}
mock_platform.system.return_value = 'Linux'
mock_platform.release.return_value = '4.12.0-1-amd64'
mock_requests.get.return_value = MagicMock(text='2.4.6', status_code=200)
mock_get_web_page.return_value = '2.4.6'
worker = VersionWorker(last_check_date, current_version)
# WHEN: The worker is run
@ -68,14 +68,14 @@ def test_worker_start(mock_requests, mock_platform):
# THEN: The check completes and the signal is emitted
expected_download_url = 'https://get.openlp.org/versions/version.txt'
expected_headers = {'User-Agent': 'OpenLP/2.0 Linux/4.12.0-1-amd64; '}
mock_requests.get.assert_called_once_with(expected_download_url, headers=expected_headers)
mock_get_web_page.assert_called_once_with(expected_download_url, headers=expected_headers)
mock_new_version.emit.assert_called_once_with('2.4.6')
mock_quit.emit.assert_called_once_with()
@patch('openlp.core.version.platform')
@patch('openlp.core.version.requests')
def test_worker_start_fail(mock_requests, mock_platform):
@patch('openlp.core.version.get_web_page')
def test_worker_start_fail(mock_get_web_page, mock_platform):
"""
Test the Version Workder.start() method with no response
"""
@ -84,7 +84,7 @@ def test_worker_start_fail(mock_requests, mock_platform):
current_version = {'full': '2.0', 'version': '2.0', 'build': None}
mock_platform.system.return_value = 'Linux'
mock_platform.release.return_value = '4.12.0-1-amd64'
mock_requests.get.return_value = MagicMock(text='2.4.6', status_code=500)
mock_get_web_page.return_value = None
worker = VersionWorker(last_check_date, current_version)
# WHEN: The worker is run
@ -95,14 +95,14 @@ def test_worker_start_fail(mock_requests, mock_platform):
# THEN: The check completes and the signal is emitted
expected_download_url = 'https://get.openlp.org/versions/version.txt'
expected_headers = {'User-Agent': 'OpenLP/2.0 Linux/4.12.0-1-amd64; '}
mock_requests.get.assert_called_once_with(expected_download_url, headers=expected_headers)
mock_get_web_page.assert_called_once_with(expected_download_url, headers=expected_headers)
mock_new_version.emit.assert_not_called()
mock_quit.emit.assert_called_once_with()
@patch('openlp.core.version.platform')
@patch('openlp.core.version.requests')
def test_worker_start_dev_version(mock_requests, mock_platform):
@patch('openlp.core.version.get_web_page')
def test_worker_start_dev_version(mock_get_web_page, mock_platform):
"""
Test the VersionWorkder.start() method for dev versions
"""
@ -111,7 +111,7 @@ def test_worker_start_dev_version(mock_requests, mock_platform):
current_version = {'full': '2.1.3', 'version': '2.1.3', 'build': None}
mock_platform.system.return_value = 'Linux'
mock_platform.release.return_value = '4.12.0-1-amd64'
mock_requests.get.return_value = MagicMock(text='2.4.6', status_code=200)
mock_get_web_page.return_value = '2.4.6'
worker = VersionWorker(last_check_date, current_version)
# WHEN: The worker is run
@ -122,14 +122,14 @@ def test_worker_start_dev_version(mock_requests, mock_platform):
# THEN: The check completes and the signal is emitted
expected_download_url = 'https://get.openlp.org/versions/dev_version.txt'
expected_headers = {'User-Agent': 'OpenLP/2.1.3 Linux/4.12.0-1-amd64; '}
mock_requests.get.assert_called_once_with(expected_download_url, headers=expected_headers)
mock_get_web_page.assert_called_once_with(expected_download_url, headers=expected_headers)
mock_new_version.emit.assert_called_once_with('2.4.6')
mock_quit.emit.assert_called_once_with()
@patch('openlp.core.version.platform')
@patch('openlp.core.version.requests')
def test_worker_start_nightly_version(mock_requests, mock_platform):
@patch('openlp.core.version.get_web_page')
def test_worker_start_nightly_version(mock_get_web_page, mock_platform):
"""
Test the VersionWorkder.start() method for nightlies
"""
@ -138,7 +138,7 @@ def test_worker_start_nightly_version(mock_requests, mock_platform):
current_version = {'full': '2.1-bzr2345', 'version': '2.1', 'build': '2345'}
mock_platform.system.return_value = 'Linux'
mock_platform.release.return_value = '4.12.0-1-amd64'
mock_requests.get.return_value = MagicMock(text='2.4.6', status_code=200)
mock_get_web_page.return_value = '2.4.6'
worker = VersionWorker(last_check_date, current_version)
# WHEN: The worker is run
@ -149,14 +149,14 @@ def test_worker_start_nightly_version(mock_requests, mock_platform):
# THEN: The check completes and the signal is emitted
expected_download_url = 'https://get.openlp.org/versions/nightly_version.txt'
expected_headers = {'User-Agent': 'OpenLP/2.1-bzr2345 Linux/4.12.0-1-amd64; '}
mock_requests.get.assert_called_once_with(expected_download_url, headers=expected_headers)
mock_get_web_page.assert_called_once_with(expected_download_url, headers=expected_headers)
mock_new_version.emit.assert_called_once_with('2.4.6')
mock_quit.emit.assert_called_once_with()
@patch('openlp.core.version.platform')
@patch('openlp.core.version.requests')
def test_worker_empty_response(mock_requests, mock_platform):
@patch('openlp.core.version.get_web_page')
def test_worker_empty_response(mock_get_web_page, mock_platform):
"""
Test the VersionWorkder.start() method for empty responses
"""
@ -165,7 +165,7 @@ def test_worker_empty_response(mock_requests, mock_platform):
current_version = {'full': '2.1-bzr2345', 'version': '2.1', 'build': '2345'}
mock_platform.system.return_value = 'Linux'
mock_platform.release.return_value = '4.12.0-1-amd64'
mock_requests.get.return_value = MagicMock(text='\n')
mock_get_web_page.return_value = '\n'
worker = VersionWorker(last_check_date, current_version)
# WHEN: The worker is run
@ -176,14 +176,14 @@ def test_worker_empty_response(mock_requests, mock_platform):
# THEN: The check completes and the signal is emitted
expected_download_url = 'https://get.openlp.org/versions/nightly_version.txt'
expected_headers = {'User-Agent': 'OpenLP/2.1-bzr2345 Linux/4.12.0-1-amd64; '}
mock_requests.get.assert_called_once_with(expected_download_url, headers=expected_headers)
mock_get_web_page.assert_called_once_with(expected_download_url, headers=expected_headers)
assert mock_new_version.emit.call_count == 0
mock_quit.emit.assert_called_once_with()
@patch('openlp.core.version.platform')
@patch('openlp.core.version.requests')
def test_worker_start_connection_error(mock_requests, mock_platform):
@patch('openlp.core.version.get_web_page')
def test_worker_start_connection_error(mock_get_web_page, mock_platform):
"""
Test the VersionWorkder.start() method when a ConnectionError happens
"""
@ -192,7 +192,7 @@ def test_worker_start_connection_error(mock_requests, mock_platform):
current_version = {'full': '2.0', 'version': '2.0', 'build': None}
mock_platform.system.return_value = 'Linux'
mock_platform.release.return_value = '4.12.0-1-amd64'
mock_requests.get.side_effect = ConnectionError('Could not connect')
mock_get_web_page.side_effect = ConnectionError('Could not connect')
worker = VersionWorker(last_check_date, current_version)
# WHEN: The worker is run
@ -203,8 +203,8 @@ def test_worker_start_connection_error(mock_requests, mock_platform):
# THEN: The check completes and the signal is emitted
expected_download_url = 'https://get.openlp.org/versions/version.txt'
expected_headers = {'User-Agent': 'OpenLP/2.0 Linux/4.12.0-1-amd64; '}
mock_requests.get.assert_called_with(expected_download_url, headers=expected_headers)
assert mock_requests.get.call_count == 3
mock_get_web_page.assert_called_with(expected_download_url, headers=expected_headers)
assert mock_get_web_page.call_count == 3
mocked_no_internet.emit.assert_called_once_with()
mocked_quit.emit.assert_called_once_with()