~tomasgroth/openlp/portable-path

« back to all changes in this revision

Viewing changes to tests/functional/openlp_core/ui/test_exceptionform.py

  • Committer: Tomas Groth
  • Date: 2019-04-30 19:02:42 UTC
  • mfrom: (2829.2.32 openlp)
  • Revision ID: tomasgroth@yahoo.dk-20190430190242-6zwjk8724tyux70m
trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
###############################################################################
5
5
# OpenLP - Open Source Lyrics Projection                                      #
6
6
# --------------------------------------------------------------------------- #
7
 
# Copyright (c) 2008-2017 OpenLP Developers                                   #
 
7
# Copyright (c) 2008-2019 OpenLP Developers                                   #
8
8
# --------------------------------------------------------------------------- #
9
9
# This program is free software; you can redistribute it and/or modify it     #
10
10
# under the terms of the GNU General Public License as published by the Free  #
24
24
"""
25
25
import os
26
26
import tempfile
 
27
from collections import OrderedDict
27
28
from unittest import TestCase
28
29
from unittest.mock import call, patch
29
30
 
32
33
from openlp.core.ui import exceptionform
33
34
from tests.helpers.testmixin import TestMixin
34
35
 
35
 
exceptionform.WEBKIT_VERSION = 'Webkit Test'
 
36
 
36
37
exceptionform.MIGRATE_VERSION = 'Migrate Test'
37
38
exceptionform.CHARDET_VERSION = 'CHARDET Test'
38
39
exceptionform.ENCHANT_VERSION = 'Enchant Test'
39
40
exceptionform.MAKO_VERSION = 'Mako Test'
40
 
exceptionform.ICU_VERSION = 'ICU Test'
41
41
exceptionform.VLC_VERSION = 'VLC Test'
42
42
 
43
43
MAIL_ITEM_TEXT = ('**OpenLP Bug Report**\nVersion: Trunk Test\n\n--- Details of the Exception. ---\n\n'
44
44
                  'Description Test\n\n --- Exception Traceback ---\nopenlp: Traceback Test\n'
45
45
                  '--- System information ---\nPlatform: Nose Test\n\n--- Library Versions ---\n'
46
 
                  'Python: Python Test\nQt5: Qt5 test\nPyQt5: PyQt5 Test\nQtWebkit: Webkit Test\n'
47
 
                  'SQLAlchemy: SqlAlchemy Test\nSQLAlchemy Migrate: Migrate Test\nBeautifulSoup: BeautifulSoup Test\n'
48
 
                  'lxml: ETree Test\nChardet: CHARDET Test\nPyEnchant: Enchant Test\nMako: Mako Test\n'
49
 
                  'pyICU: ICU Test\npyUNO bridge: UNO Bridge Test\nVLC: VLC Test\n\n')
50
 
 
51
 
 
52
 
@patch("openlp.core.ui.exceptionform.Qt.qVersion")
53
 
@patch("openlp.core.ui.exceptionform.QtGui.QDesktopServices.openUrl")
54
 
@patch("openlp.core.ui.exceptionform.get_version")
55
 
@patch("openlp.core.ui.exceptionform.sqlalchemy")
56
 
@patch("openlp.core.ui.exceptionform.bs4")
57
 
@patch("openlp.core.ui.exceptionform.etree")
58
 
@patch("openlp.core.ui.exceptionform.is_linux")
59
 
@patch("openlp.core.ui.exceptionform.platform.platform")
60
 
@patch("openlp.core.ui.exceptionform.platform.python_version")
 
46
                  'Python: Python Test\nQt5: Qt5 Test\nPyQt5: PyQt5 Test\n'
 
47
                  'SQLAlchemy: SQLAlchemy Test\nAlembic: Alembic Test\nBeautifulSoup: BeautifulSoup Test\n'
 
48
                  'lxml: ETree Test\nChardet: Chardet Test\nPyEnchant: PyEnchant Test\nMako: Mako Test\n'
 
49
                  'pyICU: pyICU Test\nVLC: VLC Test\nPyUNO: UNO Bridge Test\n')
 
50
LIBRARY_VERSIONS = OrderedDict([
 
51
    ('Python', 'Python Test'),
 
52
    ('Qt5', 'Qt5 Test'),
 
53
    ('PyQt5', 'PyQt5 Test'),
 
54
    ('SQLAlchemy', 'SQLAlchemy Test'),
 
55
    ('Alembic', 'Alembic Test'),
 
56
    ('BeautifulSoup', 'BeautifulSoup Test'),
 
57
    ('lxml', 'ETree Test'),
 
58
    ('Chardet', 'Chardet Test'),
 
59
    ('PyEnchant', 'PyEnchant Test'),
 
60
    ('Mako', 'Mako Test'),
 
61
    ('pyICU', 'pyICU Test'),
 
62
    ('VLC', 'VLC Test')
 
63
])
 
64
 
 
65
 
 
66
@patch('openlp.core.ui.exceptionform.QtGui.QDesktopServices.openUrl')
 
67
@patch('openlp.core.ui.exceptionform.get_version')
 
68
@patch('openlp.core.ui.exceptionform.get_library_versions')
 
69
@patch('openlp.core.ui.exceptionform.is_linux')
 
70
@patch('openlp.core.ui.exceptionform.platform.platform')
61
71
class TestExceptionForm(TestMixin, TestCase):
62
72
    """
63
73
    Test functionality of exception form functions
64
74
    """
65
75
    def __method_template_for_class_patches(self, __PLACEHOLDER_FOR_LOCAL_METHOD_PATCH_DECORATORS_GO_HERE__,
66
 
                                            mocked_python_version, mocked_platform, mocked_is_linux,
67
 
                                            mocked_etree, mocked_bs4, mocked_sqlalchemy, mocked_get_version,
68
 
                                            mocked_openlurl, mocked_qversion):
 
76
                                            mocked_platform, mocked_is_linux, mocked_get_library_versions,
 
77
                                            mocked_get_version, mocked_openurl):
69
78
        """
70
79
        Template so you don't have to remember the layout of class mock options for methods
71
80
        """
72
 
        mocked_etree.__version__ = 'ETree Test'
73
 
        mocked_bs4.__version__ = 'BeautifulSoup Test'
74
 
        mocked_sqlalchemy.__version__ = 'SqlAlchemy Test'
75
 
        mocked_python_version.return_value = 'Python Test'
76
 
        mocked_platform.return_value = 'Nose Test'
77
 
        mocked_qversion.return_value = 'Qt5 test'
78
81
        mocked_is_linux.return_value = False
79
82
        mocked_get_version.return_value = 'Trunk Test'
 
83
        mocked_get_library_versions.return_value = LIBRARY_VERSIONS
80
84
 
81
85
    def setUp(self):
82
86
        self.setup_application()
96
100
    @patch("openlp.core.ui.exceptionform.FileDialog")
97
101
    @patch("openlp.core.ui.exceptionform.QtCore.QUrl")
98
102
    @patch("openlp.core.ui.exceptionform.QtCore.QUrlQuery.addQueryItem")
99
 
    @patch("openlp.core.ui.exceptionform.Qt")
100
 
    def test_on_send_report_button_clicked(self, mocked_qt, mocked_add_query_item, mocked_qurl, mocked_file_dialog,
101
 
                                           mocked_ui_exception_dialog, mocked_python_version, mocked_platform,
102
 
                                           mocked_is_linux, mocked_etree, mocked_bs4, mocked_sqlalchemy,
103
 
                                           mocked_get_version, mocked_openlurl, mocked_qversion):
 
103
    def test_on_send_report_button_clicked(self, mocked_add_query_item, mocked_qurl, mocked_file_dialog,
 
104
                                           mocked_ui_exception_dialog, mocked_platform, mocked_is_linux,
 
105
                                           mocked_get_library_versions, mocked_get_version, mocked_openurl):
104
106
        """
105
107
        Test send report  creates the proper system information text
106
108
        """
107
109
        # GIVEN: Test environment
108
 
        mocked_etree.__version__ = 'ETree Test'
109
 
        mocked_bs4.__version__ = 'BeautifulSoup Test'
110
 
        mocked_sqlalchemy.__version__ = 'SqlAlchemy Test'
111
 
        mocked_python_version.return_value = 'Python Test'
112
110
        mocked_platform.return_value = 'Nose Test'
113
 
        mocked_qversion.return_value = 'Qt5 test'
114
 
        mocked_is_linux.return_value = False
115
 
        mocked_get_version.return_value = 'Trunk Test'
116
 
        mocked_qt.PYQT_VERSION_STR = 'PyQt5 Test'
117
 
        mocked_is_linux.return_value = False
118
 
        mocked_get_version.return_value = 'Trunk Test'
119
 
 
 
111
        mocked_is_linux.return_value = False
 
112
        mocked_get_version.return_value = 'Trunk Test'
 
113
        mocked_get_library_versions.return_value = LIBRARY_VERSIONS
120
114
        test_form = exceptionform.ExceptionForm()
121
115
        test_form.file_attachment = None
122
116
 
123
 
        with patch.object(test_form, '_pyuno_import') as mock_pyuno, \
 
117
        with patch.object(test_form, '_get_pyuno_version') as mock_pyuno, \
124
118
                patch.object(test_form.exception_text_edit, 'toPlainText') as mock_traceback, \
125
119
                patch.object(test_form.description_text_edit, 'toPlainText') as mock_description:
126
120
            mock_pyuno.return_value = 'UNO Bridge Test'
127
121
            mock_traceback.return_value = 'openlp: Traceback Test'
128
122
            mock_description.return_value = 'Description Test'
129
123
 
130
 
            # WHEN: on_save_report_button_clicked called
 
124
            # WHEN: on_send_report_button_clicked called
131
125
            test_form.on_send_report_button_clicked()
132
126
 
133
127
        # THEN: Verify strings were formatted properly
134
128
        mocked_add_query_item.assert_called_with('body', MAIL_ITEM_TEXT)
135
129
 
136
130
    @patch("openlp.core.ui.exceptionform.FileDialog.getSaveFileName")
137
 
    @patch("openlp.core.ui.exceptionform.Qt")
138
 
    def test_on_save_report_button_clicked(self, mocked_qt, mocked_save_filename, mocked_python_version,
139
 
                                           mocked_platform, mocked_is_linux, mocked_etree, mocked_bs4,
140
 
                                           mocked_sqlalchemy, mocked_get_version, mocked_openlurl,
141
 
                                           mocked_qversion):
 
131
    def test_on_save_report_button_clicked(self, mocked_save_filename, mocked_platform, mocked_is_linux,
 
132
                                           mocked_get_library_versions, mocked_get_version, mocked_openurl):
142
133
        """
143
134
        Test save report saves the correct information to a file
144
135
        """
145
 
        mocked_etree.__version__ = 'ETree Test'
146
 
        mocked_bs4.__version__ = 'BeautifulSoup Test'
147
 
        mocked_sqlalchemy.__version__ = 'SqlAlchemy Test'
148
 
        mocked_python_version.return_value = 'Python Test'
149
136
        mocked_platform.return_value = 'Nose Test'
150
 
        mocked_qversion.return_value = 'Qt5 test'
151
 
        mocked_qt.PYQT_VERSION_STR = 'PyQt5 Test'
152
137
        mocked_is_linux.return_value = False
153
138
        mocked_get_version.return_value = 'Trunk Test'
154
 
 
 
139
        mocked_get_library_versions.return_value = LIBRARY_VERSIONS
155
140
        with patch.object(Path, 'open') as mocked_path_open:
156
141
            test_path = Path('testfile.txt')
157
142
            mocked_save_filename.return_value = test_path, 'ext'
159
144
            test_form = exceptionform.ExceptionForm()
160
145
            test_form.file_attachment = None
161
146
 
162
 
            with patch.object(test_form, '_pyuno_import') as mock_pyuno, \
 
147
            with patch.object(test_form, '_get_pyuno_version') as mock_pyuno, \
163
148
                    patch.object(test_form.exception_text_edit, 'toPlainText') as mock_traceback, \
164
149
                    patch.object(test_form.description_text_edit, 'toPlainText') as mock_description:
165
150
                mock_pyuno.return_value = 'UNO Bridge Test'