openlp/tests/interfaces/openlp_core/ui/test_filerenamedialog.py

107 lines
4.3 KiB
Python
Raw Normal View History

2014-03-14 20:06:24 +00:00
# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
2019-04-13 13:00:22 +00:00
##########################################################################
# OpenLP - Open Source Lyrics Projection #
# ---------------------------------------------------------------------- #
# Copyright (c) 2008-2019 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/>. #
##########################################################################
2013-02-08 19:13:18 +00:00
"""
2017-10-07 07:05:07 +00:00
Package to test the openlp.core.ui package.
2013-02-08 19:13:18 +00:00
"""
from unittest import TestCase
from unittest.mock import MagicMock, patch
2013-02-08 19:13:18 +00:00
2015-11-07 00:49:40 +00:00
from PyQt5 import QtTest, QtWidgets
2017-10-07 07:05:07 +00:00
from openlp.core.common.registry import Registry
from openlp.core.ui.filerenameform import FileRenameForm
2014-03-13 20:34:46 +00:00
from tests.helpers.testmixin import TestMixin
2013-02-08 19:13:18 +00:00
2014-03-14 17:35:00 +00:00
2014-03-13 20:34:46 +00:00
class TestStartFileRenameForm(TestCase, TestMixin):
2013-02-08 19:13:18 +00:00
def setUp(self):
"""
Create the UI
"""
2013-02-17 07:54:43 +00:00
Registry.create()
self.setup_application()
2015-11-07 00:49:40 +00:00
self.main_window = QtWidgets.QMainWindow()
2013-08-31 18:17:38 +00:00
Registry().register('main_window', self.main_window)
self.form = FileRenameForm()
2013-02-08 19:13:18 +00:00
def tearDown(self):
"""
Delete all the C++ objects at the end so that we don't have a segfault
"""
del self.form
del self.main_window
2016-05-31 21:40:13 +00:00
def test_window_title(self):
2013-02-08 19:13:18 +00:00
"""
2013-02-09 21:23:43 +00:00
Test the windowTitle of the FileRenameDialog
2013-02-08 19:13:18 +00:00
"""
2015-11-07 00:49:40 +00:00
# GIVEN: A mocked QDialog.exec() method
2017-10-07 07:05:07 +00:00
with patch('PyQt5.QtWidgets.QDialog.exec'):
2013-02-09 21:23:43 +00:00
# WHEN: The form is executed with no args
2015-11-07 00:49:40 +00:00
self.form.exec()
2013-02-08 19:13:18 +00:00
2013-02-09 21:23:43 +00:00
# THEN: the window title is set correctly
2017-12-23 09:09:45 +00:00
assert self.form.windowTitle() == 'File Rename', 'The window title should be "File Rename"'
2013-02-08 19:13:18 +00:00
2013-02-09 21:23:43 +00:00
# WHEN: The form is executed with False arg
2015-11-07 00:49:40 +00:00
self.form.exec(False)
2013-02-08 19:13:18 +00:00
2013-02-09 21:23:43 +00:00
# THEN: the window title is set correctly
2017-12-23 09:09:45 +00:00
assert self.form.windowTitle() == 'File Rename', 'The window title should be "File Rename"'
2013-02-08 19:13:18 +00:00
2013-02-09 21:23:43 +00:00
# WHEN: The form is executed with True arg
2015-11-07 00:49:40 +00:00
self.form.exec(True)
2013-02-08 19:13:18 +00:00
2013-02-09 21:23:43 +00:00
# THEN: the window title is set correctly
2017-12-23 09:09:45 +00:00
assert self.form.windowTitle() == 'File Copy', 'The window title should be "File Copy"'
2013-02-08 19:13:18 +00:00
2016-05-31 21:40:13 +00:00
def test_line_edit_focus(self):
2013-02-09 21:23:43 +00:00
"""
Regression test for bug1067251
2013-03-01 11:12:23 +00:00
Test that the file_name_edit setFocus has called with True when executed
2013-02-09 21:23:43 +00:00
"""
2015-11-07 00:49:40 +00:00
# GIVEN: A mocked QDialog.exec() method and mocked file_name_edit.setFocus() method.
with patch('PyQt5.QtWidgets.QDialog.exec'):
2013-02-11 20:47:53 +00:00
mocked_set_focus = MagicMock()
2013-03-01 11:12:23 +00:00
self.form.file_name_edit.setFocus = mocked_set_focus
2013-02-08 19:13:18 +00:00
2013-02-11 20:47:53 +00:00
# WHEN: The form is executed
2015-11-07 00:49:40 +00:00
self.form.exec()
2013-02-08 19:13:18 +00:00
2013-03-01 11:12:23 +00:00
# THEN: the setFocus method of the file_name_edit has been called with True
2013-02-11 20:47:53 +00:00
mocked_set_focus.assert_called_with()
2016-05-31 21:40:13 +00:00
def test_file_name_validation(self):
2013-02-11 20:47:53 +00:00
"""
2013-03-01 11:12:23 +00:00
Test the file_name_edit validation
2013-02-11 20:47:53 +00:00
"""
# GIVEN: QLineEdit with a validator set with illegal file name characters.
# WHEN: 'Typing' a string containing invalid file characters.
2018-07-02 20:38:47 +00:00
QtTest.QTest.keyClicks(self.form.file_name_edit, r'I/n\\v?a*l|i<d> \F[i\l]e" :N+a%me')
2013-02-11 20:47:53 +00:00
2013-02-17 07:54:43 +00:00
# THEN: The text in the QLineEdit should be the same as the input string with the invalid characters filtered
2013-02-12 19:26:19 +00:00
# out.
2017-12-23 09:09:45 +00:00
assert self.form.file_name_edit.text() == 'Invalid File Name'