openlp/tests/openlp_plugins/custom/forms/test_customslideform.py

76 lines
2.9 KiB
Python
Raw Normal View History

2014-03-14 22:08:44 +00:00
# -*- coding: utf-8 -*-
2019-04-13 13:00:22 +00:00
##########################################################################
# OpenLP - Open Source Lyrics Projection #
# ---------------------------------------------------------------------- #
2022-02-06 09:10:17 +00:00
# Copyright (c) 2008-2022 OpenLP Developers #
2019-04-13 13:00:22 +00:00
# ---------------------------------------------------------------------- #
# 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/>. #
##########################################################################
2013-03-30 09:01:21 +00:00
"""
Module to test the EditCustomSlideForm.
"""
2020-03-19 20:04:28 +00:00
import pytest
from unittest.mock import MagicMock, patch
2013-03-30 09:01:21 +00:00
2015-11-07 00:49:40 +00:00
from PyQt5 import QtWidgets
2013-03-30 09:01:21 +00:00
2017-10-07 07:05:07 +00:00
from openlp.core.common.registry import Registry
2013-03-30 09:01:21 +00:00
from openlp.plugins.custom.forms.editcustomslideform import EditCustomSlideForm
@pytest.fixture()
2020-03-19 20:04:28 +00:00
def form(settings):
main_window = QtWidgets.QMainWindow()
Registry().register('main_window', main_window)
frm = EditCustomSlideForm()
yield frm
del frm
del main_window
def test_basic(form):
2013-03-30 09:01:21 +00:00
"""
2020-03-19 20:04:28 +00:00
Test if the dialog is correctly set up.
2013-03-30 09:01:21 +00:00
"""
2020-03-19 20:04:28 +00:00
# GIVEN: A mocked QDialog.exec() method
with patch('PyQt5.QtWidgets.QDialog.exec'):
# WHEN: Show the dialog.
form.exec()
2013-03-30 09:01:21 +00:00
2020-03-19 20:04:28 +00:00
# THEN: The dialog should be empty.
assert form.slide_text_edit.toPlainText() == '', 'There should not be any text in the text editor.'
2013-03-30 09:01:21 +00:00
2020-03-19 20:04:28 +00:00
def test_set_text(form):
"""
Test the set_text() method.
"""
# GIVEN: A mocked QDialog.exec() method
with patch('PyQt5.QtWidgets.QDialog.exec'):
mocked_set_focus = MagicMock()
form.slide_text_edit.setFocus = mocked_set_focus
wanted_text = 'THIS TEXT SHOULD BE SHOWN.'
2013-03-30 09:01:21 +00:00
2020-03-19 20:04:28 +00:00
# WHEN: Show the dialog and set the text.
form.exec()
form.set_text(wanted_text)
2013-03-30 09:01:21 +00:00
2020-03-19 20:04:28 +00:00
# THEN: The dialog should show the text.
assert form.slide_text_edit.toPlainText() == wanted_text, \
'The text editor should show the correct text.'
2013-03-30 09:01:21 +00:00
2020-03-19 20:04:28 +00:00
# THEN: The dialog should have focus.
mocked_set_focus.assert_called_with()