openlp/tests/functional/test_init.py

138 lines
6.1 KiB
Python
Raw Normal View History

2014-04-20 13:00:14 +00:00
# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
2016-12-31 11:05:48 +00:00
# Copyright (c) 2008-2017 OpenLP Developers #
2014-04-20 13:00:14 +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; 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.__init__ package.
"""
import os
from unittest import TestCase
2015-11-07 00:49:40 +00:00
from PyQt5 import QtCore, QtWidgets
2014-04-20 13:00:14 +00:00
2015-01-22 15:05:03 +00:00
from openlp.core import OpenLP, parse_options
2014-10-13 14:08:06 +00:00
from openlp.core.common import Settings
2014-04-20 13:00:14 +00:00
from tests.helpers.testmixin import TestMixin
from tests.functional import MagicMock, patch, call
2014-04-20 13:00:14 +00:00
TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'resources'))
class TestInit(TestCase, TestMixin):
def setUp(self):
2014-10-13 14:08:06 +00:00
self.build_settings()
2014-04-20 13:00:14 +00:00
with patch('openlp.core.common.OpenLPMixin.__init__') as constructor:
constructor.return_value = None
self.openlp = OpenLP(list())
def tearDown(self):
2014-10-13 14:08:06 +00:00
self.destroy_settings()
2014-04-20 13:00:14 +00:00
del self.openlp
def event_test(self):
"""
Test the reimplemented event method
"""
# GIVEN: A file path and a QEvent.
file_path = os.path.join(TEST_PATH, 'church.jpg')
mocked_file_method = MagicMock(return_value=file_path)
event = QtCore.QEvent(QtCore.QEvent.FileOpen)
event.file = mocked_file_method
# WHEN: Call the vent method.
result = self.openlp.event(event)
# THEN: The path should be inserted.
self.assertTrue(result, "The method should have returned True.")
mocked_file_method.assert_called_once_with()
self.assertEqual(self.openlp.args[0], file_path, "The path should be in args.")
2014-10-13 14:08:06 +00:00
2015-04-25 19:29:39 +00:00
@patch('openlp.core.is_macosx')
def application_activate_event_test(self, mocked_is_macosx):
2015-04-25 14:06:32 +00:00
"""
Test that clicking on the dock icon on Mac OS X restores the main window if it is minimized
"""
2015-04-25 19:29:39 +00:00
# GIVEN: Mac OS X and an ApplicationActivate event
mocked_is_macosx.return_value = True
event = MagicMock()
event.type.return_value = QtCore.QEvent.ApplicationActivate
mocked_main_window = MagicMock()
self.openlp.main_window = mocked_main_window
# WHEN: The icon in the dock is clicked
result = self.openlp.event(event)
2015-04-25 14:06:32 +00:00
2015-04-25 19:29:39 +00:00
# THEN:
self.assertTrue(result, "The method should have returned True.")
# self.assertFalse(self.openlp.main_window.isMinimized())
2015-04-25 14:06:32 +00:00
2014-10-13 14:08:06 +00:00
def backup_on_upgrade_first_install_test(self):
"""
Test that we don't try to backup on a new install
"""
# GIVEN: Mocked data version and OpenLP version which are the same
old_install = False
MOCKED_VERSION = {
'full': '2.2.0-bzr000',
'version': '2.2.0',
'build': 'bzr000'
}
2014-10-14 07:52:59 +00:00
Settings().setValue('core/application version', '2.2.0')
2014-10-13 14:08:06 +00:00
with patch('openlp.core.get_application_version') as mocked_get_application_version,\
2015-11-07 00:49:40 +00:00
patch('openlp.core.QtWidgets.QMessageBox.question') as mocked_question:
2014-10-13 14:08:06 +00:00
mocked_get_application_version.return_value = MOCKED_VERSION
2015-11-07 00:49:40 +00:00
mocked_question.return_value = QtWidgets.QMessageBox.No
2014-10-13 14:08:06 +00:00
# WHEN: We check if a backup should be created
self.openlp.backup_on_upgrade(old_install, False)
2014-10-13 14:08:06 +00:00
# THEN: It should not ask if we want to create a backup
2014-10-14 07:52:59 +00:00
self.assertEqual(Settings().value('core/application version'), '2.2.0', 'Version should be the same!')
2014-10-13 14:08:06 +00:00
self.assertEqual(mocked_question.call_count, 0, 'No question should have been asked!')
def backup_on_upgrade_test(self):
"""
Test that we try to backup on a new install
"""
# GIVEN: Mocked data version and OpenLP version which are different
old_install = True
MOCKED_VERSION = {
'full': '2.2.0-bzr000',
'version': '2.2.0',
'build': 'bzr000'
}
2014-10-14 07:52:59 +00:00
Settings().setValue('core/application version', '2.0.5')
self.openlp.splash = MagicMock()
self.openlp.splash.isVisible.return_value = True
2014-10-13 14:08:06 +00:00
with patch('openlp.core.get_application_version') as mocked_get_application_version,\
2015-11-07 00:49:40 +00:00
patch('openlp.core.QtWidgets.QMessageBox.question') as mocked_question:
2014-10-13 14:08:06 +00:00
mocked_get_application_version.return_value = MOCKED_VERSION
2015-11-07 00:49:40 +00:00
mocked_question.return_value = QtWidgets.QMessageBox.No
2014-10-13 14:08:06 +00:00
# WHEN: We check if a backup should be created
self.openlp.backup_on_upgrade(old_install, True)
2014-10-13 14:08:06 +00:00
# THEN: It should ask if we want to create a backup
2014-10-14 07:52:59 +00:00
self.assertEqual(Settings().value('core/application version'), '2.2.0', 'Version should be upgraded!')
2014-10-13 14:08:06 +00:00
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()