Move the shortcut test to a better place and add another test for the about form

This commit is contained in:
Raoul Snyman 2016-12-16 22:56:38 +02:00
parent 5fbbb1ae9e
commit 203ebde628
3 changed files with 92 additions and 17 deletions

View File

@ -22,26 +22,37 @@
"""
Package to test the openlp.core.ui.firsttimeform package.
"""
from unittest import TestCase
from unittest.mock import patch
from openlp.core.ui.aboutform import AboutForm
from tests.functional import patch
from tests.helpers.testmixin import TestMixin
@patch('openlp.core.ui.aboutform.get_application_version')
def test_create_about_form(mocked_get_application_version):
"""
Test creating an about form
"""
# GIVEN: An application version with a build number
mocked_get_application_version.return_value = {'version': '3.1.1', 'build': '3000'}
# WHEN: The about form is created
about_form = AboutForm(None)
# THEN: The correct version information should be in the dialog
assert 'OpenLP 3.1.1 build 3000' in about_form.about_text_edit.toPlainText()
class TestFirstTimeForm(TestCase, TestMixin):
def test_on_volunteer_button_clicked(self):
"""
Test that clicking on the "Volunteer" button opens a web page.
"""
# GIVEN: A new About dialog and a mocked out webbrowser module
with patch('openlp.core.ui.aboutform.webbrowser') as mocked_webbrowser:
about_form = AboutForm(None)
@patch('openlp.core.ui.aboutform.webbrowser')
def test_on_volunteer_button_clicked(mocked_webbrowser):
"""
Test that clicking on the "Volunteer" button opens a web page.
"""
# GIVEN: A new About dialog and a mocked out webbrowser module
about_form = AboutForm(None)
# WHEN: The "Volunteer" button is "clicked"
about_form.on_volunteer_button_clicked()
# WHEN: The "Volunteer" button is "clicked"
about_form.on_volunteer_button_clicked()
# THEN: A web browser is opened
mocked_webbrowser.open_new.assert_called_with('http://openlp.org/en/contribute')
# THEN: A web browser is opened
mocked_webbrowser.open_new.assert_called_with('http://openlp.org/en/contribute')

View File

@ -0,0 +1,60 @@
# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
# Copyright (c) 2008-2016 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; version 2 of the License. #
# #
# 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, write to the Free Software Foundation, Inc., 59 #
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
###############################################################################
"""
Package to test the openlp.core.ui.shortcutdialog package.
"""
from unittest.mock import MagicMock
from PyQt5 import QtCore
from openlp.core.ui.shortcutlistdialog import CaptureShortcutButton, ShortcutTreeWidget
def test_key_press_event():
"""
Test the keyPressEvent method
"""
# GIVEN: A checked button and a mocked event
button = CaptureShortcutButton()
button.setChecked(True)
mocked_event = MagicMock()
mocked_event.key.return_value = QtCore.Qt.Key_Space
# WHEN: keyPressEvent is called with an event that should be ignored
button.keyPressEvent(mocked_event)
# THEN: The ignore() method on the event should have been called
mocked_event.ignore.assert_called_once_with()
def test_keyboard_search():
"""
Test the keyboardSearch method of the ShortcutTreeWidget
"""
# GIVEN: A ShortcutTreeWidget
widget = ShortcutTreeWidget()
# WHEN: keyboardSearch() is called
widget.keyboardSearch('')
# THEN: Nothing happens
assert True

View File

@ -102,7 +102,7 @@ class TestInit(TestCase, TestMixin):
mocked_question.return_value = QtWidgets.QMessageBox.No
# WHEN: We check if a backup should be created
self.openlp.backup_on_upgrade(old_install)
self.openlp.backup_on_upgrade(old_install, False)
# THEN: It should not ask if we want to create a backup
self.assertEqual(Settings().value('core/application version'), '2.2.0', 'Version should be the same!')
@ -120,14 +120,18 @@ class TestInit(TestCase, TestMixin):
'build': 'bzr000'
}
Settings().setValue('core/application version', '2.0.5')
self.openlp.splash = MagicMock()
self.openlp.splash.isVisible.return_value = True
with patch('openlp.core.get_application_version') as mocked_get_application_version,\
patch('openlp.core.QtWidgets.QMessageBox.question') as mocked_question:
mocked_get_application_version.return_value = MOCKED_VERSION
mocked_question.return_value = QtWidgets.QMessageBox.No
# WHEN: We check if a backup should be created
self.openlp.backup_on_upgrade(old_install)
self.openlp.backup_on_upgrade(old_install, True)
# THEN: It should ask if we want to create a backup
self.assertEqual(Settings().value('core/application version'), '2.2.0', 'Version should be upgraded!')
self.assertEqual(mocked_question.call_count, 1, 'A question should have been asked!')
self.openlp.splash.hide.assert_called_once_with()
self.openlp.splash.show.assert_called_once_with()