forked from openlp/openlp
Merge branch 'settings_core_4' into 'master'
Settings core 4 See merge request openlp/openlp!131
This commit is contained in:
commit
b71ccfd09e
@ -31,7 +31,6 @@ from PyQt5 import QtCore, QtGui, QtWidgets
|
|||||||
from openlp.core.common.i18n import translate
|
from openlp.core.common.i18n import translate
|
||||||
from openlp.core.common.mixins import LogMixin, RegistryProperties
|
from openlp.core.common.mixins import LogMixin, RegistryProperties
|
||||||
from openlp.core.common.registry import Registry, RegistryBase
|
from openlp.core.common.registry import Registry, RegistryBase
|
||||||
from openlp.core.common.settings import Settings
|
|
||||||
from openlp.core.lib.ui import create_widget_action
|
from openlp.core.lib.ui import create_widget_action
|
||||||
from openlp.core.projectors import DialogSourceStyle
|
from openlp.core.projectors import DialogSourceStyle
|
||||||
from openlp.core.projectors.constants import E_AUTHENTICATION, E_ERROR, E_NETWORK, E_NOT_CONNECTED, E_SOCKET_TIMEOUT,\
|
from openlp.core.projectors.constants import E_AUTHENTICATION, E_ERROR, E_NETWORK, E_NOT_CONNECTED, E_SOCKET_TIMEOUT,\
|
||||||
@ -361,10 +360,10 @@ class ProjectorManager(QtWidgets.QWidget, RegistryBase, UiProjectorManager, LogM
|
|||||||
Retrieve the saved settings
|
Retrieve the saved settings
|
||||||
"""
|
"""
|
||||||
log.debug('Updating ProjectorManager settings')
|
log.debug('Updating ProjectorManager settings')
|
||||||
self.autostart = Settings().value('projector/connect on start')
|
self.autostart = self.settings.value('projector/connect on start')
|
||||||
self.poll_time = Settings().value('projector/poll time')
|
self.poll_time = self.settings.value('projector/poll time')
|
||||||
self.socket_timeout = Settings().value('projector/socket timeout')
|
self.socket_timeout = self.settings.value('projector/socket timeout')
|
||||||
self.source_select_dialog_type = Settings().value('projector/source dialog type')
|
self.source_select_dialog_type = self.settings.value('projector/source dialog type')
|
||||||
|
|
||||||
def context_menu(self, point):
|
def context_menu(self, point):
|
||||||
"""
|
"""
|
||||||
|
@ -53,7 +53,7 @@ from PyQt5 import QtCore, QtNetwork
|
|||||||
|
|
||||||
from openlp.core.common import qmd5_hash
|
from openlp.core.common import qmd5_hash
|
||||||
from openlp.core.common.i18n import translate
|
from openlp.core.common.i18n import translate
|
||||||
from openlp.core.common.settings import Settings
|
from openlp.core.common.registry import Registry
|
||||||
from openlp.core.projectors.pjlinkcommands import process_command
|
from openlp.core.projectors.pjlinkcommands import process_command
|
||||||
from openlp.core.projectors.constants import CONNECTION_ERRORS, E_AUTHENTICATION, E_CONNECTION_REFUSED, E_GENERAL, \
|
from openlp.core.projectors.constants import CONNECTION_ERRORS, E_AUTHENTICATION, E_CONNECTION_REFUSED, E_GENERAL, \
|
||||||
E_NETWORK, E_NOT_CONNECTED, E_SOCKET_TIMEOUT, PJLINK_CLASS, \
|
E_NETWORK, E_NOT_CONNECTED, E_SOCKET_TIMEOUT, PJLINK_CLASS, \
|
||||||
@ -100,8 +100,9 @@ class PJLinkUDP(QtNetwork.QUdpSocket):
|
|||||||
self.search_time = 30000 # 30 seconds for allowed time
|
self.search_time = 30000 # 30 seconds for allowed time
|
||||||
self.search_timer = QtCore.QTimer()
|
self.search_timer = QtCore.QTimer()
|
||||||
self.udp_broadcast_listen_setting = False
|
self.udp_broadcast_listen_setting = False
|
||||||
|
self.settings = Registry().get('settings')
|
||||||
log.debug('(UDP:{port}) PJLinkUDP() Initialized'.format(port=self.port))
|
log.debug('(UDP:{port}) PJLinkUDP() Initialized'.format(port=self.port))
|
||||||
if Settings().value('projector/udp broadcast listen'):
|
if self.settings.value('projector/udp broadcast listen'):
|
||||||
self.udp_start()
|
self.udp_start()
|
||||||
|
|
||||||
def udp_start(self):
|
def udp_start(self):
|
||||||
@ -110,7 +111,7 @@ class PJLinkUDP(QtNetwork.QUdpSocket):
|
|||||||
"""
|
"""
|
||||||
log.debug('(UDP:{port}) Start called'.format(port=self.port))
|
log.debug('(UDP:{port}) Start called'.format(port=self.port))
|
||||||
self.readyRead.connect(self.get_datagram)
|
self.readyRead.connect(self.get_datagram)
|
||||||
self.check_settings(checked=Settings().value('projector/udp broadcast listen'))
|
self.check_settings(checked=self.settings.value('projector/udp broadcast listen'))
|
||||||
|
|
||||||
def udp_stop(self):
|
def udp_stop(self):
|
||||||
"""
|
"""
|
||||||
|
@ -30,7 +30,7 @@ import logging
|
|||||||
import re
|
import re
|
||||||
import string
|
import string
|
||||||
|
|
||||||
from openlp.core.common.settings import Settings
|
from openlp.core.common.registry import Registry
|
||||||
|
|
||||||
from openlp.core.projectors.constants import E_AUTHENTICATION, PJLINK_DEFAULT_CODES, PJLINK_ERRORS, \
|
from openlp.core.projectors.constants import E_AUTHENTICATION, PJLINK_DEFAULT_CODES, PJLINK_ERRORS, \
|
||||||
PJLINK_ERST_DATA, PJLINK_ERST_LIST, PJLINK_ERST_STATUS, PJLINK_POWR_STATUS, PJLINK_TOKEN_SIZE, \
|
PJLINK_ERST_DATA, PJLINK_ERST_LIST, PJLINK_ERST_STATUS, PJLINK_POWR_STATUS, PJLINK_TOKEN_SIZE, \
|
||||||
@ -345,7 +345,7 @@ def process_lkup(projector, data):
|
|||||||
:param data: Data packet from remote
|
:param data: Data packet from remote
|
||||||
"""
|
"""
|
||||||
log.debug('({ip}) Processing LKUP command'.format(ip=projector.entry.name))
|
log.debug('({ip}) Processing LKUP command'.format(ip=projector.entry.name))
|
||||||
if Settings().value('projector/connect when LKUP received'):
|
if Registry().get('settings').value('projector/connect when LKUP received'):
|
||||||
projector.connect_to_host()
|
projector.connect_to_host()
|
||||||
|
|
||||||
|
|
||||||
|
@ -27,7 +27,6 @@ from PyQt5 import QtWidgets
|
|||||||
|
|
||||||
from openlp.core.common.i18n import UiStrings, translate
|
from openlp.core.common.i18n import UiStrings, translate
|
||||||
from openlp.core.common.registry import Registry
|
from openlp.core.common.registry import Registry
|
||||||
from openlp.core.common.settings import Settings
|
|
||||||
from openlp.core.lib.settingstab import SettingsTab
|
from openlp.core.lib.settingstab import SettingsTab
|
||||||
from openlp.core.projectors import DialogSourceStyle
|
from openlp.core.projectors import DialogSourceStyle
|
||||||
from openlp.core.ui.icons import UiIcons
|
from openlp.core.ui.icons import UiIcons
|
||||||
@ -132,23 +131,23 @@ class ProjectorTab(SettingsTab):
|
|||||||
"""
|
"""
|
||||||
Load the projector settings on startup
|
Load the projector settings on startup
|
||||||
"""
|
"""
|
||||||
self.connect_on_startup.setChecked(Settings().value('projector/connect on start'))
|
self.connect_on_startup.setChecked(self.settings.value('projector/connect on start'))
|
||||||
self.socket_timeout_spin_box.setValue(Settings().value('projector/socket timeout'))
|
self.socket_timeout_spin_box.setValue(self.settings.value('projector/socket timeout'))
|
||||||
self.socket_poll_spin_box.setValue(Settings().value('projector/poll time'))
|
self.socket_poll_spin_box.setValue(self.settings.value('projector/poll time'))
|
||||||
self.dialog_type_combo_box.setCurrentIndex(Settings().value('projector/source dialog type'))
|
self.dialog_type_combo_box.setCurrentIndex(self.settings.value('projector/source dialog type'))
|
||||||
self.udp_broadcast_listen.setChecked(Settings().value('projector/udp broadcast listen'))
|
self.udp_broadcast_listen.setChecked(self.settings.value('projector/udp broadcast listen'))
|
||||||
self.connect_on_linkup.setChecked(Settings().value('projector/connect when LKUP received'))
|
self.connect_on_linkup.setChecked(self.settings.value('projector/connect when LKUP received'))
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
"""
|
"""
|
||||||
Save the projector settings
|
Save the projector settings
|
||||||
"""
|
"""
|
||||||
Settings().setValue('projector/connect on start', self.connect_on_startup.isChecked())
|
self.settings.setValue('projector/connect on start', self.connect_on_startup.isChecked())
|
||||||
Settings().setValue('projector/socket timeout', self.socket_timeout_spin_box.value())
|
self.settings.setValue('projector/socket timeout', self.socket_timeout_spin_box.value())
|
||||||
Settings().setValue('projector/poll time', self.socket_poll_spin_box.value())
|
self.settings.setValue('projector/poll time', self.socket_poll_spin_box.value())
|
||||||
Settings().setValue('projector/source dialog type', self.dialog_type_combo_box.currentIndex())
|
self.settings.setValue('projector/source dialog type', self.dialog_type_combo_box.currentIndex())
|
||||||
Settings().setValue('projector/connect when LKUP received', self.connect_on_linkup.isChecked())
|
self.settings.setValue('projector/connect when LKUP received', self.connect_on_linkup.isChecked())
|
||||||
Settings().setValue('projector/udp broadcast listen', self.udp_broadcast_listen.isChecked())
|
self.settings.setValue('projector/udp broadcast listen', self.udp_broadcast_listen.isChecked())
|
||||||
self.call_udp_listener()
|
self.call_udp_listener()
|
||||||
|
|
||||||
def on_dialog_type_combo_box_changed(self):
|
def on_dialog_type_combo_box_changed(self):
|
||||||
|
@ -30,7 +30,7 @@ from PyQt5 import QtCore, QtGui, QtWidgets
|
|||||||
from openlp.core.common import CONTROL_CHARS
|
from openlp.core.common import CONTROL_CHARS
|
||||||
from openlp.core.common.i18n import UiStrings, translate
|
from openlp.core.common.i18n import UiStrings, translate
|
||||||
from openlp.core.common.path import path_to_str, str_to_path
|
from openlp.core.common.path import path_to_str, str_to_path
|
||||||
from openlp.core.common.settings import Settings
|
from openlp.core.common.registry import Registry
|
||||||
from openlp.core.lib.formattingtags import FormattingTags
|
from openlp.core.lib.formattingtags import FormattingTags
|
||||||
from openlp.core.lib.ui import create_action, create_widget_action
|
from openlp.core.lib.ui import create_action, create_widget_action
|
||||||
from openlp.core.ui.icons import UiIcons
|
from openlp.core.ui.icons import UiIcons
|
||||||
@ -72,6 +72,7 @@ class SearchEdit(QtWidgets.QLineEdit):
|
|||||||
self.clear_button.clicked.connect(self._on_clear_button_clicked)
|
self.clear_button.clicked.connect(self._on_clear_button_clicked)
|
||||||
self.textChanged.connect(self._on_search_edit_text_changed)
|
self.textChanged.connect(self._on_search_edit_text_changed)
|
||||||
self._update_style_sheet()
|
self._update_style_sheet()
|
||||||
|
self.settings = Registry().get('settings')
|
||||||
self.setAcceptDrops(False)
|
self.setAcceptDrops(False)
|
||||||
|
|
||||||
def _update_style_sheet(self):
|
def _update_style_sheet(self):
|
||||||
@ -123,7 +124,8 @@ class SearchEdit(QtWidgets.QLineEdit):
|
|||||||
self.setPlaceholderText(action.placeholder_text)
|
self.setPlaceholderText(action.placeholder_text)
|
||||||
self.menu_button.setDefaultAction(action)
|
self.menu_button.setDefaultAction(action)
|
||||||
self._current_search_type = identifier
|
self._current_search_type = identifier
|
||||||
Settings().setValue('{section}/last used search type'.format(section=self.settings_section), identifier)
|
self.settings.setValue('{section}/last used search type'.
|
||||||
|
format(section=self.settings_section), identifier)
|
||||||
self.searchTypeChanged.emit(identifier)
|
self.searchTypeChanged.emit(identifier)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -159,7 +161,7 @@ class SearchEdit(QtWidgets.QLineEdit):
|
|||||||
self.menu_button.resize(QtCore.QSize(28, 18))
|
self.menu_button.resize(QtCore.QSize(28, 18))
|
||||||
self.menu_button.setMenu(menu)
|
self.menu_button.setMenu(menu)
|
||||||
self.set_current_search_type(
|
self.set_current_search_type(
|
||||||
Settings().value('{section}/last used search type'.format(section=self.settings_section)))
|
self.settings.value('{section}/last used search type'.format(section=self.settings_section)))
|
||||||
self.menu_button.show()
|
self.menu_button.show()
|
||||||
self._update_style_sheet()
|
self._update_style_sheet()
|
||||||
|
|
||||||
|
@ -30,7 +30,6 @@ from openlp.core.common import is_win
|
|||||||
from openlp.core.common.i18n import UiStrings
|
from openlp.core.common.i18n import UiStrings
|
||||||
from openlp.core.common.mixins import RegistryProperties
|
from openlp.core.common.mixins import RegistryProperties
|
||||||
from openlp.core.common.registry import Registry
|
from openlp.core.common.registry import Registry
|
||||||
from openlp.core.common.settings import Settings
|
|
||||||
from openlp.core.lib.serviceitem import ItemCapabilities, ServiceItem
|
from openlp.core.lib.serviceitem import ItemCapabilities, ServiceItem
|
||||||
from openlp.core.widgets.layouts import AspectRatioLayout
|
from openlp.core.widgets.layouts import AspectRatioLayout
|
||||||
|
|
||||||
@ -120,7 +119,7 @@ class ListPreviewWidget(QtWidgets.QTableWidget, RegistryProperties):
|
|||||||
# Sort out image heights.
|
# Sort out image heights.
|
||||||
else:
|
else:
|
||||||
height = self.viewport().width() // self.screen_ratio
|
height = self.viewport().width() // self.screen_ratio
|
||||||
max_img_row_height = Settings().value('advanced/slide max height')
|
max_img_row_height = self.settings.value('advanced/slide max height')
|
||||||
# Adjust for row height cap if in use.
|
# Adjust for row height cap if in use.
|
||||||
if isinstance(max_img_row_height, int):
|
if isinstance(max_img_row_height, int):
|
||||||
if 0 < max_img_row_height < height:
|
if 0 < max_img_row_height < height:
|
||||||
@ -139,7 +138,7 @@ class ListPreviewWidget(QtWidgets.QTableWidget, RegistryProperties):
|
|||||||
Will scale non-image slides.
|
Will scale non-image slides.
|
||||||
"""
|
"""
|
||||||
# Only for non-text slides when row height cap in use
|
# Only for non-text slides when row height cap in use
|
||||||
max_img_row_height = Settings().value('advanced/slide max height')
|
max_img_row_height = self.settings.value('advanced/slide max height')
|
||||||
if self.service_item.is_text() or not isinstance(max_img_row_height, int) or max_img_row_height == 0:
|
if self.service_item.is_text() or not isinstance(max_img_row_height, int) or max_img_row_height == 0:
|
||||||
return
|
return
|
||||||
# Get and validate label widget containing slide & adjust max width
|
# Get and validate label widget containing slide & adjust max width
|
||||||
@ -220,7 +219,7 @@ class ListPreviewWidget(QtWidgets.QTableWidget, RegistryProperties):
|
|||||||
layout.addWidget(label)
|
layout.addWidget(label)
|
||||||
container.setLayout(layout)
|
container.setLayout(layout)
|
||||||
slide_height = width // self.screen_ratio
|
slide_height = width // self.screen_ratio
|
||||||
max_img_row_height = Settings().value('advanced/slide max height')
|
max_img_row_height = self.settings.value('advanced/slide max height')
|
||||||
if isinstance(max_img_row_height, int):
|
if isinstance(max_img_row_height, int):
|
||||||
if 0 < max_img_row_height < slide_height:
|
if 0 < max_img_row_height < slide_height:
|
||||||
slide_height = max_img_row_height
|
slide_height = max_img_row_height
|
||||||
@ -249,7 +248,7 @@ class ListPreviewWidget(QtWidgets.QTableWidget, RegistryProperties):
|
|||||||
Switches to the given row.
|
Switches to the given row.
|
||||||
"""
|
"""
|
||||||
# Retrieve setting
|
# Retrieve setting
|
||||||
auto_scrolling = Settings().value('advanced/autoscrolling')
|
auto_scrolling = self.settings.value('advanced/autoscrolling')
|
||||||
# Check if auto-scroll disabled (None) and validate value as dict containing 'dist' and 'pos'
|
# Check if auto-scroll disabled (None) and validate value as dict containing 'dist' and 'pos'
|
||||||
# 'dist' represents the slide to scroll to relative to the new slide (-1 = previous, 0 = current, 1 = next)
|
# 'dist' represents the slide to scroll to relative to the new slide (-1 = previous, 0 = current, 1 = next)
|
||||||
# 'pos' represents the vert position of of the slide (0 = in view, 1 = top, 2 = middle, 3 = bottom)
|
# 'pos' represents the vert position of of the slide (0 = in view, 1 = top, 2 = middle, 3 = bottom)
|
||||||
|
@ -24,7 +24,8 @@ The :mod:`~openlp.core.widgets.widgets` module contains custom widgets used in O
|
|||||||
from PyQt5 import QtCore, QtWidgets
|
from PyQt5 import QtCore, QtWidgets
|
||||||
|
|
||||||
from openlp.core.common.i18n import translate
|
from openlp.core.common.i18n import translate
|
||||||
from openlp.core.common.settings import ProxyMode, Settings
|
from openlp.core.common.registry import Registry
|
||||||
|
from openlp.core.common.settings import ProxyMode
|
||||||
from openlp.core.lib.ui import critical_error_message_box
|
from openlp.core.lib.ui import critical_error_message_box
|
||||||
|
|
||||||
|
|
||||||
@ -57,6 +58,7 @@ class ProxyWidget(QtWidgets.QGroupBox):
|
|||||||
:param QtWidgets.QWidget | None parent: The widgets parent
|
:param QtWidgets.QWidget | None parent: The widgets parent
|
||||||
"""
|
"""
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
|
self.settings = Registry().get('settings')
|
||||||
self._setup()
|
self._setup()
|
||||||
|
|
||||||
def _setup(self):
|
def _setup(self):
|
||||||
@ -130,24 +132,22 @@ class ProxyWidget(QtWidgets.QGroupBox):
|
|||||||
"""
|
"""
|
||||||
Load the data from the settings to the widget.
|
Load the data from the settings to the widget.
|
||||||
"""
|
"""
|
||||||
settings = Settings()
|
checked_radio = self.radio_group.button(self.settings.value('advanced/proxy mode'))
|
||||||
checked_radio = self.radio_group.button(settings.value('advanced/proxy mode'))
|
|
||||||
checked_radio.setChecked(True)
|
checked_radio.setChecked(True)
|
||||||
self.http_edit.setText(settings.value('advanced/proxy http'))
|
self.http_edit.setText(self.settings.value('advanced/proxy http'))
|
||||||
self.https_edit.setText(settings.value('advanced/proxy https'))
|
self.https_edit.setText(self.settings.value('advanced/proxy https'))
|
||||||
self.username_edit.setText(settings.value('advanced/proxy username'))
|
self.username_edit.setText(self.settings.value('advanced/proxy username'))
|
||||||
self.password_edit.setText(settings.value('advanced/proxy password'))
|
self.password_edit.setText(self.settings.value('advanced/proxy password'))
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
"""
|
"""
|
||||||
Save the widget data to the settings
|
Save the widget data to the settings
|
||||||
"""
|
"""
|
||||||
settings = Settings() # TODO: Migrate from old system
|
self.settings.setValue('advanced/proxy mode', self.radio_group.checkedId())
|
||||||
settings.setValue('advanced/proxy mode', self.radio_group.checkedId())
|
self.settings.setValue('advanced/proxy http', self.http_edit.text())
|
||||||
settings.setValue('advanced/proxy http', self.http_edit.text())
|
self.settings.setValue('advanced/proxy https', self.https_edit.text())
|
||||||
settings.setValue('advanced/proxy https', self.https_edit.text())
|
self.settings.setValue('advanced/proxy username', self.username_edit.text())
|
||||||
settings.setValue('advanced/proxy username', self.username_edit.text())
|
self.settings.setValue('advanced/proxy password', self.password_edit.text())
|
||||||
settings.setValue('advanced/proxy password', self.password_edit.text())
|
|
||||||
|
|
||||||
|
|
||||||
class ProxyDialog(QtWidgets.QDialog):
|
class ProxyDialog(QtWidgets.QDialog):
|
||||||
@ -380,11 +380,10 @@ class ScreenSelectionWidget(QtWidgets.QWidget):
|
|||||||
Save the screen settings
|
Save the screen settings
|
||||||
"""
|
"""
|
||||||
self._save_screen(self.current_screen)
|
self._save_screen(self.current_screen)
|
||||||
settings = Settings()
|
|
||||||
screen_settings = {}
|
screen_settings = {}
|
||||||
for screen in self.screens:
|
for screen in self.screens:
|
||||||
screen_settings[screen.number] = screen.to_dict()
|
screen_settings[screen.number] = screen.to_dict()
|
||||||
settings.setValue('core/screens', screen_settings)
|
Registry().get('settings').setValue('core/screens', screen_settings)
|
||||||
# On save update the screens as well
|
# On save update the screens as well
|
||||||
|
|
||||||
def use_simple_view(self):
|
def use_simple_view(self):
|
||||||
|
@ -27,6 +27,8 @@ from tempfile import mkstemp
|
|||||||
from unittest.mock import MagicMock
|
from unittest.mock import MagicMock
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
from pytestqt.qt_compat import qt_api
|
||||||
|
|
||||||
from PyQt5 import QtCore, QtWidgets # noqa
|
from PyQt5 import QtCore, QtWidgets # noqa
|
||||||
sys.modules['PyQt5.QtWebEngineWidgets'] = MagicMock()
|
sys.modules['PyQt5.QtWebEngineWidgets'] = MagicMock()
|
||||||
|
|
||||||
@ -37,8 +39,9 @@ from openlp.core.common.settings import Settings
|
|||||||
|
|
||||||
|
|
||||||
@pytest.yield_fixture
|
@pytest.yield_fixture
|
||||||
def qapp():
|
def qapp(qtbot):
|
||||||
"""An instance of QApplication"""
|
"""An instance of QApplication"""
|
||||||
|
qt_api.QApplication.instance()
|
||||||
app = OpenLP()
|
app = OpenLP()
|
||||||
yield app
|
yield app
|
||||||
del app
|
del app
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
Package to test the openlp.core.widgets.views package.
|
Package to test the openlp.core.widgets.views package.
|
||||||
"""
|
"""
|
||||||
import os
|
import os
|
||||||
|
import pytest
|
||||||
from types import GeneratorType
|
from types import GeneratorType
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
from unittest.mock import MagicMock, call, patch
|
from unittest.mock import MagicMock, call, patch
|
||||||
@ -29,13 +30,30 @@ from unittest.mock import MagicMock, call, patch
|
|||||||
from PyQt5 import QtGui
|
from PyQt5 import QtGui
|
||||||
|
|
||||||
from openlp.core.common.i18n import UiStrings
|
from openlp.core.common.i18n import UiStrings
|
||||||
# from openlp.core.lib import ImageSource
|
|
||||||
from openlp.core.widgets.views import ListPreviewWidget, ListWidgetWithDnD, TreeWidgetWithDnD, handle_mime_data_urls
|
from openlp.core.widgets.views import ListPreviewWidget, ListWidgetWithDnD, TreeWidgetWithDnD, handle_mime_data_urls
|
||||||
from openlp.core.ui.icons import UiIcons
|
from openlp.core.ui.icons import UiIcons
|
||||||
|
|
||||||
CLAPPERBOARD = UiIcons().clapperboard
|
CLAPPERBOARD = UiIcons().clapperboard
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.yield_fixture
|
||||||
|
def preview_widget_env():
|
||||||
|
"""Local test setup"""
|
||||||
|
parent_patcher = patch('openlp.core.widgets.views.ListPreviewWidget.parent')
|
||||||
|
mocked_parent = parent_patcher.start()
|
||||||
|
mocked_parent.width.return_value = 100
|
||||||
|
|
||||||
|
# Mock self.viewport().width()
|
||||||
|
viewport_patcher = patch('openlp.core.widgets.views.ListPreviewWidget.viewport')
|
||||||
|
mocked_viewport = viewport_patcher.start()
|
||||||
|
mocked_viewport_obj = MagicMock()
|
||||||
|
mocked_viewport_obj.width.return_value = 200
|
||||||
|
mocked_viewport.return_value = mocked_viewport_obj
|
||||||
|
yield mocked_parent, mocked_viewport_obj
|
||||||
|
parent_patcher.stop()
|
||||||
|
viewport_patcher.stop()
|
||||||
|
|
||||||
|
|
||||||
class TestHandleMimeDataUrls(TestCase):
|
class TestHandleMimeDataUrls(TestCase):
|
||||||
"""
|
"""
|
||||||
Test the :func:`openlp.core.widgets.views.handle_mime_data_urls` function.
|
Test the :func:`openlp.core.widgets.views.handle_mime_data_urls` function.
|
||||||
@ -88,35 +106,7 @@ class TestHandleMimeDataUrls(TestCase):
|
|||||||
assert result == [mocked_path_instance_1, mocked_path_instance_2, mocked_path_instance_3]
|
assert result == [mocked_path_instance_1, mocked_path_instance_2, mocked_path_instance_3]
|
||||||
|
|
||||||
|
|
||||||
class TestListPreviewWidget(TestCase):
|
def test_new_list_preview_widget(preview_widget_env, mock_settings):
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
"""
|
|
||||||
Mock out stuff for all the tests
|
|
||||||
"""
|
|
||||||
# Mock self.parent().width()
|
|
||||||
self.parent_patcher = patch('openlp.core.widgets.views.ListPreviewWidget.parent')
|
|
||||||
self.mocked_parent = self.parent_patcher.start()
|
|
||||||
self.mocked_parent.width.return_value = 100
|
|
||||||
self.addCleanup(self.parent_patcher.stop)
|
|
||||||
|
|
||||||
# Mock Settings().value()
|
|
||||||
self.Settings_patcher = patch('openlp.core.widgets.views.Settings')
|
|
||||||
self.mocked_Settings = self.Settings_patcher.start()
|
|
||||||
self.mocked_Settings_obj = MagicMock()
|
|
||||||
self.mocked_Settings_obj.value.return_value = None
|
|
||||||
self.mocked_Settings.return_value = self.mocked_Settings_obj
|
|
||||||
self.addCleanup(self.Settings_patcher.stop)
|
|
||||||
|
|
||||||
# Mock self.viewport().width()
|
|
||||||
self.viewport_patcher = patch('openlp.core.widgets.views.ListPreviewWidget.viewport')
|
|
||||||
self.mocked_viewport = self.viewport_patcher.start()
|
|
||||||
self.mocked_viewport_obj = MagicMock()
|
|
||||||
self.mocked_viewport_obj.width.return_value = 200
|
|
||||||
self.mocked_viewport.return_value = self.mocked_viewport_obj
|
|
||||||
self.addCleanup(self.viewport_patcher.stop)
|
|
||||||
|
|
||||||
def test_new_list_preview_widget(self):
|
|
||||||
"""
|
"""
|
||||||
Test that creating an instance of ListPreviewWidget works
|
Test that creating an instance of ListPreviewWidget works
|
||||||
"""
|
"""
|
||||||
@ -129,11 +119,12 @@ class TestListPreviewWidget(TestCase):
|
|||||||
assert list_preview_widget is not None, 'The ListPreviewWidget object should not be None'
|
assert list_preview_widget is not None, 'The ListPreviewWidget object should not be None'
|
||||||
assert list_preview_widget.screen_ratio == 1, 'Should not be called'
|
assert list_preview_widget.screen_ratio == 1, 'Should not be called'
|
||||||
|
|
||||||
|
|
||||||
@patch(u'openlp.core.widgets.views.ListPreviewWidget.image_manager')
|
@patch(u'openlp.core.widgets.views.ListPreviewWidget.image_manager')
|
||||||
@patch(u'openlp.core.widgets.views.ListPreviewWidget.resizeRowsToContents')
|
@patch(u'openlp.core.widgets.views.ListPreviewWidget.resizeRowsToContents')
|
||||||
@patch(u'openlp.core.widgets.views.ListPreviewWidget.setRowHeight')
|
@patch(u'openlp.core.widgets.views.ListPreviewWidget.setRowHeight')
|
||||||
def test_replace_service_item_thumbs(self, mocked_setRowHeight, mocked_resizeRowsToContents,
|
def test_replace_service_item_thumbs(mocked_setRowHeight, mocked_resizeRowsToContents, mocked_image_manager,
|
||||||
mocked_image_manager):
|
preview_widget_env, mock_settings):
|
||||||
"""
|
"""
|
||||||
Test that thubmails for different slides are loaded properly in replace_service_item.
|
Test that thubmails for different slides are loaded properly in replace_service_item.
|
||||||
"""
|
"""
|
||||||
@ -141,9 +132,10 @@ class TestListPreviewWidget(TestCase):
|
|||||||
# different ServiceItem(s), an ImageManager, and a ListPreviewWidget.
|
# different ServiceItem(s), an ImageManager, and a ListPreviewWidget.
|
||||||
|
|
||||||
# Mock Settings().value('advanced/slide max height')
|
# Mock Settings().value('advanced/slide max height')
|
||||||
self.mocked_Settings_obj.value.return_value = 0
|
mock_settings.value.return_value = 0
|
||||||
# Mock self.viewport().width()
|
# Mock self.viewport().width()
|
||||||
self.mocked_viewport_obj.width.return_value = 200
|
mocked_viewport_obj = preview_widget_env[1]
|
||||||
|
mocked_viewport_obj.width.return_value = 200
|
||||||
# Mock Image service item
|
# Mock Image service item
|
||||||
mocked_img_service_item = MagicMock()
|
mocked_img_service_item = MagicMock()
|
||||||
mocked_img_service_item.is_text.return_value = False
|
mocked_img_service_item.is_text.return_value = False
|
||||||
@ -175,9 +167,11 @@ class TestListPreviewWidget(TestCase):
|
|||||||
# call('TEST3', ImageSource.CommandPlugins), call('TEST4', ImageSource.CommandPlugins)]
|
# call('TEST3', ImageSource.CommandPlugins), call('TEST4', ImageSource.CommandPlugins)]
|
||||||
# mocked_image_manager.get_image.assert_has_calls(calls)
|
# mocked_image_manager.get_image.assert_has_calls(calls)
|
||||||
|
|
||||||
|
|
||||||
@patch(u'openlp.core.widgets.views.ListPreviewWidget.resizeRowsToContents')
|
@patch(u'openlp.core.widgets.views.ListPreviewWidget.resizeRowsToContents')
|
||||||
@patch(u'openlp.core.widgets.views.ListPreviewWidget.setRowHeight')
|
@patch(u'openlp.core.widgets.views.ListPreviewWidget.setRowHeight')
|
||||||
def test_replace_recalculate_layout_text(self, mocked_setRowHeight, mocked_resizeRowsToContents):
|
def test_replace_recalculate_layout_text(mocked_setRowHeight, mocked_resizeRowsToContents,
|
||||||
|
preview_widget_env, mock_settings):
|
||||||
"""
|
"""
|
||||||
Test if "Max height for non-text slides..." enabled, txt slides unchanged in replace_service_item & __recalc...
|
Test if "Max height for non-text slides..." enabled, txt slides unchanged in replace_service_item & __recalc...
|
||||||
"""
|
"""
|
||||||
@ -185,9 +179,10 @@ class TestListPreviewWidget(TestCase):
|
|||||||
# a text ServiceItem and a ListPreviewWidget.
|
# a text ServiceItem and a ListPreviewWidget.
|
||||||
|
|
||||||
# Mock Settings().value('advanced/slide max height')
|
# Mock Settings().value('advanced/slide max height')
|
||||||
self.mocked_Settings_obj.value.return_value = 100
|
mock_settings.value.return_value = 100
|
||||||
# Mock self.viewport().width()
|
# Mock self.viewport().width()
|
||||||
self.mocked_viewport_obj.width.return_value = 200
|
mocked_viewport_obj = preview_widget_env[1]
|
||||||
|
mocked_viewport_obj.width.return_value = 200
|
||||||
# Mock text service item
|
# Mock text service item
|
||||||
service_item = MagicMock()
|
service_item = MagicMock()
|
||||||
service_item.is_text.return_value = True
|
service_item.is_text.return_value = True
|
||||||
@ -197,7 +192,7 @@ class TestListPreviewWidget(TestCase):
|
|||||||
list_preview_widget = ListPreviewWidget(None, 1)
|
list_preview_widget = ListPreviewWidget(None, 1)
|
||||||
list_preview_widget.replace_service_item(service_item, 200, 0)
|
list_preview_widget.replace_service_item(service_item, 200, 0)
|
||||||
# Change viewport width before forcing a resize
|
# Change viewport width before forcing a resize
|
||||||
self.mocked_viewport_obj.width.return_value = 400
|
mocked_viewport_obj.width.return_value = 400
|
||||||
|
|
||||||
# WHEN: __recalculate_layout() is called (via resizeEvent)
|
# WHEN: __recalculate_layout() is called (via resizeEvent)
|
||||||
list_preview_widget.resizeEvent(None)
|
list_preview_widget.resizeEvent(None)
|
||||||
@ -207,9 +202,11 @@ class TestListPreviewWidget(TestCase):
|
|||||||
assert mocked_resizeRowsToContents.call_count == 2, 'Should be called'
|
assert mocked_resizeRowsToContents.call_count == 2, 'Should be called'
|
||||||
assert mocked_setRowHeight.call_count == 0, 'Should not be called'
|
assert mocked_setRowHeight.call_count == 0, 'Should not be called'
|
||||||
|
|
||||||
|
|
||||||
@patch(u'openlp.core.widgets.views.ListPreviewWidget.resizeRowsToContents')
|
@patch(u'openlp.core.widgets.views.ListPreviewWidget.resizeRowsToContents')
|
||||||
@patch(u'openlp.core.widgets.views.ListPreviewWidget.setRowHeight')
|
@patch(u'openlp.core.widgets.views.ListPreviewWidget.setRowHeight')
|
||||||
def test_replace_recalculate_layout_img(self, mocked_setRowHeight, mocked_resizeRowsToContents):
|
def test_replace_recalculate_layout_img(mocked_setRowHeight, mocked_resizeRowsToContents,
|
||||||
|
preview_widget_env, mock_settings):
|
||||||
"""
|
"""
|
||||||
Test if "Max height for non-text slides..." disabled, img slides unchanged in replace_service_item & __recalc...
|
Test if "Max height for non-text slides..." disabled, img slides unchanged in replace_service_item & __recalc...
|
||||||
"""
|
"""
|
||||||
@ -217,9 +214,10 @@ class TestListPreviewWidget(TestCase):
|
|||||||
# an image ServiceItem and a ListPreviewWidget.
|
# an image ServiceItem and a ListPreviewWidget.
|
||||||
|
|
||||||
# Mock Settings().value('advanced/slide max height')
|
# Mock Settings().value('advanced/slide max height')
|
||||||
self.mocked_Settings_obj.value.return_value = 0
|
mock_settings.value.return_value = 0
|
||||||
# Mock self.viewport().width()
|
# Mock self.viewport().width()
|
||||||
self.mocked_viewport_obj.width.return_value = 200
|
mocked_viewport_obj = preview_widget_env[1]
|
||||||
|
mocked_viewport_obj.width.return_value = 200
|
||||||
# Mock image service item
|
# Mock image service item
|
||||||
service_item = MagicMock()
|
service_item = MagicMock()
|
||||||
service_item.is_text.return_value = False
|
service_item.is_text.return_value = False
|
||||||
@ -230,11 +228,11 @@ class TestListPreviewWidget(TestCase):
|
|||||||
list_preview_widget = ListPreviewWidget(None, 1)
|
list_preview_widget = ListPreviewWidget(None, 1)
|
||||||
list_preview_widget.replace_service_item(service_item, 200, 0)
|
list_preview_widget.replace_service_item(service_item, 200, 0)
|
||||||
# Change viewport width before forcing a resize
|
# Change viewport width before forcing a resize
|
||||||
self.mocked_viewport_obj.width.return_value = 400
|
mocked_viewport_obj.width.return_value = 400
|
||||||
|
|
||||||
# WHEN: __recalculate_layout() is called (via resizeEvent)
|
# WHEN: __recalculate_layout() is called (via resizeEvent)
|
||||||
list_preview_widget.resizeEvent(None)
|
list_preview_widget.resizeEvent(None)
|
||||||
self.mocked_Settings_obj.value.return_value = None
|
mock_settings.value.return_value = None
|
||||||
list_preview_widget.resizeEvent(None)
|
list_preview_widget.resizeEvent(None)
|
||||||
|
|
||||||
# THEN: resizeRowsToContents() should not be called, while setRowHeight() should be called
|
# THEN: resizeRowsToContents() should not be called, while setRowHeight() should be called
|
||||||
@ -244,9 +242,11 @@ class TestListPreviewWidget(TestCase):
|
|||||||
# calls = [call(0, 200), call(1, 200), call(0, 400), call(1, 400), call(0, 400), call(1, 400)]
|
# calls = [call(0, 200), call(1, 200), call(0, 400), call(1, 400), call(0, 400), call(1, 400)]
|
||||||
# mocked_setRowHeight.assert_has_calls(calls)
|
# mocked_setRowHeight.assert_has_calls(calls)
|
||||||
|
|
||||||
|
|
||||||
@patch(u'openlp.core.widgets.views.ListPreviewWidget.resizeRowsToContents')
|
@patch(u'openlp.core.widgets.views.ListPreviewWidget.resizeRowsToContents')
|
||||||
@patch(u'openlp.core.widgets.views.ListPreviewWidget.setRowHeight')
|
@patch(u'openlp.core.widgets.views.ListPreviewWidget.setRowHeight')
|
||||||
def test_replace_recalculate_layout_img_max(self, mocked_setRowHeight, mocked_resizeRowsToContents):
|
def test_replace_recalculate_layout_img_max(mocked_setRowHeight, mocked_resizeRowsToContents,
|
||||||
|
preview_widget_env, mock_settings):
|
||||||
"""
|
"""
|
||||||
Test if "Max height for non-text slides..." enabled, img slides resized in replace_service_item & __recalc...
|
Test if "Max height for non-text slides..." enabled, img slides resized in replace_service_item & __recalc...
|
||||||
"""
|
"""
|
||||||
@ -254,9 +254,10 @@ class TestListPreviewWidget(TestCase):
|
|||||||
# an image ServiceItem and a ListPreviewWidget.
|
# an image ServiceItem and a ListPreviewWidget.
|
||||||
|
|
||||||
# Mock Settings().value('advanced/slide max height')
|
# Mock Settings().value('advanced/slide max height')
|
||||||
self.mocked_Settings_obj.value.return_value = 100
|
mock_settings.value.return_value = 100
|
||||||
# Mock self.viewport().width()
|
# Mock self.viewport().width()
|
||||||
self.mocked_viewport_obj.width.return_value = 200
|
mocked_viewport_obj = preview_widget_env[1]
|
||||||
|
mocked_viewport_obj.width.return_value = 200
|
||||||
# Mock image service item
|
# Mock image service item
|
||||||
service_item = MagicMock()
|
service_item = MagicMock()
|
||||||
service_item.is_text.return_value = False
|
service_item.is_text.return_value = False
|
||||||
@ -267,7 +268,7 @@ class TestListPreviewWidget(TestCase):
|
|||||||
list_preview_widget = ListPreviewWidget(None, 1)
|
list_preview_widget = ListPreviewWidget(None, 1)
|
||||||
list_preview_widget.replace_service_item(service_item, 200, 0)
|
list_preview_widget.replace_service_item(service_item, 200, 0)
|
||||||
# Change viewport width before forcing a resize
|
# Change viewport width before forcing a resize
|
||||||
self.mocked_viewport_obj.width.return_value = 400
|
mocked_viewport_obj.width.return_value = 400
|
||||||
|
|
||||||
# WHEN: __recalculate_layout() is called (via resizeEvent)
|
# WHEN: __recalculate_layout() is called (via resizeEvent)
|
||||||
list_preview_widget.resizeEvent(None)
|
list_preview_widget.resizeEvent(None)
|
||||||
@ -279,9 +280,11 @@ class TestListPreviewWidget(TestCase):
|
|||||||
# calls = [call(0, 100), call(1, 100), call(0, 100), call(1, 100)]
|
# calls = [call(0, 100), call(1, 100), call(0, 100), call(1, 100)]
|
||||||
# mocked_setRowHeight.assert_has_calls(calls)
|
# mocked_setRowHeight.assert_has_calls(calls)
|
||||||
|
|
||||||
|
|
||||||
@patch(u'openlp.core.widgets.views.ListPreviewWidget.resizeRowsToContents')
|
@patch(u'openlp.core.widgets.views.ListPreviewWidget.resizeRowsToContents')
|
||||||
@patch(u'openlp.core.widgets.views.ListPreviewWidget.setRowHeight')
|
@patch(u'openlp.core.widgets.views.ListPreviewWidget.setRowHeight')
|
||||||
def test_replace_recalculate_layout_img_auto(self, mocked_setRowHeight, mocked_resizeRowsToContents):
|
def test_replace_recalculate_layout_img_auto(mocked_setRowHeight, mocked_resizeRowsToContents,
|
||||||
|
preview_widget_env, mock_settings):
|
||||||
"""
|
"""
|
||||||
Test if "Max height for non-text slides..." auto, img slides resized in replace_service_item & __recalc...
|
Test if "Max height for non-text slides..." auto, img slides resized in replace_service_item & __recalc...
|
||||||
"""
|
"""
|
||||||
@ -289,10 +292,11 @@ class TestListPreviewWidget(TestCase):
|
|||||||
# an image ServiceItem and a ListPreviewWidget.
|
# an image ServiceItem and a ListPreviewWidget.
|
||||||
|
|
||||||
# Mock Settings().value('advanced/slide max height')
|
# Mock Settings().value('advanced/slide max height')
|
||||||
self.mocked_Settings_obj.value.return_value = -4
|
mock_settings.value.return_value = -4
|
||||||
# Mock self.viewport().width()
|
# Mock self.viewport().width()
|
||||||
self.mocked_viewport_obj.width.return_value = 200
|
mocked_viewport_obj = preview_widget_env[1]
|
||||||
self.mocked_viewport_obj.height.return_value = 600
|
mocked_viewport_obj.width.return_value = 200
|
||||||
|
mocked_viewport_obj.height.return_value = 600
|
||||||
# Mock image service item
|
# Mock image service item
|
||||||
service_item = MagicMock()
|
service_item = MagicMock()
|
||||||
service_item.is_text.return_value = False
|
service_item.is_text.return_value = False
|
||||||
@ -303,11 +307,11 @@ class TestListPreviewWidget(TestCase):
|
|||||||
list_preview_widget = ListPreviewWidget(None, 1)
|
list_preview_widget = ListPreviewWidget(None, 1)
|
||||||
list_preview_widget.replace_service_item(service_item, 200, 0)
|
list_preview_widget.replace_service_item(service_item, 200, 0)
|
||||||
# Change viewport width before forcing a resize
|
# Change viewport width before forcing a resize
|
||||||
self.mocked_viewport_obj.width.return_value = 400
|
mocked_viewport_obj.width.return_value = 400
|
||||||
|
|
||||||
# WHEN: __recalculate_layout() is called (via screen_size_changed)
|
# WHEN: __recalculate_layout() is called (via screen_size_changed)
|
||||||
list_preview_widget.screen_size_changed(1)
|
list_preview_widget.screen_size_changed(1)
|
||||||
self.mocked_viewport_obj.height.return_value = 200
|
mocked_viewport_obj.height.return_value = 200
|
||||||
list_preview_widget.screen_size_changed(1)
|
list_preview_widget.screen_size_changed(1)
|
||||||
|
|
||||||
# THEN: resizeRowsToContents() should not be called, while setRowHeight() should be called
|
# THEN: resizeRowsToContents() should not be called, while setRowHeight() should be called
|
||||||
@ -317,10 +321,12 @@ class TestListPreviewWidget(TestCase):
|
|||||||
# calls = [call(0, 100), call(1, 100), call(0, 150), call(1, 150), call(0, 100), call(1, 100)]
|
# calls = [call(0, 100), call(1, 100), call(0, 150), call(1, 150), call(0, 100), call(1, 100)]
|
||||||
# mocked_setRowHeight.assert_has_calls(calls)
|
# mocked_setRowHeight.assert_has_calls(calls)
|
||||||
|
|
||||||
|
|
||||||
@patch(u'openlp.core.widgets.views.ListPreviewWidget.resizeRowsToContents')
|
@patch(u'openlp.core.widgets.views.ListPreviewWidget.resizeRowsToContents')
|
||||||
@patch(u'openlp.core.widgets.views.ListPreviewWidget.setRowHeight')
|
@patch(u'openlp.core.widgets.views.ListPreviewWidget.setRowHeight')
|
||||||
@patch(u'openlp.core.widgets.views.ListPreviewWidget.cellWidget')
|
@patch(u'openlp.core.widgets.views.ListPreviewWidget.cellWidget')
|
||||||
def test_row_resized_text(self, mocked_cellWidget, mocked_setRowHeight, mocked_resizeRowsToContents):
|
def test_row_resized_text(mocked_cellWidget, mocked_setRowHeight, mocked_resizeRowsToContents,
|
||||||
|
preview_widget_env, mock_settings):
|
||||||
"""
|
"""
|
||||||
Test if "Max height for non-text slides..." enabled, text-based slides not affected in row_resized.
|
Test if "Max height for non-text slides..." enabled, text-based slides not affected in row_resized.
|
||||||
"""
|
"""
|
||||||
@ -328,9 +334,10 @@ class TestListPreviewWidget(TestCase):
|
|||||||
# a text ServiceItem and a ListPreviewWidget.
|
# a text ServiceItem and a ListPreviewWidget.
|
||||||
|
|
||||||
# Mock Settings().value('advanced/slide max height')
|
# Mock Settings().value('advanced/slide max height')
|
||||||
self.mocked_Settings_obj.value.return_value = 100
|
mock_settings.value.return_value = 100
|
||||||
# Mock self.viewport().width()
|
# Mock self.viewport().width()
|
||||||
self.mocked_viewport_obj.width.return_value = 200
|
mocked_viewport_obj = preview_widget_env[1]
|
||||||
|
mocked_viewport_obj.width.return_value = 200
|
||||||
# Mock text service item
|
# Mock text service item
|
||||||
service_item = MagicMock()
|
service_item = MagicMock()
|
||||||
service_item.is_text.return_value = True
|
service_item.is_text.return_value = True
|
||||||
@ -351,10 +358,12 @@ class TestListPreviewWidget(TestCase):
|
|||||||
# THEN: self.cellWidget(row, 0).children()[1].setMaximumWidth() should not be called
|
# THEN: self.cellWidget(row, 0).children()[1].setMaximumWidth() should not be called
|
||||||
assert mocked_cellWidget_child.setMaximumWidth.call_count == 0, 'Should not be called'
|
assert mocked_cellWidget_child.setMaximumWidth.call_count == 0, 'Should not be called'
|
||||||
|
|
||||||
|
|
||||||
@patch(u'openlp.core.widgets.views.ListPreviewWidget.resizeRowsToContents')
|
@patch(u'openlp.core.widgets.views.ListPreviewWidget.resizeRowsToContents')
|
||||||
@patch(u'openlp.core.widgets.views.ListPreviewWidget.setRowHeight')
|
@patch(u'openlp.core.widgets.views.ListPreviewWidget.setRowHeight')
|
||||||
@patch(u'openlp.core.widgets.views.ListPreviewWidget.cellWidget')
|
@patch(u'openlp.core.widgets.views.ListPreviewWidget.cellWidget')
|
||||||
def test_row_resized_img(self, mocked_cellWidget, mocked_setRowHeight, mocked_resizeRowsToContents):
|
def test_row_resized_img(mocked_cellWidget, mocked_setRowHeight, mocked_resizeRowsToContents,
|
||||||
|
preview_widget_env, mock_settings):
|
||||||
"""
|
"""
|
||||||
Test if "Max height for non-text slides..." disabled, image-based slides not affected in row_resized.
|
Test if "Max height for non-text slides..." disabled, image-based slides not affected in row_resized.
|
||||||
"""
|
"""
|
||||||
@ -362,9 +371,10 @@ class TestListPreviewWidget(TestCase):
|
|||||||
# an image ServiceItem and a ListPreviewWidget.
|
# an image ServiceItem and a ListPreviewWidget.
|
||||||
|
|
||||||
# Mock Settings().value('advanced/slide max height')
|
# Mock Settings().value('advanced/slide max height')
|
||||||
self.mocked_Settings_obj.value.return_value = 0
|
mock_settings.value.return_value = 0
|
||||||
# Mock self.viewport().width()
|
# Mock self.viewport().width()
|
||||||
self.mocked_viewport_obj.width.return_value = 200
|
mocked_viewport_obj = preview_widget_env[1]
|
||||||
|
mocked_viewport_obj.width.return_value = 200
|
||||||
# Mock image service item
|
# Mock image service item
|
||||||
service_item = MagicMock()
|
service_item = MagicMock()
|
||||||
service_item.is_text.return_value = False
|
service_item.is_text.return_value = False
|
||||||
@ -382,16 +392,18 @@ class TestListPreviewWidget(TestCase):
|
|||||||
|
|
||||||
# WHEN: row_resized() is called
|
# WHEN: row_resized() is called
|
||||||
list_preview_widget.row_resized(0, 100, 150)
|
list_preview_widget.row_resized(0, 100, 150)
|
||||||
self.mocked_Settings_obj.value.return_value = None
|
mock_settings.value.return_value = None
|
||||||
list_preview_widget.row_resized(0, 100, 150)
|
list_preview_widget.row_resized(0, 100, 150)
|
||||||
|
|
||||||
# THEN: self.cellWidget(row, 0).children()[1].setMaximumWidth() should not be called
|
# THEN: self.cellWidget(row, 0).children()[1].setMaximumWidth() should not be called
|
||||||
assert mocked_cellWidget_child.setMaximumWidth.call_count == 0, 'Should not be called'
|
assert mocked_cellWidget_child.setMaximumWidth.call_count == 0, 'Should not be called'
|
||||||
|
|
||||||
|
|
||||||
@patch(u'openlp.core.widgets.views.ListPreviewWidget.resizeRowsToContents')
|
@patch(u'openlp.core.widgets.views.ListPreviewWidget.resizeRowsToContents')
|
||||||
@patch(u'openlp.core.widgets.views.ListPreviewWidget.setRowHeight')
|
@patch(u'openlp.core.widgets.views.ListPreviewWidget.setRowHeight')
|
||||||
@patch(u'openlp.core.widgets.views.ListPreviewWidget.cellWidget')
|
@patch(u'openlp.core.widgets.views.ListPreviewWidget.cellWidget')
|
||||||
def test_row_resized_img_max(self, mocked_cellWidget, mocked_setRowHeight, mocked_resizeRowsToContents):
|
def test_row_resized_img_max(mocked_cellWidget, mocked_setRowHeight, mocked_resizeRowsToContents,
|
||||||
|
preview_widget_env, mock_settings):
|
||||||
"""
|
"""
|
||||||
Test if "Max height for non-text slides..." enabled, image-based slides are scaled in row_resized.
|
Test if "Max height for non-text slides..." enabled, image-based slides are scaled in row_resized.
|
||||||
"""
|
"""
|
||||||
@ -399,9 +411,9 @@ class TestListPreviewWidget(TestCase):
|
|||||||
# an image ServiceItem and a ListPreviewWidget.
|
# an image ServiceItem and a ListPreviewWidget.
|
||||||
|
|
||||||
# Mock Settings().value('advanced/slide max height')
|
# Mock Settings().value('advanced/slide max height')
|
||||||
self.mocked_Settings_obj.value.return_value = 100
|
mock_settings.value.return_value = 100
|
||||||
# Mock self.viewport().width()
|
# Mock self.viewport().width()
|
||||||
self.mocked_viewport_obj.width.return_value = 200
|
mock_settings.width.return_value = 200
|
||||||
# Mock image service item
|
# Mock image service item
|
||||||
service_item = MagicMock()
|
service_item = MagicMock()
|
||||||
service_item.is_text.return_value = False
|
service_item.is_text.return_value = False
|
||||||
@ -423,10 +435,12 @@ class TestListPreviewWidget(TestCase):
|
|||||||
# THEN: self.cellWidget(row, 0).children()[1].setMaximumWidth() should be called
|
# THEN: self.cellWidget(row, 0).children()[1].setMaximumWidth() should be called
|
||||||
mocked_cellWidget_child.setMaximumWidth.assert_called_once_with(150)
|
mocked_cellWidget_child.setMaximumWidth.assert_called_once_with(150)
|
||||||
|
|
||||||
|
|
||||||
@patch(u'openlp.core.widgets.views.ListPreviewWidget.resizeRowsToContents')
|
@patch(u'openlp.core.widgets.views.ListPreviewWidget.resizeRowsToContents')
|
||||||
@patch(u'openlp.core.widgets.views.ListPreviewWidget.setRowHeight')
|
@patch(u'openlp.core.widgets.views.ListPreviewWidget.setRowHeight')
|
||||||
@patch(u'openlp.core.widgets.views.ListPreviewWidget.cellWidget')
|
@patch(u'openlp.core.widgets.views.ListPreviewWidget.cellWidget')
|
||||||
def test_row_resized_setting_changed(self, mocked_cellWidget, mocked_setRowHeight, mocked_resizeRowsToContents):
|
def test_row_resized_setting_changed(mocked_cellWidget, mocked_setRowHeight, mocked_resizeRowsToContents,
|
||||||
|
preview_widget_env, mock_settings):
|
||||||
"""
|
"""
|
||||||
Test if "Max height for non-text slides..." enabled while item live, program doesn't crash on row_resized.
|
Test if "Max height for non-text slides..." enabled while item live, program doesn't crash on row_resized.
|
||||||
"""
|
"""
|
||||||
@ -434,9 +448,10 @@ class TestListPreviewWidget(TestCase):
|
|||||||
# an image ServiceItem and a ListPreviewWidget.
|
# an image ServiceItem and a ListPreviewWidget.
|
||||||
|
|
||||||
# Mock Settings().value('advanced/slide max height')
|
# Mock Settings().value('advanced/slide max height')
|
||||||
self.mocked_Settings_obj.value.return_value = 0
|
mock_settings.value.return_value = 0
|
||||||
# Mock self.viewport().width()
|
# Mock self.viewport().width()
|
||||||
self.mocked_viewport_obj.width.return_value = 200
|
mocked_viewport_obj = preview_widget_env[1]
|
||||||
|
mocked_viewport_obj.width.return_value = 200
|
||||||
# Mock image service item
|
# Mock image service item
|
||||||
service_item = MagicMock()
|
service_item = MagicMock()
|
||||||
service_item.is_text.return_value = False
|
service_item.is_text.return_value = False
|
||||||
@ -450,25 +465,27 @@ class TestListPreviewWidget(TestCase):
|
|||||||
# init ListPreviewWidget and load service item
|
# init ListPreviewWidget and load service item
|
||||||
list_preview_widget = ListPreviewWidget(None, 1)
|
list_preview_widget = ListPreviewWidget(None, 1)
|
||||||
list_preview_widget.replace_service_item(service_item, 200, 0)
|
list_preview_widget.replace_service_item(service_item, 200, 0)
|
||||||
self.mocked_Settings_obj.value.return_value = 100
|
mock_settings.value.return_value = 100
|
||||||
|
|
||||||
# WHEN: row_resized() is called
|
# WHEN: row_resized() is called
|
||||||
list_preview_widget.row_resized(0, 100, 150)
|
list_preview_widget.row_resized(0, 100, 150)
|
||||||
|
|
||||||
# THEN: self.cellWidget(row, 0).children()[1].setMaximumWidth() should fail
|
# THEN: self.cellWidget(row, 0).children()[1].setMaximumWidth() should fail
|
||||||
self.assertRaises(Exception)
|
assert Exception
|
||||||
|
|
||||||
|
|
||||||
@patch(u'openlp.core.widgets.views.ListPreviewWidget.selectRow')
|
@patch(u'openlp.core.widgets.views.ListPreviewWidget.selectRow')
|
||||||
@patch(u'openlp.core.widgets.views.ListPreviewWidget.scrollToItem')
|
@patch(u'openlp.core.widgets.views.ListPreviewWidget.scrollToItem')
|
||||||
@patch(u'openlp.core.widgets.views.ListPreviewWidget.item')
|
@patch(u'openlp.core.widgets.views.ListPreviewWidget.item')
|
||||||
@patch(u'openlp.core.widgets.views.ListPreviewWidget.slide_count')
|
@patch(u'openlp.core.widgets.views.ListPreviewWidget.slide_count')
|
||||||
def test_autoscroll_setting_invalid(self, mocked_slide_count, mocked_item, mocked_scrollToItem, mocked_selectRow):
|
def test_autoscroll_setting_invalid(mocked_slide_count, mocked_item, mocked_scrollToItem, mocked_selectRow,
|
||||||
|
preview_widget_env, mock_settings):
|
||||||
"""
|
"""
|
||||||
Test if 'advanced/autoscrolling' setting None or invalid, that no autoscrolling occurs on change_slide().
|
Test if 'advanced/autoscrolling' setting None or invalid, that no autoscrolling occurs on change_slide().
|
||||||
"""
|
"""
|
||||||
# GIVEN: A setting for autoscrolling and a ListPreviewWidget.
|
# GIVEN: A setting for autoscrolling and a ListPreviewWidget.
|
||||||
# Mock Settings().value('advanced/autoscrolling')
|
# Mock Settings().value('advanced/autoscrolling')
|
||||||
self.mocked_Settings_obj.value.return_value = None
|
mock_settings.value.return_value = None
|
||||||
# Mocked returns
|
# Mocked returns
|
||||||
mocked_slide_count.return_value = 1
|
mocked_slide_count.return_value = 1
|
||||||
mocked_item.return_value = None
|
mocked_item.return_value = None
|
||||||
@ -477,15 +494,15 @@ class TestListPreviewWidget(TestCase):
|
|||||||
|
|
||||||
# WHEN: change_slide() is called
|
# WHEN: change_slide() is called
|
||||||
list_preview_widget.change_slide(0)
|
list_preview_widget.change_slide(0)
|
||||||
self.mocked_Settings_obj.value.return_value = 1
|
mock_settings.value.return_value = 1
|
||||||
list_preview_widget.change_slide(0)
|
list_preview_widget.change_slide(0)
|
||||||
self.mocked_Settings_obj.value.return_value = {'fail': 1}
|
mock_settings.value.return_value = {'fail': 1}
|
||||||
list_preview_widget.change_slide(0)
|
list_preview_widget.change_slide(0)
|
||||||
self.mocked_Settings_obj.value.return_value = {'dist': 1, 'fail': 1}
|
mock_settings.value.return_value = {'dist': 1, 'fail': 1}
|
||||||
list_preview_widget.change_slide(0)
|
list_preview_widget.change_slide(0)
|
||||||
self.mocked_Settings_obj.value.return_value = {'dist': 'fail', 'pos': 1}
|
mock_settings.value.return_value = {'dist': 'fail', 'pos': 1}
|
||||||
list_preview_widget.change_slide(0)
|
list_preview_widget.change_slide(0)
|
||||||
self.mocked_Settings_obj.value.return_value = {'dist': 1, 'pos': 'fail'}
|
mock_settings.value.return_value = {'dist': 1, 'pos': 'fail'}
|
||||||
list_preview_widget.change_slide(0)
|
list_preview_widget.change_slide(0)
|
||||||
|
|
||||||
# THEN: no further functions should be called
|
# THEN: no further functions should be called
|
||||||
@ -494,17 +511,19 @@ class TestListPreviewWidget(TestCase):
|
|||||||
assert mocked_selectRow.call_count == 0, 'Should not be called'
|
assert mocked_selectRow.call_count == 0, 'Should not be called'
|
||||||
assert mocked_item.call_count == 0, 'Should not be called'
|
assert mocked_item.call_count == 0, 'Should not be called'
|
||||||
|
|
||||||
|
|
||||||
@patch(u'openlp.core.widgets.views.ListPreviewWidget.selectRow')
|
@patch(u'openlp.core.widgets.views.ListPreviewWidget.selectRow')
|
||||||
@patch(u'openlp.core.widgets.views.ListPreviewWidget.scrollToItem')
|
@patch(u'openlp.core.widgets.views.ListPreviewWidget.scrollToItem')
|
||||||
@patch(u'openlp.core.widgets.views.ListPreviewWidget.item')
|
@patch(u'openlp.core.widgets.views.ListPreviewWidget.item')
|
||||||
@patch(u'openlp.core.widgets.views.ListPreviewWidget.slide_count')
|
@patch(u'openlp.core.widgets.views.ListPreviewWidget.slide_count')
|
||||||
def test_autoscroll_dist_bounds(self, mocked_slide_count, mocked_item, mocked_scrollToItem, mocked_selectRow):
|
def test_autoscroll_dist_bounds(mocked_slide_count, mocked_item, mocked_scrollToItem, mocked_selectRow,
|
||||||
|
preview_widget_env, mock_settings):
|
||||||
"""
|
"""
|
||||||
Test if 'advanced/autoscrolling' setting asks to scroll beyond list bounds, that it does not beyond.
|
Test if 'advanced/autoscrolling' setting asks to scroll beyond list bounds, that it does not beyond.
|
||||||
"""
|
"""
|
||||||
# GIVEN: A setting for autoscrolling and a ListPreviewWidget.
|
# GIVEN: A setting for autoscrolling and a ListPreviewWidget.
|
||||||
# Mock Settings().value('advanced/autoscrolling')
|
# Mock Settings().value('advanced/autoscrolling')
|
||||||
self.mocked_Settings_obj.value.return_value = {'dist': -1, 'pos': 1}
|
mock_settings.value.return_value = {'dist': -1, 'pos': 1}
|
||||||
# Mocked returns
|
# Mocked returns
|
||||||
mocked_slide_count.return_value = 1
|
mocked_slide_count.return_value = 1
|
||||||
mocked_item.return_value = None
|
mocked_item.return_value = None
|
||||||
@ -513,7 +532,7 @@ class TestListPreviewWidget(TestCase):
|
|||||||
|
|
||||||
# WHEN: change_slide() is called
|
# WHEN: change_slide() is called
|
||||||
list_preview_widget.change_slide(0)
|
list_preview_widget.change_slide(0)
|
||||||
self.mocked_Settings_obj.value.return_value = {'dist': 1, 'pos': 1}
|
mock_settings.value.return_value = {'dist': 1, 'pos': 1}
|
||||||
list_preview_widget.change_slide(0)
|
list_preview_widget.change_slide(0)
|
||||||
|
|
||||||
# THEN: no further functions should be called
|
# THEN: no further functions should be called
|
||||||
@ -524,17 +543,19 @@ class TestListPreviewWidget(TestCase):
|
|||||||
calls = [call(0, 0), call(0, 0)]
|
calls = [call(0, 0), call(0, 0)]
|
||||||
mocked_item.assert_has_calls(calls)
|
mocked_item.assert_has_calls(calls)
|
||||||
|
|
||||||
|
|
||||||
@patch(u'openlp.core.widgets.views.ListPreviewWidget.selectRow')
|
@patch(u'openlp.core.widgets.views.ListPreviewWidget.selectRow')
|
||||||
@patch(u'openlp.core.widgets.views.ListPreviewWidget.scrollToItem')
|
@patch(u'openlp.core.widgets.views.ListPreviewWidget.scrollToItem')
|
||||||
@patch(u'openlp.core.widgets.views.ListPreviewWidget.item')
|
@patch(u'openlp.core.widgets.views.ListPreviewWidget.item')
|
||||||
@patch(u'openlp.core.widgets.views.ListPreviewWidget.slide_count')
|
@patch(u'openlp.core.widgets.views.ListPreviewWidget.slide_count')
|
||||||
def test_autoscroll_normal(self, mocked_slide_count, mocked_item, mocked_scrollToItem, mocked_selectRow):
|
def test_autoscroll_normal(mocked_slide_count, mocked_item, mocked_scrollToItem, mocked_selectRow,
|
||||||
|
preview_widget_env, mock_settings):
|
||||||
"""
|
"""
|
||||||
Test if 'advanced/autoscrolling' setting valid, autoscrolling called as expected.
|
Test if 'advanced/autoscrolling' setting valid, autoscrolling called as expected.
|
||||||
"""
|
"""
|
||||||
# GIVEN: A setting for autoscrolling and a ListPreviewWidget.
|
# GIVEN: A setting for autoscrolling and a ListPreviewWidget.
|
||||||
# Mock Settings().value('advanced/autoscrolling')
|
# Mock Settings().value('advanced/autoscrolling')
|
||||||
self.mocked_Settings_obj.value.return_value = {'dist': -1, 'pos': 1}
|
mock_settings.value.return_value = {'dist': -1, 'pos': 1}
|
||||||
# Mocked returns
|
# Mocked returns
|
||||||
mocked_slide_count.return_value = 3
|
mocked_slide_count.return_value = 3
|
||||||
mocked_item.return_value = None
|
mocked_item.return_value = None
|
||||||
@ -543,9 +564,9 @@ class TestListPreviewWidget(TestCase):
|
|||||||
|
|
||||||
# WHEN: change_slide() is called
|
# WHEN: change_slide() is called
|
||||||
list_preview_widget.change_slide(1)
|
list_preview_widget.change_slide(1)
|
||||||
self.mocked_Settings_obj.value.return_value = {'dist': 0, 'pos': 1}
|
mock_settings.value.return_value = {'dist': 0, 'pos': 1}
|
||||||
list_preview_widget.change_slide(1)
|
list_preview_widget.change_slide(1)
|
||||||
self.mocked_Settings_obj.value.return_value = {'dist': 1, 'pos': 1}
|
mock_settings.value.return_value = {'dist': 1, 'pos': 1}
|
||||||
list_preview_widget.change_slide(1)
|
list_preview_widget.change_slide(1)
|
||||||
|
|
||||||
# THEN: no further functions should be called
|
# THEN: no further functions should be called
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
Module to test the EditCustomForm.
|
Module to test the EditCustomForm.
|
||||||
"""
|
"""
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
from unittest.mock import MagicMock, call, patch
|
from unittest.mock import MagicMock, call
|
||||||
|
|
||||||
from PyQt5 import QtCore, QtGui, QtTest, QtWidgets
|
from PyQt5 import QtCore, QtGui, QtTest, QtWidgets
|
||||||
|
|
||||||
@ -56,11 +56,7 @@ class TestSearchEdit(TestCase, TestMixin):
|
|||||||
self.setup_application()
|
self.setup_application()
|
||||||
self.main_window = QtWidgets.QMainWindow()
|
self.main_window = QtWidgets.QMainWindow()
|
||||||
Registry().register('main_window', self.main_window)
|
Registry().register('main_window', self.main_window)
|
||||||
|
Registry().register('settings', MagicMock(**{'value.return_value': SearchTypes.First}))
|
||||||
settings_patcher = patch(
|
|
||||||
'openlp.core.widgets.edits.Settings', return_value=MagicMock(**{'value.return_value': SearchTypes.First}))
|
|
||||||
self.addCleanup(settings_patcher.stop)
|
|
||||||
self.mocked_settings = settings_patcher.start()
|
|
||||||
|
|
||||||
self.search_edit = SearchEdit(self.main_window, 'settings_section')
|
self.search_edit = SearchEdit(self.main_window, 'settings_section')
|
||||||
# To complete set up we have to set the search types.
|
# To complete set up we have to set the search types.
|
||||||
@ -86,7 +82,7 @@ class TestSearchEdit(TestCase, TestMixin):
|
|||||||
# settings
|
# settings
|
||||||
assert self.search_edit.current_search_type() == SearchTypes.First, \
|
assert self.search_edit.current_search_type() == SearchTypes.First, \
|
||||||
"The first search type should be selected."
|
"The first search type should be selected."
|
||||||
self.mocked_settings().setValue.assert_called_once_with('settings_section/last used search type', 0)
|
Registry().get('settings').setValue.assert_called_once_with('settings_section/last used search type', 0)
|
||||||
|
|
||||||
def test_set_current_search_type(self):
|
def test_set_current_search_type(self):
|
||||||
"""
|
"""
|
||||||
@ -102,7 +98,7 @@ class TestSearchEdit(TestCase, TestMixin):
|
|||||||
"The search type should be SearchTypes.Second"
|
"The search type should be SearchTypes.Second"
|
||||||
assert self.search_edit.placeholderText() == SECOND_PLACEHOLDER_TEXT, \
|
assert self.search_edit.placeholderText() == SECOND_PLACEHOLDER_TEXT, \
|
||||||
"The correct placeholder text should be 'Second Placeholder Text'."
|
"The correct placeholder text should be 'Second Placeholder Text'."
|
||||||
self.mocked_settings().setValue.assert_has_calls(
|
Registry().get('settings').setValue.assert_has_calls(
|
||||||
[call('settings_section/last used search type', 0), call('settings_section/last used search type', 1)])
|
[call('settings_section/last used search type', 0), call('settings_section/last used search type', 1)])
|
||||||
|
|
||||||
def test_clear_button_visibility(self):
|
def test_clear_button_visibility(self):
|
||||||
|
@ -26,6 +26,7 @@ from unittest import TestCase
|
|||||||
from unittest.mock import call, patch
|
from unittest.mock import call, patch
|
||||||
|
|
||||||
import openlp.core.projectors.pjlink
|
import openlp.core.projectors.pjlink
|
||||||
|
from openlp.core.common.settings import Settings
|
||||||
from openlp.core.common.registry import Registry
|
from openlp.core.common.registry import Registry
|
||||||
from openlp.core.projectors.constants import PJLINK_PORT
|
from openlp.core.projectors.constants import PJLINK_PORT
|
||||||
from openlp.core.projectors.pjlink import PJLinkUDP
|
from openlp.core.projectors.pjlink import PJLinkUDP
|
||||||
@ -46,6 +47,7 @@ class TestPJLinkBase(TestCase, TestMixin):
|
|||||||
self.setup_application()
|
self.setup_application()
|
||||||
self.build_settings()
|
self.build_settings()
|
||||||
Registry.create()
|
Registry.create()
|
||||||
|
Registry().register('settings', Settings())
|
||||||
"""
|
"""
|
||||||
with patch('openlp.core.projectors.db.init_url') as mocked_init_url:
|
with patch('openlp.core.projectors.db.init_url') as mocked_init_url:
|
||||||
if os.path.exists(TEST_DB):
|
if os.path.exists(TEST_DB):
|
||||||
|
@ -32,17 +32,7 @@ from openlp.core.widgets.widgets import ProxyWidget, ProxyDialog, ScreenButton,
|
|||||||
from tests.helpers.testmixin import TestMixin
|
from tests.helpers.testmixin import TestMixin
|
||||||
|
|
||||||
|
|
||||||
class TestProxyWidget(TestCase, TestMixin):
|
def test_radio_button_exclusivity_no_proxy(settings):
|
||||||
"""
|
|
||||||
Test the EditCustomForm.
|
|
||||||
"""
|
|
||||||
def setUp(self):
|
|
||||||
"""
|
|
||||||
Create the UI
|
|
||||||
"""
|
|
||||||
self.setup_application()
|
|
||||||
|
|
||||||
def test_radio_button_exclusivity_no_proxy(self):
|
|
||||||
"""
|
"""
|
||||||
Test that only one radio button can be checked at a time, and that the line edits are only enabled when the
|
Test that only one radio button can be checked at a time, and that the line edits are only enabled when the
|
||||||
`manual_proxy_radio` is checked
|
`manual_proxy_radio` is checked
|
||||||
@ -62,7 +52,8 @@ class TestProxyWidget(TestCase, TestMixin):
|
|||||||
assert proxy_widget.username_edit.isEnabled() is False
|
assert proxy_widget.username_edit.isEnabled() is False
|
||||||
assert proxy_widget.password_edit.isEnabled() is False
|
assert proxy_widget.password_edit.isEnabled() is False
|
||||||
|
|
||||||
def test_radio_button_exclusivity_system_proxy(self):
|
|
||||||
|
def test_radio_button_exclusivity_system_proxy(settings):
|
||||||
"""
|
"""
|
||||||
Test that only one radio button can be checked at a time, and that the line edits are only enabled when the
|
Test that only one radio button can be checked at a time, and that the line edits are only enabled when the
|
||||||
`manual_proxy_radio` is checked
|
`manual_proxy_radio` is checked
|
||||||
@ -82,7 +73,8 @@ class TestProxyWidget(TestCase, TestMixin):
|
|||||||
assert proxy_widget.username_edit.isEnabled() is False
|
assert proxy_widget.username_edit.isEnabled() is False
|
||||||
assert proxy_widget.password_edit.isEnabled() is False
|
assert proxy_widget.password_edit.isEnabled() is False
|
||||||
|
|
||||||
def test_radio_button_exclusivity_manual_proxy(self):
|
|
||||||
|
def test_radio_button_exclusivity_manual_proxy(settings):
|
||||||
"""
|
"""
|
||||||
Test that only one radio button can be checked at a time, and that the line edits are only enabled when the
|
Test that only one radio button can be checked at a time, and that the line edits are only enabled when the
|
||||||
`manual_proxy_radio` is checked
|
`manual_proxy_radio` is checked
|
||||||
@ -102,7 +94,8 @@ class TestProxyWidget(TestCase, TestMixin):
|
|||||||
assert proxy_widget.username_edit.isEnabled() is True
|
assert proxy_widget.username_edit.isEnabled() is True
|
||||||
assert proxy_widget.password_edit.isEnabled() is True
|
assert proxy_widget.password_edit.isEnabled() is True
|
||||||
|
|
||||||
def test_proxy_widget_load_default_settings(self):
|
|
||||||
|
def test_proxy_widget_load_default_settings(settings):
|
||||||
"""
|
"""
|
||||||
Test that the default settings are loaded from the config correctly
|
Test that the default settings are loaded from the config correctly
|
||||||
"""
|
"""
|
||||||
@ -119,15 +112,13 @@ class TestProxyWidget(TestCase, TestMixin):
|
|||||||
assert proxy_widget.username_edit.text() == ''
|
assert proxy_widget.username_edit.text() == ''
|
||||||
assert proxy_widget.password_edit.text() == ''
|
assert proxy_widget.password_edit.text() == ''
|
||||||
|
|
||||||
|
|
||||||
@patch.object(ProxyWidget, 'load')
|
@patch.object(ProxyWidget, 'load')
|
||||||
@patch('openlp.core.widgets.widgets.Settings')
|
def test_proxy_widget_save_no_proxy_settings(proxy_widget_load_patcher, qapp, mock_settings):
|
||||||
def test_proxy_widget_save_no_proxy_settings(self, settings_patcher, proxy_widget_load_patcher):
|
|
||||||
"""
|
"""
|
||||||
Test that the settings are saved correctly
|
Test that the settings are saved correctly
|
||||||
"""
|
"""
|
||||||
# GIVEN: A Mocked settings instance of the proxy widget with some known values set
|
# GIVEN: A Mocked settings instance of the proxy widget with some known values set
|
||||||
settings_instance = MagicMock()
|
|
||||||
settings_patcher.return_value = settings_instance
|
|
||||||
proxy_widget = ProxyWidget()
|
proxy_widget = ProxyWidget()
|
||||||
proxy_widget.no_proxy_radio.setChecked(True)
|
proxy_widget.no_proxy_radio.setChecked(True)
|
||||||
proxy_widget.http_edit.setText('')
|
proxy_widget.http_edit.setText('')
|
||||||
@ -139,22 +130,20 @@ class TestProxyWidget(TestCase, TestMixin):
|
|||||||
proxy_widget.save()
|
proxy_widget.save()
|
||||||
|
|
||||||
# THEN: The settings should be set as expected
|
# THEN: The settings should be set as expected
|
||||||
settings_instance.setValue.assert_has_calls(
|
mock_settings.setValue.assert_has_calls(
|
||||||
[call('advanced/proxy mode', ProxyMode.NO_PROXY),
|
[call('advanced/proxy mode', ProxyMode.NO_PROXY),
|
||||||
call('advanced/proxy http', ''),
|
call('advanced/proxy http', ''),
|
||||||
call('advanced/proxy https', ''),
|
call('advanced/proxy https', ''),
|
||||||
call('advanced/proxy username', ''),
|
call('advanced/proxy username', ''),
|
||||||
call('advanced/proxy password', '')])
|
call('advanced/proxy password', '')])
|
||||||
|
|
||||||
|
|
||||||
@patch.object(ProxyWidget, 'load')
|
@patch.object(ProxyWidget, 'load')
|
||||||
@patch('openlp.core.widgets.widgets.Settings')
|
def test_proxy_widget_save_manual_settings(proxy_widget_load_patcher, qapp, mock_settings):
|
||||||
def test_proxy_widget_save_manual_settings(self, settings_patcher, proxy_widget_load_patcher):
|
|
||||||
"""
|
"""
|
||||||
Test that the settings are saved correctly
|
Test that the settings are saved correctly
|
||||||
"""
|
"""
|
||||||
# GIVEN: A Mocked and instance of the proxy widget with some known values set
|
# GIVEN: A Mocked and instance of the proxy widget with some known values set
|
||||||
settings_instance = MagicMock()
|
|
||||||
settings_patcher.return_value = settings_instance
|
|
||||||
proxy_widget = ProxyWidget()
|
proxy_widget = ProxyWidget()
|
||||||
proxy_widget.manual_proxy_radio.setChecked(True)
|
proxy_widget.manual_proxy_radio.setChecked(True)
|
||||||
proxy_widget.http_edit.setText('http_proxy_server:port')
|
proxy_widget.http_edit.setText('http_proxy_server:port')
|
||||||
@ -166,7 +155,7 @@ class TestProxyWidget(TestCase, TestMixin):
|
|||||||
proxy_widget.save()
|
proxy_widget.save()
|
||||||
|
|
||||||
# THEN: The settings should be set as expected
|
# THEN: The settings should be set as expected
|
||||||
settings_instance.setValue.assert_has_calls(
|
mock_settings.setValue.assert_has_calls(
|
||||||
[call('advanced/proxy mode', ProxyMode.MANUAL_PROXY),
|
[call('advanced/proxy mode', ProxyMode.MANUAL_PROXY),
|
||||||
call('advanced/proxy http', 'http_proxy_server:port'),
|
call('advanced/proxy http', 'http_proxy_server:port'),
|
||||||
call('advanced/proxy https', 'https_proxy_server:port'),
|
call('advanced/proxy https', 'https_proxy_server:port'),
|
||||||
@ -174,26 +163,15 @@ class TestProxyWidget(TestCase, TestMixin):
|
|||||||
call('advanced/proxy password', 'password')])
|
call('advanced/proxy password', 'password')])
|
||||||
|
|
||||||
|
|
||||||
class TestProxyDialog(TestCase, TestMixin):
|
def test_proxy_dialog_init(settings):
|
||||||
"""Test the ProxyDialog"""
|
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
"""Test setup"""
|
|
||||||
self.setup_application()
|
|
||||||
self.build_settings()
|
|
||||||
|
|
||||||
def tearDown(self):
|
|
||||||
"""Teardown tests"""
|
|
||||||
del self.app
|
|
||||||
|
|
||||||
def test_init(self):
|
|
||||||
"""Test that the ProxyDialog is created successfully"""
|
"""Test that the ProxyDialog is created successfully"""
|
||||||
# GIVEN: ProxyDialog class
|
# GIVEN: ProxyDialog class
|
||||||
# WHEN: It is instantiated
|
# WHEN: It is instantiated
|
||||||
# THEN: There should be no problems
|
# THEN: There should be no problems
|
||||||
ProxyDialog()
|
ProxyDialog()
|
||||||
|
|
||||||
def test_accept(self):
|
|
||||||
|
def test_proxy_dialog_accept(settings):
|
||||||
"""Test that the accept() method of the ProxyDialog works correctly"""
|
"""Test that the accept() method of the ProxyDialog works correctly"""
|
||||||
# GIVEN: An instance of a ProxyDialog with a mocked out widget
|
# GIVEN: An instance of a ProxyDialog with a mocked out widget
|
||||||
dlg = ProxyDialog()
|
dlg = ProxyDialog()
|
||||||
@ -206,8 +184,7 @@ class TestProxyDialog(TestCase, TestMixin):
|
|||||||
dlg.proxy_widget.save.assert_called_once()
|
dlg.proxy_widget.save.assert_called_once()
|
||||||
|
|
||||||
|
|
||||||
class TestSceenButton(TestCase):
|
def test_screen_button_initialisation():
|
||||||
def test_screen_button_initialisation(self):
|
|
||||||
"""
|
"""
|
||||||
Test the initialisation of the ScreenButton object
|
Test the initialisation of the ScreenButton object
|
||||||
"""
|
"""
|
||||||
@ -405,29 +382,6 @@ class TestScreenSelectionWidget(TestCase, TestMixin):
|
|||||||
mocked_widget.deleteLater.assert_called_once()
|
mocked_widget.deleteLater.assert_called_once()
|
||||||
mocked_screen_button_group.removeButton.assert_called_once_with(mocked_widget)
|
mocked_screen_button_group.removeButton.assert_called_once_with(mocked_widget)
|
||||||
|
|
||||||
def test_save(self):
|
|
||||||
"""
|
|
||||||
Test that the save() method saves the screens
|
|
||||||
"""
|
|
||||||
# GIVEN: A ScreenSelectionWidget and a bunch o' mocks
|
|
||||||
mocked_screen = MagicMock(**{'number': 0, 'to_dict.return_value': {'number': 0}})
|
|
||||||
instance = ScreenSelectionWidget()
|
|
||||||
instance._save_screen = MagicMock()
|
|
||||||
instance.screens = [mocked_screen]
|
|
||||||
instance.current_screen = mocked_screen
|
|
||||||
|
|
||||||
# WHEN: Save is called
|
|
||||||
with patch('openlp.core.widgets.widgets.Settings') as MockSettings:
|
|
||||||
mocked_settings = MagicMock()
|
|
||||||
MockSettings.return_value = mocked_settings
|
|
||||||
instance.save()
|
|
||||||
|
|
||||||
# THEN: The right things should happen
|
|
||||||
instance._save_screen.assert_called_once_with(mocked_screen)
|
|
||||||
MockSettings.assert_called_once()
|
|
||||||
mocked_screen.to_dict.assert_called_once()
|
|
||||||
mocked_settings.setValue.assert_called_once_with('core/screens', {0: {'number': 0}})
|
|
||||||
|
|
||||||
def test_on_identify_timer_shot(self):
|
def test_on_identify_timer_shot(self):
|
||||||
"""
|
"""
|
||||||
Test that the _on_identify_timer_shot() method removes the labels from the screens
|
Test that the _on_identify_timer_shot() method removes the labels from the screens
|
||||||
@ -525,3 +479,22 @@ class TestScreenSelectionWidget(TestCase, TestMixin):
|
|||||||
'checkbox for that screen.', parent=instance, question=False)
|
'checkbox for that screen.', parent=instance, question=False)
|
||||||
assert instance.use_screen_check_box.isChecked() is True
|
assert instance.use_screen_check_box.isChecked() is True
|
||||||
assert instance.display_group_box.isChecked() is True
|
assert instance.display_group_box.isChecked() is True
|
||||||
|
|
||||||
|
|
||||||
|
def test_screen_selection_save(mock_settings):
|
||||||
|
"""
|
||||||
|
Test that the save() method saves the screens
|
||||||
|
"""
|
||||||
|
# GIVEN: A ScreenSelectionWidget and a bunch o' mocks
|
||||||
|
mocked_screen = MagicMock(**{'number': 0, 'to_dict.return_value': {'number': 0}})
|
||||||
|
instance = ScreenSelectionWidget()
|
||||||
|
instance._save_screen = MagicMock()
|
||||||
|
instance.screens = [mocked_screen]
|
||||||
|
instance.current_screen = mocked_screen
|
||||||
|
|
||||||
|
instance.save()
|
||||||
|
|
||||||
|
# THEN: The right things should happen
|
||||||
|
instance._save_screen.assert_called_once_with(mocked_screen)
|
||||||
|
mocked_screen.to_dict.assert_called_once()
|
||||||
|
mock_settings.setValue.assert_called_once_with('core/screens', {0: {'number': 0}})
|
||||||
|
Loading…
Reference in New Issue
Block a user