32
33
from openlp.core.ui import exceptionform
33
34
from tests.helpers.testmixin import TestMixin
35
exceptionform.WEBKIT_VERSION = 'Webkit Test'
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'
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')
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'),
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'),
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):
63
73
Test functionality of exception form functions
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):
70
79
Template so you don't have to remember the layout of class mock options for methods
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
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):
105
107
Test send report creates the proper system information text
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'
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
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'
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()
133
127
# THEN: Verify strings were formatted properly
134
128
mocked_add_query_item.assert_called_with('body', MAIL_ITEM_TEXT)
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,
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):
143
134
Test save report saves the correct information to a file
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'
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'