openlp/tests/interfaces/openlp_core_ui/test_filerenamedialog.py

84 lines
2.9 KiB
Python
Raw Normal View History

2013-02-08 19:13:18 +00:00
"""
Package to test the openlp.core.ui package.
"""
from unittest import TestCase
2013-02-11 20:47:53 +00:00
from mock import MagicMock, patch
2013-02-08 19:13:18 +00:00
from openlp.core.lib import Registry
from openlp.core.ui import filerenameform
2013-02-11 20:47:53 +00:00
from PyQt4 import QtGui, QtTest
2013-02-08 19:13:18 +00:00
class TestStartFileRenameForm(TestCase):
def setUp(self):
"""
Create the UI
"""
2013-02-17 07:54:43 +00:00
Registry.create()
self.app = QtGui.QApplication.instance()
2013-02-08 19:13:18 +00:00
self.main_window = QtGui.QMainWindow()
Registry().register(u'main_window', self.main_window)
self.form = filerenameform.FileRenameForm()
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
del self.app
2013-02-09 21:23:43 +00:00
def window_title_test(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
"""
2013-02-09 21:23:43 +00:00
# GIVEN: A mocked QDialog.exec_() method
with patch(u'PyQt4.QtGui.QDialog.exec_') as mocked_exec:
2013-02-09 21:23:43 +00:00
# WHEN: The form is executed with no args
2013-02-08 19:13:18 +00:00
self.form.exec_()
2013-02-09 21:23:43 +00:00
# THEN: the window title is set correctly
self.assertEqual(self.form.windowTitle(), u'File Rename', u'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
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
self.assertEqual(self.form.windowTitle(), u'File Rename', u'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
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
self.assertEqual(self.form.windowTitle(), u'File Copy', u'The window title should be "File Copy"')
2013-02-08 19:13:18 +00:00
2013-02-09 21:23:43 +00:00
def line_edit_focus_test(self):
"""
Regression test for bug1067251
Test that the fileNameEdit setFocus has called with True when executed
"""
2013-02-11 20:47:53 +00:00
# GIVEN: A mocked QDialog.exec_() method and mocked fileNameEdit.setFocus() method.
with patch(u'PyQt4.QtGui.QDialog.exec_') as mocked_exec:
mocked_set_focus = MagicMock()
self.form.fileNameEdit.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
2013-02-08 19:13:18 +00:00
self.form.exec_()
2013-02-09 21:23:43 +00:00
# THEN: the setFocus method of the fileNameEdit has been called with True
2013-02-11 20:47:53 +00:00
mocked_set_focus.assert_called_with()
def file_name_validation_test(self):
"""
Test the fileNameEdit validation
"""
# GIVEN: QLineEdit with a validator set with illegal file name characters.
# WHEN: 'Typing' a string containing invalid file characters.
QtTest.QTest.keyClicks(self.form.fileNameEdit, u'I/n\\v?a*l|i<d> \F[i\l]e" :N+a%me')
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.
2013-02-11 20:47:53 +00:00
self.assertEqual(self.form.fileNameEdit.text(), u'Invalid File Name')