Merge lp:~diegosarmentero/ubuntu-sso-client/qt-signals into lp:ubuntu-sso-client
- qt-signals
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Roberto Alsina |
Approved revision: | 856 |
Merged at revision: | 861 |
Proposed branch: | lp:~diegosarmentero/ubuntu-sso-client/qt-signals |
Merge into: | lp:ubuntu-sso-client |
Prerequisite: | lp:~diegosarmentero/ubuntu-sso-client/qt-refactor |
Diff against target: |
743 lines (+253/-74) 13 files modified
ubuntu_sso/qt/current_user_sign_in_page.py (+10/-16) ubuntu_sso/qt/email_verification_page.py (+9/-11) ubuntu_sso/qt/forgotten_password_page.py (+4/-2) ubuntu_sso/qt/gui.py (+0/-5) ubuntu_sso/qt/reset_password_page.py (+4/-7) ubuntu_sso/qt/setup_account_page.py (+8/-6) ubuntu_sso/qt/sign_in_page.py (+8/-6) ubuntu_sso/qt/tests/test_current_user_sign_in_page.py (+31/-17) ubuntu_sso/qt/tests/test_email_verification.py (+18/-0) ubuntu_sso/qt/tests/test_forgotten_password.py (+10/-1) ubuntu_sso/qt/tests/test_setup_account.py (+45/-0) ubuntu_sso/qt/tests/test_sign_in_page.py (+27/-1) ubuntu_sso/qt/ubuntu_sso_wizard.py (+79/-2) |
To merge this branch: | bzr merge lp:~diegosarmentero/ubuntu-sso-client/qt-signals |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Roberto Alsina (community) | Approve | ||
Natalia Bidart (community) | Approve | ||
Review via email: mp+92580@code.launchpad.net |
Commit message
- Added signals for the different pages, letting the wizard decide what to do in each case.
Description of the change
Roberto Alsina (ralsina) wrote : | # |
+1 nice way not to fight the toolkit ;-)
Ubuntu One Auto Pilot (otto-pilot) wrote : | # |
The attempt to merge lp:~diegosarmentero/ubuntu-sso-client/qt-signals into lp:ubuntu-sso-client failed. Below is the output from the failed tests.
*** Running GTK test suite for ubuntu_sso ***
ubuntu_
AccountTestCase
test_
test_
test_
test_
test_
test_
test_
test_
test_
test_
test_
test_
test_
test_
test_
test_
test_
test_
test_
test_
test_
test_
EnvironOverri
test_
test_
test_
twisted.
TestCase
runTest ... [OK]
ubuntu_
TimestampedAu
test_
ubuntu_
BasicTestCase
runTest ... [OK]
ClearCredenti
test_
test_
CredentialsCa
test_
test_
test_
test_
tes...
Ubuntu One Auto Pilot (otto-pilot) wrote : | # |
No proposals found for merge of lp:~diegosarmentero/ubuntu-sso-client/qt-refactor into lp:ubuntu-sso-client.
Ubuntu One Auto Pilot (otto-pilot) wrote : | # |
The attempt to merge lp:~diegosarmentero/ubuntu-sso-client/qt-signals into lp:ubuntu-sso-client failed. Below is the output from the failed tests.
*** Running GTK test suite for ubuntu_sso ***
ubuntu_
AccountTestCase
test_
test_
test_
test_
test_
test_
test_
test_
test_
test_
test_
test_
test_
test_
test_
test_
test_
test_
test_
test_
test_
test_
EnvironOverri
test_
test_
test_
twisted.
TestCase
runTest ... [OK]
ubuntu_
TimestampedAu
test_
ubuntu_
BasicTestCase
runTest ... [OK]
ClearCredenti
test_
test_
CredentialsCa
test_
test_
test_
test_
tes...
Preview Diff
1 | === modified file 'ubuntu_sso/qt/current_user_sign_in_page.py' |
2 | --- ubuntu_sso/qt/current_user_sign_in_page.py 2012-02-10 21:27:52 +0000 |
3 | +++ ubuntu_sso/qt/current_user_sign_in_page.py 2012-02-10 21:27:52 +0000 |
4 | @@ -18,7 +18,7 @@ |
5 | |
6 | import gettext |
7 | |
8 | -from PyQt4 import QtGui |
9 | +from PyQt4 import QtGui, QtCore |
10 | from twisted.internet import defer |
11 | |
12 | from ubuntu_sso.qt import build_general_error_message |
13 | @@ -40,6 +40,10 @@ |
14 | class CurrentUserSignInPage(SSOWizardPage): |
15 | """Wizard Page that lets a current user Sign into Ubuntu One.""" |
16 | |
17 | + userLoggedIn = QtCore.pyqtSignal('QString', 'QString') |
18 | + passwordForgotten = QtCore.pyqtSignal() |
19 | + userNotValidated = QtCore.pyqtSignal('QString', 'QString') |
20 | + |
21 | def __init__(self, ui, *args, **kwargs): |
22 | super(CurrentUserSignInPage, self).__init__(ui, *args, **kwargs) |
23 | |
24 | @@ -53,14 +57,11 @@ |
25 | } |
26 | self.setup_page() |
27 | |
28 | - # pylint: disable=W0212 |
29 | def on_user_not_validated(self, *args): |
30 | """Show the validate email page.""" |
31 | - self.next = self.wizard()._pages[self.wizard().email_verification] |
32 | email = unicode(self.ui.email_edit.text()) |
33 | - self.wizard().page(self.next).set_titles(email) |
34 | - self.wizard().next() |
35 | - # pylint: enable=W0212 |
36 | + password = unicode(self.ui.password_edit.text()) |
37 | + self.userNotValidated.emit(email, password) |
38 | |
39 | @defer.inlineCallbacks |
40 | def setup_page(self): |
41 | @@ -98,10 +99,6 @@ |
42 | self.ui.sign_in_button.style().polish( |
43 | self.ui.sign_in_button) |
44 | |
45 | - def cleanupPage(self): |
46 | - """Reset the state of the wizard if Verification code was visited.""" |
47 | - self.wizard()._next_id = None |
48 | - |
49 | def _set_translated_strings(self): |
50 | """Set the translated strings.""" |
51 | logger.debug('CurrentUserSignInPage._set_translated_strings') |
52 | @@ -148,17 +145,14 @@ |
53 | self.message_box.critical(self, self.app_name, |
54 | build_general_error_message(error)) |
55 | |
56 | - # pylint: disable=W0212 |
57 | def on_logged_in(self, app_name, result): |
58 | """We managed to log in.""" |
59 | logger.info('Logged in for %s', app_name) |
60 | - self.next = self.wizard()._pages[self.wizard().success] |
61 | - self.wizard().next() |
62 | + email = unicode(self.ui.email_edit.text()) |
63 | + self.userLoggedIn.emit(app_name, email) |
64 | logger.debug('Wizard.loginSuccess emitted.') |
65 | |
66 | def on_forgotten_password(self): |
67 | """Show the user the forgotten password page.""" |
68 | logger.info('Forgotten password') |
69 | - self.next = self.wizard()._pages[self.wizard().forgotten] |
70 | - self.wizard().next() |
71 | - # pylint: enable=W0212 |
72 | + self.passwordForgotten.emit() |
73 | |
74 | === modified file 'ubuntu_sso/qt/email_verification_page.py' |
75 | --- ubuntu_sso/qt/email_verification_page.py 2012-02-10 21:27:52 +0000 |
76 | +++ ubuntu_sso/qt/email_verification_page.py 2012-02-10 21:27:52 +0000 |
77 | @@ -16,6 +16,7 @@ |
78 | |
79 | """Email Verification page UI.""" |
80 | |
81 | +from PyQt4 import QtCore |
82 | from twisted.internet import defer |
83 | |
84 | from ubuntu_sso.qt import build_general_error_message |
85 | @@ -34,9 +35,12 @@ |
86 | class EmailVerificationPage(SSOWizardPage): |
87 | """Widget used to input the email verification code.""" |
88 | |
89 | + registrationSuccess = QtCore.pyqtSignal('QString', 'QString') |
90 | + |
91 | def __init__(self, ui, *args, **kwargs): |
92 | super(EmailVerificationPage, self).__init__(ui, *args, **kwargs) |
93 | self.email = '' |
94 | + self.password = '' |
95 | self._signals = { |
96 | 'EmailValidated': |
97 | self._filter_by_app_name(self.on_email_validated), |
98 | @@ -76,10 +80,8 @@ |
99 | self.next_button.setEnabled(enabled) |
100 | self.next_button.setProperty('DisabledState', |
101 | not self.next_button.isEnabled()) |
102 | - self.next_button.style().unpolish( |
103 | - self.next_button) |
104 | - self.next_button.style().polish( |
105 | - self.next_button) |
106 | + self.next_button.style().unpolish(self.next_button) |
107 | + self.next_button.style().polish(self.next_button) |
108 | |
109 | def _set_titles(self): |
110 | """Set the different titles.""" |
111 | @@ -96,23 +98,19 @@ |
112 | Since the subtitle contains data that is only known after SetupAccount |
113 | and _set_titles is only called on initialization. |
114 | """ |
115 | - self.email = email |
116 | self._set_titles() |
117 | |
118 | def validate_email(self): |
119 | """Call the next action.""" |
120 | logger.debug('EmailVerificationController.validate_email') |
121 | - email = unicode(self.wizard().field('email_address').toString()) |
122 | - password = unicode(self.wizard().field('password').toString()) |
123 | code = unicode(self.ui.verification_code_edit.text()) |
124 | - self.backend.validate_email(self.app_name, email, |
125 | - password, code) |
126 | + self.backend.validate_email(self.app_name, |
127 | + self.email, self.password, code) |
128 | |
129 | def on_email_validated(self, app_name, *args, **kwargs): |
130 | """Signal thrown after the email is validated.""" |
131 | logger.info('EmailVerificationController.on_email_validated') |
132 | - email = self.wizard().field('email_address').toString() |
133 | - self.wizard().registrationSuccess.emit(app_name, email) |
134 | + self.registrationSuccess.emit(app_name, self.email) |
135 | |
136 | def on_email_validation_error(self, app_name, error): |
137 | """Signal thrown when there's a problem validating the email.""" |
138 | |
139 | === modified file 'ubuntu_sso/qt/forgotten_password_page.py' |
140 | --- ubuntu_sso/qt/forgotten_password_page.py 2012-02-10 21:27:52 +0000 |
141 | +++ ubuntu_sso/qt/forgotten_password_page.py 2012-02-10 21:27:52 +0000 |
142 | @@ -16,6 +16,7 @@ |
143 | |
144 | """Forgotten Password page UI.""" |
145 | |
146 | +from PyQt4 import QtCore |
147 | from twisted.internet import defer |
148 | |
149 | from ubuntu_sso.qt.gui import SSOWizardEnhancedEditPage |
150 | @@ -33,6 +34,8 @@ |
151 | class ForgottenPasswordPage(SSOWizardEnhancedEditPage): |
152 | """Widget used to deal with users that forgot the password.""" |
153 | |
154 | + passwordResetTokenSent = QtCore.pyqtSignal() |
155 | + |
156 | def __init__(self, ui, *args, **kwargs): |
157 | super(ForgottenPasswordPage, self).__init__(ui, *args, **kwargs) |
158 | self._signals = { |
159 | @@ -160,8 +163,7 @@ |
160 | def on_password_reset_token_sent(self): |
161 | """Action taken when we managed to get the password reset done.""" |
162 | # ignore the result and move to the reset page |
163 | - self.next = self.wizard()._pages[self.wizard().reset_password] |
164 | - self.wizard().next() |
165 | + self.passwordResetTokenSent.emit() |
166 | # pylint: enable=W0212 |
167 | |
168 | def on_password_reset_error(self, app_name, error): |
169 | |
170 | === modified file 'ubuntu_sso/qt/gui.py' |
171 | --- ubuntu_sso/qt/gui.py 2012-02-10 21:27:52 +0000 |
172 | +++ ubuntu_sso/qt/gui.py 2012-02-10 21:27:52 +0000 |
173 | @@ -94,7 +94,6 @@ |
174 | self.header.set_subtitle(subtitle) |
175 | self.layout().insertWidget(0, self.header) |
176 | self.message_box = QMessageBox |
177 | - self.next = -1 |
178 | self._signals = {} |
179 | self._signals_receivers = {} |
180 | self.backend = None |
181 | @@ -108,10 +107,6 @@ |
182 | defer.returnValue(self.backend) |
183 | |
184 | # pylint: disable=C0103 |
185 | - def nextId(self): |
186 | - """Provide the next id.""" |
187 | - return self.next |
188 | - |
189 | def resizeEvent(self, event): |
190 | """Resize the overlay to fit all the widget.""" |
191 | QWizardPage.resizeEvent(self, event) |
192 | |
193 | === modified file 'ubuntu_sso/qt/reset_password_page.py' |
194 | --- ubuntu_sso/qt/reset_password_page.py 2012-02-10 21:27:52 +0000 |
195 | +++ ubuntu_sso/qt/reset_password_page.py 2012-02-10 21:27:52 +0000 |
196 | @@ -17,6 +17,7 @@ |
197 | """Reset Password page UI.""" |
198 | |
199 | from PyQt4.QtCore import SIGNAL |
200 | +from PyQt4.QtCore import pyqtSignal |
201 | from PyQt4.QtGui import QApplication |
202 | from twisted.internet import defer |
203 | |
204 | @@ -42,6 +43,8 @@ |
205 | class ResetPasswordPage(SSOWizardEnhancedEditPage): |
206 | """Widget used to allow the user change his password.""" |
207 | |
208 | + passwordChanged = pyqtSignal('QString') |
209 | + |
210 | def __init__(self, ui, app_name=None, parent=None): |
211 | """Create a new instance.""" |
212 | super(ResetPasswordPage, self).__init__(ui, app_name, parent) |
213 | @@ -173,14 +176,8 @@ |
214 | def on_password_changed(self, app_name, result): |
215 | """Let user know that the password was changed.""" |
216 | email = unicode(self.wizard().forgotten.ui.email_line_edit.text()) |
217 | - self.wizard().current_user.ui.email_edit.setText(email) |
218 | self.overlay.hide() |
219 | - current_user_id = self.wizard().current_user_page_id |
220 | - visited_pages = self.wizard().visitedPages() |
221 | - for index in reversed(visited_pages): |
222 | - if index == current_user_id: |
223 | - break |
224 | - self.wizard().back() |
225 | + self.passwordChanged.emit(email) |
226 | |
227 | def on_password_change_error(self, app_name, error): |
228 | """Let the user know that there was an error.""" |
229 | |
230 | === modified file 'ubuntu_sso/qt/setup_account_page.py' |
231 | --- ubuntu_sso/qt/setup_account_page.py 2012-02-10 21:27:52 +0000 |
232 | +++ ubuntu_sso/qt/setup_account_page.py 2012-02-10 21:27:52 +0000 |
233 | @@ -87,6 +87,8 @@ |
234 | class SetupAccountPage(SSOWizardEnhancedEditPage): |
235 | """Customized Setup Account page for SSO.""" |
236 | |
237 | + userRegistered = QtCore.pyqtSignal('QString', 'QString') |
238 | + |
239 | def __init__(self, ui, subtitle, toc_link, policy_link, *args, **kwargs): |
240 | super(SetupAccountPage, self).__init__(ui, *args, **kwargs) |
241 | self._subtitle = subtitle |
242 | @@ -287,7 +289,7 @@ |
243 | logger.debug('SetUpAccountPage._set_titles') |
244 | self.header.set_title( |
245 | JOIN_HEADER_LABEL % {'app_name': self.app_name}) |
246 | - self.header.set_subtitle(self.wizard().help_text) |
247 | + self.header.set_subtitle(self._subtitle) |
248 | |
249 | def _register_fields(self): |
250 | """Register the diff fields of the Ui.""" |
251 | @@ -338,8 +340,9 @@ |
252 | def on_user_registered(self, app_name, result): |
253 | """Execute when the user did register.""" |
254 | logger.debug('SetUpAccountPage.on_user_registered') |
255 | - self.next = self.wizard().email_verification_page_id |
256 | - self.wizard().next() |
257 | + email = unicode(self.ui.email_edit.text()) |
258 | + password = unicode(self.ui.password_edit.text()) |
259 | + self.userRegistered.emit(email, password) |
260 | |
261 | def validate_form(self): |
262 | """Validate the info of the form and return an error.""" |
263 | @@ -390,9 +393,8 @@ |
264 | self.backend.register_user(self.app_name, email, |
265 | password, name, captcha_id, |
266 | captcha_solution) |
267 | - # Update validation page's title, which contains the email |
268 | - self.next = self.wizard()._pages[self.wizard().email_verification] |
269 | - self.wizard().page(self.next).set_titles(email) |
270 | + # Update validation page's title, which contains the email |
271 | + self.userRegistered.emit(email, password) |
272 | # pylint: enable=W0212 |
273 | |
274 | def is_correct_email(self, email_address): |
275 | |
276 | === modified file 'ubuntu_sso/qt/sign_in_page.py' |
277 | --- ubuntu_sso/qt/sign_in_page.py 2012-02-10 21:27:52 +0000 |
278 | +++ ubuntu_sso/qt/sign_in_page.py 2012-02-10 21:27:52 +0000 |
279 | @@ -18,7 +18,7 @@ |
280 | |
281 | import gettext |
282 | |
283 | -from PyQt4 import QtGui |
284 | +from PyQt4 import QtGui, QtCore |
285 | |
286 | from ubuntu_sso.qt.gui import SSOWizardPage |
287 | from ubuntu_sso.logger import setup_logging |
288 | @@ -36,6 +36,10 @@ |
289 | class SignInPage(SSOWizardPage): |
290 | """Wizard Page that lets the user Sign into Ubuntu One.""" |
291 | |
292 | + existingAccountSelected = QtCore.pyqtSignal() |
293 | + newAccountSelected = QtCore.pyqtSignal() |
294 | + singInCanceled = QtCore.pyqtSignal() |
295 | + |
296 | def __init__(self, ui, image_pixmap, *args, **kwargs): |
297 | super(SignInPage, self).__init__(ui, *args, **kwargs) |
298 | self.ui.image_label.setPixmap(image_pixmap) |
299 | @@ -62,14 +66,12 @@ |
300 | def _set_next_existing(self): |
301 | """Set the next id and fire signal.""" |
302 | logger.debug('SignInPage._set_next_existing') |
303 | - self.next = self.wizard().current_user_page_id |
304 | - self.wizard().next() |
305 | + self.existingAccountSelected.emit() |
306 | |
307 | def _set_next_new(self): |
308 | """Set the next id and fire signal.""" |
309 | logger.debug('SignInPage._set_next_new') |
310 | - self.next = self.wizard().setup_account_page_id |
311 | - self.wizard().next() |
312 | + self.newAccountSelected.emit() |
313 | |
314 | # Invalid names of Qt-inherited methods |
315 | # pylint: disable=C0103 |
316 | @@ -77,7 +79,7 @@ |
317 | def initializePage(self): |
318 | """Setup UI details.""" |
319 | self.ui.cancel_button.setText(_("Close window and setup later")) |
320 | - self.ui.cancel_button.clicked.connect(self.wizard().reject) |
321 | + self.ui.cancel_button.clicked.connect(self.singInCanceled.emit) |
322 | # Layout without custom button 1, |
323 | # without finish button |
324 | # without cancel |
325 | |
326 | === modified file 'ubuntu_sso/qt/tests/test_current_user_sign_in_page.py' |
327 | --- ubuntu_sso/qt/tests/test_current_user_sign_in_page.py 2012-02-10 21:27:52 +0000 |
328 | +++ ubuntu_sso/qt/tests/test_current_user_sign_in_page.py 2012-02-10 21:27:52 +0000 |
329 | @@ -26,6 +26,7 @@ |
330 | FakedBackend, |
331 | FakedObject, |
332 | FakePageUiStyle, |
333 | + FakeSignal, |
334 | FakeWizard, |
335 | FakeWizardButtonStyle, |
336 | ) |
337 | @@ -40,6 +41,13 @@ |
338 | def setUp(self): |
339 | yield super(CurrentUserSignInTestCase, self).setUp() |
340 | self.patch(gui.main, "get_sso_client", FakedBackend) |
341 | + self.signals_results = [] |
342 | + self.patch(current_user_sign_in_page.CurrentUserSignInPage, |
343 | + "userLoggedIn", FakeSignal()) |
344 | + self.patch(current_user_sign_in_page.CurrentUserSignInPage, |
345 | + "passwordForgotten", FakeSignal()) |
346 | + self.patch(current_user_sign_in_page.CurrentUserSignInPage, |
347 | + "userNotValidated", FakeSignal()) |
348 | self.ui = current_user_sign_in_page.CurrentUserSignInPage( |
349 | current_user_sign_in_ui.Ui_CurrentUserSignInPage(), |
350 | parent=None) |
351 | @@ -79,18 +87,17 @@ |
352 | |
353 | def test_on_user_not_validated(self): |
354 | """Test the navigation flow on user not validated.""" |
355 | - self.ui.on_user_not_validated() |
356 | - self.assertTrue('next' in self.wizard.called) |
357 | - self.assertEqual(self.ui.next, self.wizard.email_verification_id) |
358 | - |
359 | - def test_next_id(self): |
360 | - """Test if the object return the proper next id.""" |
361 | - email = 'email@example.com' |
362 | + email = 'email@example' |
363 | + password = 'password' |
364 | self.ui.ui.email_edit.setText(email) |
365 | + self.ui.ui.password_edit.setText(password) |
366 | + |
367 | + def slot(email, password): |
368 | + """Fake slot.""" |
369 | + self.signals_results.append((email, password)) |
370 | + self.ui.userNotValidated.connect(slot) |
371 | self.ui.on_user_not_validated() |
372 | - next_id = self.ui.nextId() |
373 | - self.assertEqual(next_id, self.wizard.email_verification_id) |
374 | - self.assertTrue(('set_titles', email) in self.wizard.called) |
375 | + self.assertTrue((email, password) in self.signals_results) |
376 | |
377 | def test_initialize_page(self): |
378 | """Test the initialization method.""" |
379 | @@ -111,11 +118,6 @@ |
380 | self.assertTrue(button.properties['unpolish']) |
381 | self.assertTrue(button.properties['polish']) |
382 | |
383 | - def test_cleanup_page(self): |
384 | - """Test the cleanupPage method.""" |
385 | - self.ui.cleanupPage() |
386 | - self.assertEqual(self.wizard._next_id, None) |
387 | - |
388 | def test_set_translated_strings(self): |
389 | """Test the translated string method.""" |
390 | self.ui._set_translated_strings() |
391 | @@ -191,11 +193,23 @@ |
392 | def test_on_logged_in(self): |
393 | """Test the on_login_error method.""" |
394 | app_name = 'my_app' |
395 | + email = 'email@example' |
396 | self.ui.app_name = app_name |
397 | + self.ui.ui.email_edit.setText(email) |
398 | + |
399 | + def slot(app, email): |
400 | + """Fake slot.""" |
401 | + self.signals_results.append((app, email)) |
402 | + self.ui.userLoggedIn.connect(slot) |
403 | self.ui.on_logged_in(app_name, None) |
404 | - self.assertEqual(self.ui.next, self.wizard.success_id) |
405 | + self.assertTrue((app_name, email) in self.signals_results) |
406 | |
407 | def test_on_forgotten_password(self): |
408 | """Test the on_login_error method.""" |
409 | + |
410 | + def slot(): |
411 | + """Fake slot.""" |
412 | + self.signals_results.append(1) |
413 | + self.ui.passwordForgotten.connect(slot) |
414 | self.ui.on_forgotten_password() |
415 | - self.assertEqual(self.ui.next, self.wizard.forgotten_id) |
416 | + self.assertTrue(1 in self.signals_results) |
417 | |
418 | === modified file 'ubuntu_sso/qt/tests/test_email_verification.py' |
419 | --- ubuntu_sso/qt/tests/test_email_verification.py 2012-02-10 21:27:52 +0000 |
420 | +++ ubuntu_sso/qt/tests/test_email_verification.py 2012-02-10 21:27:52 +0000 |
421 | @@ -26,6 +26,7 @@ |
422 | FakedBackend, |
423 | FakedObject, |
424 | FakePageUiStyle, |
425 | + FakeSignal, |
426 | FakeWizard, |
427 | ) |
428 | from ubuntu_sso.qt.ui import email_verification_ui |
429 | @@ -38,7 +39,10 @@ |
430 | @defer.inlineCallbacks |
431 | def setUp(self): |
432 | yield super(EmailVerificationTestCase, self).setUp() |
433 | + self.signals_results = [] |
434 | self.patch(gui.main, "get_sso_client", FakedBackend) |
435 | + self.patch(email_verification_page.EmailVerificationPage, |
436 | + "registrationSuccess", FakeSignal()) |
437 | self.ui = email_verification_page.EmailVerificationPage( |
438 | email_verification_ui.Ui_EmailVerificationPage(), |
439 | parent=None) |
440 | @@ -149,3 +153,17 @@ |
441 | self.ui.on_email_validation_error(app_name, error) |
442 | expected = ((self.ui, app_name, ''), {}) |
443 | self.assertTrue(expected, self._called) |
444 | + |
445 | + def test_on_email_validated(self): |
446 | + """Test the on_email_validated method.""" |
447 | + app_name = 'my_app' |
448 | + email = 'email@example' |
449 | + self.ui.app_name = app_name |
450 | + self.ui.email = email |
451 | + |
452 | + def slot(app, email): |
453 | + """Fake slot.""" |
454 | + self.signals_results.append((app, email)) |
455 | + self.ui.registrationSuccess.connect(slot) |
456 | + self.ui.on_email_validated(app_name) |
457 | + self.assertTrue((app_name, email) in self.signals_results) |
458 | |
459 | === modified file 'ubuntu_sso/qt/tests/test_forgotten_password.py' |
460 | --- ubuntu_sso/qt/tests/test_forgotten_password.py 2012-02-10 21:27:52 +0000 |
461 | +++ ubuntu_sso/qt/tests/test_forgotten_password.py 2012-02-10 21:27:52 +0000 |
462 | @@ -26,6 +26,7 @@ |
463 | FakedBackend, |
464 | FakedObject, |
465 | FakePageUiStyle, |
466 | + FakeSignal, |
467 | FakeWizard, |
468 | ) |
469 | from ubuntu_sso.qt.ui import forgotten_password_ui |
470 | @@ -38,6 +39,9 @@ |
471 | @defer.inlineCallbacks |
472 | def setUp(self): |
473 | yield super(ForgottenPasswordTestCase, self).setUp() |
474 | + self.signals_results = [] |
475 | + self.patch(forgotten_password_page.ForgottenPasswordPage, |
476 | + "passwordResetTokenSent", FakeSignal()) |
477 | self.patch(gui.main, "get_sso_client", FakedBackend) |
478 | self.ui = forgotten_password_page.ForgottenPasswordPage( |
479 | forgotten_password_ui.Ui_ForgottenPasswordPage(), |
480 | @@ -201,8 +205,13 @@ |
481 | |
482 | def test_on_password_reset_token_sent(self): |
483 | """Test on_password_reset_token_sent method.""" |
484 | + |
485 | + def slot(): |
486 | + """Fake slot.""" |
487 | + self.signals_results.append(1) |
488 | + self.ui.passwordResetTokenSent.connect(slot) |
489 | self.ui.on_password_reset_token_sent() |
490 | - self.assertEqual(self.ui.next, self.wizard.reset_password_id) |
491 | + self.assertTrue(1 in self.signals_results) |
492 | |
493 | def test_on_password_reset_error(self): |
494 | """Test on_password_reset_error method.""" |
495 | |
496 | === modified file 'ubuntu_sso/qt/tests/test_setup_account.py' |
497 | --- ubuntu_sso/qt/tests/test_setup_account.py 2012-02-10 21:27:52 +0000 |
498 | +++ ubuntu_sso/qt/tests/test_setup_account.py 2012-02-10 21:27:52 +0000 |
499 | @@ -26,7 +26,9 @@ |
500 | from ubuntu_sso.qt.tests import ( |
501 | BaseTestCase, |
502 | FakedBackend, |
503 | + FakedObject, |
504 | FakeOverlay, |
505 | + FakeSignal, |
506 | FakeWizard, |
507 | ) |
508 | from ubuntu_sso.qt.ui import setup_account_ui |
509 | @@ -39,6 +41,9 @@ |
510 | def setUp(self): |
511 | yield super(SetupAccountTestCase, self).setUp() |
512 | self.patch(gui.main, "get_sso_client", FakedBackend) |
513 | + self.signals_results = [] |
514 | + self.patch(setup_account_page.SetupAccountPage, |
515 | + "userRegistered", FakeSignal()) |
516 | self.ui = setup_account_page.SetupAccountPage( |
517 | setup_account_ui.Ui_SetUpAccountPage(), |
518 | 'subtitle', |
519 | @@ -126,6 +131,46 @@ |
520 | self.ui.focus_changed(self.ui.ui.confirm_password_edit, None) |
521 | self.assertTrue(self._called) |
522 | |
523 | + def test_on_user_registered(self): |
524 | + """Test on_user_registered method.""" |
525 | + exposed_methods = ['register_user'] |
526 | + self.patch(FakedObject, "exposed_methods", exposed_methods) |
527 | + faked_object = FakedObject() |
528 | + self.patch(self.ui, "backend", faked_object) |
529 | + self.patch(self.ui, "validate_form", lambda: True) |
530 | + |
531 | + email = 'email@example' |
532 | + password = 'password' |
533 | + name = 'name' |
534 | + captcha_id = 1 |
535 | + captcha_solution = 'solution' |
536 | + self.ui.ui.email_edit.setText(email) |
537 | + self.ui.ui.password_edit.setText(password) |
538 | + self.ui.ui.name_edit.setText(name) |
539 | + self.ui.captcha_id = captcha_id |
540 | + self.ui.ui.captcha_solution_edit.setText(captcha_solution) |
541 | + |
542 | + def slot(email, password): |
543 | + """Fake slot.""" |
544 | + self.signals_results.append((email, password)) |
545 | + self.ui.userRegistered.connect(slot) |
546 | + self.ui.set_next_validation() |
547 | + self.assertTrue((email, password) in self.signals_results) |
548 | + |
549 | + def test_set_next_validation(self): |
550 | + """Test on_user_registered method.""" |
551 | + email = 'email@example' |
552 | + password = 'password' |
553 | + self.ui.ui.email_edit.setText(email) |
554 | + self.ui.ui.password_edit.setText(password) |
555 | + |
556 | + def slot(email, password): |
557 | + """Fake slot.""" |
558 | + self.signals_results.append((email, password)) |
559 | + self.ui.userRegistered.connect(slot) |
560 | + self.ui.on_user_registered('app_name', None) |
561 | + self.assertTrue((email, password) in self.signals_results) |
562 | + |
563 | |
564 | class SetupAccountFakeWizardTestCase(BaseTestCase): |
565 | """Test the SetupAccountPage code.""" |
566 | |
567 | === modified file 'ubuntu_sso/qt/tests/test_sign_in_page.py' |
568 | --- ubuntu_sso/qt/tests/test_sign_in_page.py 2012-02-10 21:27:52 +0000 |
569 | +++ ubuntu_sso/qt/tests/test_sign_in_page.py 2012-02-10 21:27:52 +0000 |
570 | @@ -21,7 +21,7 @@ |
571 | |
572 | from ubuntu_sso.qt import sign_in_page as gui |
573 | from ubuntu_sso.qt.ui.choose_sign_in_ui import Ui_ChooseSignInPage |
574 | -from ubuntu_sso.qt.tests import BaseTestCase, FakeMainWindow |
575 | +from ubuntu_sso.qt.tests import BaseTestCase, FakeMainWindow, FakeSignal |
576 | |
577 | |
578 | class SignInPageTestCase(BaseTestCase): |
579 | @@ -31,6 +31,10 @@ |
580 | def setUp(self): |
581 | """Initialize this test instance.""" |
582 | yield super(SignInPageTestCase, self).setUp() |
583 | + self.signals_results = [] |
584 | + self.patch(gui.SignInPage, "existingAccountSelected", FakeSignal()) |
585 | + self.patch(gui.SignInPage, "newAccountSelected", FakeSignal()) |
586 | + self.patch(gui.SignInPage, "singInCanceled", FakeSignal()) |
587 | self.ui = gui.SignInPage(Ui_ChooseSignInPage(), QtGui.QPixmap()) |
588 | |
589 | def test_show_event(self): |
590 | @@ -41,3 +45,25 @@ |
591 | self.ui.show() |
592 | self.addCleanup(self.ui.hide) |
593 | self.assertTrue(self.ui.ui.existing_account_button.isDefault()) |
594 | + |
595 | + # pylint: disable=W0212 |
596 | + def test_set_next_existing(self): |
597 | + """Test _set_next_existing method.""" |
598 | + |
599 | + def slot(): |
600 | + """Fake slot.""" |
601 | + self.signals_results.append(1) |
602 | + self.ui.existingAccountSelected.connect(slot) |
603 | + self.ui._set_next_existing() |
604 | + self.assertTrue(1 in self.signals_results) |
605 | + |
606 | + def test_set_next_new(self): |
607 | + """Test _set_next_existing method.""" |
608 | + |
609 | + def slot(): |
610 | + """Fake slot.""" |
611 | + self.signals_results.append(1) |
612 | + self.ui.newAccountSelected.connect(slot) |
613 | + self.ui._set_next_new() |
614 | + self.assertTrue(1 in self.signals_results) |
615 | + # pylint: enable=W0212 |
616 | |
617 | === modified file 'ubuntu_sso/qt/ubuntu_sso_wizard.py' |
618 | --- ubuntu_sso/qt/ubuntu_sso_wizard.py 2012-02-10 21:27:52 +0000 |
619 | +++ ubuntu_sso/qt/ubuntu_sso_wizard.py 2012-02-10 21:27:52 +0000 |
620 | @@ -58,6 +58,7 @@ |
621 | """Create a new wizard.""" |
622 | parent = kwargs.get('parent') |
623 | super(UbuntuSSOWizard, self).__init__(parent) |
624 | + self._next_id = -1 |
625 | |
626 | # store common useful data provided by the app |
627 | self.app_name = app_name |
628 | @@ -77,18 +78,36 @@ |
629 | app_name=self.app_name, |
630 | title='Sign in', |
631 | parent=self) |
632 | + self.sign_in_page.singInCanceled.connect(self.reject) |
633 | + self.sign_in_page.existingAccountSelected.connect( |
634 | + self._move_to_login_page) |
635 | + self.sign_in_page.newAccountSelected.connect( |
636 | + self._move_to_setup_account_page) |
637 | + |
638 | self.setup_account = SetupAccountPage(Ui_SetUpAccountPage(), |
639 | self.help_text, |
640 | self.tc_url, |
641 | self.policy_url, |
642 | app_name=self.app_name, |
643 | parent=self) |
644 | + self.setup_account.userRegistered.connect( |
645 | + self._move_to_email_verification_page) |
646 | + |
647 | self.current_user = CurrentUserSignInPage(Ui_CurrentUserSignInPage(), |
648 | app_name=self.app_name, |
649 | parent=self) |
650 | + self.current_user.userNotValidated.connect( |
651 | + self._move_to_email_verification_page) |
652 | + self.current_user.userLoggedIn.connect(self._move_to_success_page) |
653 | + self.current_user.passwordForgotten.connect( |
654 | + self._move_to_forgotten_page) |
655 | + |
656 | self.email_verification = EmailVerificationPage( |
657 | Ui_EmailVerificationPage(), |
658 | app_name=self.app_name) |
659 | + self.email_verification.registrationSuccess.connect( |
660 | + self._move_to_success_page) |
661 | + |
662 | self.success = SuccessPage(Ui_SuccessPage(), |
663 | app_name=self.app_name, parent=self) |
664 | self.error = ErrorPage(Ui_ErrorPage(), |
665 | @@ -96,9 +115,14 @@ |
666 | self.forgotten = ForgottenPasswordPage(Ui_ForgottenPasswordPage(), |
667 | app_name=self.app_name, |
668 | parent=self) |
669 | + self.forgotten.passwordResetTokenSent.connect( |
670 | + self._move_to_forgotten_page) |
671 | + |
672 | self.reset_password = ResetPasswordPage(Ui_ResetPasswordPage(), |
673 | app_name=self.app_name, |
674 | parent=self) |
675 | + self.reset_password.passwordChanged.connect( |
676 | + self._go_back_to_current_page) |
677 | # store the ids of the pages so that it is easier to access them later |
678 | pages = [self.sign_in_page, self.setup_account, |
679 | self.email_verification, self.current_user, self.success, |
680 | @@ -118,8 +142,61 @@ |
681 | self.setWizardStyle(QWizard.ModernStyle) |
682 | self.button(QWizard.CancelButton).clicked.connect( |
683 | self.on_user_cancelation) |
684 | - self.loginSuccess.connect(self.on_login_success) |
685 | - self.registrationSuccess.connect(self.on_registration_success) |
686 | + |
687 | + # pylint: disable=C0103 |
688 | + def nextId(self): |
689 | + """Return the id of the next page.""" |
690 | + return self._next_id |
691 | + # pylint: enable=C0103 |
692 | + |
693 | + def _go_back_to_current_page(self, email): |
694 | + """Move back until it reaches the current user sign in page. """ |
695 | + self.current_user.ui.email_edit.setText(email) |
696 | + current_user_id = self.current_user_page_id |
697 | + visited_pages = self.visitedPages() |
698 | + for index in reversed(visited_pages): |
699 | + if index == current_user_id: |
700 | + break |
701 | + self.back() |
702 | + |
703 | + def _move_to_reset_password_page(self): |
704 | + """Move to the reset password page wizard.""" |
705 | + self._next_id = self.reset_password_page_id |
706 | + self.next() |
707 | + self._next_id = -1 |
708 | + |
709 | + def _move_to_email_verification_page(self, email, password): |
710 | + """Move to the email verification page wizard.""" |
711 | + self._next_id = self.email_verification_page_id |
712 | + self.email_verification.email = unicode(email) |
713 | + self.email_verification.password = unicode(password) |
714 | + self.email_verification.set_titles(email) |
715 | + self.next() |
716 | + self._next_id = -1 |
717 | + |
718 | + def _move_to_setup_account_page(self): |
719 | + """Move to the setup account page wizard.""" |
720 | + self._next_id = self.setup_account_page_id |
721 | + self.next() |
722 | + self._next_id = -1 |
723 | + |
724 | + def _move_to_login_page(self): |
725 | + """Move to the login page wizard.""" |
726 | + self._next_id = self.current_user_page_id |
727 | + self.next() |
728 | + self._next_id = -1 |
729 | + |
730 | + def _move_to_success_page(self, app_name='', email=''): |
731 | + """Move to the success page wizard.""" |
732 | + self._next_id = self.success_page_id |
733 | + self.next() |
734 | + self._next_id = -1 |
735 | + |
736 | + def _move_to_forgotten_page(self): |
737 | + """Move to the forgotten page wizard.""" |
738 | + self._next_id = self.forgotten_password_page_id |
739 | + self.next() |
740 | + self._next_id = -1 |
741 | |
742 | @property |
743 | def sign_in_page_id(self): |
Loosk good!