Merge lp:~raoul-snyman/openlp/bug-1533246 into lp:openlp

Proposed by Raoul Snyman
Status: Merged
Merged at revision: 2614
Proposed branch: lp:~raoul-snyman/openlp/bug-1533246
Merge into: lp:openlp
Diff against target: 327 lines (+189/-37)
3 files modified
openlp/core/common/settings.py (+15/-30)
openlp/core/ui/shortcutlistform.py (+10/-2)
tests/interfaces/openlp_core_ui/test_shortcutlistform.py (+164/-5)
To merge this branch: bzr merge lp:~raoul-snyman/openlp/bug-1533246
Reviewer Review Type Date Requested Status
David Wales (community) Approve
Tim Bentley Approve
Review via email: mp+285229@code.launchpad.net

This proposal supersedes a proposal from 2016-02-04.

Description of the change

Fixed a problem with the shortcuts.
Also tried to make the alternate clear button on the shortcuts dialog a little less weird.

Add this to your merge proposal:
--------------------------------
lp:~raoul-snyman/openlp/bug-1533246 (revision 2616)
[SUCCESS] https://ci.openlp.io/job/Branch-01-Pull/1275/
[SUCCESS] https://ci.openlp.io/job/Branch-02-Functional-Tests/1199/
[SUCCESS] https://ci.openlp.io/job/Branch-03-Interface-Tests/1138/
[SUCCESS] https://ci.openlp.io/job/Branch-04a-Windows_Functional_Tests/974/
[FAILURE] https://ci.openlp.io/job/Branch-04b-Windows_Interface_Tests/566/
Stopping after failure

To post a comment you must log in.
Revision history for this message
David Wales (daviewales) wrote : Posted in a previous version of this proposal

Starting on line 197, there is a repeated comment which says:

# WHEN: The even is handled

But should say

# WHEN: The event is handled

Running this search and replace on the code should fix it if you use vim:

%s/ even / event /g

Alternatively, I'm sure you know how to use the search and replace in your favourite editor.

review: Needs Fixing
Revision history for this message
Tim Bentley (trb143) :
review: Approve
Revision history for this message
David Wales (daviewales) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'openlp/core/common/settings.py'
--- openlp/core/common/settings.py 2016-01-10 16:01:43 +0000
+++ openlp/core/common/settings.py 2016-02-05 19:02:39 +0000
@@ -252,68 +252,56 @@
252 'shortcuts/blankScreen': [QtGui.QKeySequence(QtCore.Qt.Key_Period)],252 'shortcuts/blankScreen': [QtGui.QKeySequence(QtCore.Qt.Key_Period)],
253 'shortcuts/collapse': [QtGui.QKeySequence(QtCore.Qt.Key_Minus)],253 'shortcuts/collapse': [QtGui.QKeySequence(QtCore.Qt.Key_Minus)],
254 'shortcuts/desktopScreen': [QtGui.QKeySequence(QtCore.Qt.Key_D)],254 'shortcuts/desktopScreen': [QtGui.QKeySequence(QtCore.Qt.Key_D)],
255 'shortcuts/delete': [QtGui.QKeySequence(QtGui.QKeySequence.Delete),255 'shortcuts/delete': [QtGui.QKeySequence(QtGui.QKeySequence.Delete)],
256 QtGui.QKeySequence(QtCore.Qt.Key_Delete)],
257 'shortcuts/down': [QtGui.QKeySequence(QtCore.Qt.Key_Down)],256 'shortcuts/down': [QtGui.QKeySequence(QtCore.Qt.Key_Down)],
258 'shortcuts/editSong': [],257 'shortcuts/editSong': [],
259 'shortcuts/escapeItem': [QtGui.QKeySequence(QtCore.Qt.Key_Escape)],258 'shortcuts/escapeItem': [QtGui.QKeySequence(QtCore.Qt.Key_Escape)],
260 'shortcuts/expand': [QtGui.QKeySequence(QtCore.Qt.Key_Plus)],259 'shortcuts/expand': [QtGui.QKeySequence(QtCore.Qt.Key_Plus)],
261 'shortcuts/exportThemeItem': [],260 'shortcuts/exportThemeItem': [],
262 'shortcuts/fileNewItem': [QtGui.QKeySequence(QtGui.QKeySequence.New),261 'shortcuts/fileNewItem': [QtGui.QKeySequence(QtGui.QKeySequence.New)],
263 QtGui.QKeySequence(QtCore.Qt.CTRL + QtCore.Qt.Key_N)],262 'shortcuts/fileSaveAsItem': [QtGui.QKeySequence(QtGui.QKeySequence.SaveAs)],
264 'shortcuts/fileSaveAsItem': [QtGui.QKeySequence(QtGui.QKeySequence.SaveAs),263 'shortcuts/fileExitItem': [QtGui.QKeySequence(QtGui.QKeySequence.Quit)],
265 QtGui.QKeySequence(QtCore.Qt.CTRL + QtCore.Qt.SHIFT + QtCore.Qt.Key_S)],264 'shortcuts/fileSaveItem': [QtGui.QKeySequence(QtGui.QKeySequence.Save)],
266 'shortcuts/fileExitItem': [QtGui.QKeySequence(QtGui.QKeySequence.Quit),265 'shortcuts/fileOpenItem': [QtGui.QKeySequence(QtGui.QKeySequence.Open)],
267 QtGui.QKeySequence(QtCore.Qt.ALT + QtCore.Qt.Key_F4)],
268 'shortcuts/fileSaveItem': [QtGui.QKeySequence(QtGui.QKeySequence.Save),
269 QtGui.QKeySequence(QtCore.Qt.CTRL + QtCore.Qt.Key_S)],
270 'shortcuts/fileOpenItem': [QtGui.QKeySequence(QtGui.QKeySequence.Open),
271 QtGui.QKeySequence(QtCore.Qt.CTRL + QtCore.Qt.Key_O)],
272 'shortcuts/goLive': [],266 'shortcuts/goLive': [],
273 'shortcuts/importThemeItem': [],267 'shortcuts/importThemeItem': [],
274 'shortcuts/importBibleItem': [],268 'shortcuts/importBibleItem': [],
275 'shortcuts/listViewBiblesDeleteItem': [QtGui.QKeySequence(QtGui.QKeySequence.Delete),269 'shortcuts/listViewBiblesDeleteItem': [QtGui.QKeySequence(QtGui.QKeySequence.Delete)],
276 QtGui.QKeySequence(QtCore.Qt.Key_Delete)],
277 'shortcuts/listViewBiblesPreviewItem': [QtGui.QKeySequence(QtCore.Qt.Key_Return),270 'shortcuts/listViewBiblesPreviewItem': [QtGui.QKeySequence(QtCore.Qt.Key_Return),
278 QtGui.QKeySequence(QtCore.Qt.Key_Enter)],271 QtGui.QKeySequence(QtCore.Qt.Key_Enter)],
279 'shortcuts/listViewBiblesLiveItem': [QtGui.QKeySequence(QtCore.Qt.SHIFT + QtCore.Qt.Key_Return),272 'shortcuts/listViewBiblesLiveItem': [QtGui.QKeySequence(QtCore.Qt.SHIFT + QtCore.Qt.Key_Return),
280 QtGui.QKeySequence(QtCore.Qt.SHIFT + QtCore.Qt.Key_Enter)],273 QtGui.QKeySequence(QtCore.Qt.SHIFT + QtCore.Qt.Key_Enter)],
281 'shortcuts/listViewBiblesServiceItem': [QtGui.QKeySequence(QtCore.Qt.Key_Plus),274 'shortcuts/listViewBiblesServiceItem': [QtGui.QKeySequence(QtCore.Qt.Key_Plus),
282 QtGui.QKeySequence(QtCore.Qt.Key_Equal)],275 QtGui.QKeySequence(QtCore.Qt.Key_Equal)],
283 'shortcuts/listViewCustomDeleteItem': [QtGui.QKeySequence(QtGui.QKeySequence.Delete),276 'shortcuts/listViewCustomDeleteItem': [QtGui.QKeySequence(QtGui.QKeySequence.Delete)],
284 QtGui.QKeySequence(QtCore.Qt.Key_Delete)],
285 'shortcuts/listViewCustomPreviewItem': [QtGui.QKeySequence(QtCore.Qt.Key_Return),277 'shortcuts/listViewCustomPreviewItem': [QtGui.QKeySequence(QtCore.Qt.Key_Return),
286 QtGui.QKeySequence(QtCore.Qt.Key_Enter)],278 QtGui.QKeySequence(QtCore.Qt.Key_Enter)],
287 'shortcuts/listViewCustomLiveItem': [QtGui.QKeySequence(QtCore.Qt.SHIFT + QtCore.Qt.Key_Return),279 'shortcuts/listViewCustomLiveItem': [QtGui.QKeySequence(QtCore.Qt.SHIFT + QtCore.Qt.Key_Return),
288 QtGui.QKeySequence(QtCore.Qt.SHIFT + QtCore.Qt.Key_Enter)],280 QtGui.QKeySequence(QtCore.Qt.SHIFT + QtCore.Qt.Key_Enter)],
289 'shortcuts/listViewCustomServiceItem': [QtGui.QKeySequence(QtCore.Qt.Key_Plus),281 'shortcuts/listViewCustomServiceItem': [QtGui.QKeySequence(QtCore.Qt.Key_Plus),
290 QtGui.QKeySequence(QtCore.Qt.Key_Equal)],282 QtGui.QKeySequence(QtCore.Qt.Key_Equal)],
291 'shortcuts/listViewImagesDeleteItem': [QtGui.QKeySequence(QtGui.QKeySequence.Delete),283 'shortcuts/listViewImagesDeleteItem': [QtGui.QKeySequence(QtGui.QKeySequence.Delete)],
292 QtGui.QKeySequence(QtCore.Qt.Key_Delete)],
293 'shortcuts/listViewImagesPreviewItem': [QtGui.QKeySequence(QtCore.Qt.Key_Return),284 'shortcuts/listViewImagesPreviewItem': [QtGui.QKeySequence(QtCore.Qt.Key_Return),
294 QtGui.QKeySequence(QtCore.Qt.Key_Enter)],285 QtGui.QKeySequence(QtCore.Qt.Key_Enter)],
295 'shortcuts/listViewImagesLiveItem': [QtGui.QKeySequence(QtCore.Qt.SHIFT + QtCore.Qt.Key_Return),286 'shortcuts/listViewImagesLiveItem': [QtGui.QKeySequence(QtCore.Qt.SHIFT + QtCore.Qt.Key_Return),
296 QtGui.QKeySequence(QtCore.Qt.SHIFT + QtCore.Qt.Key_Enter)],287 QtGui.QKeySequence(QtCore.Qt.SHIFT + QtCore.Qt.Key_Enter)],
297 'shortcuts/listViewImagesServiceItem': [QtGui.QKeySequence(QtCore.Qt.Key_Plus),288 'shortcuts/listViewImagesServiceItem': [QtGui.QKeySequence(QtCore.Qt.Key_Plus),
298 QtGui.QKeySequence(QtCore.Qt.Key_Equal)],289 QtGui.QKeySequence(QtCore.Qt.Key_Equal)],
299 'shortcuts/listViewMediaDeleteItem': [QtGui.QKeySequence(QtGui.QKeySequence.Delete),290 'shortcuts/listViewMediaDeleteItem': [QtGui.QKeySequence(QtGui.QKeySequence.Delete)],
300 QtGui.QKeySequence(QtCore.Qt.Key_Delete)],
301 'shortcuts/listViewMediaPreviewItem': [QtGui.QKeySequence(QtCore.Qt.Key_Return),291 'shortcuts/listViewMediaPreviewItem': [QtGui.QKeySequence(QtCore.Qt.Key_Return),
302 QtGui.QKeySequence(QtCore.Qt.Key_Enter)],292 QtGui.QKeySequence(QtCore.Qt.Key_Enter)],
303 'shortcuts/listViewMediaLiveItem': [QtGui.QKeySequence(QtCore.Qt.SHIFT + QtCore.Qt.Key_Return),293 'shortcuts/listViewMediaLiveItem': [QtGui.QKeySequence(QtCore.Qt.SHIFT + QtCore.Qt.Key_Return),
304 QtGui.QKeySequence(QtCore.Qt.SHIFT + QtCore.Qt.Key_Enter)],294 QtGui.QKeySequence(QtCore.Qt.SHIFT + QtCore.Qt.Key_Enter)],
305 'shortcuts/listViewMediaServiceItem': [QtGui.QKeySequence(QtCore.Qt.Key_Plus),295 'shortcuts/listViewMediaServiceItem': [QtGui.QKeySequence(QtCore.Qt.Key_Plus),
306 QtGui.QKeySequence(QtCore.Qt.Key_Equal)],296 QtGui.QKeySequence(QtCore.Qt.Key_Equal)],
307 'shortcuts/listViewPresentationsDeleteItem': [QtGui.QKeySequence(QtGui.QKeySequence.Delete),297 'shortcuts/listViewPresentationsDeleteItem': [QtGui.QKeySequence(QtGui.QKeySequence.Delete)],
308 QtGui.QKeySequence(QtCore.Qt.Key_Delete)],
309 'shortcuts/listViewPresentationsPreviewItem': [QtGui.QKeySequence(QtCore.Qt.Key_Return),298 'shortcuts/listViewPresentationsPreviewItem': [QtGui.QKeySequence(QtCore.Qt.Key_Return),
310 QtGui.QKeySequence(QtCore.Qt.Key_Enter)],299 QtGui.QKeySequence(QtCore.Qt.Key_Enter)],
311 'shortcuts/listViewPresentationsLiveItem': [QtGui.QKeySequence(QtCore.Qt.SHIFT + QtCore.Qt.Key_Return),300 'shortcuts/listViewPresentationsLiveItem': [QtGui.QKeySequence(QtCore.Qt.SHIFT + QtCore.Qt.Key_Return),
312 QtGui.QKeySequence(QtCore.Qt.SHIFT + QtCore.Qt.Key_Enter)],301 QtGui.QKeySequence(QtCore.Qt.SHIFT + QtCore.Qt.Key_Enter)],
313 'shortcuts/listViewPresentationsServiceItem': [QtGui.QKeySequence(QtCore.Qt.Key_Plus),302 'shortcuts/listViewPresentationsServiceItem': [QtGui.QKeySequence(QtCore.Qt.Key_Plus),
314 QtGui.QKeySequence(QtCore.Qt.Key_Equal)],303 QtGui.QKeySequence(QtCore.Qt.Key_Equal)],
315 'shortcuts/listViewSongsDeleteItem': [QtGui.QKeySequence(QtGui.QKeySequence.Delete),304 'shortcuts/listViewSongsDeleteItem': [QtGui.QKeySequence(QtGui.QKeySequence.Delete)],
316 QtGui.QKeySequence(QtCore.Qt.Key_Delete)],
317 'shortcuts/listViewSongsPreviewItem': [QtGui.QKeySequence(QtCore.Qt.Key_Return),305 'shortcuts/listViewSongsPreviewItem': [QtGui.QKeySequence(QtCore.Qt.Key_Return),
318 QtGui.QKeySequence(QtCore.Qt.Key_Enter)],306 QtGui.QKeySequence(QtCore.Qt.Key_Enter)],
319 'shortcuts/listViewSongsLiveItem': [QtGui.QKeySequence(QtCore.Qt.SHIFT + QtCore.Qt.Key_Return),307 'shortcuts/listViewSongsLiveItem': [QtGui.QKeySequence(QtCore.Qt.SHIFT + QtCore.Qt.Key_Return),
@@ -337,8 +325,7 @@
337 'shortcuts/nextService': [QtGui.QKeySequence(QtCore.Qt.Key_Right)],325 'shortcuts/nextService': [QtGui.QKeySequence(QtCore.Qt.Key_Right)],
338 'shortcuts/newService': [],326 'shortcuts/newService': [],
339 'shortcuts/offlineHelpItem': [QtGui.QKeySequence(QtGui.QKeySequence.HelpContents)],327 'shortcuts/offlineHelpItem': [QtGui.QKeySequence(QtGui.QKeySequence.HelpContents)],
340 'shortcuts/onlineHelpItem': [QtGui.QKeySequence(QtGui.QKeySequence.HelpContents),328 'shortcuts/onlineHelpItem': [QtGui.QKeySequence(QtGui.QKeySequence.HelpContents)],
341 QtGui.QKeySequence(QtCore.Qt.ALT + QtCore.Qt.Key_F1)],
342 'shortcuts/openService': [],329 'shortcuts/openService': [],
343 'shortcuts/saveService': [],330 'shortcuts/saveService': [],
344 'shortcuts/previousItem_live': [QtGui.QKeySequence(QtCore.Qt.Key_Up),331 'shortcuts/previousItem_live': [QtGui.QKeySequence(QtCore.Qt.Key_Up),
@@ -351,12 +338,10 @@
351 'shortcuts/previousService': [QtGui.QKeySequence(QtCore.Qt.Key_Left)],338 'shortcuts/previousService': [QtGui.QKeySequence(QtCore.Qt.Key_Left)],
352 'shortcuts/previousItem_preview': [QtGui.QKeySequence(QtCore.Qt.Key_Up),339 'shortcuts/previousItem_preview': [QtGui.QKeySequence(QtCore.Qt.Key_Up),
353 QtGui.QKeySequence(QtCore.Qt.Key_PageUp)],340 QtGui.QKeySequence(QtCore.Qt.Key_PageUp)],
354 'shortcuts/printServiceItem': [QtGui.QKeySequence(QtGui.QKeySequence.Print),341 'shortcuts/printServiceItem': [QtGui.QKeySequence(QtGui.QKeySequence.Print)],
355 QtGui.QKeySequence(QtCore.Qt.CTRL + QtCore.Qt.Key_P)],
356 'shortcuts/songExportItem': [],342 'shortcuts/songExportItem': [],
357 'shortcuts/songUsageStatus': [QtGui.QKeySequence(QtCore.Qt.Key_F4)],343 'shortcuts/songUsageStatus': [QtGui.QKeySequence(QtCore.Qt.Key_F4)],
358 'shortcuts/searchShortcut': [QtGui.QKeySequence(QtGui.QKeySequence.Find),344 'shortcuts/searchShortcut': [QtGui.QKeySequence(QtGui.QKeySequence.Find)],
359 QtGui.QKeySequence(QtCore.Qt.CTRL + QtCore.Qt.Key_F)],
360 'shortcuts/settingsShortcutsItem': [],345 'shortcuts/settingsShortcutsItem': [],
361 'shortcuts/settingsImportItem': [],346 'shortcuts/settingsImportItem': [],
362 'shortcuts/settingsPluginListItem': [QtGui.QKeySequence(QtCore.Qt.ALT + QtCore.Qt.Key_F7)],347 'shortcuts/settingsPluginListItem': [QtGui.QKeySequence(QtCore.Qt.ALT + QtCore.Qt.Key_F7)],
363348
=== modified file 'openlp/core/ui/shortcutlistform.py'
--- openlp/core/ui/shortcutlistform.py 2016-01-09 16:26:14 +0000
+++ openlp/core/ui/shortcutlistform.py 2016-02-05 19:02:39 +0000
@@ -320,9 +320,17 @@
320 """320 """
321 if not toggled:321 if not toggled:
322 return322 return
323 self.on_primary_push_button_clicked(False)323 action = self._current_item_action()
324 self.on_alternate_push_button_clicked(False)324 shortcuts = self._action_shortcuts(action)
325 self.refresh_shortcut_list()325 self.refresh_shortcut_list()
326 primary_button_text = ''
327 alternate_button_text = ''
328 if shortcuts:
329 primary_button_text = self.get_shortcut_string(shortcuts[0], for_display=True)
330 if len(shortcuts) == 2:
331 alternate_button_text = self.get_shortcut_string(shortcuts[1], for_display=True)
332 self.primary_push_button.setText(primary_button_text)
333 self.alternate_push_button.setText(alternate_button_text)
326334
327 def save(self):335 def save(self):
328 """336 """
329337
=== modified file 'tests/interfaces/openlp_core_ui/test_shortcutlistform.py'
--- tests/interfaces/openlp_core_ui/test_shortcutlistform.py 2015-12-31 22:46:06 +0000
+++ tests/interfaces/openlp_core_ui/test_shortcutlistform.py 2016-02-05 19:02:39 +0000
@@ -24,11 +24,12 @@
24"""24"""
25from unittest import TestCase25from unittest import TestCase
2626
27from PyQt5 import QtWidgets27from PyQt5 import QtCore, QtGui, QtWidgets
2828
29from openlp.core.common import Registry29from openlp.core.common import Registry
30from openlp.core.ui.shortcutlistform import ShortcutListForm30from openlp.core.ui.shortcutlistform import ShortcutListForm
31from tests.interfaces import patch31
32from tests.interfaces import MagicMock, patch
32from tests.helpers.testmixin import TestMixin33from tests.helpers.testmixin import TestMixin
3334
3435
@@ -59,13 +60,171 @@
59 button = QtWidgets.QPushButton()60 button = QtWidgets.QPushButton()
60 checked = True61 checked = True
61 enabled = True62 enabled = True
62 text = "new!"63 text = 'new!'
6364
64 # WHEN: Call the method.65 # WHEN: Call the method.
65 with patch('PyQt5.QtWidgets.QPushButton.setChecked') as mocked_check_method:66 with patch('PyQt5.QtWidgets.QPushButton.setChecked') as mocked_check_method:
66 self.form._adjust_button(button, checked, enabled, text)67 self.form._adjust_button(button, checked, enabled, text)
6768
68 # THEN: The button should be changed.69 # THEN: The button should be changed.
69 self.assertEqual(button.text(), text, "The text should match.")70 self.assertEqual(button.text(), text, 'The text should match.')
70 mocked_check_method.assert_called_once_with(True)71 mocked_check_method.assert_called_once_with(True)
71 self.assertEqual(button.isEnabled(), enabled, "The button should be disabled.")72 self.assertEqual(button.isEnabled(), enabled, 'The button should be disabled.')
73
74 def space_key_press_event_test(self):
75 """
76 Test the keyPressEvent when the spacebar was pressed
77 """
78 # GIVEN: A key event that is a space
79 mocked_event = MagicMock()
80 mocked_event.key.return_value = QtCore.Qt.Key_Space
81
82 # WHEN: The event is handled
83 with patch.object(self.form, 'keyReleaseEvent') as mocked_key_release_event:
84 self.form.keyPressEvent(mocked_event)
85
86 # THEN: The key should be released
87 mocked_key_release_event.assert_called_with(mocked_event)
88 self.assertEqual(0, mocked_event.accept.call_count)
89
90 def primary_push_button_checked_key_press_event_test(self):
91 """
92 Test the keyPressEvent when the primary push button is checked
93 """
94 # GIVEN: The primary push button is checked
95 with patch.object(self.form, 'keyReleaseEvent') as mocked_key_release_event, \
96 patch.object(self.form.primary_push_button, 'isChecked') as mocked_is_checked:
97 mocked_is_checked.return_value = True
98 mocked_event = MagicMock()
99
100 # WHEN: The event is handled
101 self.form.keyPressEvent(mocked_event)
102
103 # THEN: The key should be released
104 mocked_key_release_event.assert_called_with(mocked_event)
105 self.assertEqual(0, mocked_event.accept.call_count)
106
107 def alternate_push_button_checked_key_press_event_test(self):
108 """
109 Test the keyPressEvent when the alternate push button is checked
110 """
111 # GIVEN: The primary push button is checked
112 with patch.object(self.form, 'keyReleaseEvent') as mocked_key_release_event, \
113 patch.object(self.form.alternate_push_button, 'isChecked') as mocked_is_checked:
114 mocked_is_checked.return_value = True
115 mocked_event = MagicMock()
116
117 # WHEN: The event is handled
118 self.form.keyPressEvent(mocked_event)
119
120 # THEN: The key should be released
121 mocked_key_release_event.assert_called_with(mocked_event)
122 self.assertEqual(0, mocked_event.accept.call_count)
123
124 def escape_key_press_event_test(self):
125 """
126 Test the keyPressEvent when the escape key was pressed
127 """
128 # GIVEN: A key event that is an escape
129 mocked_event = MagicMock()
130 mocked_event.key.return_value = QtCore.Qt.Key_Escape
131
132 # WHEN: The event is handled
133 with patch.object(self.form, 'close') as mocked_close:
134 self.form.keyPressEvent(mocked_event)
135
136 # THEN: The key should be released
137 mocked_event.accept.assert_called_with()
138 mocked_close.assert_called_with()
139
140 def on_default_radio_button_not_toggled_test(self):
141 """
142 Test that the default radio button method exits early when the button is not toggled
143 """
144 # GIVEN: A not-toggled custom radio button
145 with patch.object(self.form, '_current_item_action') as mocked_current_item_action:
146
147 # WHEN: The clicked method is called
148 self.form.on_default_radio_button_clicked(False)
149
150 # THEN: The method should exit early (i.e. the rest of the methods are not called)
151 self.assertEqual(0, mocked_current_item_action.call_count)
152
153 def on_default_radio_button_clicked_no_action_test(self):
154 """
155 Test that nothing happens when an action hasn't been selected and you click the default radio button
156 """
157 # GIVEN: Some mocked out methods, a current action, and some shortcuts
158 with patch.object(self.form, '_current_item_action') as mocked_current_item_action, \
159 patch.object(self.form, '_action_shortcuts') as mocked_action_shortcuts:
160 mocked_current_item_action.return_value = None
161
162 # WHEN: The default radio button is clicked
163 self.form.on_default_radio_button_clicked(True)
164
165 # THEN: The method should exit early (i.e. the rest of the methods are not called)
166 mocked_current_item_action.assert_called_with()
167 self.assertEqual(0, mocked_action_shortcuts.call_count)
168
169 def on_default_radio_button_clicked_test(self):
170 """
171 Test that the values are copied across correctly when the default radio button is selected
172 """
173 # GIVEN: Some mocked out methods, a current action, and some shortcuts
174 with patch.object(self.form, '_current_item_action') as mocked_current_item_action, \
175 patch.object(self.form, '_action_shortcuts') as mocked_action_shortcuts, \
176 patch.object(self.form, 'refresh_shortcut_list') as mocked_refresh_shortcut_list, \
177 patch.object(self.form, 'get_shortcut_string') as mocked_get_shortcut_string, \
178 patch.object(self.form.primary_push_button, 'setText') as mocked_set_text:
179 mocked_action = MagicMock()
180 mocked_action.default_shortcuts = [QtCore.Qt.Key_Escape]
181 mocked_current_item_action.return_value = mocked_action
182 mocked_action_shortcuts.return_value = [QtCore.Qt.Key_Escape]
183 mocked_get_shortcut_string.return_value = 'Esc'
184
185 # WHEN: The default radio button is clicked
186 self.form.on_default_radio_button_clicked(True)
187
188 # THEN: The shorcuts should be copied across
189 mocked_current_item_action.assert_called_with()
190 mocked_action_shortcuts.assert_called_with(mocked_action)
191 mocked_refresh_shortcut_list.assert_called_with()
192 mocked_set_text.assert_called_with('Esc')
193
194 def on_custom_radio_button_not_toggled_test(self):
195 """
196 Test that the custom radio button method exits early when the button is not toggled
197 """
198 # GIVEN: A not-toggled custom radio button
199 with patch.object(self.form, '_current_item_action') as mocked_current_item_action:
200
201 # WHEN: The clicked method is called
202 self.form.on_custom_radio_button_clicked(False)
203
204 # THEN: The method should exit early (i.e. the rest of the methods are not called)
205 self.assertEqual(0, mocked_current_item_action.call_count)
206
207 def on_custom_radio_button_clicked_test(self):
208 """
209 Test that the values are copied across correctly when the custom radio button is selected
210 """
211 # GIVEN: Some mocked out methods, a current action, and some shortcuts
212 with patch.object(self.form, '_current_item_action') as mocked_current_item_action, \
213 patch.object(self.form, '_action_shortcuts') as mocked_action_shortcuts, \
214 patch.object(self.form, 'refresh_shortcut_list') as mocked_refresh_shortcut_list, \
215 patch.object(self.form, 'get_shortcut_string') as mocked_get_shortcut_string, \
216 patch.object(self.form.primary_push_button, 'setText') as mocked_set_text:
217 mocked_action = MagicMock()
218 mocked_current_item_action.return_value = mocked_action
219 mocked_action_shortcuts.return_value = [QtCore.Qt.Key_Escape]
220 mocked_get_shortcut_string.return_value = 'Esc'
221
222 # WHEN: The custom radio button is clicked
223 self.form.on_custom_radio_button_clicked(True)
224
225 # THEN: The shorcuts should be copied across
226 mocked_current_item_action.assert_called_with()
227 mocked_action_shortcuts.assert_called_with(mocked_action)
228 mocked_refresh_shortcut_list.assert_called_with()
229 mocked_set_text.assert_called_with('Esc')
230