2016-06-24 12:39:47 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2019-04-13 13:00:22 +00:00
|
|
|
##########################################################################
|
|
|
|
# OpenLP - Open Source Lyrics Projection #
|
|
|
|
# ---------------------------------------------------------------------- #
|
2020-01-01 02:53:08 +00:00
|
|
|
# Copyright (c) 2008-2020 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/>. #
|
|
|
|
##########################################################################
|
2016-06-24 12:39:47 +00:00
|
|
|
"""
|
|
|
|
Package to test the openlp.core.ui.exeptionform package.
|
|
|
|
"""
|
|
|
|
import os
|
|
|
|
import tempfile
|
2017-12-02 00:35:21 +00:00
|
|
|
from collections import OrderedDict
|
2019-05-22 06:47:00 +00:00
|
|
|
from pathlib import Path
|
2016-06-24 12:39:47 +00:00
|
|
|
from unittest import TestCase
|
2017-09-24 18:59:49 +00:00
|
|
|
from unittest.mock import call, patch
|
2016-06-24 12:39:47 +00:00
|
|
|
|
2020-02-09 20:24:05 +00:00
|
|
|
from openlp.core.common.settings import Settings
|
2017-12-28 08:22:55 +00:00
|
|
|
from openlp.core.common.registry import Registry
|
2017-04-24 05:17:55 +00:00
|
|
|
from openlp.core.ui import exceptionform
|
2016-06-24 12:39:47 +00:00
|
|
|
from tests.helpers.testmixin import TestMixin
|
|
|
|
|
2018-10-02 04:39:42 +00:00
|
|
|
|
2016-06-24 12:39:47 +00:00
|
|
|
exceptionform.MIGRATE_VERSION = 'Migrate Test'
|
|
|
|
exceptionform.CHARDET_VERSION = 'CHARDET Test'
|
|
|
|
exceptionform.ENCHANT_VERSION = 'Enchant Test'
|
|
|
|
exceptionform.MAKO_VERSION = 'Mako Test'
|
|
|
|
exceptionform.VLC_VERSION = 'VLC Test'
|
|
|
|
|
|
|
|
MAIL_ITEM_TEXT = ('**OpenLP Bug Report**\nVersion: Trunk Test\n\n--- Details of the Exception. ---\n\n'
|
|
|
|
'Description Test\n\n --- Exception Traceback ---\nopenlp: Traceback Test\n'
|
|
|
|
'--- System information ---\nPlatform: Nose Test\n\n--- Library Versions ---\n'
|
2018-12-01 05:52:49 +00:00
|
|
|
'Python: Python Test\nQt5: Qt5 Test\nPyQt5: PyQt5 Test\n'
|
|
|
|
'SQLAlchemy: SQLAlchemy Test\nAlembic: Alembic Test\nBeautifulSoup: BeautifulSoup Test\n'
|
|
|
|
'lxml: ETree Test\nChardet: Chardet Test\nPyEnchant: PyEnchant Test\nMako: Mako Test\n'
|
|
|
|
'pyICU: pyICU Test\nVLC: VLC Test\nPyUNO: UNO Bridge Test\n')
|
|
|
|
LIBRARY_VERSIONS = OrderedDict([
|
|
|
|
('Python', 'Python Test'),
|
|
|
|
('Qt5', 'Qt5 Test'),
|
|
|
|
('PyQt5', 'PyQt5 Test'),
|
|
|
|
('SQLAlchemy', 'SQLAlchemy Test'),
|
|
|
|
('Alembic', 'Alembic Test'),
|
|
|
|
('BeautifulSoup', 'BeautifulSoup Test'),
|
|
|
|
('lxml', 'ETree Test'),
|
|
|
|
('Chardet', 'Chardet Test'),
|
|
|
|
('PyEnchant', 'PyEnchant Test'),
|
|
|
|
('Mako', 'Mako Test'),
|
|
|
|
('pyICU', 'pyICU Test'),
|
|
|
|
('VLC', 'VLC Test')
|
|
|
|
])
|
2017-12-02 00:35:21 +00:00
|
|
|
|
|
|
|
|
2018-12-01 05:52:49 +00:00
|
|
|
@patch('openlp.core.ui.exceptionform.QtGui.QDesktopServices.openUrl')
|
|
|
|
@patch('openlp.core.ui.exceptionform.get_version')
|
|
|
|
@patch('openlp.core.ui.exceptionform.get_library_versions')
|
|
|
|
@patch('openlp.core.ui.exceptionform.is_linux')
|
|
|
|
@patch('openlp.core.ui.exceptionform.platform.platform')
|
2016-06-24 12:39:47 +00:00
|
|
|
class TestExceptionForm(TestMixin, TestCase):
|
|
|
|
"""
|
|
|
|
Test functionality of exception form functions
|
|
|
|
"""
|
2017-09-13 06:08:38 +00:00
|
|
|
def __method_template_for_class_patches(self, __PLACEHOLDER_FOR_LOCAL_METHOD_PATCH_DECORATORS_GO_HERE__,
|
2017-12-02 00:35:21 +00:00
|
|
|
mocked_platform, mocked_is_linux, mocked_get_library_versions,
|
2018-12-01 05:52:49 +00:00
|
|
|
mocked_get_version, mocked_openurl):
|
2016-06-25 11:39:57 +00:00
|
|
|
"""
|
|
|
|
Template so you don't have to remember the layout of class mock options for methods
|
|
|
|
"""
|
|
|
|
mocked_is_linux.return_value = False
|
2017-09-13 06:08:38 +00:00
|
|
|
mocked_get_version.return_value = 'Trunk Test'
|
2017-12-02 00:35:21 +00:00
|
|
|
mocked_get_library_versions.return_value = LIBRARY_VERSIONS
|
2016-06-25 11:39:57 +00:00
|
|
|
|
2016-06-24 12:39:47 +00:00
|
|
|
def setUp(self):
|
|
|
|
self.setup_application()
|
|
|
|
self.app.setApplicationVersion('0.0')
|
|
|
|
# Set up a fake "set_normal_cursor" method since we're not dealing with an actual OpenLP application object
|
|
|
|
self.app.set_normal_cursor = lambda: None
|
|
|
|
self.app.process_events = lambda: None
|
|
|
|
Registry.create()
|
|
|
|
Registry().register('application', self.app)
|
2020-02-09 20:24:05 +00:00
|
|
|
Registry().register('settings', Settings())
|
2016-06-24 12:39:47 +00:00
|
|
|
self.tempfile = os.path.join(tempfile.gettempdir(), 'testfile')
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
if os.path.isfile(self.tempfile):
|
|
|
|
os.remove(self.tempfile)
|
|
|
|
|
|
|
|
@patch("openlp.core.ui.exceptionform.Ui_ExceptionDialog")
|
2017-09-07 21:52:39 +00:00
|
|
|
@patch("openlp.core.ui.exceptionform.FileDialog")
|
2016-06-24 12:39:47 +00:00
|
|
|
@patch("openlp.core.ui.exceptionform.QtCore.QUrl")
|
|
|
|
@patch("openlp.core.ui.exceptionform.QtCore.QUrlQuery.addQueryItem")
|
2017-12-02 00:35:21 +00:00
|
|
|
def test_on_send_report_button_clicked(self, mocked_add_query_item, mocked_qurl, mocked_file_dialog,
|
|
|
|
mocked_ui_exception_dialog, mocked_platform, mocked_is_linux,
|
2018-12-01 05:52:49 +00:00
|
|
|
mocked_get_library_versions, mocked_get_version, mocked_openurl):
|
2016-06-24 12:39:47 +00:00
|
|
|
"""
|
2016-06-25 11:39:57 +00:00
|
|
|
Test send report creates the proper system information text
|
2016-06-24 12:39:47 +00:00
|
|
|
"""
|
|
|
|
# GIVEN: Test environment
|
|
|
|
mocked_platform.return_value = 'Nose Test'
|
2016-06-25 11:39:57 +00:00
|
|
|
mocked_is_linux.return_value = False
|
2017-09-13 06:08:38 +00:00
|
|
|
mocked_get_version.return_value = 'Trunk Test'
|
2017-12-02 00:35:21 +00:00
|
|
|
mocked_get_library_versions.return_value = LIBRARY_VERSIONS
|
2016-06-24 12:39:47 +00:00
|
|
|
test_form = exceptionform.ExceptionForm()
|
|
|
|
test_form.file_attachment = None
|
2016-06-25 11:39:57 +00:00
|
|
|
|
2017-12-02 00:35:21 +00:00
|
|
|
with patch.object(test_form, '_get_pyuno_version') as mock_pyuno, \
|
2017-09-24 18:59:49 +00:00
|
|
|
patch.object(test_form.exception_text_edit, 'toPlainText') as mock_traceback, \
|
|
|
|
patch.object(test_form.description_text_edit, 'toPlainText') as mock_description:
|
|
|
|
mock_pyuno.return_value = 'UNO Bridge Test'
|
|
|
|
mock_traceback.return_value = 'openlp: Traceback Test'
|
|
|
|
mock_description.return_value = 'Description Test'
|
2016-06-24 12:39:47 +00:00
|
|
|
|
2018-12-01 05:52:49 +00:00
|
|
|
# WHEN: on_send_report_button_clicked called
|
2017-09-24 18:59:49 +00:00
|
|
|
test_form.on_send_report_button_clicked()
|
2016-06-24 12:39:47 +00:00
|
|
|
|
2016-06-25 11:39:57 +00:00
|
|
|
# THEN: Verify strings were formatted properly
|
|
|
|
mocked_add_query_item.assert_called_with('body', MAIL_ITEM_TEXT)
|
|
|
|
|
2017-08-26 15:06:11 +00:00
|
|
|
@patch("openlp.core.ui.exceptionform.FileDialog.getSaveFileName")
|
2017-12-02 00:35:21 +00:00
|
|
|
def test_on_save_report_button_clicked(self, mocked_save_filename, mocked_platform, mocked_is_linux,
|
2018-12-01 05:52:49 +00:00
|
|
|
mocked_get_library_versions, mocked_get_version, mocked_openurl):
|
2016-06-25 11:39:57 +00:00
|
|
|
"""
|
|
|
|
Test save report saves the correct information to a file
|
|
|
|
"""
|
|
|
|
mocked_platform.return_value = 'Nose Test'
|
|
|
|
mocked_is_linux.return_value = False
|
2017-09-13 06:08:38 +00:00
|
|
|
mocked_get_version.return_value = 'Trunk Test'
|
2017-12-02 00:35:21 +00:00
|
|
|
mocked_get_library_versions.return_value = LIBRARY_VERSIONS
|
2017-09-24 18:59:49 +00:00
|
|
|
with patch.object(Path, 'open') as mocked_path_open:
|
|
|
|
test_path = Path('testfile.txt')
|
|
|
|
mocked_save_filename.return_value = test_path, 'ext'
|
|
|
|
|
|
|
|
test_form = exceptionform.ExceptionForm()
|
|
|
|
test_form.file_attachment = None
|
2016-06-25 11:39:57 +00:00
|
|
|
|
2017-12-02 00:35:21 +00:00
|
|
|
with patch.object(test_form, '_get_pyuno_version') as mock_pyuno, \
|
2017-09-24 18:59:49 +00:00
|
|
|
patch.object(test_form.exception_text_edit, 'toPlainText') as mock_traceback, \
|
|
|
|
patch.object(test_form.description_text_edit, 'toPlainText') as mock_description:
|
|
|
|
mock_pyuno.return_value = 'UNO Bridge Test'
|
|
|
|
mock_traceback.return_value = 'openlp: Traceback Test'
|
|
|
|
mock_description.return_value = 'Description Test'
|
2016-06-25 11:39:57 +00:00
|
|
|
|
2017-09-24 18:59:49 +00:00
|
|
|
# WHEN: on_save_report_button_clicked called
|
|
|
|
test_form.on_save_report_button_clicked()
|
2016-06-25 11:39:57 +00:00
|
|
|
|
|
|
|
# THEN: Verify proper calls to save file
|
|
|
|
# self.maxDiff = None
|
2017-09-24 18:59:49 +00:00
|
|
|
mocked_path_open.assert_has_calls([call().__enter__().write(MAIL_ITEM_TEXT)])
|