diff --git a/openlp/core/api/http/__init__.py b/openlp/core/api/http/__init__.py index d06059d38..25b75cabf 100644 --- a/openlp/core/api/http/__init__.py +++ b/openlp/core/api/http/__init__.py @@ -24,7 +24,7 @@ from functools import wraps from webob import Response -from openlp.core.common.settings import Settings +from openlp.core.common.registry import Registry def check_auth(auth): @@ -34,8 +34,8 @@ def check_auth(auth): :param auth: the authorisation object which needs to be tested :return Whether authentication have been successful """ - auth_code = "{user}:{password}".format(user=Settings().value('api/user id'), - password=Settings().value('api/password')) + auth_code = "{user}:{password}".format(user=Registry().get('settings').value('api/user id'), + password=Registry().get('settings').value('api/password')) try: auth_base = base64.b64encode(auth_code) except TypeError: @@ -64,7 +64,7 @@ def requires_auth(f): """ @wraps(f) def decorated(*args, **kwargs): - if not Settings().value('api/authentication enabled'): + if not Registry().get('settings').value('api/authentication enabled'): return f(*args, **kwargs) req = args[0] if not hasattr(req, 'authorization'): diff --git a/openlp/core/api/http/server.py b/openlp/core/api/http/server.py index ac3c35f37..e279c5d47 100644 --- a/openlp/core/api/http/server.py +++ b/openlp/core/api/http/server.py @@ -36,7 +36,6 @@ from openlp.core.common.i18n import UiStrings, translate from openlp.core.common.mixins import LogMixin, RegistryProperties from openlp.core.common.path import create_paths from openlp.core.common.registry import Registry, RegistryBase -from openlp.core.common.settings import Settings from openlp.core.threading import ThreadWorker, run_thread from openlp.core.api import app as application @@ -52,8 +51,8 @@ class HttpWorker(ThreadWorker): """ Run the thread. """ - address = Settings().value('api/ip address') - port = Settings().value('api/port') + address = Registry().get('settings').value('api/ip address') + port = Registry().get('settings').value('api/port') Registry().execute('get_website_version') try: application.static_folder = str(AppLocation.get_section_data_path('remotes') / 'static') @@ -113,7 +112,7 @@ class HttpServer(RegistryBase, RegistryProperties, LogMixin): time.sleep(1) progress.close() self.application.process_events() - Settings().setValue('remotes/download version', self.version) + self.settings.setValue('remotes/download version', self.version) def website_version(self): """ diff --git a/openlp/core/api/lib.py b/openlp/core/api/lib.py index 41790b05b..8d730c3ff 100644 --- a/openlp/core/api/lib.py +++ b/openlp/core/api/lib.py @@ -1,14 +1,33 @@ +# -*- coding: utf-8 -*- + +########################################################################## +# OpenLP - Open Source Lyrics Projection # +# ---------------------------------------------------------------------- # +# Copyright (c) 2008-2020 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, either version 3 of the License, or # +# (at your option) any later version. # +# # +# 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, see . # +########################################################################## import json from flask import jsonify, Response, request from functools import wraps -from openlp.core.common.settings import Settings from openlp.core.common.registry import Registry def login_required(f): @wraps(f) def decorated(*args, **kwargs): - if not Settings().value('api/authentication enabled'): + if not Registry().get('settings').value('api/authentication enabled'): return f(*args, **kwargs) token = request.headers.get('Authorization', '') if token == Registry().get('authentication_token'): @@ -33,14 +52,14 @@ def extract_request(json_string, name): # ----------------------- OLD AUTH SECTION --------------------- def check_auth(username, password): - return Settings().value('api/user id') == username and \ - Settings().value('api/password') == password + return Registry().get('settings').value('api/user id') == username and \ + Registry().get('settings').value('api/password') == password def old_auth(f): @wraps(f) def decorated(*args, **kwargs): - if not Settings().value('api/authentication enabled'): + if not Registry().get('settings').value('api/authentication enabled'): return f(*args, **kwargs) auth = request.authorization if not auth or not check_auth(auth.username, auth.password): diff --git a/openlp/core/api/main.py b/openlp/core/api/main.py index fafa51395..1855988a5 100644 --- a/openlp/core/api/main.py +++ b/openlp/core/api/main.py @@ -1,3 +1,24 @@ +# -*- coding: utf-8 -*- + +########################################################################## +# OpenLP - Open Source Lyrics Projection # +# ---------------------------------------------------------------------- # +# Copyright (c) 2008-2020 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, either version 3 of the License, or # +# (at your option) any later version. # +# # +# 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, see . # +########################################################################## + from flask import Blueprint, send_from_directory from openlp.core.common.applocation import AppLocation diff --git a/openlp/core/api/poll.py b/openlp/core/api/poll.py index a744cdc4d..1beadfe3d 100644 --- a/openlp/core/api/poll.py +++ b/openlp/core/api/poll.py @@ -23,7 +23,6 @@ import json from openlp.core.common.httputils import get_web_page from openlp.core.common.mixins import RegistryProperties -from openlp.core.common.settings import Settings class Poller(RegistryProperties): @@ -44,14 +43,14 @@ class Poller(RegistryProperties): 'service': self.service_manager.service_id, 'slide': self.live_controller.selected_row or 0, 'item': self.live_controller.service_item.unique_identifier if self.live_controller.service_item else '', - 'twelve': Settings().value('api/twelve hour'), + 'twelve': self.settings.value('api/twelve hour'), 'blank': self.live_controller.blank_screen.isChecked(), 'theme': self.live_controller.theme_screen.isChecked(), 'display': self.live_controller.desktop_screen.isChecked(), 'version': 3, - 'isSecure': Settings().value('api/authentication enabled'), + 'isSecure': self.settings.value('api/authentication enabled'), 'isAuthorised': False, - 'chordNotation': Settings().value('songs/chord notation'), + 'chordNotation': self.settings.value('songs/chord notation'), 'isStageActive': self.is_stage_active(), 'isLiveActive': self.is_live_active(), 'isChordsActive': self.is_chords_active() diff --git a/openlp/core/api/tab.py b/openlp/core/api/tab.py index 3c7dfbf12..caa3219e5 100644 --- a/openlp/core/api/tab.py +++ b/openlp/core/api/tab.py @@ -26,7 +26,6 @@ from PyQt5 import QtCore, QtGui, QtWidgets from openlp.core.common import get_network_interfaces from openlp.core.common.i18n import UiStrings, translate from openlp.core.common.registry import Registry -from openlp.core.common.settings import Settings from openlp.core.lib.settingstab import SettingsTab from openlp.core.ui.icons import UiIcons @@ -211,16 +210,16 @@ class ApiTab(SettingsTab): """ Load the configuration and update the server configuration if necessary """ - self.port_spin_box.setText(str(Settings().value(self.settings_section + '/port'))) - self.address_edit.setText(Settings().value(self.settings_section + '/ip address')) - self.twelve_hour = Settings().value(self.settings_section + '/twelve hour') + self.port_spin_box.setText(str(self.settings.value(self.settings_section + '/port'))) + self.address_edit.setText(self.settings.value(self.settings_section + '/ip address')) + self.twelve_hour = self.settings.value(self.settings_section + '/twelve hour') self.twelve_hour_check_box.setChecked(self.twelve_hour) - self.thumbnails = Settings().value(self.settings_section + '/thumbnails') + self.thumbnails = self.settings.value(self.settings_section + '/thumbnails') self.thumbnails_check_box.setChecked(self.thumbnails) - self.user_login_group_box.setChecked(Settings().value(self.settings_section + '/authentication enabled')) - self.user_id.setText(Settings().value(self.settings_section + '/user id')) - self.password.setText(Settings().value(self.settings_section + '/password')) - self.current_version_value.setText(Settings().value('remotes/download version')) + self.user_login_group_box.setChecked(self.settings.value(self.settings_section + '/authentication enabled')) + self.user_id.setText(self.settings.value(self.settings_section + '/user id')) + self.password.setText(self.settings.value(self.settings_section + '/password')) + self.current_version_value.setText(self.settings.value('remotes/download version')) self.master_version_value.setText(Registry().get_flag('website_version')) if self.master_version_value.text() == self.current_version_value.text(): self.update_site_group_box.setEnabled(False) @@ -230,14 +229,14 @@ class ApiTab(SettingsTab): """ Save the configuration and update the server configuration if necessary """ - if Settings().value(self.settings_section + '/ip address') != self.address_edit.text(): + if self.settings.value(self.settings_section + '/ip address') != self.address_edit.text(): self.settings_form.register_post_process('remotes_config_updated') - Settings().setValue(self.settings_section + '/ip address', self.address_edit.text()) - Settings().setValue(self.settings_section + '/twelve hour', self.twelve_hour) - Settings().setValue(self.settings_section + '/thumbnails', self.thumbnails) - Settings().setValue(self.settings_section + '/authentication enabled', self.user_login_group_box.isChecked()) - Settings().setValue(self.settings_section + '/user id', self.user_id.text()) - Settings().setValue(self.settings_section + '/password', self.password.text()) + self.settings.setValue(self.settings_section + '/ip address', self.address_edit.text()) + self.settings.setValue(self.settings_section + '/twelve hour', self.twelve_hour) + self.settings.setValue(self.settings_section + '/thumbnails', self.thumbnails) + self.settings.setValue(self.settings_section + '/authentication enabled', self.user_login_group_box.isChecked()) + self.settings.setValue(self.settings_section + '/user id', self.user_id.text()) + self.settings.setValue(self.settings_section + '/password', self.password.text()) if self.update_site_group_box.isChecked(): self.settings_form.register_post_process('download_website') diff --git a/openlp/core/api/versions/__init__.py b/openlp/core/api/versions/__init__.py index e69de29bb..fa1ec5512 100644 --- a/openlp/core/api/versions/__init__.py +++ b/openlp/core/api/versions/__init__.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- + +########################################################################## +# OpenLP - Open Source Lyrics Projection # +# ---------------------------------------------------------------------- # +# Copyright (c) 2008-2020 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, either version 3 of the License, or # +# (at your option) any later version. # +# # +# 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, see . # +########################################################################## diff --git a/openlp/core/api/versions/v1/__init__.py b/openlp/core/api/versions/v1/__init__.py index 3d2e61c46..e10750971 100644 --- a/openlp/core/api/versions/v1/__init__.py +++ b/openlp/core/api/versions/v1/__init__.py @@ -1,3 +1,24 @@ +# -*- coding: utf-8 -*- + +########################################################################## +# OpenLP - Open Source Lyrics Projection # +# ---------------------------------------------------------------------- # +# Copyright (c) 2008-2020 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, either version 3 of the License, or # +# (at your option) any later version. # +# # +# 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, see . # +########################################################################## + from openlp.core.api.versions.v1.controller import controller_views from openlp.core.api.versions.v1.core import core_views from openlp.core.api.versions.v1.service import service_views diff --git a/openlp/core/api/versions/v1/controller.py b/openlp/core/api/versions/v1/controller.py index 0d26fd978..090cd2d32 100644 --- a/openlp/core/api/versions/v1/controller.py +++ b/openlp/core/api/versions/v1/controller.py @@ -1,3 +1,23 @@ +# -*- coding: utf-8 -*- + +########################################################################## +# OpenLP - Open Source Lyrics Projection # +# ---------------------------------------------------------------------- # +# Copyright (c) 2008-2020 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, either version 3 of the License, or # +# (at your option) any later version. # +# # +# 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, see . # +########################################################################## import os import logging import urllib.request @@ -6,7 +26,6 @@ from pathlib import Path from openlp.core.api.lib import old_auth, old_success_response, extract_request from openlp.core.common.registry import Registry from openlp.core.common.applocation import AppLocation -from openlp.core.common.settings import Settings from openlp.core.lib import create_thumb from openlp.core.lib.serviceitem import ItemCapabilities @@ -35,7 +54,8 @@ def controller_text_api(): item['chords_text'] = str(frame.get('chords_text', '')) item['text'] = frame['text'] item['html'] = current_item.get_rendered_frame(index) - elif current_item.is_image() and not frame.get('image', '') and Settings().value('api/thumbnails'): + elif current_item.is_image() and not frame.get('image', '') and \ + Registry().get('settings').value('api/thumbnails'): thumbnail_path = os.path.join('images', 'thumbnails', frame['title']) full_thumbnail_path = AppLocation.get_data_path() / thumbnail_path if not full_thumbnail_path.exists(): @@ -50,7 +70,8 @@ def controller_text_api(): item['title'] = str(frame['display_title']) if current_item.is_capable(ItemCapabilities.HasNotes): item['slide_notes'] = str(frame['notes']) - if current_item.is_capable(ItemCapabilities.HasThumbnails) and Settings().value('api/thumbnails'): + if current_item.is_capable(ItemCapabilities.HasThumbnails) and \ + Registry().get('settings').value('api/thumbnails'): # If the file is under our app directory tree send the portion after the match data_path = str(AppLocation.get_data_path()) if frame['image'][0:len(data_path)] == data_path: diff --git a/openlp/core/api/versions/v1/core.py b/openlp/core/api/versions/v1/core.py index 4782574b5..90d1bcd2d 100644 --- a/openlp/core/api/versions/v1/core.py +++ b/openlp/core/api/versions/v1/core.py @@ -1,3 +1,23 @@ +# -*- coding: utf-8 -*- + +########################################################################## +# OpenLP - Open Source Lyrics Projection # +# ---------------------------------------------------------------------- # +# Copyright (c) 2008-2020 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, either version 3 of the License, or # +# (at your option) any later version. # +# # +# 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, see . # +########################################################################## from openlp.core.api.lib import old_auth, old_success_response from openlp.core.common.registry import Registry from openlp.core.lib import image_to_byte @@ -6,7 +26,6 @@ from openlp.core.state import State from flask import jsonify, Blueprint - core_views = Blueprint('old_core', __name__) diff --git a/openlp/core/api/versions/v1/service.py b/openlp/core/api/versions/v1/service.py index 4e99321c0..958ca3540 100644 --- a/openlp/core/api/versions/v1/service.py +++ b/openlp/core/api/versions/v1/service.py @@ -1,3 +1,23 @@ +# -*- coding: utf-8 -*- + +########################################################################## +# OpenLP - Open Source Lyrics Projection # +# ---------------------------------------------------------------------- # +# Copyright (c) 2008-2020 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, either version 3 of the License, or # +# (at your option) any later version. # +# # +# 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, see . # +########################################################################## from openlp.core.api.lib import old_auth, old_success_response, extract_request from flask import jsonify, request, Blueprint diff --git a/openlp/core/api/versions/v2/__init__.py b/openlp/core/api/versions/v2/__init__.py index 9e76f8c11..f19e68f80 100644 --- a/openlp/core/api/versions/v2/__init__.py +++ b/openlp/core/api/versions/v2/__init__.py @@ -1,3 +1,24 @@ +# -*- coding: utf-8 -*- + +########################################################################## +# OpenLP - Open Source Lyrics Projection # +# ---------------------------------------------------------------------- # +# Copyright (c) 2008-2020 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, either version 3 of the License, or # +# (at your option) any later version. # +# # +# 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, see . # +########################################################################## + from openlp.core.api.versions.v2.controller import controller_views from openlp.core.api.versions.v2.core import core from openlp.core.api.versions.v2.service import service_views diff --git a/openlp/core/api/versions/v2/controller.py b/openlp/core/api/versions/v2/controller.py index fdf5faf3e..3754f8a19 100644 --- a/openlp/core/api/versions/v2/controller.py +++ b/openlp/core/api/versions/v2/controller.py @@ -1,3 +1,23 @@ +# -*- coding: utf-8 -*- + +########################################################################## +# OpenLP - Open Source Lyrics Projection # +# ---------------------------------------------------------------------- # +# Copyright (c) 2008-2020 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, either version 3 of the License, or # +# (at your option) any later version. # +# # +# 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, see . # +########################################################################## import os import urllib.request from pathlib import Path @@ -5,7 +25,6 @@ from pathlib import Path from openlp.core.api.lib import login_required from openlp.core.common.registry import Registry from openlp.core.common.applocation import AppLocation -from openlp.core.common.settings import Settings from openlp.core.lib import create_thumb from openlp.core.lib.serviceitem import ItemCapabilities @@ -31,7 +50,8 @@ def controller_text_api(): item['chords_text'] = str(frame.get('chords_text', '')) item['text'] = frame['text'] item['html'] = current_item.get_rendered_frame(index) - elif current_item.is_image() and not frame.get('image', '') and Settings().value('api/thumbnails'): + elif current_item.is_image() and not frame.get('image', '') and \ + Registry().get('settings').value('api/thumbnails'): thumbnail_path = os.path.join('images', 'thumbnails', frame['title']) full_thumbnail_path = AppLocation.get_data_path() / thumbnail_path if not full_thumbnail_path.exists(): @@ -46,7 +66,8 @@ def controller_text_api(): item['title'] = str(frame['display_title']) if current_item.is_capable(ItemCapabilities.HasNotes): item['slide_notes'] = str(frame['notes']) - if current_item.is_capable(ItemCapabilities.HasThumbnails) and Settings().value('api/thumbnails'): + if current_item.is_capable(ItemCapabilities.HasThumbnails) and \ + Registry().get('settings').value('api/thumbnails'): # If the file is under our app directory tree send the portion after the match data_path = str(AppLocation.get_data_path()) if frame['image'][0:len(data_path)] == data_path: diff --git a/openlp/core/api/versions/v2/core.py b/openlp/core/api/versions/v2/core.py index 4a9db0eda..3d98840be 100644 --- a/openlp/core/api/versions/v2/core.py +++ b/openlp/core/api/versions/v2/core.py @@ -1,13 +1,31 @@ +# -*- coding: utf-8 -*- + +########################################################################## +# OpenLP - Open Source Lyrics Projection # +# ---------------------------------------------------------------------- # +# Copyright (c) 2008-2020 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, either version 3 of the License, or # +# (at your option) any later version. # +# # +# 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, see . # +########################################################################## from openlp.core.api.lib import login_required from openlp.core.common.registry import Registry -from openlp.core.common.settings import Settings from openlp.core.lib import image_to_byte from openlp.core.lib.plugin import PluginStatus, StringContent from openlp.core.state import State from flask import jsonify, request, abort, Blueprint - core = Blueprint('core', __name__) @@ -43,8 +61,8 @@ def plugin_list(): @core.route('/system') def system_information(): data = {} - data['websocket_port'] = Settings().value('api/websocket port') - data['login_required'] = Settings().value('api/authentication enabled') + data['websocket_port'] = Registry().get('settings').value('api/websocket port') + data['login_required'] = Registry().get('settings').value('api/authentication enabled') return jsonify(data) @@ -55,7 +73,8 @@ def login(): abort(400) username = data.get('username', '') password = data.get('password', '') - if username == Settings().value('api/user id') and password == Settings().value('api/password'): + if username == Registry().get('settings').value('api/user id') and \ + password == Registry().get('settings').value('api/password'): return jsonify({'token': Registry().get('authentication_token')}) else: return '', 401 diff --git a/openlp/core/api/versions/v2/service.py b/openlp/core/api/versions/v2/service.py index 89ab62c6c..8ff88b2a3 100644 --- a/openlp/core/api/versions/v2/service.py +++ b/openlp/core/api/versions/v2/service.py @@ -1,3 +1,24 @@ +# -*- coding: utf-8 -*- + +########################################################################## +# OpenLP - Open Source Lyrics Projection # +# ---------------------------------------------------------------------- # +# Copyright (c) 2008-2020 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, either version 3 of the License, or # +# (at your option) any later version. # +# # +# 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, see . # +########################################################################## + from openlp.core.api.lib import login_required from flask import jsonify, request, abort, Blueprint diff --git a/openlp/core/api/websockets.py b/openlp/core/api/websockets.py index e7499aef7..6f10fa37f 100644 --- a/openlp/core/api/websockets.py +++ b/openlp/core/api/websockets.py @@ -31,7 +31,6 @@ from websockets import serve from openlp.core.common.mixins import LogMixin, RegistryProperties from openlp.core.common.registry import Registry -from openlp.core.common.settings import Settings from openlp.core.threading import ThreadWorker, run_thread @@ -76,8 +75,8 @@ class WebSocketWorker(ThreadWorker, RegistryProperties, LogMixin): """ Run the worker. """ - address = Settings().value('api/ip address') - port = Settings().value('api/websocket port') + address = Registry().get('settings').value('api/ip address') + port = Registry().get('settings').value('api/websocket port') # Start the event loop self.event_loop = asyncio.new_event_loop() asyncio.set_event_loop(self.event_loop) diff --git a/openlp/core/api/zeroconf.py b/openlp/core/api/zeroconf.py index d917d6381..7a8615a20 100644 --- a/openlp/core/api/zeroconf.py +++ b/openlp/core/api/zeroconf.py @@ -29,7 +29,6 @@ from zeroconf import ServiceInfo, Zeroconf from openlp.core.common import get_network_interfaces from openlp.core.common.registry import Registry -from openlp.core.common.settings import Settings from openlp.core.threading import ThreadWorker, run_thread @@ -91,8 +90,8 @@ def start_zeroconf(): # When we're running tests, just skip this set up if this flag is set if Registry().get_flag('no_web_server'): return - http_port = Settings().value('api/port') - ws_port = Settings().value('api/websocket port') + http_port = Registry().get('settings').value('api/port') + ws_port = Registry().get('settings').value('api/websocket port') for name, interface in get_network_interfaces().items(): worker = ZeroconfWorker(interface['ip'], http_port, ws_port) run_thread(worker, 'api_zeroconf_{name}'.format(name=name)) diff --git a/openlp/core/common/applocation.py b/openlp/core/common/applocation.py index a2e80ec57..40c754d7e 100644 --- a/openlp/core/common/applocation.py +++ b/openlp/core/common/applocation.py @@ -31,7 +31,7 @@ import appdirs import openlp from openlp.core.common import get_frozen_path, is_macosx, is_win from openlp.core.common.path import create_paths -from openlp.core.common.settings import Settings +from openlp.core.common.registry import Registry log = logging.getLogger(__name__) @@ -79,8 +79,8 @@ class AppLocation(object): :rtype: Path """ # Check if we have a different data location. - if Settings().contains('advanced/data path'): - path = Path(Settings().value('advanced/data path')) + if Registry().get('settings').contains('advanced/data path'): + path = Path(Registry().get('settings').value('advanced/data path')) else: path = AppLocation.get_directory(AppLocation.DataDir) create_paths(path) diff --git a/openlp/core/common/httputils.py b/openlp/core/common/httputils.py index 49d3ac21d..6a2dbf7b9 100644 --- a/openlp/core/common/httputils.py +++ b/openlp/core/common/httputils.py @@ -34,7 +34,7 @@ from PyQt5 import QtCore from openlp.core.common import trace_error_handler from openlp.core.common.registry import Registry -from openlp.core.common.settings import ProxyMode, Settings +from openlp.core.common.settings import ProxyMode from openlp.core.threading import ThreadWorker @@ -77,7 +77,7 @@ def get_proxy_settings(mode=None): :return: A dict using the format expected by the requests library. :rtype: dict | None """ - settings = Settings() + settings = Registry().get('settings') if mode is None: mode = settings.value('advanced/proxy mode') if mode == ProxyMode.NO_PROXY: diff --git a/openlp/core/common/i18n.py b/openlp/core/common/i18n.py index e63833454..6df83d7d5 100644 --- a/openlp/core/common/i18n.py +++ b/openlp/core/common/i18n.py @@ -30,7 +30,7 @@ from PyQt5 import QtCore, QtWidgets from openlp.core.common import Singleton, is_macosx, is_win from openlp.core.common.applocation import AppLocation -from openlp.core.common.settings import Settings +from openlp.core.common.registry import Registry log = logging.getLogger(__name__) @@ -265,7 +265,7 @@ class LanguageManager(object): """ Retrieve a saved language to use from settings """ - language = Settings().value('core/language') + language = Registry().get('settings').value('core/language') language = str(language) log.info("Language file: '{language}' Loaded from conf file".format(language=language)) m = re.match(r'\[(.*)\]', language) @@ -293,7 +293,7 @@ class LanguageManager(object): language = str(qm_list[action_name]) if LanguageManager.auto_language: language = '[{language}]'.format(language=language) - Settings().setValue('core/language', language) + Registry().get('settings').setValue('core/language', language) log.info("Language file: '{language}' written to conf file".format(language=language)) if message: QtWidgets.QMessageBox.information(None, diff --git a/openlp/plugins/alerts/remote.py b/openlp/plugins/alerts/remote.py index 3bbbcb133..79fad3aad 100644 --- a/openlp/plugins/alerts/remote.py +++ b/openlp/plugins/alerts/remote.py @@ -1,3 +1,23 @@ +# -*- coding: utf-8 -*- + +########################################################################## +# OpenLP - Open Source Lyrics Projection # +# ---------------------------------------------------------------------- # +# Copyright (c) 2008-2020 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, either version 3 of the License, or # +# (at your option) any later version. # +# # +# 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, see . # +########################################################################## from flask import Blueprint, request, abort from openlp.core.api import app diff --git a/openlp/plugins/bibles/remote.py b/openlp/plugins/bibles/remote.py index d5fc05d96..9426c0cf7 100644 --- a/openlp/plugins/bibles/remote.py +++ b/openlp/plugins/bibles/remote.py @@ -4,7 +4,7 @@ ############################################################################### # OpenLP - Open Source Lyrics Projection # # --------------------------------------------------------------------------- # -# Copyright (c) 2008-2019 OpenLP Developers # +# Copyright (c) 2008-2020 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 # diff --git a/openlp/plugins/custom/remote.py b/openlp/plugins/custom/remote.py index 8fb1a34df..23904db17 100644 --- a/openlp/plugins/custom/remote.py +++ b/openlp/plugins/custom/remote.py @@ -4,7 +4,7 @@ ############################################################################### # OpenLP - Open Source Lyrics Projection # # --------------------------------------------------------------------------- # -# Copyright (c) 2008-2019 OpenLP Developers # +# Copyright (c) 2008-2020 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 # diff --git a/openlp/plugins/images/remote.py b/openlp/plugins/images/remote.py index 29d4507bd..ba3e10e42 100644 --- a/openlp/plugins/images/remote.py +++ b/openlp/plugins/images/remote.py @@ -4,7 +4,7 @@ ############################################################################### # OpenLP - Open Source Lyrics Projection # # --------------------------------------------------------------------------- # -# Copyright (c) 2008-2019 OpenLP Developers # +# Copyright (c) 2008-2020 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 # diff --git a/openlp/plugins/media/remote.py b/openlp/plugins/media/remote.py index 4ebddef00..f419ef3d0 100644 --- a/openlp/plugins/media/remote.py +++ b/openlp/plugins/media/remote.py @@ -4,7 +4,7 @@ ############################################################################### # OpenLP - Open Source Lyrics Projection # # --------------------------------------------------------------------------- # -# Copyright (c) 2008-2019 OpenLP Developers # +# Copyright (c) 2008-2020 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 # diff --git a/openlp/plugins/presentations/remote.py b/openlp/plugins/presentations/remote.py index 6cb3fd2ba..0a97a10d4 100644 --- a/openlp/plugins/presentations/remote.py +++ b/openlp/plugins/presentations/remote.py @@ -4,7 +4,7 @@ ############################################################################### # OpenLP - Open Source Lyrics Projection # # --------------------------------------------------------------------------- # -# Copyright (c) 2008-2019 OpenLP Developers # +# Copyright (c) 2008-2020 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 # diff --git a/openlp/plugins/songs/remote.py b/openlp/plugins/songs/remote.py index 207230248..c7bd83e20 100644 --- a/openlp/plugins/songs/remote.py +++ b/openlp/plugins/songs/remote.py @@ -4,7 +4,7 @@ ############################################################################### # OpenLP - Open Source Lyrics Projection # # --------------------------------------------------------------------------- # -# Copyright (c) 2008-2019 OpenLP Developers # +# Copyright (c) 2008-2020 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 # diff --git a/tests/functional/openlp_core/api/endpoint/test_controller.py b/tests/functional/openlp_core/api/endpoint/test_controller.py index 3ced8dc86..3c45f9108 100644 --- a/tests/functional/openlp_core/api/endpoint/test_controller.py +++ b/tests/functional/openlp_core/api/endpoint/test_controller.py @@ -30,6 +30,7 @@ from openlp.core.state import State # Mock QtWebEngineWidgets # sys.modules['PyQt5.QtWebEngineWidgets'] = MagicMock() +from openlp.core.common.settings import Settings from openlp.core.common.registry import Registry from openlp.core.display.screens import ScreenList from openlp.core.lib.serviceitem import ServiceItem @@ -78,7 +79,7 @@ class TestController(TestCase): Registry().register('renderer', self.mocked_renderer) flask_app.config['TESTING'] = True self.client = flask_app.test_client() - Registry().register('settings', MagicMock(**{'value.return_value': 'english'})) + Registry().register('settings', Settings()) def test_controller_text_empty(self): """ diff --git a/tests/functional/openlp_core/api/http/test_init.py b/tests/functional/openlp_core/api/http/test_init.py index b8613fe88..b158b5ca8 100644 --- a/tests/functional/openlp_core/api/http/test_init.py +++ b/tests/functional/openlp_core/api/http/test_init.py @@ -43,6 +43,7 @@ class TestInit(TestCase, TestMixin): Registry().register('service_list', MagicMock()) self.build_settings() self.password = 'c3VwZXJmbHk6bGFtYXM=' + Registry().register('settings', Settings()) def tearDown(self): self.destroy_settings() diff --git a/tests/functional/openlp_core/api/test_tab.py b/tests/functional/openlp_core/api/test_tab.py index 8d1efd95a..4e310a3f5 100644 --- a/tests/functional/openlp_core/api/test_tab.py +++ b/tests/functional/openlp_core/api/test_tab.py @@ -60,6 +60,7 @@ class TestApiTab(TestCase, TestMixin): self.parent = QtWidgets.QMainWindow() Registry().create() Registry().set_flag('website_version', '00-00-0000') + Registry().register('settings', Settings()) self.form = ApiTab(self.parent) self.interfaces = get_network_interfaces() diff --git a/tests/functional/openlp_core/api/test_websockets.py b/tests/functional/openlp_core/api/test_websockets.py index 299fc445b..344f2a251 100644 --- a/tests/functional/openlp_core/api/test_websockets.py +++ b/tests/functional/openlp_core/api/test_websockets.py @@ -54,6 +54,7 @@ class TestWSServer(TestCase, TestMixin): self.build_settings() Settings().extend_default_settings(__default_settings__) Registry().create() + Registry().register('settings', Settings()) self.poll = Poller() def tearDown(self): diff --git a/tests/functional/openlp_core/api/v2/test_controller.py b/tests/functional/openlp_core/api/v2/test_controller.py index 514e821d0..f109f7af5 100644 --- a/tests/functional/openlp_core/api/v2/test_controller.py +++ b/tests/functional/openlp_core/api/v2/test_controller.py @@ -24,15 +24,15 @@ def test_controller_set_does_not_accept_get(flask_client): assert res.status_code == 405 -def test_controller_set_calls_live_controller(flask_client): +def test_controller_set_calls_live_controller(flask_client, settings): fake_live_controller = MagicMock() - Registry.create().register('live_controller', fake_live_controller) + Registry().register('live_controller', fake_live_controller) res = flask_client.post('/api/v2/controller/show', json=dict(id=400)) assert res.status_code == 204 fake_live_controller.slidecontroller_live_set.emit.assert_called_once_with([400]) -def test_controller_direction_requires_login(flask_client): +def test_controller_direction_requires_login(flask_client, settings): Settings().setValue('api/authentication enabled', True) res = flask_client.post('/api/v2/controller/progress', json=dict()) Settings().setValue('api/authentication enabled', False) @@ -44,14 +44,14 @@ def test_controller_direction_does_not_accept_get(flask_client): assert res.status_code == 405 -def test_controller_direction_does_fails_on_wrong_data(flask_client): +def test_controller_direction_does_fails_on_wrong_data(flask_client, settings): res = flask_client.post('/api/v2/controller/progress', json=dict(action='foo')) assert res.status_code == 400 -def test_controller_direction_calls_service_manager(flask_client): +def test_controller_direction_calls_service_manager(flask_client, settings): fake_live_controller = MagicMock() - Registry.create().register('live_controller', fake_live_controller) + Registry().register('live_controller', fake_live_controller) res = flask_client.post('/api/v2/controller/progress', json=dict(action='next')) assert res.status_code == 204 fake_live_controller.slidecontroller_live_next.emit.assert_called_once() diff --git a/tests/functional/openlp_core/api/v2/test_core.py b/tests/functional/openlp_core/api/v2/test_core.py index 1a67e63ac..11914c974 100644 --- a/tests/functional/openlp_core/api/v2/test_core.py +++ b/tests/functional/openlp_core/api/v2/test_core.py @@ -27,7 +27,7 @@ def test_plugins_returns_list(flask_client): assert res[0]['name'] == plugin.text_strings[StringContent.Name]['plural'] -def test_system_information(flask_client): +def test_system_information(flask_client, settings): Settings().setValue('api/authentication enabled', False) res = flask_client.get('/api/v2/core/system').get_json() assert res['websocket_port'] > 0 @@ -53,12 +53,12 @@ def test_login_without_data_returns_400(flask_client): assert res.status_code == 400 -def test_login_with_invalid_credetials_returns_401(flask_client): +def test_login_with_invalid_credetials_returns_401(flask_client, settings): res = flask_client.post('/api/v2/core/login', json=dict(username='openlp', password='invalid')) assert res.status_code == 401 -def test_login_with_valid_credetials_returns_token(flask_client): +def test_login_with_valid_credetials_returns_token(flask_client, settings): Registry().register('authentication_token', 'foobar') res = flask_client.post('/api/v2/core/login', json=dict(username='openlp', password='password')) assert res.status_code == 200 @@ -77,7 +77,7 @@ def test_retrieving_image(flask_client): assert res['binary_image'] != '' -def test_toggle_display_requires_login(flask_client): +def test_toggle_display_requires_login(flask_client, settings): Settings().setValue('api/authentication enabled', True) res = flask_client.post('/api/v2/core/display') Settings().setValue('api/authentication enabled', False) @@ -89,19 +89,19 @@ def test_toggle_display_does_not_allow_get(flask_client): assert res.status_code == 405 -def test_toggle_display_invalid_action(flask_client): +def test_toggle_display_invalid_action(flask_client, settings): res = flask_client.post('/api/v2/core/display', json={'display': 'foo'}) assert res.status_code == 400 -def test_toggle_display_valid_action_updates_controller(flask_client): +def test_toggle_display_valid_action_updates_controller(flask_client, settings): class FakeController: class Emitter: def emit(self, value): self.set = value slidecontroller_toggle_display = Emitter() controller = FakeController() - Registry.create().register('live_controller', controller) + Registry().register('live_controller', controller) res = flask_client.post('/api/v2/core/display', json={'display': 'show'}) assert res.status_code == 204 assert controller.slidecontroller_toggle_display.set == 'show' diff --git a/tests/functional/openlp_core/api/v2/test_service.py b/tests/functional/openlp_core/api/v2/test_service.py index 9341b3711..f6d6a8b12 100644 --- a/tests/functional/openlp_core/api/v2/test_service.py +++ b/tests/functional/openlp_core/api/v2/test_service.py @@ -5,52 +5,52 @@ from openlp.core.common.registry import Registry from openlp.core.common.settings import Settings -def test_retrieve_service_items(flask_client): +def test_retrieve_service_items(flask_client, settings): pytest.skip() res = flask_client.get('/api/v2/service/items').get_json() assert len(res) == 0 -def test_service_set_requires_login(flask_client): +def test_service_set_requires_login(flask_client, settings): Settings().setValue('api/authentication enabled', True) res = flask_client.post('/api/v2/service/show', json=dict()) Settings().setValue('api/authentication enabled', False) assert res.status_code == 401 -def test_service_set_does_not_accept_get(flask_client): +def test_service_set_does_not_accept_get(flask_client, settings): res = flask_client.get('/api/v2/service/show') assert res.status_code == 405 -def test_service_set_calls_service_manager(flask_client): +def test_service_set_calls_service_manager(flask_client, settings): fake_service_manager = MagicMock() - Registry.create().register('service_manager', fake_service_manager) + Registry().register('service_manager', fake_service_manager) res = flask_client.post('/api/v2/service/show', json=dict(id=400)) assert res.status_code == 204 fake_service_manager.set_item.assert_called_once_with(400) -def test_service_direction_requires_login(flask_client): +def test_service_direction_requires_login(flask_client, settings): Settings().setValue('api/authentication enabled', True) res = flask_client.post('/api/v2/service/progress', json=dict()) Settings().setValue('api/authentication enabled', False) assert res.status_code == 401 -def test_service_direction_does_not_accept_get(flask_client): +def test_service_direction_does_not_accept_get(flask_client, settings): res = flask_client.get('/api/v2/service/progress') assert res.status_code == 405 -def test_service_direction_does_fails_on_wrong_data(flask_client): +def test_service_direction_does_fails_on_wrong_data(flask_client, settings): res = flask_client.post('/api/v2/service/progress', json=dict(action='foo')) assert res.status_code == 400 -def test_service_direction_calls_service_manager(flask_client): +def test_service_direction_calls_service_manager(flask_client, settings): fake_service_manager = MagicMock() - Registry.create().register('service_manager', fake_service_manager) + Registry().register('service_manager', fake_service_manager) res = flask_client.post('/api/v2/service/progress', json=dict(action='next')) assert res.status_code == 204 fake_service_manager.servicemanager_next_item.emit.assert_called_once() diff --git a/tests/functional/openlp_core/common/test_applocation.py b/tests/functional/openlp_core/common/test_applocation.py index a5953b056..4b00cb234 100644 --- a/tests/functional/openlp_core/common/test_applocation.py +++ b/tests/functional/openlp_core/common/test_applocation.py @@ -32,16 +32,15 @@ from openlp.core.common.applocation import AppLocation FILE_LIST = ['file1', 'file2', 'file3.txt', 'file4.txt', 'file5.mp3', 'file6.mp3'] -@patch('openlp.core.common.applocation.Settings') @patch('openlp.core.common.applocation.AppLocation.get_directory') @patch('openlp.core.common.applocation.create_paths') @patch('openlp.core.common.applocation.os') -def test_get_data_path(mocked_os, mocked_create_paths, mocked_get_directory, MockSettings): +def test_get_data_path(mocked_os, mocked_create_paths, mocked_get_directory, mock_settings): """ Test the AppLocation.get_data_path() method """ # GIVEN: A mocked out Settings class and a mocked out AppLocation.get_directory() - MockSettings.return_value.contains.return_value = False + mock_settings.contains.return_value = False mocked_get_directory.return_value = Path('tests', 'dir') mocked_create_paths.return_value = True mocked_os.path.normpath.return_value = Path('tests', 'dir') @@ -50,27 +49,26 @@ def test_get_data_path(mocked_os, mocked_create_paths, mocked_get_directory, Moc data_path = AppLocation.get_data_path() # THEN: check that all the correct methods were called, and the result is correct - MockSettings.return_value.contains.assert_called_with('advanced/data path') + mock_settings.contains.assert_called_with('advanced/data path') mocked_get_directory.assert_called_with(AppLocation.DataDir) mocked_create_paths.assert_called_with(Path('tests', 'dir')) assert data_path == Path('tests', 'dir'), 'Result should be "tests/dir"' -@patch('openlp.core.common.applocation.Settings') -def test_get_data_path_with_custom_location(MockSettings): +def test_get_data_path_with_custom_location(mock_settings): """ Test the AppLocation.get_data_path() method when a custom location is set in the settings """ # GIVEN: A mocked out Settings class which returns a custom data location - MockSettings.return_value.contains.return_value = True - MockSettings.return_value.value.return_value = Path('custom', 'dir') + mock_settings.contains.return_value = True + mock_settings.value.return_value = Path('custom', 'dir') # WHEN: we call AppLocation.get_data_path() data_path = AppLocation.get_data_path() # THEN: the mocked Settings methods were called and the value returned was our set up value - MockSettings.return_value.contains.assert_called_with('advanced/data path') - MockSettings.return_value.value.assert_called_with('advanced/data path') + mock_settings.contains.assert_called_with('advanced/data path') + mock_settings.value.assert_called_with('advanced/data path') assert data_path == Path('custom', 'dir'), 'Result should be "custom/dir"' diff --git a/tests/functional/openlp_core/common/test_httputils.py b/tests/functional/openlp_core/common/test_httputils.py index d3beb0586..93f8dbf35 100644 --- a/tests/functional/openlp_core/common/test_httputils.py +++ b/tests/functional/openlp_core/common/test_httputils.py @@ -29,6 +29,7 @@ from unittest.mock import MagicMock, patch from openlp.core.common.httputils import ProxyMode, download_file, get_proxy_settings, get_url_file_size, \ get_user_agent, get_web_page +from openlp.core.common.registry import Registry from openlp.core.common.settings import Settings from tests.helpers.testmixin import TestMixin @@ -39,6 +40,8 @@ class TestHttpUtils(TestCase, TestMixin): """ def setUp(self): self.tempfile = os.path.join(tempfile.gettempdir(), 'testfile') + Registry.create() + Registry().register('settings', Settings()) def tearDown(self): if os.path.isfile(self.tempfile): @@ -137,7 +140,7 @@ class TestHttpUtils(TestCase, TestMixin): mocked_requests.get.assert_called_once_with(fake_url, headers={'User-Agent': 'user_agent'}, proxies=None, timeout=30.0) mocked_get_user_agent.assert_called_once_with() - assert MockRegistry.call_count == 0, 'The Registry() object should have never been called' + assert MockRegistry.call_count == 1, 'The Registry() object should have been called once' assert returned_page == 'text', 'The returned page should be the mock object' @patch('openlp.core.common.httputils.requests') @@ -245,35 +248,10 @@ class TestHttpUtils(TestCase, TestMixin): class TestGetProxySettings(TestCase, TestMixin): def setUp(self): self.build_settings() + Registry.create() + Registry().register('settings', Settings()) self.addCleanup(self.destroy_settings) - @patch('openlp.core.common.httputils.Settings') - def test_mode_arg_specified(self, mocked_settings): - """ - Test that the argument is used rather than reading the 'advanced/proxy mode' setting - """ - # GIVEN: Mocked settings - - # WHEN: Calling `get_proxy_settings` with the mode arg specified - get_proxy_settings(mode=ProxyMode.NO_PROXY) - - # THEN: The mode arg should have been used rather than looking it up in the settings - mocked_settings().value.assert_not_called() - - @patch('openlp.core.common.httputils.Settings') - def test_mode_incorrect_arg_specified(self, mocked_settings): - """ - Test that the system settings are used when the mode arg specieied is invalid - """ - # GIVEN: Mocked settings - - # WHEN: Calling `get_proxy_settings` with an invalid mode arg specified - result = get_proxy_settings(mode='qwerty') - - # THEN: An None should be returned - mocked_settings().value.assert_not_called() - assert result is None - def test_no_proxy_mode(self): """ Test that a dictionary with http and https values are set to None is returned, when `NO_PROXY` mode is specified @@ -352,3 +330,30 @@ class TestGetProxySettings(TestCase, TestMixin): # THEN: The returned value should be the proxy servers set to None assert result == {'http': None, 'https': None} + + +def test_mode_arg_specified(mock_settings): + """ + Test that the argument is used rather than reading the 'advanced/proxy mode' setting + """ + # GIVEN: Mocked settings + + # WHEN: Calling `get_proxy_settings` with the mode arg specified + get_proxy_settings(mode=ProxyMode.NO_PROXY) + + # THEN: The mode arg should have been used rather than looking it up in the settings + mock_settings.value.assert_not_called() + + +def test_mode_incorrect_arg_specified(mock_settings): + """ + Test that the system settings are used when the mode arg specieied is invalid + """ + # GIVEN: Mocked settings + + # WHEN: Calling `get_proxy_settings` with an invalid mode arg specified + result = get_proxy_settings(mode='qwerty') + + # THEN: An None should be returned + mock_settings.value.assert_not_called() + assert result is None diff --git a/tests/functional/openlp_core/common/test_i18n.py b/tests/functional/openlp_core/common/test_i18n.py index 470733be8..cc2e8e646 100644 --- a/tests/functional/openlp_core/common/test_i18n.py +++ b/tests/functional/openlp_core/common/test_i18n.py @@ -155,7 +155,7 @@ def test_check_same_instance(): assert first_instance is second_instance, 'Two UiStrings objects should be the same instance' -def test_get_language_from_settings(): +def test_get_language_from_settings(settings): assert LanguageManager.get_language() == 'en' diff --git a/tests/functional/openlp_core/ui/test_advancedtab.py b/tests/functional/openlp_core/ui/test_advancedtab.py index e783b7e24..28b10aa16 100644 --- a/tests/functional/openlp_core/ui/test_advancedtab.py +++ b/tests/functional/openlp_core/ui/test_advancedtab.py @@ -24,6 +24,7 @@ Package to test the openlp.core.ui.advancedtab package. from unittest import TestCase from openlp.core.common.registry import Registry +from openlp.core.common.settings import Settings from openlp.core.ui.advancedtab import AdvancedTab from openlp.core.ui.settingsform import SettingsForm from tests.helpers.testmixin import TestMixin @@ -36,6 +37,7 @@ class TestAdvancedTab(TestCase, TestMixin): Set up a few things for the tests """ Registry.create() + Registry().register('settings', Settings()) def test_creation(self): """ diff --git a/tests/functional/openlp_core/ui/test_first_time.py b/tests/functional/openlp_core/ui/test_first_time.py index 07b099445..69a0f149b 100644 --- a/tests/functional/openlp_core/ui/test_first_time.py +++ b/tests/functional/openlp_core/ui/test_first_time.py @@ -21,32 +21,26 @@ """ Package to test the openlp.core.utils.__init__ package. """ -from unittest import TestCase from unittest.mock import patch from openlp.core.common.httputils import CONNECTION_RETRIES, get_web_page -from tests.helpers.testmixin import TestMixin -class TestFirstTimeWizard(TestMixin, TestCase): +@patch('openlp.core.common.httputils.requests') +def test_webpage_connection_retry(mocked_requests, mock_settings): """ - Test First Time Wizard import functions + Test get_web_page will attempt CONNECTION_RETRIES+1 connections - bug 1409031 """ - @patch('openlp.core.common.httputils.requests') - def test_webpage_connection_retry(self, mocked_requests): - """ - Test get_web_page will attempt CONNECTION_RETRIES+1 connections - bug 1409031 - """ - # GIVEN: Initial settings and mocks - mocked_requests.get.side_effect = OSError('Unable to connect') + # GIVEN: Initial settings and mocks + mocked_requests.get.side_effect = OSError('Unable to connect') - # WHEN: A webpage is requested - try: - get_web_page('http://localhost') - except Exception as e: - assert isinstance(e, ConnectionError) + # WHEN: A webpage is requested + try: + get_web_page('http://localhost') + except Exception as e: + assert isinstance(e, ConnectionError) - # THEN: urlopen should have been called CONNECTION_RETRIES + 1 count - assert mocked_requests.get.call_count == CONNECTION_RETRIES, \ - 'get should have been called {} times, but was only called {} times'.format( - CONNECTION_RETRIES, mocked_requests.get.call_count) + # THEN: urlopen should have been called CONNECTION_RETRIES + 1 count + assert mocked_requests.get.call_count == CONNECTION_RETRIES, \ + 'get should have been called {} times, but was only called {} times'.format( + CONNECTION_RETRIES, mocked_requests.get.call_count) diff --git a/tests/functional/openlp_core/ui/test_mainwindow.py b/tests/functional/openlp_core/ui/test_mainwindow.py index 011ed3e50..c3836f57e 100644 --- a/tests/functional/openlp_core/ui/test_mainwindow.py +++ b/tests/functional/openlp_core/ui/test_mainwindow.py @@ -31,6 +31,7 @@ from PyQt5 import QtCore, QtWidgets from openlp.core.state import State from openlp.core.common.i18n import UiStrings from openlp.core.common.registry import Registry +from openlp.core.common.settings import Settings from openlp.core.display.screens import ScreenList from openlp.core.ui.mainwindow import MainWindow from tests.helpers.testmixin import TestMixin @@ -64,6 +65,7 @@ class TestMainWindow(TestCase, TestMixin): self.app.process_events = MagicMock() self.app.args = [] Registry().register('application', self.app) + Registry().register('settings', Settings()) Registry().set_flag('no_web_server', True) self.add_toolbar_action_patcher = patch('openlp.core.ui.mainwindow.create_action') self.mocked_add_toolbar_action = self.add_toolbar_action_patcher.start() @@ -161,8 +163,8 @@ class TestMainWindow(TestCase, TestMixin): # WHEN: you check the started functions # THEN: the following registry functions should have been registered - expected_service_list = ['application', 'main_window', 'http_server', 'authentication_token', 'settings_form', - 'service_manager', 'theme_manager', 'projector_manager'] + expected_service_list = ['application', 'settings', 'main_window', 'http_server', 'authentication_token', + 'settings_form', 'service_manager', 'theme_manager', 'projector_manager'] expected_functions_list = ['bootstrap_initialise', 'bootstrap_post_set_up', 'bootstrap_completion', 'theme_update_global', 'config_screen_changed'] assert list(self.registry.service_list.keys()) == expected_service_list, \ diff --git a/tests/functional/openlp_plugins/presentations/test_impresscontroller.py b/tests/functional/openlp_plugins/presentations/test_impresscontroller.py index 30e6079c8..39a71831c 100644 --- a/tests/functional/openlp_plugins/presentations/test_impresscontroller.py +++ b/tests/functional/openlp_plugins/presentations/test_impresscontroller.py @@ -47,6 +47,8 @@ class TestImpressController(TestCase, TestMixin): self.mock_plugin = MagicMock() self.temp_folder = mkdtemp() self.mock_plugin.settings_section = self.temp_folder + Registry.create() + Registry().register('settings', Settings()) def tearDown(self): """ diff --git a/tests/functional/openlp_plugins/presentations/test_powerpointcontroller.py b/tests/functional/openlp_plugins/presentations/test_powerpointcontroller.py index 727c44216..5f2c69369 100644 --- a/tests/functional/openlp_plugins/presentations/test_powerpointcontroller.py +++ b/tests/functional/openlp_plugins/presentations/test_powerpointcontroller.py @@ -58,6 +58,8 @@ class TestPowerpointController(TestCase, TestMixin): self.mock_plugin = MagicMock() self.temp_folder = mkdtemp() self.mock_plugin.settings_section = self.temp_folder + Registry.create() + Registry().register('settings', Settings()) def tearDown(self): """ diff --git a/tests/functional/openlp_plugins/songs/test_db.py b/tests/functional/openlp_plugins/songs/test_db.py index 8c2292a09..38ace534a 100644 --- a/tests/functional/openlp_plugins/songs/test_db.py +++ b/tests/functional/openlp_plugins/songs/test_db.py @@ -26,6 +26,8 @@ import shutil from tempfile import mkdtemp from unittest import TestCase +from openlp.core.common.registry import Registry +from openlp.core.common.settings import Settings from openlp.core.lib.db import upgrade_db from openlp.plugins.songs.lib import upgrade from openlp.plugins.songs.lib.db import Author, AuthorType, Book, Song @@ -42,6 +44,8 @@ class TestDB(TestCase): Setup for tests """ self.tmp_folder = mkdtemp() + Registry.create() + Registry().register('settings', Settings()) def tearDown(self): """ diff --git a/tests/interfaces/openlp_core/ui/test_mainwindow.py b/tests/interfaces/openlp_core/ui/test_mainwindow.py index ca76d789b..a8884e7b3 100644 --- a/tests/interfaces/openlp_core/ui/test_mainwindow.py +++ b/tests/interfaces/openlp_core/ui/test_mainwindow.py @@ -29,6 +29,7 @@ from PyQt5 import QtGui from openlp.core.state import State from openlp.core.common import is_macosx from openlp.core.common.registry import Registry +from openlp.core.common.settings import Settings from openlp.core.lib.plugin import PluginStatus from openlp.core.ui.mainwindow import MainWindow from tests.helpers.testmixin import TestMixin @@ -49,6 +50,7 @@ class TestMainWindow(TestCase, TestMixin): self.app.set_normal_cursor = MagicMock() self.app.args = [] Registry().register('application', self.app) + Registry().register('settings', Settings()) Registry().set_flag('no_web_server', True) mocked_plugin = MagicMock() mocked_plugin.status = PluginStatus.Active diff --git a/tests/interfaces/openlp_core/ui/test_servicemanager.py b/tests/interfaces/openlp_core/ui/test_servicemanager.py index 160eab3da..67174be9a 100644 --- a/tests/interfaces/openlp_core/ui/test_servicemanager.py +++ b/tests/interfaces/openlp_core/ui/test_servicemanager.py @@ -26,6 +26,7 @@ from unittest.mock import MagicMock, patch from PyQt5 import QtCore, QtGui, QtWidgets +from openlp.core.common.settings import Settings from openlp.core.common.registry import Registry from openlp.core.lib.serviceitem import ItemCapabilities, ServiceItem from openlp.core.ui.servicemanager import ServiceManager @@ -56,6 +57,7 @@ class TestServiceManager(TestCase, TestMixin): self.setup_application() Registry().register('application', MagicMock()) Registry().register('main_window', MagicMock(service_manager_settings_section='servicemanager')) + Registry().register('settings', Settings()) self.service_manager = ServiceManager() self.add_toolbar_action_patcher = patch('openlp.core.ui.servicemanager.OpenLPToolbar.add_toolbar_action') self.mocked_add_toolbar_action = self.add_toolbar_action_patcher.start() diff --git a/tests/interfaces/openlp_plugins/bibles/test_lib_http.py b/tests/interfaces/openlp_plugins/bibles/test_lib_http.py index cf62a748b..703de1f03 100644 --- a/tests/interfaces/openlp_plugins/bibles/test_lib_http.py +++ b/tests/interfaces/openlp_plugins/bibles/test_lib_http.py @@ -26,6 +26,7 @@ from unittest import TestCase, skipIf from unittest.mock import MagicMock from openlp.core.common.registry import Registry +from openlp.core.common.settings import Settings from openlp.plugins.bibles.lib.importers.http import BGExtract, BSExtract, CWExtract IS_CI = 'GITLAB_CI' in os.environ or 'APPVEYOR' in os.environ @@ -42,6 +43,7 @@ class TestBibleHTTP(TestCase): Registry().register('service_list', MagicMock()) Registry().register('application', MagicMock()) Registry().register('main_window', MagicMock()) + Registry().register('settings', Settings()) def test_bible_gateway_extract_books(self): """ diff --git a/tests/interfaces/openlp_plugins/bibles/test_lib_manager.py b/tests/interfaces/openlp_plugins/bibles/test_lib_manager.py index f3a256e83..90873a8ed 100644 --- a/tests/interfaces/openlp_plugins/bibles/test_lib_manager.py +++ b/tests/interfaces/openlp_plugins/bibles/test_lib_manager.py @@ -53,10 +53,11 @@ class TestBibleManager(TestCase, TestMixin): 'bibles/end separator': '', } Settings().extend_default_settings(bible_settings) - with patch('openlp.core.common.applocation.Settings') as mocked_class, \ - patch('openlp.core.common.applocation.AppLocation.get_section_data_path') as mocked_get_data_path, \ + with patch('openlp.core.common.applocation.AppLocation.get_section_data_path') as mocked_get_data_path, \ patch('openlp.core.common.applocation.AppLocation.get_files') as mocked_get_files: # GIVEN: A mocked out Settings class and a mocked out AppLocation.get_files() + mocked_class = MagicMock() + Registry().register('settings', mocked_class.return_value) mocked_settings = mocked_class.return_value mocked_settings.contains.return_value = False mocked_get_files.return_value = ["tests.sqlite"] diff --git a/tests/interfaces/openlp_plugins/bibles/test_lib_parse_reference.py b/tests/interfaces/openlp_plugins/bibles/test_lib_parse_reference.py index 858f29b94..e21564543 100644 --- a/tests/interfaces/openlp_plugins/bibles/test_lib_parse_reference.py +++ b/tests/interfaces/openlp_plugins/bibles/test_lib_parse_reference.py @@ -54,12 +54,11 @@ class TestBibleManager(TestCase, TestMixin): 'bibles/end separator': '', } Settings().extend_default_settings(bible_settings) - with patch('openlp.core.common.applocation.Settings') as mocked_class, \ - patch('openlp.core.common.applocation.AppLocation.get_section_data_path') as mocked_get_data_path, \ + with patch('openlp.core.common.applocation.AppLocation.get_section_data_path') as mocked_get_data_path, \ patch('openlp.core.common.applocation.AppLocation.get_files') as mocked_get_files: # GIVEN: A mocked out Settings class and a mocked out AppLocation.get_files() - mocked_settings = mocked_class.return_value - mocked_settings.contains.return_value = False + mocked_class = MagicMock() + Registry().register('settings', mocked_class.return_value) mocked_get_files.return_value = ["tests.sqlite"] mocked_get_data_path.return_value = TEST_RESOURCES_PATH + "/bibles" self.manager = BibleManager(MagicMock()) diff --git a/tests/openlp_core/api/test_zeroconf.py b/tests/openlp_core/api/test_zeroconf.py index 901c559b6..96cf3ee34 100644 --- a/tests/openlp_core/api/test_zeroconf.py +++ b/tests/openlp_core/api/test_zeroconf.py @@ -83,11 +83,9 @@ def test_zeroconf_worker_stop(): @patch('openlp.core.api.zeroconf.get_network_interfaces') @patch('openlp.core.api.zeroconf.Registry') -@patch('openlp.core.api.zeroconf.Settings') @patch('openlp.core.api.zeroconf.ZeroconfWorker') @patch('openlp.core.api.zeroconf.run_thread') -def test_start_zeroconf(mocked_run_thread, MockedZeroconfWorker, MockedSettings, MockedRegistry, - mocked_get_network_interfaces): +def test_start_zeroconf(mocked_run_thread, MockedZeroconfWorker, MockedRegistry, mocked_get_network_interfaces): """Test the start_zeroconf() function""" # GIVEN: A whole bunch of stuff that's mocked out mocked_get_network_interfaces.return_value = { @@ -100,7 +98,7 @@ def test_start_zeroconf(mocked_run_thread, MockedZeroconfWorker, MockedSettings, } } MockedRegistry.return_value.get_flag.return_value = False - MockedSettings.return_value.value.side_effect = [8000, 8001] + MockedRegistry.settings.return_value.value.side_effect = [8000, 8001] mocked_worker = MagicMock() MockedZeroconfWorker.return_value = mocked_worker diff --git a/tests/openlp_core/projectors/test_projector_db.py b/tests/openlp_core/projectors/test_projector_db.py index 3c5969fb2..78b2a6e72 100644 --- a/tests/openlp_core/projectors/test_projector_db.py +++ b/tests/openlp_core/projectors/test_projector_db.py @@ -31,6 +31,7 @@ from unittest import TestCase from unittest.mock import MagicMock, patch from openlp.core.common.registry import Registry +from openlp.core.common.settings import Settings from openlp.core.lib.db import upgrade_db from openlp.core.projectors import upgrade from openlp.core.projectors.constants import PJLINK_PORT @@ -143,6 +144,7 @@ class TestProjectorDB(TestCase, TestMixin): self.app.set_normal_cursor = MagicMock() self.app.args = [] Registry().register('application', self.app) + Registry().register('settings', Settings()) Registry().set_flag('no_web_server', True) # Mock classes and methods used by mainwindow. with patch('openlp.core.ui.mainwindow.SettingsForm'), \ diff --git a/tests/openlp_core/projectors/test_projector_editform.py b/tests/openlp_core/projectors/test_projector_editform.py index 800f19fe9..8592f8eea 100644 --- a/tests/openlp_core/projectors/test_projector_editform.py +++ b/tests/openlp_core/projectors/test_projector_editform.py @@ -27,6 +27,7 @@ from unittest import TestCase from unittest.mock import patch from openlp.core.common.registry import Registry +from openlp.core.common.settings import Settings from openlp.core.projectors.db import Projector, ProjectorDB from openlp.core.projectors.editform import ProjectorEditForm from tests.helpers.testmixin import TestMixin @@ -46,6 +47,7 @@ class TestProjectorEditForm(TestCase, TestMixin): self.setup_application() self.build_settings() Registry.create() + Registry().register('settings', Settings()) with patch('openlp.core.projectors.db.init_url') as mocked_init_url: if os.path.exists(TEST_DB): os.unlink(TEST_DB) diff --git a/tests/openlp_core/projectors/test_projector_sourceform.py b/tests/openlp_core/projectors/test_projector_sourceform.py index 7b020ab0d..18b2ccdca 100644 --- a/tests/openlp_core/projectors/test_projector_sourceform.py +++ b/tests/openlp_core/projectors/test_projector_sourceform.py @@ -31,6 +31,7 @@ from unittest.mock import patch from PyQt5.QtWidgets import QDialog from openlp.core.common.registry import Registry +from openlp.core.common.settings import Settings from openlp.core.projectors.constants import PJLINK_DEFAULT_CODES, PJLINK_DEFAULT_SOURCES from openlp.core.projectors.db import Projector, ProjectorDB from openlp.core.projectors.sourceselectform import SourceSelectSingle, source_group @@ -65,6 +66,8 @@ class ProjectorSourceFormTest(TestCase, TestMixin): self.setup_application() self.build_settings() Registry.create() + Registry().register('settings', Settings()) + # Do not try to recreate if we've already been created from a previous test if not hasattr(self, 'projectordb'): self.projectordb = ProjectorDB() diff --git a/tests/openlp_core/projectors/test_projectormanager.py b/tests/openlp_core/projectors/test_projectormanager.py index 4810ad09b..4f602720d 100644 --- a/tests/openlp_core/projectors/test_projectormanager.py +++ b/tests/openlp_core/projectors/test_projectormanager.py @@ -26,6 +26,7 @@ from unittest import TestCase from unittest.mock import MagicMock, patch from openlp.core.common.registry import Registry +from openlp.core.common.settings import Settings from openlp.core.projectors.db import ProjectorDB from openlp.core.projectors.editform import ProjectorEditForm from openlp.core.projectors.manager import ProjectorManager @@ -44,6 +45,7 @@ class TestProjectorManager(TestCase, TestMixin): self.setup_application() self.build_settings() Registry.create() + Registry().register('settings', Settings()) with patch('openlp.core.projectors.db.init_url') as mocked_init_url: if os.path.exists(TEST_DB): os.unlink(TEST_DB)