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
1=== modified file 'openlp/plugins/songs/forms/songselectform.py'
2--- openlp/plugins/songs/forms/songselectform.py 2014-08-27 23:18:06 +0000
3+++ openlp/plugins/songs/forms/songselectform.py 2014-11-09 01:00:56 +0000
4@@ -89,13 +89,19 @@
5
6 def __init__(self, parent=None, plugin=None, db_manager=None):
7 QtGui.QDialog.__init__(self, parent)
8+ self.plugin = plugin
9+ self.db_manager = db_manager
10 self.setup_ui(self)
11+
12+ def initialise(self):
13+ """
14+ Initialise the SongSelectForm
15+ """
16 self.thread = None
17 self.worker = None
18 self.song_count = 0
19 self.song = None
20- self.plugin = plugin
21- self.song_select_importer = SongSelectImport(db_manager)
22+ self.song_select_importer = SongSelectImport(self.db_manager)
23 self.save_password_checkbox.toggled.connect(self.on_save_password_checkbox_toggled)
24 self.login_button.clicked.connect(self.on_login_button_clicked)
25 self.search_button.clicked.connect(self.on_search_button_clicked)
26@@ -264,6 +270,9 @@
27 self.login_progress_bar.setValue(0)
28 self.login_spacer.setVisible(True)
29 self.login_button.setEnabled(True)
30+ self.username_edit.setEnabled(True)
31+ self.password_edit.setEnabled(True)
32+ self.save_password_checkbox.setEnabled(True)
33 self.search_combobox.setFocus()
34 self.application.process_events()
35
36
37=== modified file 'openlp/plugins/songs/songsplugin.py'
38--- openlp/plugins/songs/songsplugin.py 2014-07-09 12:33:26 +0000
39+++ openlp/plugins/songs/songsplugin.py 2014-11-09 01:00:56 +0000
40@@ -104,6 +104,7 @@
41 log.info('Songs Initialising')
42 super(SongsPlugin, self).initialise()
43 self.songselect_form = SongSelectForm(Registry().get('main_window'), self, self.manager)
44+ self.songselect_form.initialise()
45 self.song_import_item.setVisible(True)
46 self.song_export_item.setVisible(True)
47 self.tools_reindex_item.setVisible(True)
48
49=== modified file 'tests/functional/openlp_plugins/songs/test_songselect.py'
50--- tests/functional/openlp_plugins/songs/test_songselect.py 2014-05-07 10:25:36 +0000
51+++ tests/functional/openlp_plugins/songs/test_songselect.py 2014-11-09 01:00:56 +0000
52@@ -31,14 +31,17 @@
53 """
54 from unittest import TestCase
55 from urllib.error import URLError
56+from openlp.core import Registry
57+from openlp.plugins.songs.forms.songselectform import SongSelectForm
58 from openlp.plugins.songs.lib import Author, Song
59
60 from openlp.plugins.songs.lib.songselect import SongSelectImport, LOGOUT_URL, BASE_URL
61
62 from tests.functional import MagicMock, patch, call
63-
64-
65-class TestSongSelect(TestCase):
66+from tests.helpers.testmixin import TestMixin
67+
68+
69+class TestSongSelectImport(TestCase, TestMixin):
70 """
71 Test the :class:`~openlp.plugins.songs.lib.songselect.SongSelectImport` class
72 """
73@@ -380,3 +383,87 @@
74 mocked_db_manager.get_object_filtered.assert_called_with(MockedAuthor, False)
75 self.assertEqual(0, MockedAuthor.populate.call_count, 'A new author should not have been instantiated')
76 self.assertEqual(1, len(result.authors_songs), 'There should only be one author')
77+
78+
79+class TestSongSelectForm(TestCase, TestMixin):
80+ """
81+ Test the :class:`~openlp.plugins.songs.forms.songselectform.SongSelectForm` class
82+ """
83+ def setUp(self):
84+ """
85+ Some set up for this test suite
86+ """
87+ self.setup_application()
88+ self.app.setApplicationVersion('0.0')
89+ self.app.process_events = lambda: None
90+ Registry.create()
91+ Registry().register('application', self.app)
92+
93+ def create_form_test(self):
94+ """
95+ Test that we can create the SongSelect form
96+ """
97+ # GIVEN: The SongSelectForm class and a mocked db manager
98+ mocked_plugin = MagicMock()
99+ mocked_db_manager = MagicMock()
100+
101+ # WHEN: We create an instance
102+ ssform = SongSelectForm(None, mocked_plugin, mocked_db_manager)
103+
104+ # THEN: The correct properties should have been assigned
105+ self.assertEqual(mocked_plugin, ssform.plugin, 'The correct plugin should have been assigned')
106+ self.assertEqual(mocked_db_manager, ssform.db_manager, 'The correct db_manager should have been assigned')
107+
108+ def login_fails_test(self):
109+ """
110+ Test that when the login fails, the form returns to the correct state
111+ """
112+ # GIVEN: A valid SongSelectForm with a mocked out SongSelectImport, and a bunch of mocked out controls
113+ with patch('openlp.plugins.songs.forms.songselectform.SongSelectImport') as MockedSongSelectImport, \
114+ patch('openlp.plugins.songs.forms.songselectform.QtGui.QMessageBox.critical') as mocked_critical, \
115+ patch('openlp.plugins.songs.forms.songselectform.translate') as mocked_translate:
116+ mocked_song_select_import = MagicMock()
117+ mocked_song_select_import.login.return_value = False
118+ MockedSongSelectImport.return_value = mocked_song_select_import
119+ mocked_translate.side_effect = lambda *args: args[1]
120+ ssform = SongSelectForm(None, MagicMock(), MagicMock())
121+ ssform.initialise()
122+ with patch.object(ssform, 'username_edit') as mocked_username_edit, \
123+ patch.object(ssform, 'password_edit') as mocked_password_edit, \
124+ patch.object(ssform, 'save_password_checkbox') as mocked_save_password_checkbox, \
125+ patch.object(ssform, 'login_button') as mocked_login_button, \
126+ patch.object(ssform, 'login_spacer') as mocked_login_spacer, \
127+ patch.object(ssform, 'login_progress_bar') as mocked_login_progress_bar, \
128+ patch.object(ssform.application, 'process_events') as mocked_process_events:
129+
130+ # WHEN: The login button is clicked, and the login is rigged to fail
131+ ssform.on_login_button_clicked()
132+
133+ # THEN: The right things should have happened in the right order
134+ expected_username_calls = [call(False), call(True)]
135+ expected_password_calls = [call(False), call(True)]
136+ expected_save_password_calls = [call(False), call(True)]
137+ expected_login_btn_calls = [call(False), call(True)]
138+ expected_login_spacer_calls = [call(False), call(True)]
139+ expected_login_progress_visible_calls = [call(True), call(False)]
140+ expected_login_progress_value_calls = [call(0), call(0)]
141+ self.assertEqual(expected_username_calls, mocked_username_edit.setEnabled.call_args_list,
142+ 'The username edit should be disabled then enabled')
143+ self.assertEqual(expected_password_calls, mocked_password_edit.setEnabled.call_args_list,
144+ 'The password edit should be disabled then enabled')
145+ self.assertEqual(expected_save_password_calls, mocked_save_password_checkbox.setEnabled.call_args_list,
146+ 'The save password checkbox should be disabled then enabled')
147+ self.assertEqual(expected_login_btn_calls, mocked_login_button.setEnabled.call_args_list,
148+ 'The login button should be disabled then enabled')
149+ self.assertEqual(expected_login_spacer_calls, mocked_login_spacer.setVisible.call_args_list,
150+ 'Thee login spacer should be make invisible, then visible')
151+ self.assertEqual(expected_login_progress_visible_calls,
152+ mocked_login_progress_bar.setVisible.call_args_list,
153+ 'Thee login progress bar should be make visible, then invisible')
154+ self.assertEqual(expected_login_progress_value_calls, mocked_login_progress_bar.setValue.call_args_list,
155+ 'Thee login progress bar should have the right values set')
156+ self.assertEqual(2, mocked_process_events.call_count,
157+ 'The process_events() method should be called twice')
158+ mocked_critical.assert_called_with(ssform, 'Error Logging In', 'There was a problem logging in, '
159+ 'perhaps your username or password is '
160+ 'incorrect?')