Merge lp:~raoul-snyman/openlp/off-by-one-2.4 into lp:openlp/2.4
- off-by-one-2.4
- Merge into 2.4
Proposed by
Raoul Snyman
Status: | Merged | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Merged at revision: | 2674 | ||||||||||||
Proposed branch: | lp:~raoul-snyman/openlp/off-by-one-2.4 | ||||||||||||
Merge into: | lp:openlp/2.4 | ||||||||||||
Diff against target: |
410 lines (+247/-25) 3 files modified
openlp/plugins/songs/forms/editsongform.py (+30/-24) tests/functional/openlp_plugins/songs/test_editsongform.py (+2/-1) tests/interfaces/openlp_plugins/songs/forms/test_authorsform.py (+215/-0) |
||||||||||||
To merge this branch: | bzr merge lp:~raoul-snyman/openlp/off-by-one-2.4 | ||||||||||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Tim Bentley | Approve | ||
Review via email: mp+318720@code.launchpad.net |
This proposal supersedes a proposal from 2017-03-02.
Commit message
Description of the change
Fix bug #1666005 and bug #1668994
Add this to your merge proposal:
-------
lp:~raoul-snyman/openlp/off-by-one-2.4 (revision 2676)
[SUCCESS] https:/
[SUCCESS] https:/
[SUCCESS] https:/
[SUCCESS] https:/
[SUCCESS] https:/
[SUCCESS] https:/
[SUCCESS] https:/
To post a comment you must log in.
Revision history for this message
Tim Bentley (trb143) : | # |
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'openlp/plugins/songs/forms/editsongform.py' | |||
2 | --- openlp/plugins/songs/forms/editsongform.py 2016-12-31 11:05:48 +0000 | |||
3 | +++ openlp/plugins/songs/forms/editsongform.py 2017-03-02 05:06:04 +0000 | |||
4 | @@ -31,7 +31,8 @@ | |||
5 | 31 | 31 | ||
6 | 32 | from PyQt5 import QtCore, QtWidgets | 32 | from PyQt5 import QtCore, QtWidgets |
7 | 33 | 33 | ||
9 | 34 | from openlp.core.common import Registry, RegistryProperties, AppLocation, UiStrings, check_directory_exists, translate | 34 | from openlp.core.common import Registry, RegistryProperties, AppLocation, UiStrings, check_directory_exists, \ |
10 | 35 | translate, is_macosx | ||
11 | 35 | from openlp.core.lib import FileDialog, PluginStatus, MediaType, create_separated_list | 36 | from openlp.core.lib import FileDialog, PluginStatus, MediaType, create_separated_list |
12 | 36 | from openlp.core.lib.ui import set_case_insensitive_completer, critical_error_message_box, find_and_set_in_combo_box | 37 | from openlp.core.lib.ui import set_case_insensitive_completer, critical_error_message_box, find_and_set_in_combo_box |
13 | 37 | from openlp.plugins.songs.lib import VerseType, clean_song | 38 | from openlp.plugins.songs.lib import VerseType, clean_song |
14 | @@ -118,7 +119,8 @@ | |||
15 | 118 | cache.append(obj.name) | 119 | cache.append(obj.name) |
16 | 119 | combo.setItemData(row, obj.id) | 120 | combo.setItemData(row, obj.id) |
17 | 120 | set_case_insensitive_completer(cache, combo) | 121 | set_case_insensitive_completer(cache, combo) |
19 | 121 | combo.setEditText('') | 122 | combo.setCurrentIndex(-1) |
20 | 123 | combo.setCurrentText('') | ||
21 | 122 | 124 | ||
22 | 123 | def _add_author_to_list(self, author, author_type): | 125 | def _add_author_to_list(self, author, author_type): |
23 | 124 | """ | 126 | """ |
24 | @@ -352,7 +354,8 @@ | |||
25 | 352 | self.authors_combo_box.setItemData(row, author.id) | 354 | self.authors_combo_box.setItemData(row, author.id) |
26 | 353 | self.authors.append(author.display_name) | 355 | self.authors.append(author.display_name) |
27 | 354 | set_case_insensitive_completer(self.authors, self.authors_combo_box) | 356 | set_case_insensitive_completer(self.authors, self.authors_combo_box) |
29 | 355 | self.authors_combo_box.setEditText('') | 357 | self.authors_combo_box.setCurrentIndex(-1) |
30 | 358 | self.authors_combo_box.setCurrentText('') | ||
31 | 356 | 359 | ||
32 | 357 | # Types | 360 | # Types |
33 | 358 | self.author_types_combo_box.clear() | 361 | self.author_types_combo_box.clear() |
34 | @@ -382,7 +385,8 @@ | |||
35 | 382 | self.themes = theme_list | 385 | self.themes = theme_list |
36 | 383 | self.theme_combo_box.addItems(theme_list) | 386 | self.theme_combo_box.addItems(theme_list) |
37 | 384 | set_case_insensitive_completer(self.themes, self.theme_combo_box) | 387 | set_case_insensitive_completer(self.themes, self.theme_combo_box) |
39 | 385 | self.theme_combo_box.setEditText('') | 388 | self.theme_combo_box.setCurrentIndex(-1) |
40 | 389 | self.theme_combo_box.setCurrentText('') | ||
41 | 386 | 390 | ||
42 | 387 | def load_media_files(self): | 391 | def load_media_files(self): |
43 | 388 | """ | 392 | """ |
44 | @@ -421,7 +425,8 @@ | |||
45 | 421 | self.load_topics() | 425 | self.load_topics() |
46 | 422 | self.load_songbooks() | 426 | self.load_songbooks() |
47 | 423 | self.load_media_files() | 427 | self.load_media_files() |
49 | 424 | self.theme_combo_box.setEditText('') | 428 | self.theme_combo_box.setCurrentIndex(-1) |
50 | 429 | self.theme_combo_box.setCurrentText('') | ||
51 | 425 | # it's a new song to preview is not possible | 430 | # it's a new song to preview is not possible |
52 | 426 | self.preview_button.setVisible(False) | 431 | self.preview_button.setVisible(False) |
53 | 427 | 432 | ||
54 | @@ -446,8 +451,8 @@ | |||
55 | 446 | find_and_set_in_combo_box(self.theme_combo_box, str(self.song.theme_name)) | 451 | find_and_set_in_combo_box(self.theme_combo_box, str(self.song.theme_name)) |
56 | 447 | else: | 452 | else: |
57 | 448 | # Clear the theme combo box in case it was previously set (bug #1212801) | 453 | # Clear the theme combo box in case it was previously set (bug #1212801) |
60 | 449 | self.theme_combo_box.setEditText('') | 454 | self.theme_combo_box.setCurrentIndex(-1) |
61 | 450 | self.theme_combo_box.setCurrentIndex(0) | 455 | self.theme_combo_box.setCurrentText('') |
62 | 451 | self.copyright_edit.setText(self.song.copyright if self.song.copyright else '') | 456 | self.copyright_edit.setText(self.song.copyright if self.song.copyright else '') |
63 | 452 | self.comments_edit.setPlainText(self.song.comments if self.song.comments else '') | 457 | self.comments_edit.setPlainText(self.song.comments if self.song.comments else '') |
64 | 453 | self.ccli_number_edit.setText(self.song.ccli_number if self.song.ccli_number else '') | 458 | self.ccli_number_edit.setText(self.song.ccli_number if self.song.ccli_number else '') |
65 | @@ -550,12 +555,7 @@ | |||
66 | 550 | item = int(self.authors_combo_box.currentIndex()) | 555 | item = int(self.authors_combo_box.currentIndex()) |
67 | 551 | text = self.authors_combo_box.currentText().strip(' \r\n\t') | 556 | text = self.authors_combo_box.currentText().strip(' \r\n\t') |
68 | 552 | author_type = self.author_types_combo_box.itemData(self.author_types_combo_box.currentIndex()) | 557 | author_type = self.author_types_combo_box.itemData(self.author_types_combo_box.currentIndex()) |
75 | 553 | # This if statement is for OS X, which doesn't seem to work well with | 558 | if item == -1 and text: |
70 | 554 | # the QCompleter auto-completion class. See bug #812628. | ||
71 | 555 | if text in self.authors: | ||
72 | 556 | # Index 0 is a blank string, so add 1 | ||
73 | 557 | item = self.authors.index(text) + 1 | ||
74 | 558 | if item == 0 and text: | ||
76 | 559 | if QtWidgets.QMessageBox.question( | 559 | if QtWidgets.QMessageBox.question( |
77 | 560 | self, | 560 | self, |
78 | 561 | translate('SongsPlugin.EditSongForm', 'Add Author'), | 561 | translate('SongsPlugin.EditSongForm', 'Add Author'), |
79 | @@ -570,10 +570,11 @@ | |||
80 | 570 | self.manager.save_object(author) | 570 | self.manager.save_object(author) |
81 | 571 | self._add_author_to_list(author, author_type) | 571 | self._add_author_to_list(author, author_type) |
82 | 572 | self.load_authors() | 572 | self.load_authors() |
84 | 573 | self.authors_combo_box.setEditText('') | 573 | self.authors_combo_box.setCurrentIndex(-1) |
85 | 574 | self.authors_combo_box.setCurrentText('') | ||
86 | 574 | else: | 575 | else: |
87 | 575 | return | 576 | return |
89 | 576 | elif item > 0: | 577 | elif item >= 0: |
90 | 577 | item_id = (self.authors_combo_box.itemData(item)) | 578 | item_id = (self.authors_combo_box.itemData(item)) |
91 | 578 | author = self.manager.get_object(Author, item_id) | 579 | author = self.manager.get_object(Author, item_id) |
92 | 579 | if self.authors_list_view.findItems(author.get_display_name(author_type), QtCore.Qt.MatchExactly): | 580 | if self.authors_list_view.findItems(author.get_display_name(author_type), QtCore.Qt.MatchExactly): |
93 | @@ -581,7 +582,8 @@ | |||
94 | 581 | message=translate('SongsPlugin.EditSongForm', 'This author is already in the list.')) | 582 | message=translate('SongsPlugin.EditSongForm', 'This author is already in the list.')) |
95 | 582 | else: | 583 | else: |
96 | 583 | self._add_author_to_list(author, author_type) | 584 | self._add_author_to_list(author, author_type) |
98 | 584 | self.authors_combo_box.setEditText('') | 585 | self.authors_combo_box.setCurrentIndex(-1) |
99 | 586 | self.authors_combo_box.setCurrentText('') | ||
100 | 585 | else: | 587 | else: |
101 | 586 | QtWidgets.QMessageBox.warning( | 588 | QtWidgets.QMessageBox.warning( |
102 | 587 | self, UiStrings().NISs, | 589 | self, UiStrings().NISs, |
103 | @@ -633,7 +635,7 @@ | |||
104 | 633 | def on_topic_add_button_clicked(self): | 635 | def on_topic_add_button_clicked(self): |
105 | 634 | item = int(self.topics_combo_box.currentIndex()) | 636 | item = int(self.topics_combo_box.currentIndex()) |
106 | 635 | text = self.topics_combo_box.currentText() | 637 | text = self.topics_combo_box.currentText() |
108 | 636 | if item == 0 and text: | 638 | if item == -1 and text: |
109 | 637 | if QtWidgets.QMessageBox.question( | 639 | if QtWidgets.QMessageBox.question( |
110 | 638 | self, translate('SongsPlugin.EditSongForm', 'Add Topic'), | 640 | self, translate('SongsPlugin.EditSongForm', 'Add Topic'), |
111 | 639 | translate('SongsPlugin.EditSongForm', 'This topic does not exist, do you want to add it?'), | 641 | translate('SongsPlugin.EditSongForm', 'This topic does not exist, do you want to add it?'), |
112 | @@ -645,10 +647,11 @@ | |||
113 | 645 | topic_item.setData(QtCore.Qt.UserRole, topic.id) | 647 | topic_item.setData(QtCore.Qt.UserRole, topic.id) |
114 | 646 | self.topics_list_view.addItem(topic_item) | 648 | self.topics_list_view.addItem(topic_item) |
115 | 647 | self.load_topics() | 649 | self.load_topics() |
117 | 648 | self.topics_combo_box.setEditText('') | 650 | self.topics_combo_box.setCurrentIndex(-1) |
118 | 651 | self.topics_combo_box.setCurrentText('') | ||
119 | 649 | else: | 652 | else: |
120 | 650 | return | 653 | return |
122 | 651 | elif item > 0: | 654 | elif item >= 0: |
123 | 652 | item_id = (self.topics_combo_box.itemData(item)) | 655 | item_id = (self.topics_combo_box.itemData(item)) |
124 | 653 | topic = self.manager.get_object(Topic, item_id) | 656 | topic = self.manager.get_object(Topic, item_id) |
125 | 654 | if self.topics_list_view.findItems(str(topic.name), QtCore.Qt.MatchExactly): | 657 | if self.topics_list_view.findItems(str(topic.name), QtCore.Qt.MatchExactly): |
126 | @@ -658,7 +661,8 @@ | |||
127 | 658 | topic_item = QtWidgets.QListWidgetItem(str(topic.name)) | 661 | topic_item = QtWidgets.QListWidgetItem(str(topic.name)) |
128 | 659 | topic_item.setData(QtCore.Qt.UserRole, topic.id) | 662 | topic_item.setData(QtCore.Qt.UserRole, topic.id) |
129 | 660 | self.topics_list_view.addItem(topic_item) | 663 | self.topics_list_view.addItem(topic_item) |
131 | 661 | self.topics_combo_box.setEditText('') | 664 | self.topics_combo_box.setCurrentIndex(-1) |
132 | 665 | self.topics_combo_box.setCurrentText('') | ||
133 | 662 | else: | 666 | else: |
134 | 663 | QtWidgets.QMessageBox.warning( | 667 | QtWidgets.QMessageBox.warning( |
135 | 664 | self, UiStrings().NISs, | 668 | self, UiStrings().NISs, |
136 | @@ -678,7 +682,7 @@ | |||
137 | 678 | def on_songbook_add_button_clicked(self): | 682 | def on_songbook_add_button_clicked(self): |
138 | 679 | item = int(self.songbooks_combo_box.currentIndex()) | 683 | item = int(self.songbooks_combo_box.currentIndex()) |
139 | 680 | text = self.songbooks_combo_box.currentText() | 684 | text = self.songbooks_combo_box.currentText() |
141 | 681 | if item == 0 and text: | 685 | if item == -1 and text: |
142 | 682 | if QtWidgets.QMessageBox.question( | 686 | if QtWidgets.QMessageBox.question( |
143 | 683 | self, translate('SongsPlugin.EditSongForm', 'Add Songbook'), | 687 | self, translate('SongsPlugin.EditSongForm', 'Add Songbook'), |
144 | 684 | translate('SongsPlugin.EditSongForm', 'This Songbook does not exist, do you want to add it?'), | 688 | translate('SongsPlugin.EditSongForm', 'This Songbook does not exist, do you want to add it?'), |
145 | @@ -688,11 +692,12 @@ | |||
146 | 688 | self.manager.save_object(songbook) | 692 | self.manager.save_object(songbook) |
147 | 689 | self.add_songbook_entry_to_list(songbook.id, songbook.name, self.songbook_entry_edit.text()) | 693 | self.add_songbook_entry_to_list(songbook.id, songbook.name, self.songbook_entry_edit.text()) |
148 | 690 | self.load_songbooks() | 694 | self.load_songbooks() |
150 | 691 | self.songbooks_combo_box.setEditText('') | 695 | self.songbooks_combo_box.setCurrentIndex(-1) |
151 | 696 | self.songbooks_combo_box.setCurrentText('') | ||
152 | 692 | self.songbook_entry_edit.clear() | 697 | self.songbook_entry_edit.clear() |
153 | 693 | else: | 698 | else: |
154 | 694 | return | 699 | return |
156 | 695 | elif item > 0: | 700 | elif item >= 0: |
157 | 696 | item_id = (self.songbooks_combo_box.itemData(item)) | 701 | item_id = (self.songbooks_combo_box.itemData(item)) |
158 | 697 | songbook = self.manager.get_object(Book, item_id) | 702 | songbook = self.manager.get_object(Book, item_id) |
159 | 698 | if self.songbooks_list_view.findItems(str(songbook.name), QtCore.Qt.MatchExactly): | 703 | if self.songbooks_list_view.findItems(str(songbook.name), QtCore.Qt.MatchExactly): |
160 | @@ -700,7 +705,8 @@ | |||
161 | 700 | message=translate('SongsPlugin.EditSongForm', 'This Songbook is already in the list.')) | 705 | message=translate('SongsPlugin.EditSongForm', 'This Songbook is already in the list.')) |
162 | 701 | else: | 706 | else: |
163 | 702 | self.add_songbook_entry_to_list(songbook.id, songbook.name, self.songbook_entry_edit.text()) | 707 | self.add_songbook_entry_to_list(songbook.id, songbook.name, self.songbook_entry_edit.text()) |
165 | 703 | self.songbooks_combo_box.setEditText('') | 708 | self.songbooks_combo_box.setCurrentIndex(-1) |
166 | 709 | self.songbooks_combo_box.setCurrentText('') | ||
167 | 704 | self.songbook_entry_edit.clear() | 710 | self.songbook_entry_edit.clear() |
168 | 705 | else: | 711 | else: |
169 | 706 | QtWidgets.QMessageBox.warning( | 712 | QtWidgets.QMessageBox.warning( |
170 | 707 | 713 | ||
171 | === modified file 'tests/functional/openlp_plugins/songs/test_editsongform.py' | |||
172 | --- tests/functional/openlp_plugins/songs/test_editsongform.py 2016-12-31 11:05:48 +0000 | |||
173 | +++ tests/functional/openlp_plugins/songs/test_editsongform.py 2017-03-02 05:06:04 +0000 | |||
174 | @@ -106,4 +106,5 @@ | |||
175 | 106 | mocked_cache.append.assert_called_once_with('Charles') | 106 | mocked_cache.append.assert_called_once_with('Charles') |
176 | 107 | mocked_combo.setItemData.assert_called_once_with(0, 1) | 107 | mocked_combo.setItemData.assert_called_once_with(0, 1) |
177 | 108 | mocked_set_case_insensitive_completer.assert_called_once_with(mocked_cache, mocked_combo) | 108 | mocked_set_case_insensitive_completer.assert_called_once_with(mocked_cache, mocked_combo) |
179 | 109 | mocked_combo.setEditText.assert_called_once_with('') | 109 | mocked_combo.setCurrentIndex.assert_called_once_with(-1) |
180 | 110 | mocked_combo.setCurrentText.assert_called_once_with('') | ||
181 | 110 | 111 | ||
182 | === modified file 'tests/interfaces/openlp_plugins/songs/forms/test_authorsform.py' | |||
183 | --- tests/interfaces/openlp_plugins/songs/forms/test_authorsform.py 2016-12-31 11:05:48 +0000 | |||
184 | +++ tests/interfaces/openlp_plugins/songs/forms/test_authorsform.py 2017-03-02 05:06:04 +0000 | |||
185 | @@ -23,6 +23,7 @@ | |||
186 | 23 | Package to test the openlp.plugins.songs.forms.authorsform package. | 23 | Package to test the openlp.plugins.songs.forms.authorsform package. |
187 | 24 | """ | 24 | """ |
188 | 25 | from unittest import TestCase | 25 | from unittest import TestCase |
189 | 26 | from unittest.mock import patch | ||
190 | 26 | 27 | ||
191 | 27 | from PyQt5 import QtWidgets | 28 | from PyQt5 import QtWidgets |
192 | 28 | 29 | ||
193 | @@ -138,3 +139,217 @@ | |||
194 | 138 | 139 | ||
195 | 139 | # THEN: The display_name_edit should have the correct value | 140 | # THEN: The display_name_edit should have the correct value |
196 | 140 | self.assertEqual(self.form.display_edit.text(), display_name, 'The display name should be set correctly') | 141 | self.assertEqual(self.form.display_edit.text(), display_name, 'The display name should be set correctly') |
197 | 142 | |||
198 | 143 | @patch('openlp.plugins.songs.forms.authorsform.QtWidgets.QDialog.exec') | ||
199 | 144 | def test_exec(self, mocked_exec): | ||
200 | 145 | """ | ||
201 | 146 | Test the exec() method | ||
202 | 147 | """ | ||
203 | 148 | # GIVEN: An authors for and various mocked objects | ||
204 | 149 | with patch.object(self.form.first_name_edit, 'clear') as mocked_first_name_edit_clear, \ | ||
205 | 150 | patch.object(self.form.last_name_edit, 'clear') as mocked_last_name_edit_clear, \ | ||
206 | 151 | patch.object(self.form.display_edit, 'clear') as mocked_display_edit_clear, \ | ||
207 | 152 | patch.object(self.form.first_name_edit, 'setFocus') as mocked_first_name_edit_setFocus: | ||
208 | 153 | # WHEN: The exec() method is called | ||
209 | 154 | self.form.exec(clear=True) | ||
210 | 155 | |||
211 | 156 | # THEN: The clear and exec() methods should have been called | ||
212 | 157 | mocked_first_name_edit_clear.assert_called_once_with() | ||
213 | 158 | mocked_last_name_edit_clear.assert_called_once_with() | ||
214 | 159 | mocked_display_edit_clear.assert_called_once_with() | ||
215 | 160 | mocked_first_name_edit_setFocus.assert_called_once_with() | ||
216 | 161 | mocked_exec.assert_called_once_with(self.form) | ||
217 | 162 | |||
218 | 163 | def test_first_name_edited(self): | ||
219 | 164 | """ | ||
220 | 165 | Test the on_first_name_edited() method | ||
221 | 166 | """ | ||
222 | 167 | # GIVEN: An author form | ||
223 | 168 | self.form.auto_display_name = True | ||
224 | 169 | |||
225 | 170 | with patch.object(self.form.last_name_edit, 'text') as mocked_last_name_edit_text, \ | ||
226 | 171 | patch.object(self.form.display_edit, 'setText') as mocked_display_edit_setText: | ||
227 | 172 | mocked_last_name_edit_text.return_value = 'Newton' | ||
228 | 173 | |||
229 | 174 | # WHEN: on_first_name_edited() is called | ||
230 | 175 | self.form.on_first_name_edited('John') | ||
231 | 176 | |||
232 | 177 | # THEN: The display name should be updated | ||
233 | 178 | assert mocked_last_name_edit_text.call_count == 2 | ||
234 | 179 | mocked_display_edit_setText.assert_called_once_with('John Newton') | ||
235 | 180 | |||
236 | 181 | def test_first_name_edited_no_auto(self): | ||
237 | 182 | """ | ||
238 | 183 | Test the on_first_name_edited() method without auto_display_name | ||
239 | 184 | """ | ||
240 | 185 | # GIVEN: An author form | ||
241 | 186 | self.form.auto_display_name = False | ||
242 | 187 | |||
243 | 188 | with patch.object(self.form.last_name_edit, 'text') as mocked_last_name_edit_text, \ | ||
244 | 189 | patch.object(self.form.display_edit, 'setText') as mocked_display_edit_setText: | ||
245 | 190 | |||
246 | 191 | # WHEN: on_first_name_edited() is called | ||
247 | 192 | self.form.on_first_name_edited('John') | ||
248 | 193 | |||
249 | 194 | # THEN: The display name should not be updated | ||
250 | 195 | assert mocked_last_name_edit_text.call_count == 0 | ||
251 | 196 | assert mocked_display_edit_setText.call_count == 0 | ||
252 | 197 | |||
253 | 198 | def test_last_name_edited(self): | ||
254 | 199 | """ | ||
255 | 200 | Test the on_last_name_edited() method | ||
256 | 201 | """ | ||
257 | 202 | # GIVEN: An author form | ||
258 | 203 | self.form.auto_display_name = True | ||
259 | 204 | |||
260 | 205 | with patch.object(self.form.first_name_edit, 'text') as mocked_first_name_edit_text, \ | ||
261 | 206 | patch.object(self.form.display_edit, 'setText') as mocked_display_edit_setText: | ||
262 | 207 | mocked_first_name_edit_text.return_value = 'John' | ||
263 | 208 | |||
264 | 209 | # WHEN: on_last_name_edited() is called | ||
265 | 210 | self.form.on_last_name_edited('Newton') | ||
266 | 211 | |||
267 | 212 | # THEN: The display name should be updated | ||
268 | 213 | assert mocked_first_name_edit_text.call_count == 2 | ||
269 | 214 | mocked_display_edit_setText.assert_called_once_with('John Newton') | ||
270 | 215 | |||
271 | 216 | def test_last_name_edited_no_auto(self): | ||
272 | 217 | """ | ||
273 | 218 | Test the on_last_name_edited() method without auto_display_name | ||
274 | 219 | """ | ||
275 | 220 | # GIVEN: An author form | ||
276 | 221 | self.form.auto_display_name = False | ||
277 | 222 | |||
278 | 223 | with patch.object(self.form.first_name_edit, 'text') as mocked_first_name_edit_text, \ | ||
279 | 224 | patch.object(self.form.display_edit, 'setText') as mocked_display_edit_setText: | ||
280 | 225 | |||
281 | 226 | # WHEN: on_last_name_edited() is called | ||
282 | 227 | self.form.on_last_name_edited('Newton') | ||
283 | 228 | |||
284 | 229 | # THEN: The display name should not be updated | ||
285 | 230 | assert mocked_first_name_edit_text.call_count == 0 | ||
286 | 231 | assert mocked_display_edit_setText.call_count == 0 | ||
287 | 232 | |||
288 | 233 | @patch('openlp.plugins.songs.forms.authorsform.critical_error_message_box') | ||
289 | 234 | def test_accept_no_first_name(self, mocked_critical_error): | ||
290 | 235 | """ | ||
291 | 236 | Test the accept() method with no first name | ||
292 | 237 | """ | ||
293 | 238 | # GIVEN: A form and no text in thefirst name edit | ||
294 | 239 | with patch.object(self.form.first_name_edit, 'text') as mocked_first_name_edit_text, \ | ||
295 | 240 | patch.object(self.form.first_name_edit, 'setFocus') as mocked_first_name_edit_setFocus: | ||
296 | 241 | mocked_first_name_edit_text.return_value = '' | ||
297 | 242 | |||
298 | 243 | # WHEN: accept() is called | ||
299 | 244 | result = self.form.accept() | ||
300 | 245 | |||
301 | 246 | # THEN: The result should be false and a critical error displayed | ||
302 | 247 | assert result is False | ||
303 | 248 | mocked_critical_error.assert_called_once_with(message='You need to type in the first name of the author.') | ||
304 | 249 | mocked_first_name_edit_text.assert_called_once_with() | ||
305 | 250 | mocked_first_name_edit_setFocus.assert_called_once_with() | ||
306 | 251 | |||
307 | 252 | @patch('openlp.plugins.songs.forms.authorsform.critical_error_message_box') | ||
308 | 253 | def test_accept_no_last_name(self, mocked_critical_error): | ||
309 | 254 | """ | ||
310 | 255 | Test the accept() method with no last name | ||
311 | 256 | """ | ||
312 | 257 | # GIVEN: A form and no text in the last name edit | ||
313 | 258 | with patch.object(self.form.first_name_edit, 'text') as mocked_first_name_edit_text, \ | ||
314 | 259 | patch.object(self.form.last_name_edit, 'text') as mocked_last_name_edit_text, \ | ||
315 | 260 | patch.object(self.form.last_name_edit, 'setFocus') as mocked_last_name_edit_setFocus: | ||
316 | 261 | mocked_first_name_edit_text.return_value = 'John' | ||
317 | 262 | mocked_last_name_edit_text.return_value = '' | ||
318 | 263 | |||
319 | 264 | # WHEN: accept() is called | ||
320 | 265 | result = self.form.accept() | ||
321 | 266 | |||
322 | 267 | # THEN: The result should be false and a critical error displayed | ||
323 | 268 | assert result is False | ||
324 | 269 | mocked_critical_error.assert_called_once_with(message='You need to type in the last name of the author.') | ||
325 | 270 | mocked_first_name_edit_text.assert_called_once_with() | ||
326 | 271 | mocked_last_name_edit_text.assert_called_once_with() | ||
327 | 272 | mocked_last_name_edit_setFocus.assert_called_once_with() | ||
328 | 273 | |||
329 | 274 | @patch('openlp.plugins.songs.forms.authorsform.critical_error_message_box') | ||
330 | 275 | def test_accept_no_display_name_no_combine(self, mocked_critical_error): | ||
331 | 276 | """ | ||
332 | 277 | Test the accept() method with no display name and no combining | ||
333 | 278 | """ | ||
334 | 279 | # GIVEN: A form and no text in the display name edit | ||
335 | 280 | mocked_critical_error.return_value = QtWidgets.QMessageBox.No | ||
336 | 281 | with patch.object(self.form.first_name_edit, 'text') as mocked_first_name_edit_text, \ | ||
337 | 282 | patch.object(self.form.last_name_edit, 'text') as mocked_last_name_edit_text, \ | ||
338 | 283 | patch.object(self.form.display_edit, 'text') as mocked_display_edit_text, \ | ||
339 | 284 | patch.object(self.form.display_edit, 'setFocus') as mocked_display_edit_setFocus: | ||
340 | 285 | mocked_first_name_edit_text.return_value = 'John' | ||
341 | 286 | mocked_last_name_edit_text.return_value = 'Newton' | ||
342 | 287 | mocked_display_edit_text.return_value = '' | ||
343 | 288 | |||
344 | 289 | # WHEN: accept() is called | ||
345 | 290 | result = self.form.accept() | ||
346 | 291 | |||
347 | 292 | # THEN: The result should be false and a critical error displayed | ||
348 | 293 | assert result is False | ||
349 | 294 | mocked_critical_error.assert_called_once_with( | ||
350 | 295 | message='You have not set a display name for the author, combine the first and last names?', | ||
351 | 296 | parent=self.form, question=True) | ||
352 | 297 | mocked_first_name_edit_text.assert_called_once_with() | ||
353 | 298 | mocked_last_name_edit_text.assert_called_once_with() | ||
354 | 299 | mocked_display_edit_text.assert_called_once_with() | ||
355 | 300 | mocked_display_edit_setFocus.assert_called_once_with() | ||
356 | 301 | |||
357 | 302 | @patch('openlp.plugins.songs.forms.authorsform.critical_error_message_box') | ||
358 | 303 | @patch('openlp.plugins.songs.forms.authorsform.QtWidgets.QDialog.accept') | ||
359 | 304 | def test_accept_no_display_name(self, mocked_accept, mocked_critical_error): | ||
360 | 305 | """ | ||
361 | 306 | Test the accept() method with no display name and auto-combine | ||
362 | 307 | """ | ||
363 | 308 | # GIVEN: A form and no text in the display name edit | ||
364 | 309 | mocked_accept.return_value = True | ||
365 | 310 | mocked_critical_error.return_value = QtWidgets.QMessageBox.Yes | ||
366 | 311 | with patch.object(self.form.first_name_edit, 'text') as mocked_first_name_edit_text, \ | ||
367 | 312 | patch.object(self.form.last_name_edit, 'text') as mocked_last_name_edit_text, \ | ||
368 | 313 | patch.object(self.form.display_edit, 'text') as mocked_display_edit_text, \ | ||
369 | 314 | patch.object(self.form.display_edit, 'setText') as mocked_display_edit_setText: | ||
370 | 315 | mocked_first_name_edit_text.return_value = 'John' | ||
371 | 316 | mocked_last_name_edit_text.return_value = 'Newton' | ||
372 | 317 | mocked_display_edit_text.return_value = '' | ||
373 | 318 | |||
374 | 319 | # WHEN: accept() is called | ||
375 | 320 | result = self.form.accept() | ||
376 | 321 | |||
377 | 322 | # THEN: The result should be false and a critical error displayed | ||
378 | 323 | assert result is True | ||
379 | 324 | mocked_critical_error.assert_called_once_with( | ||
380 | 325 | message='You have not set a display name for the author, combine the first and last names?', | ||
381 | 326 | parent=self.form, question=True) | ||
382 | 327 | assert mocked_first_name_edit_text.call_count == 2 | ||
383 | 328 | assert mocked_last_name_edit_text.call_count == 2 | ||
384 | 329 | mocked_display_edit_text.assert_called_once_with() | ||
385 | 330 | mocked_display_edit_setText.assert_called_once_with('John Newton') | ||
386 | 331 | mocked_accept.assert_called_once_with(self.form) | ||
387 | 332 | |||
388 | 333 | @patch('openlp.plugins.songs.forms.authorsform.QtWidgets.QDialog.accept') | ||
389 | 334 | def test_accept(self, mocked_accept): | ||
390 | 335 | """ | ||
391 | 336 | Test the accept() method | ||
392 | 337 | """ | ||
393 | 338 | # GIVEN: A form and text in the right places | ||
394 | 339 | mocked_accept.return_value = True | ||
395 | 340 | with patch.object(self.form.first_name_edit, 'text') as mocked_first_name_edit_text, \ | ||
396 | 341 | patch.object(self.form.last_name_edit, 'text') as mocked_last_name_edit_text, \ | ||
397 | 342 | patch.object(self.form.display_edit, 'text') as mocked_display_edit_text: | ||
398 | 343 | mocked_first_name_edit_text.return_value = 'John' | ||
399 | 344 | mocked_last_name_edit_text.return_value = 'Newton' | ||
400 | 345 | mocked_display_edit_text.return_value = 'John Newton' | ||
401 | 346 | |||
402 | 347 | # WHEN: accept() is called | ||
403 | 348 | result = self.form.accept() | ||
404 | 349 | |||
405 | 350 | # THEN: The result should be false and a critical error displayed | ||
406 | 351 | assert result is True | ||
407 | 352 | mocked_first_name_edit_text.assert_called_once_with() | ||
408 | 353 | mocked_last_name_edit_text.assert_called_once_with() | ||
409 | 354 | mocked_display_edit_text.assert_called_once_with() | ||
410 | 355 | mocked_accept.assert_called_once_with(self.form) |