Merge branch 'test_update_02' into 'master'

Update Tests - 02

See merge request openlp/openlp!319
This commit is contained in:
Raoul Snyman 2021-04-15 17:25:59 +00:00
commit 1473ba8bba
7 changed files with 489 additions and 594 deletions

View File

@ -1,157 +0,0 @@
# -*- coding: utf-8 -*-
##########################################################################
# OpenLP - Open Source Lyrics Projection #
# ---------------------------------------------------------------------- #
# Copyright (c) 2008-2021 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 <https://www.gnu.org/licenses/>. #
##########################################################################
"""
Package to test the screens tab functionality (primarily ScreenSelectionWidget and ScreenButton classes)
within openlp/core/widgets/widgets.py
"""
import pytest
from unittest.mock import MagicMock, patch
from PyQt5 import QtWidgets, QtCore, QtTest
from openlp.core.widgets.widgets import ScreenSelectionWidget
@pytest.fixture()
def form(settings):
test_form = ScreenSelectionWidget()
return test_form
def mocked_screens(customGeometry):
screen0 = MagicMock()
screen0.number = 0
screen0.is_display = True
screen0.is_primary = False
screen0.geometry = QtCore.QRect(-271, -1080, 1920, 1080)
screen0.custom_geometry = customGeometry
screen0.__str__.return_value = "Screen 1"
screen1 = MagicMock()
screen1.number = 1
screen1.is_display = False
screen1.is_primary = True
screen1.geometry = QtCore.QRect(0, 0, 1366, 768)
screen1.custom_geometry = customGeometry
screen1.__str__.return_value = "Screen 2"
return [screen0, screen1]
@patch('openlp.core.display.screens.ScreenList')
def test_screen_buttons_show_pixels(mocked_screenList, form):
'''
Test that the screen buttons show the screen sizes in pixels
'''
# GIVEN: A mocked extended desktop configuration
mocked_screenList.return_value = mocked_screens(None)
form.screens = mocked_screenList()
# WHEN: When I go into screen settings for the display screen
ScreenSelectionWidget.load(form)
# THEN: The screen buttons should show the correct size of that screen
screen_0_button = form.findChild(QtWidgets.QPushButton, 'screen_0_button')
screen_1_button = form.findChild(QtWidgets.QPushButton, 'screen_1_button')
assert '1920' in str(screen_0_button.text())
assert '1080' in str(screen_0_button.text())
assert '1366' in str(screen_1_button.text())
assert '768' in str(screen_1_button.text())
@patch('openlp.core.display.screens.ScreenList')
def test_spinboxes_no_previous_custom_geometry(mocked_screenList, form):
"""
Test screen custom geometry can be changed from None
"""
# GIVEN: A mocked extended desktop configuration
mocked_screenList.return_value = mocked_screens(None)
form.screens = mocked_screenList()
# WHEN: When I go into screen settings for the display screen and set the custom geometry
ScreenSelectionWidget.load(form)
QtTest.QTest.mouseClick(form.custom_geometry_button, QtCore.Qt.LeftButton)
QtTest.QTest.keyClick(form.left_spin_box, QtCore.Qt.Key_Up)
QtTest.QTest.keyClick(form.top_spin_box, QtCore.Qt.Key_Up)
QtTest.QTest.keyClick(form.width_spin_box, QtCore.Qt.Key_Down)
QtTest.QTest.keyClick(form.height_spin_box, QtCore.Qt.Key_Down)
# THEN: The spin boxes should show the correct values
assert form.left_spin_box.value() == 1
assert form.top_spin_box.value() == 1
assert form.width_spin_box.value() == 1919
assert form.height_spin_box.value() == 1079
@patch('openlp.core.display.screens.ScreenList')
def test_spinboxes_with_previous_custom_geometry(mocked_screenList, form):
"""
Test screen existing custom geometry can be changed
"""
# GIVEN: A mocked extended desktop configuration
testGeometry = QtCore.QRect(1, 1, 1919, 1079)
mocked_screenList.return_value = mocked_screens(testGeometry)
form.screens = mocked_screenList()
# WHEN: When I go into screen settings for the display screen and update the custom geometry
ScreenSelectionWidget.load(form)
QtTest.QTest.mouseClick(form.custom_geometry_button, QtCore.Qt.LeftButton)
QtTest.QTest.keyClick(form.left_spin_box, QtCore.Qt.Key_Up)
QtTest.QTest.keyClick(form.top_spin_box, QtCore.Qt.Key_Up)
QtTest.QTest.keyClick(form.width_spin_box, QtCore.Qt.Key_Down)
QtTest.QTest.keyClick(form.height_spin_box, QtCore.Qt.Key_Down)
# THEN: The spin boxes should show the updated values
assert form.left_spin_box.value() == 2
assert form.top_spin_box.value() == 2
assert form.width_spin_box.value() == 1918
assert form.height_spin_box.value() == 1078
@patch('openlp.core.display.screens.ScreenList')
def test_spinboxes_going_outside_screen_geometry(mocked_screenList, form):
"""
Test screen existing custom geometry can be increased beyond the bounds of the screen
"""
# GIVEN: A mocked extended desktop configuration
testGeometry = QtCore.QRect(1, 1, 1919, 1079)
mocked_screenList.return_value = mocked_screens(testGeometry)
form.screens = mocked_screenList()
# WHEN: When I go into screen settings for the display screen and
# update the custom geometry to be outside the screen coordinates
ScreenSelectionWidget.load(form)
QtTest.QTest.mouseClick(form.custom_geometry_button, QtCore.Qt.LeftButton)
for _ in range(2):
QtTest.QTest.keyClick(form.left_spin_box, QtCore.Qt.Key_Down)
QtTest.QTest.keyClick(form.top_spin_box, QtCore.Qt.Key_Down)
QtTest.QTest.keyClick(form.width_spin_box, QtCore.Qt.Key_Up)
QtTest.QTest.keyClick(form.height_spin_box, QtCore.Qt.Key_Up)
# THEN: The spin boxes should show the updated values
assert form.left_spin_box.value() == -1
assert form.top_spin_box.value() == -1
assert form.width_spin_box.value() == 1921
assert form.height_spin_box.value() == 1081

View File

@ -1,20 +0,0 @@
# -*- coding: utf-8 -*-
##########################################################################
# OpenLP - Open Source Lyrics Projection #
# ---------------------------------------------------------------------- #
# Copyright (c) 2008-2021 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 <https://www.gnu.org/licenses/>. #
##########################################################################

View File

@ -1,68 +0,0 @@
# -*- coding: utf-8 -*-
##########################################################################
# OpenLP - Open Source Lyrics Projection #
# ---------------------------------------------------------------------- #
# Copyright (c) 2008-2021 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 <https://www.gnu.org/licenses/>. #
##########################################################################
"""
Functional tests to test the AppLocation class and related methods.
"""
from openlp.core.common import is_not_image_file
from tests.utils.constants import RESOURCE_PATH
def test_is_not_image_empty():
"""
Test the method handles an empty string
"""
# Given and empty string
file_name = ""
# WHEN testing for it
result = is_not_image_file(file_name)
# THEN the result is false
assert result is True, 'The missing file test should return True'
def test_is_not_image_with_image_file():
"""
Test the method handles an image file
"""
# Given and empty string
file_path = RESOURCE_PATH / 'church.jpg'
# WHEN testing for it
result = is_not_image_file(file_path)
# THEN the result is false
assert result is False, 'The file is present so the test should return False'
def test_is_not_image_with_none_image_file():
"""
Test the method handles a non image file
"""
# Given and empty string
file_path = RESOURCE_PATH / 'presentations' / 'test.ppt'
# WHEN testing for it
result = is_not_image_file(file_path)
# THEN the result is false
assert result is True, 'The file is not an image file so the test should return True'

View File

@ -1,101 +0,0 @@
# -*- coding: utf-8 -*-
##########################################################################
# OpenLP - Open Source Lyrics Projection #
# ---------------------------------------------------------------------- #
# Copyright (c) 2008-2021 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 <https://www.gnu.org/licenses/>. #
##########################################################################
"""
Package to test the openlp.core.ui.mainwindow package.
"""
import pytest
from unittest.mock import MagicMock, patch
from PyQt5 import QtGui
from openlp.core.state import State
from openlp.core.common.registry import Registry
from openlp.core.lib.plugin import PluginStatus
from openlp.core.ui.mainwindow import MainWindow
@pytest.fixture()
def main_window(settings, state):
"""
Create the UI
"""
Registry().set_flag('no_web_server', True)
mocked_plugin = MagicMock()
mocked_plugin.status = PluginStatus.Active
mocked_plugin.icon = QtGui.QIcon()
Registry().register('mock_plugin', mocked_plugin)
State().add_service("mock", 1, is_plugin=True, status=PluginStatus.Active)
# Mock classes and methods used by mainwindow.
with patch('openlp.core.ui.mainwindow.SettingsForm'), \
patch('openlp.core.ui.mainwindow.OpenLPDockWidget'), \
patch('openlp.core.ui.mainwindow.QtWidgets.QToolBox'), \
patch('openlp.core.ui.mainwindow.QtWidgets.QMainWindow.addDockWidget'), \
patch('openlp.core.ui.mainwindow.ServiceManager'), \
patch('openlp.core.ui.mainwindow.ThemeManager'), \
patch('openlp.core.ui.mainwindow.ProjectorManager'), \
patch('openlp.core.ui.mainwindow.HttpServer'), \
patch('openlp.core.ui.mainwindow.WebSocketServer'), \
patch('openlp.core.ui.mainwindow.start_zeroconf'), \
patch('openlp.core.ui.mainwindow.PluginForm'):
return MainWindow()
def test_restore_current_media_manager_item(main_window):
"""
Regression test for bug #1152509.
"""
# save current plugin: True; current media plugin: 2
main_window.settings.setValue('advanced/save current plugin', True)
main_window.settings.setValue('advanced/current media plugin', 2)
# WHEN: Call the restore method.
main_window.restore_current_media_manager_item()
# THEN: The current widget should have been set.
main_window.media_tool_box.setCurrentIndex.assert_called_with(2)
def test_projector_manager_dock_locked(main_window):
"""
Projector Manager enable UI options - bug #1390702
"""
# GIVEN: A mocked projector manager dock item:
projector_dock = main_window.projector_manager_dock
# WHEN: main_window.lock_panel action is triggered
main_window.lock_panel.triggered.emit(True)
# THEN: Projector manager dock should have been called with disable UI features
projector_dock.setFeatures.assert_called_with(0)
def test_projector_manager_dock_unlocked(main_window):
"""
Projector Manager disable UI options - bug #1390702
"""
# GIVEN: A mocked projector manager dock item:
projector_dock = main_window.projector_manager_dock
# WHEN: main_window.lock_panel action is triggered
main_window.lock_panel.triggered.emit(False)
# THEN: Projector manager dock should have been called with enable UI features
projector_dock.setFeatures.assert_called_with(7)

View File

@ -23,9 +23,12 @@ Interface tests to test the themeManager class and related methods.
"""
from unittest.mock import MagicMock
from openlp.core.common import is_not_image_file
from openlp.core.common.registry import Registry
from openlp.core.common.utils import wait_for, is_uuid
from tests.utils.constants import RESOURCE_PATH
def test_wait_for(registry):
"""
@ -57,3 +60,45 @@ def test_uuid_not_valid():
def test_uuid_valid():
"""Test that an valid string UUID returns True"""
assert is_uuid('2596ac84-9735-11ea-a665-8fa61362d04a'), 'is_uuid() should return True when given a valid UUID'
def test_is_not_image_empty():
"""
Test the method handles an empty string
"""
# Given and empty string
file_name = ""
# WHEN testing for it
result = is_not_image_file(file_name)
# THEN the result is false
assert result is True, 'The missing file test should return True'
def test_is_not_image_with_image_file():
"""
Test the method handles an image file
"""
# Given and empty string
file_path = RESOURCE_PATH / 'church.jpg'
# WHEN testing for it
result = is_not_image_file(file_path)
# THEN the result is false
assert result is False, 'The file is present so the test should return False'
def test_is_not_image_with_none_image_file():
"""
Test the method handles a non image file
"""
# Given and empty string
file_path = RESOURCE_PATH / 'presentations' / 'test.ppt'
# WHEN testing for it
result = is_not_image_file(file_path)
# THEN the result is false
assert result is True, 'The file is not an image file so the test should return True'

View File

@ -28,11 +28,13 @@ from unittest.mock import MagicMock, patch
from shutil import rmtree
from tempfile import mkdtemp
from PyQt5 import QtCore, QtWidgets
from PyQt5 import QtCore, QtWidgets, QtGui
from openlp.core.common.i18n import UiStrings
from openlp.core.common.registry import Registry
from openlp.core.display.screens import ScreenList
from openlp.core.lib.plugin import PluginStatus
from openlp.core.state import State
from openlp.core.ui.mainwindow import MainWindow
from tests.utils.constants import TEST_RESOURCES_PATH, RESOURCE_PATH
@ -75,6 +77,32 @@ def main_window(state, settings, mocked_qapp):
add_toolbar_action_patcher.stop()
@pytest.fixture()
def main_window_reduced(settings, state):
"""
Create the UI
"""
Registry().set_flag('no_web_server', True)
mocked_plugin = MagicMock()
mocked_plugin.status = PluginStatus.Active
mocked_plugin.icon = QtGui.QIcon()
Registry().register('mock_plugin', mocked_plugin)
State().add_service("mock", 1, is_plugin=True, status=PluginStatus.Active)
# Mock classes and methods used by mainwindow.
with patch('openlp.core.ui.mainwindow.SettingsForm'), \
patch('openlp.core.ui.mainwindow.OpenLPDockWidget'), \
patch('openlp.core.ui.mainwindow.QtWidgets.QToolBox'), \
patch('openlp.core.ui.mainwindow.QtWidgets.QMainWindow.addDockWidget'), \
patch('openlp.core.ui.mainwindow.ServiceManager'), \
patch('openlp.core.ui.mainwindow.ThemeManager'), \
patch('openlp.core.ui.mainwindow.ProjectorManager'), \
patch('openlp.core.ui.mainwindow.HttpServer'), \
patch('openlp.core.ui.mainwindow.WebSocketServer'), \
patch('openlp.core.ui.mainwindow.start_zeroconf'), \
patch('openlp.core.ui.mainwindow.PluginForm'):
return MainWindow()
def test_cmd_line_file(main_window):
"""
Test that passing a service file from the command line loads the service.
@ -341,3 +369,46 @@ def test_change_data_directory(mocked_get_directory, mocked_get_data_path, mocke
# Clean up
rmtree(temp_folder)
rmtree(temp_new_data_folder)
def test_restore_current_media_manager_item(main_window_reduced):
"""
Regression test for bug #1152509.
"""
# save current plugin: True; current media plugin: 2
main_window_reduced.settings.setValue('advanced/save current plugin', True)
main_window_reduced.settings.setValue('advanced/current media plugin', 2)
# WHEN: Call the restore method.
main_window_reduced.restore_current_media_manager_item()
# THEN: The current widget should have been set.
main_window_reduced.media_tool_box.setCurrentIndex.assert_called_with(2)
def test_projector_manager_dock_locked(main_window_reduced):
"""
Projector Manager enable UI options - bug #1390702
"""
# GIVEN: A mocked projector manager dock item:
projector_dock = main_window_reduced.projector_manager_dock
# WHEN: main_window.lock_panel action is triggered
main_window_reduced.lock_panel.triggered.emit(True)
# THEN: Projector manager dock should have been called with disable UI features
projector_dock.setFeatures.assert_called_with(0)
def test_projector_manager_dock_unlocked(main_window_reduced):
"""
Projector Manager disable UI options - bug #1390702
"""
# GIVEN: A mocked projector manager dock item:
projector_dock = main_window_reduced.projector_manager_dock
# WHEN: main_window.lock_panel action is triggered
main_window_reduced.lock_panel.triggered.emit(False)
# THEN: Projector manager dock should have been called with enable UI features
projector_dock.setFeatures.assert_called_with(7)

View File

@ -21,15 +21,38 @@
"""
Package to test the openlp.core.widgets.widgets package.
"""
from unittest import TestCase
import pytest
from unittest.mock import MagicMock, call, patch
from PyQt5 import QtCore, QtWidgets
from PyQt5 import QtCore, QtWidgets, QtTest
from openlp.core.common.settings import ProxyMode
from openlp.core.display.screens import Screen
from openlp.core.widgets.widgets import ProxyWidget, ProxyDialog, ScreenButton, ScreenSelectionWidget
from tests.helpers.testmixin import TestMixin
@pytest.fixture()
def form(settings):
test_form = ScreenSelectionWidget()
return test_form
def mocked_screens(custom_geometry):
screen0 = MagicMock()
screen0.number = 0
screen0.is_display = True
screen0.is_primary = False
screen0.geometry = QtCore.QRect(-271, -1080, 1920, 1080)
screen0.custom_geometry = custom_geometry
screen0.__str__.return_value = "Screen 1"
screen1 = MagicMock()
screen1.number = 1
screen1.is_display = False
screen1.is_primary = True
screen1.geometry = QtCore.QRect(0, 0, 1366, 768)
screen1.custom_geometry = custom_geometry
screen1.__str__.return_value = "Screen 2"
return [screen0, screen1]
def test_radio_button_exclusivity_no_proxy(settings):
@ -204,18 +227,7 @@ def test_screen_button_initialisation():
assert instance.text() == 'Mocked Screen Object'
class TestScreenSelectionWidget(TestCase, TestMixin):
def setUp(self):
"""Test setup"""
self.setup_application()
self.build_settings()
def tearDown(self):
"""Tear down tests"""
del self.app
def test_init_default_args(self):
def test_init_default_args():
"""
Test the initialisation of ScreenSelectionWidget, when initialised with default arguments
"""
@ -232,7 +244,8 @@ class TestScreenSelectionWidget(TestCase, TestMixin):
mocked_timer.setSingleShot.assert_called_once_with(True)
mocked_timer.setInterval.assert_called_once_with(3000)
def test_init_with_args(self):
def test_init_with_args():
"""
Test the initialisation of ScreenSelectionWidget, when initialised with the screens keyword arg set
"""
@ -251,7 +264,8 @@ class TestScreenSelectionWidget(TestCase, TestMixin):
mocked_timer.setSingleShot.assert_called_once_with(True)
mocked_timer.setInterval.assert_called_once_with(3000)
def test_save_screen_none(self):
def test_save_screen_none():
"""
Test ScreenSelectionWidget._save_screen when called with the screen arg set as None
"""
@ -265,7 +279,8 @@ class TestScreenSelectionWidget(TestCase, TestMixin):
# THEN: _save_screen should return without attempting to write to the screen object
instance.display_group_box.isChecked.assert_not_called()
def test_save_screen_not_display(self):
def test_save_screen_not_display():
"""
Test ScreenSelectionWidget._save_screen when the display_group_box is not checked.
"""
@ -283,7 +298,8 @@ class TestScreenSelectionWidget(TestCase, TestMixin):
# THEN: _save_screen should should be set to False
assert mocked_screen_object.is_display is False
def test_save_screen_display(self):
def test_save_screen_display():
"""
Test ScreenSelectionWidget._save_screen when the display_group_box is checked.
"""
@ -300,8 +316,9 @@ class TestScreenSelectionWidget(TestCase, TestMixin):
# THEN: _save_screen should should be set to True
assert mocked_screen_object.is_display is True
@patch('openlp.core.widgets.widgets.QtCore.QRect')
def test_save_screen_full_screen(self, mocked_q_rect):
@patch('openlp.core.widgets.widgets.QtCore.QRect')
def test_save_screen_full_screen(mocked_q_rect):
"""
Test ScreenSelectionWidget._save_screen when the display is set to full screen
"""
@ -318,8 +335,9 @@ class TestScreenSelectionWidget(TestCase, TestMixin):
# THEN: _save_screen should not attempt to save a custom geometry
mocked_q_rect.assert_not_called()
@patch('openlp.core.widgets.widgets.QtCore.QRect')
def test_save_screen_custom_geometry(self, mocked_q_rect):
@patch('openlp.core.widgets.widgets.QtCore.QRect')
def test_save_screen_custom_geometry(mocked_q_rect):
"""
Test ScreenSelectionWidget._save_screen when a custom geometry is set
"""
@ -340,7 +358,8 @@ class TestScreenSelectionWidget(TestCase, TestMixin):
# THEN: _save_screen should save the custom geometry
mocked_q_rect.assert_called_once_with(100, 200, 300, 400)
def test_setup_spin_box(self):
def test_setup_spin_box():
"""
Test that ScreenSelectionWidget._setup_spin_box sets up the given spinbox correctly
"""
@ -356,7 +375,8 @@ class TestScreenSelectionWidget(TestCase, TestMixin):
spin_box_mock.setMaximum.assert_called_once_with(100)
spin_box_mock.setValue.assert_called_once_with(50)
def test_load(self):
def test_load():
"""
Test that ScreenSelectionWidget.load() loads the screens correctly
"""
@ -383,7 +403,8 @@ class TestScreenSelectionWidget(TestCase, TestMixin):
mocked_widget.deleteLater.assert_called_once()
mocked_screen_button_group.removeButton.assert_called_once_with(mocked_widget)
def test_on_identify_timer_shot(self):
def test_on_identify_timer_shot():
"""
Test that the _on_identify_timer_shot() method removes the labels from the screens
"""
@ -401,7 +422,8 @@ class TestScreenSelectionWidget(TestCase, TestMixin):
mocked_label.deleteLater.assert_called_once()
assert instance.identify_labels == []
def test_on_identify_button_clicked(self):
def test_on_identify_button_clicked():
"""
Test that the on_identify_button_clicked() method shows a label on each screen
"""
@ -436,7 +458,8 @@ class TestScreenSelectionWidget(TestCase, TestMixin):
assert instance.identify_labels == [mocked_label]
instance.timer.start.assert_called_once()
def test_on_display_clicked_with_checked(self):
def test_on_display_clicked_with_checked():
"""
Test that the on_display_clicked() sets the first screen as display when the checkbx is checked
"""
@ -455,7 +478,8 @@ class TestScreenSelectionWidget(TestCase, TestMixin):
assert mocked_screen_1.is_display is True
assert mocked_screen_2.is_display is False
def test_on_display_clicked_with_unchecked(self):
def test_on_display_clicked_with_unchecked():
"""
Test that the on_display_clicked() disallows the checkbox to be unchecked
"""
@ -499,3 +523,104 @@ def test_screen_selection_save(mock_settings):
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}})
@patch('openlp.core.display.screens.ScreenList')
def test_screen_buttons_show_pixels(mocked_screenList, form):
'''
Test that the screen buttons show the screen sizes in pixels
'''
# GIVEN: A mocked extended desktop configuration
mocked_screenList.return_value = mocked_screens(None)
form.screens = mocked_screenList()
# WHEN: When I go into screen settings for the display screen
ScreenSelectionWidget.load(form)
# THEN: The screen buttons should show the correct size of that screen
screen_0_button = form.findChild(QtWidgets.QPushButton, 'screen_0_button')
screen_1_button = form.findChild(QtWidgets.QPushButton, 'screen_1_button')
assert '1920' in str(screen_0_button.text())
assert '1080' in str(screen_0_button.text())
assert '1366' in str(screen_1_button.text())
assert '768' in str(screen_1_button.text())
@patch('openlp.core.display.screens.ScreenList')
def test_spinboxes_no_previous_custom_geometry(mocked_screenList, form):
"""
Test screen custom geometry can be changed from None
"""
# GIVEN: A mocked extended desktop configuration
mocked_screenList.return_value = mocked_screens(None)
form.screens = mocked_screenList()
# WHEN: When I go into screen settings for the display screen and set the custom geometry
ScreenSelectionWidget.load(form)
QtTest.QTest.mouseClick(form.custom_geometry_button, QtCore.Qt.LeftButton)
QtTest.QTest.keyClick(form.left_spin_box, QtCore.Qt.Key_Up)
QtTest.QTest.keyClick(form.top_spin_box, QtCore.Qt.Key_Up)
QtTest.QTest.keyClick(form.width_spin_box, QtCore.Qt.Key_Down)
QtTest.QTest.keyClick(form.height_spin_box, QtCore.Qt.Key_Down)
# THEN: The spin boxes should show the correct values
assert form.left_spin_box.value() == 1
assert form.top_spin_box.value() == 1
assert form.width_spin_box.value() == 1919
assert form.height_spin_box.value() == 1079
@patch('openlp.core.display.screens.ScreenList')
def test_spinboxes_with_previous_custom_geometry(mocked_screenList, form):
"""
Test screen existing custom geometry can be changed
"""
# GIVEN: A mocked extended desktop configuration
testGeometry = QtCore.QRect(1, 1, 1919, 1079)
mocked_screenList.return_value = mocked_screens(testGeometry)
form.screens = mocked_screenList()
# WHEN: When I go into screen settings for the display screen and update the custom geometry
ScreenSelectionWidget.load(form)
QtTest.QTest.mouseClick(form.custom_geometry_button, QtCore.Qt.LeftButton)
QtTest.QTest.keyClick(form.left_spin_box, QtCore.Qt.Key_Up)
QtTest.QTest.keyClick(form.top_spin_box, QtCore.Qt.Key_Up)
QtTest.QTest.keyClick(form.width_spin_box, QtCore.Qt.Key_Down)
QtTest.QTest.keyClick(form.height_spin_box, QtCore.Qt.Key_Down)
# THEN: The spin boxes should show the updated values
assert form.left_spin_box.value() == 2
assert form.top_spin_box.value() == 2
assert form.width_spin_box.value() == 1918
assert form.height_spin_box.value() == 1078
@patch('openlp.core.display.screens.ScreenList')
def test_spinboxes_going_outside_screen_geometry(mocked_screenList, form):
"""
Test screen existing custom geometry can be increased beyond the bounds of the screen
"""
# GIVEN: A mocked extended desktop configuration
testGeometry = QtCore.QRect(1, 1, 1919, 1079)
mocked_screenList.return_value = mocked_screens(testGeometry)
form.screens = mocked_screenList()
# WHEN: When I go into screen settings for the display screen and
# update the custom geometry to be outside the screen coordinates
ScreenSelectionWidget.load(form)
QtTest.QTest.mouseClick(form.custom_geometry_button, QtCore.Qt.LeftButton)
for _ in range(2):
QtTest.QTest.keyClick(form.left_spin_box, QtCore.Qt.Key_Down)
QtTest.QTest.keyClick(form.top_spin_box, QtCore.Qt.Key_Down)
QtTest.QTest.keyClick(form.width_spin_box, QtCore.Qt.Key_Up)
QtTest.QTest.keyClick(form.height_spin_box, QtCore.Qt.Key_Up)
# THEN: The spin boxes should show the updated values
assert form.left_spin_box.value() == -1
assert form.top_spin_box.value() == -1
assert form.width_spin_box.value() == 1921
assert form.height_spin_box.value() == 1081