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

Proposed by Raoul Snyman
Status: Merged
Merged at revision: 2443
Proposed branch: lp:~raoul-snyman/openlp/bug-1306950
Merge into: lp:openlp
Diff against target: 160 lines (+102/-5)
3 files modified
openlp/plugins/songs/forms/songselectform.py (+11/-2)
openlp/plugins/songs/songsplugin.py (+1/-0)
tests/functional/openlp_plugins/songs/test_songselect.py (+90/-3)
To merge this branch: bzr merge lp:~raoul-snyman/openlp/bug-1306950
Reviewer Review Type Date Requested Status
Tim Bentley Approve
Review via email: mp+241192@code.launchpad.net
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
=== modified file 'openlp/plugins/songs/forms/songselectform.py'
--- openlp/plugins/songs/forms/songselectform.py 2014-08-27 23:18:06 +0000
+++ openlp/plugins/songs/forms/songselectform.py 2014-11-09 01:00:56 +0000
@@ -89,13 +89,19 @@
8989
90 def __init__(self, parent=None, plugin=None, db_manager=None):90 def __init__(self, parent=None, plugin=None, db_manager=None):
91 QtGui.QDialog.__init__(self, parent)91 QtGui.QDialog.__init__(self, parent)
92 self.plugin = plugin
93 self.db_manager = db_manager
92 self.setup_ui(self)94 self.setup_ui(self)
95
96 def initialise(self):
97 """
98 Initialise the SongSelectForm
99 """
93 self.thread = None100 self.thread = None
94 self.worker = None101 self.worker = None
95 self.song_count = 0102 self.song_count = 0
96 self.song = None103 self.song = None
97 self.plugin = plugin104 self.song_select_importer = SongSelectImport(self.db_manager)
98 self.song_select_importer = SongSelectImport(db_manager)
99 self.save_password_checkbox.toggled.connect(self.on_save_password_checkbox_toggled)105 self.save_password_checkbox.toggled.connect(self.on_save_password_checkbox_toggled)
100 self.login_button.clicked.connect(self.on_login_button_clicked)106 self.login_button.clicked.connect(self.on_login_button_clicked)
101 self.search_button.clicked.connect(self.on_search_button_clicked)107 self.search_button.clicked.connect(self.on_search_button_clicked)
@@ -264,6 +270,9 @@
264 self.login_progress_bar.setValue(0)270 self.login_progress_bar.setValue(0)
265 self.login_spacer.setVisible(True)271 self.login_spacer.setVisible(True)
266 self.login_button.setEnabled(True)272 self.login_button.setEnabled(True)
273 self.username_edit.setEnabled(True)
274 self.password_edit.setEnabled(True)
275 self.save_password_checkbox.setEnabled(True)
267 self.search_combobox.setFocus()276 self.search_combobox.setFocus()
268 self.application.process_events()277 self.application.process_events()
269278
270279
=== modified file 'openlp/plugins/songs/songsplugin.py'
--- openlp/plugins/songs/songsplugin.py 2014-07-09 12:33:26 +0000
+++ openlp/plugins/songs/songsplugin.py 2014-11-09 01:00:56 +0000
@@ -104,6 +104,7 @@
104 log.info('Songs Initialising')104 log.info('Songs Initialising')
105 super(SongsPlugin, self).initialise()105 super(SongsPlugin, self).initialise()
106 self.songselect_form = SongSelectForm(Registry().get('main_window'), self, self.manager)106 self.songselect_form = SongSelectForm(Registry().get('main_window'), self, self.manager)
107 self.songselect_form.initialise()
107 self.song_import_item.setVisible(True)108 self.song_import_item.setVisible(True)
108 self.song_export_item.setVisible(True)109 self.song_export_item.setVisible(True)
109 self.tools_reindex_item.setVisible(True)110 self.tools_reindex_item.setVisible(True)
110111
=== modified file 'tests/functional/openlp_plugins/songs/test_songselect.py'
--- tests/functional/openlp_plugins/songs/test_songselect.py 2014-05-07 10:25:36 +0000
+++ tests/functional/openlp_plugins/songs/test_songselect.py 2014-11-09 01:00:56 +0000
@@ -31,14 +31,17 @@
31"""31"""
32from unittest import TestCase32from unittest import TestCase
33from urllib.error import URLError33from urllib.error import URLError
34from openlp.core import Registry
35from openlp.plugins.songs.forms.songselectform import SongSelectForm
34from openlp.plugins.songs.lib import Author, Song36from openlp.plugins.songs.lib import Author, Song
3537
36from openlp.plugins.songs.lib.songselect import SongSelectImport, LOGOUT_URL, BASE_URL38from openlp.plugins.songs.lib.songselect import SongSelectImport, LOGOUT_URL, BASE_URL
3739
38from tests.functional import MagicMock, patch, call40from tests.functional import MagicMock, patch, call
3941from tests.helpers.testmixin import TestMixin
4042
41class TestSongSelect(TestCase):43
44class TestSongSelectImport(TestCase, TestMixin):
42 """45 """
43 Test the :class:`~openlp.plugins.songs.lib.songselect.SongSelectImport` class46 Test the :class:`~openlp.plugins.songs.lib.songselect.SongSelectImport` class
44 """47 """
@@ -380,3 +383,87 @@
380 mocked_db_manager.get_object_filtered.assert_called_with(MockedAuthor, False)383 mocked_db_manager.get_object_filtered.assert_called_with(MockedAuthor, False)
381 self.assertEqual(0, MockedAuthor.populate.call_count, 'A new author should not have been instantiated')384 self.assertEqual(0, MockedAuthor.populate.call_count, 'A new author should not have been instantiated')
382 self.assertEqual(1, len(result.authors_songs), 'There should only be one author')385 self.assertEqual(1, len(result.authors_songs), 'There should only be one author')
386
387
388class TestSongSelectForm(TestCase, TestMixin):
389 """
390 Test the :class:`~openlp.plugins.songs.forms.songselectform.SongSelectForm` class
391 """
392 def setUp(self):
393 """
394 Some set up for this test suite
395 """
396 self.setup_application()
397 self.app.setApplicationVersion('0.0')
398 self.app.process_events = lambda: None
399 Registry.create()
400 Registry().register('application', self.app)
401
402 def create_form_test(self):
403 """
404 Test that we can create the SongSelect form
405 """
406 # GIVEN: The SongSelectForm class and a mocked db manager
407 mocked_plugin = MagicMock()
408 mocked_db_manager = MagicMock()
409
410 # WHEN: We create an instance
411 ssform = SongSelectForm(None, mocked_plugin, mocked_db_manager)
412
413 # THEN: The correct properties should have been assigned
414 self.assertEqual(mocked_plugin, ssform.plugin, 'The correct plugin should have been assigned')
415 self.assertEqual(mocked_db_manager, ssform.db_manager, 'The correct db_manager should have been assigned')
416
417 def login_fails_test(self):
418 """
419 Test that when the login fails, the form returns to the correct state
420 """
421 # GIVEN: A valid SongSelectForm with a mocked out SongSelectImport, and a bunch of mocked out controls
422 with patch('openlp.plugins.songs.forms.songselectform.SongSelectImport') as MockedSongSelectImport, \
423 patch('openlp.plugins.songs.forms.songselectform.QtGui.QMessageBox.critical') as mocked_critical, \
424 patch('openlp.plugins.songs.forms.songselectform.translate') as mocked_translate:
425 mocked_song_select_import = MagicMock()
426 mocked_song_select_import.login.return_value = False
427 MockedSongSelectImport.return_value = mocked_song_select_import
428 mocked_translate.side_effect = lambda *args: args[1]
429 ssform = SongSelectForm(None, MagicMock(), MagicMock())
430 ssform.initialise()
431 with patch.object(ssform, 'username_edit') as mocked_username_edit, \
432 patch.object(ssform, 'password_edit') as mocked_password_edit, \
433 patch.object(ssform, 'save_password_checkbox') as mocked_save_password_checkbox, \
434 patch.object(ssform, 'login_button') as mocked_login_button, \
435 patch.object(ssform, 'login_spacer') as mocked_login_spacer, \
436 patch.object(ssform, 'login_progress_bar') as mocked_login_progress_bar, \
437 patch.object(ssform.application, 'process_events') as mocked_process_events:
438
439 # WHEN: The login button is clicked, and the login is rigged to fail
440 ssform.on_login_button_clicked()
441
442 # THEN: The right things should have happened in the right order
443 expected_username_calls = [call(False), call(True)]
444 expected_password_calls = [call(False), call(True)]
445 expected_save_password_calls = [call(False), call(True)]
446 expected_login_btn_calls = [call(False), call(True)]
447 expected_login_spacer_calls = [call(False), call(True)]
448 expected_login_progress_visible_calls = [call(True), call(False)]
449 expected_login_progress_value_calls = [call(0), call(0)]
450 self.assertEqual(expected_username_calls, mocked_username_edit.setEnabled.call_args_list,
451 'The username edit should be disabled then enabled')
452 self.assertEqual(expected_password_calls, mocked_password_edit.setEnabled.call_args_list,
453 'The password edit should be disabled then enabled')
454 self.assertEqual(expected_save_password_calls, mocked_save_password_checkbox.setEnabled.call_args_list,
455 'The save password checkbox should be disabled then enabled')
456 self.assertEqual(expected_login_btn_calls, mocked_login_button.setEnabled.call_args_list,
457 'The login button should be disabled then enabled')
458 self.assertEqual(expected_login_spacer_calls, mocked_login_spacer.setVisible.call_args_list,
459 'Thee login spacer should be make invisible, then visible')
460 self.assertEqual(expected_login_progress_visible_calls,
461 mocked_login_progress_bar.setVisible.call_args_list,
462 'Thee login progress bar should be make visible, then invisible')
463 self.assertEqual(expected_login_progress_value_calls, mocked_login_progress_bar.setValue.call_args_list,
464 'Thee login progress bar should have the right values set')
465 self.assertEqual(2, mocked_process_events.call_count,
466 'The process_events() method should be called twice')
467 mocked_critical.assert_called_with(ssform, 'Error Logging In', 'There was a problem logging in, '
468 'perhaps your username or password is '
469 'incorrect?')