Merge lp:~diegosarmentero/ubuntu-sso-client/931452 into lp:ubuntu-sso-client
- 931452
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Natalia Bidart |
Approved revision: | 878 |
Merged at revision: | 877 |
Proposed branch: | lp:~diegosarmentero/ubuntu-sso-client/931452 |
Merge into: | lp:ubuntu-sso-client |
Diff against target: |
752 lines (+219/-95) 15 files modified
ubuntu_sso/qt/current_user_sign_in_page.py (+5/-1) ubuntu_sso/qt/email_verification_page.py (+6/-1) ubuntu_sso/qt/forgotten_password_page.py (+11/-3) ubuntu_sso/qt/gui.py (+7/-0) ubuntu_sso/qt/reset_password_page.py (+8/-1) ubuntu_sso/qt/setup_account_page.py (+13/-4) ubuntu_sso/qt/tests/__init__.py (+22/-2) ubuntu_sso/qt/tests/test_current_user_sign_in_page.py (+26/-22) ubuntu_sso/qt/tests/test_email_verification.py (+9/-11) ubuntu_sso/qt/tests/test_forgotten_password.py (+16/-9) ubuntu_sso/qt/tests/test_network_detection.py (+2/-4) ubuntu_sso/qt/tests/test_reset_password.py (+77/-31) ubuntu_sso/qt/tests/test_setup_account.py (+13/-2) ubuntu_sso/qt/tests/test_sign_in_page.py (+2/-2) ubuntu_sso/qt/tests/test_ubuntu_sso_wizard.py (+2/-2) |
To merge this branch: | bzr merge lp:~diegosarmentero/ubuntu-sso-client/931452 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Natalia Bidart (community) | Approve | ||
Brian Curtin (community) | Approve | ||
Manuel de la Peña (community) | Approve | ||
Review via email: mp+93003@code.launchpad.net |
Commit message
- Fixed: Qt UI: must call the backend passing reply_handler and error_handler (LP: #931452).
Description of the change
Manuel de la Peña (mandel) wrote : | # |
+1 nice use of partial!!!
Natalia Bidart (nataliabidart) wrote : | # |
The reply_handler and error_handler have to be passed to every backend call.
Also, I would advice using something like the gtk assert_
Diego Sarmentero (diegosarmentero) wrote : | # |
> Nice use of functools.partial
>
> The only change I would suggest is fairly minor: Your test conditions are
> always assertTrue(x in y). You could instead do assertIn(x, y).
Thanks for the suggestion Brian, done!
Diego Sarmentero (diegosarmentero) wrote : | # |
> The reply_handler and error_handler have to be passed to every backend call.
> Also, I would advice using something like the gtk assert_
> avoid duplicating the same code to assert the same things in every method.
Done!
- 874. By Diego Sarmentero
-
Several fixes regarding the tests
- 875. By Diego Sarmentero
-
Conflict resolved
- 876. By Diego Sarmentero
-
Removed commented code.
Brian Curtin (brian.curtin) wrote : | # |
Looks good to me.
Natalia Bidart (nataliabidart) wrote : | # |
Branch looks good!
Can you please use the new assert_
Natalia Bidart (nataliabidart) wrote : | # |
Hum, found a test failure, so changing my vote:
=======
[ERROR]
Traceback (most recent call last):
File "/home/
self.
exceptions.
ubuntu_
- 877. By Diego Sarmentero
-
Tests fixed
- 878. By Diego Sarmentero
-
Removing unnecessary lines of tests
Natalia Bidart (nataliabidart) wrote : | # |
Looks great!
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-13 20:27:48 +0000 |
3 | +++ ubuntu_sso/qt/current_user_sign_in_page.py 2012-02-17 14:21:18 +0000 |
4 | @@ -17,10 +17,12 @@ |
5 | """Page to allow the user to login into Ubuntu Single Sign On.""" |
6 | |
7 | import gettext |
8 | +from functools import partial |
9 | |
10 | from PyQt4 import QtGui, QtCore |
11 | from twisted.internet import defer |
12 | |
13 | +from ubuntu_sso import NO_OP |
14 | from ubuntu_sso.qt import build_general_error_message |
15 | from ubuntu_sso.qt.gui import SSOWizardPage |
16 | from ubuntu_sso.logger import setup_logging |
17 | @@ -147,7 +149,9 @@ |
18 | args = args + (self.ping_url,) |
19 | else: |
20 | f = self.backend.login |
21 | - f(*args) |
22 | + |
23 | + error_handler = partial(self._handle_error, f, self.on_login_error) |
24 | + f(*args, reply_handler=NO_OP, error_handler=error_handler) |
25 | |
26 | def on_login_error(self, app_name, error): |
27 | """There was an error when login in.""" |
28 | |
29 | === modified file 'ubuntu_sso/qt/email_verification_page.py' |
30 | --- ubuntu_sso/qt/email_verification_page.py 2012-02-13 14:04:27 +0000 |
31 | +++ ubuntu_sso/qt/email_verification_page.py 2012-02-17 14:21:18 +0000 |
32 | @@ -16,9 +16,12 @@ |
33 | |
34 | """Email Verification page UI.""" |
35 | |
36 | +from functools import partial |
37 | + |
38 | from PyQt4 import QtCore |
39 | from twisted.internet import defer |
40 | |
41 | +from ubuntu_sso import NO_OP |
42 | from ubuntu_sso.qt import build_general_error_message |
43 | from ubuntu_sso.qt.gui import SSOWizardPage |
44 | from ubuntu_sso.logger import setup_logging |
45 | @@ -115,7 +118,9 @@ |
46 | logger.info('Calling validate_email with email %r, password <hidden>, ' |
47 | 'app_name %r and email_token %r.', self.email, |
48 | self.app_name, code) |
49 | - f(*args) |
50 | + error_handler = partial(self._handle_error, f, |
51 | + self.on_email_validation_error) |
52 | + f(*args, reply_handler=NO_OP, error_handler=error_handler) |
53 | |
54 | def on_email_validated(self, app_name, *args, **kwargs): |
55 | """Signal thrown after the email is validated.""" |
56 | |
57 | === modified file 'ubuntu_sso/qt/forgotten_password_page.py' |
58 | --- ubuntu_sso/qt/forgotten_password_page.py 2012-02-13 21:50:16 +0000 |
59 | +++ ubuntu_sso/qt/forgotten_password_page.py 2012-02-17 14:21:18 +0000 |
60 | @@ -16,9 +16,12 @@ |
61 | |
62 | """Forgotten Password page UI.""" |
63 | |
64 | +from functools import partial |
65 | + |
66 | from PyQt4 import QtCore |
67 | from twisted.internet import defer |
68 | |
69 | +from ubuntu_sso import NO_OP |
70 | from ubuntu_sso.qt.gui import SSOWizardEnhancedEditPage |
71 | from ubuntu_sso.utils.ui import ( |
72 | EMAIL_LABEL, |
73 | @@ -139,10 +142,15 @@ |
74 | def _connect_ui(self): |
75 | """Connect the diff signals from the Ui.""" |
76 | self.email_address_line_edit.textChanged.connect(self._validate) |
77 | + args = (self.app_name, self.email_address) |
78 | + f = self.backend.request_password_reset_token |
79 | + |
80 | + error_handler = partial(self._handle_error, f, |
81 | + self.on_password_reset_error) |
82 | + |
83 | self.send_button.clicked.connect( |
84 | - lambda: self.backend.request_password_reset_token( |
85 | - self.app_name, |
86 | - self.email_address)) |
87 | + lambda: f(*args, reply_handler=NO_OP, |
88 | + error_handler=error_handler)) |
89 | self.try_again_button.clicked.connect(self.on_try_again) |
90 | |
91 | def _validate(self): |
92 | |
93 | === modified file 'ubuntu_sso/qt/gui.py' |
94 | --- ubuntu_sso/qt/gui.py 2012-02-13 16:16:03 +0000 |
95 | +++ ubuntu_sso/qt/gui.py 2012-02-17 14:21:18 +0000 |
96 | @@ -37,6 +37,7 @@ |
97 | from ubuntu_sso import main |
98 | from ubuntu_sso.qt.loadingoverlay import LoadingOverlay |
99 | from ubuntu_sso.logger import setup_logging |
100 | +from ubuntu_sso.utils.ui import GENERIC_BACKEND_ERROR |
101 | |
102 | |
103 | _ = gettext.gettext |
104 | @@ -149,6 +150,12 @@ |
105 | match = self.backend.connect_to_signal(signal, method) |
106 | self._signals_receivers[signal] = match |
107 | |
108 | + def _handle_error(self, remote_call, handler, error): |
109 | + """Handle any error when calling the remote backend.""" |
110 | + logger.error('Remote call %r failed with: %r', remote_call, error) |
111 | + errordict = {'message': GENERIC_BACKEND_ERROR} |
112 | + handler(self.app_name, errordict) |
113 | + |
114 | |
115 | class EnhancedLineEdit(object): |
116 | """Represents and enhanced lineedit. |
117 | |
118 | === modified file 'ubuntu_sso/qt/reset_password_page.py' |
119 | --- ubuntu_sso/qt/reset_password_page.py 2012-02-10 21:09:38 +0000 |
120 | +++ ubuntu_sso/qt/reset_password_page.py 2012-02-17 14:21:18 +0000 |
121 | @@ -16,11 +16,14 @@ |
122 | |
123 | """Reset Password page UI.""" |
124 | |
125 | +from functools import partial |
126 | + |
127 | from PyQt4.QtCore import SIGNAL |
128 | from PyQt4.QtCore import pyqtSignal |
129 | from PyQt4.QtGui import QApplication |
130 | from twisted.internet import defer |
131 | |
132 | +from ubuntu_sso import NO_OP |
133 | from ubuntu_sso.qt import build_general_error_message |
134 | from ubuntu_sso.qt.gui import SSOWizardEnhancedEditPage |
135 | from ubuntu_sso.qt import common |
136 | @@ -193,7 +196,11 @@ |
137 | password = unicode(self.ui.password_line_edit.text()) |
138 | logger.info('Setting new password for %r and email %r with code %r', |
139 | self.app_name, email, code) |
140 | - self.backend.set_new_password(self.app_name, email, code, password) |
141 | + args = (self.app_name, email, code, password) |
142 | + f = self.backend.set_new_password |
143 | + error_handler = partial(self._handle_error, f, |
144 | + self.on_password_change_error) |
145 | + f(*args, reply_handler=NO_OP, error_handler=error_handler) |
146 | |
147 | def is_correct_password_confirmation(self, password): |
148 | """Return if the password is correct.""" |
149 | |
150 | === modified file 'ubuntu_sso/qt/setup_account_page.py' |
151 | --- ubuntu_sso/qt/setup_account_page.py 2012-02-13 20:27:48 +0000 |
152 | +++ ubuntu_sso/qt/setup_account_page.py 2012-02-17 14:21:18 +0000 |
153 | @@ -19,6 +19,7 @@ |
154 | import StringIO |
155 | import tempfile |
156 | import os |
157 | +from functools import partial |
158 | |
159 | # pylint: disable=F0401 |
160 | try: |
161 | @@ -30,6 +31,7 @@ |
162 | from PyQt4 import QtGui, QtCore |
163 | from twisted.internet import defer |
164 | |
165 | +from ubuntu_sso import NO_OP |
166 | from ubuntu_sso.qt import build_general_error_message |
167 | from ubuntu_sso.qt import common |
168 | from ubuntu_sso.qt.gui import SSOWizardEnhancedEditPage |
169 | @@ -284,7 +286,11 @@ |
170 | fd = tempfile.TemporaryFile(mode='r') |
171 | file_name = fd.name |
172 | self.captcha_file = file_name |
173 | - self.backend.generate_captcha(self.app_name, file_name) |
174 | + args = (self.app_name, file_name) |
175 | + f = self.backend.generate_captcha |
176 | + error_handler = partial(self._handle_error, f, |
177 | + self.on_captcha_generation_error) |
178 | + f(*args, reply_handler=NO_OP, error_handler=error_handler) |
179 | self.on_captcha_refreshing() |
180 | |
181 | def _set_titles(self): |
182 | @@ -393,9 +399,12 @@ |
183 | # validate the current info of the form, try to perform the action |
184 | # to register the user, and then move foward |
185 | if self.validate_form(): |
186 | - self.backend.register_user(self.app_name, email, |
187 | - password, name, captcha_id, |
188 | - captcha_solution) |
189 | + args = (self.app_name, email, password, name, captcha_id, |
190 | + captcha_solution) |
191 | + f = self.backend.register_user |
192 | + error_handler = partial(self._handle_error, f, |
193 | + self.on_user_registration_error) |
194 | + f(*args, reply_handler=NO_OP, error_handler=error_handler) |
195 | # Update validation page's title, which contains the email |
196 | self.userRegistered.emit(email, password) |
197 | # pylint: enable=W0212 |
198 | |
199 | === modified file 'ubuntu_sso/qt/tests/__init__.py' |
200 | --- ubuntu_sso/qt/tests/__init__.py 2012-02-09 18:28:40 +0000 |
201 | +++ ubuntu_sso/qt/tests/__init__.py 2012-02-17 14:21:18 +0000 |
202 | @@ -21,7 +21,10 @@ |
203 | from twisted.trial.unittest import TestCase |
204 | from ubuntu_sso.qt import loadingoverlay |
205 | |
206 | -from ubuntu_sso import main |
207 | +from ubuntu_sso import ( |
208 | + main, |
209 | + NO_OP, |
210 | +) |
211 | |
212 | |
213 | class FakedObject(object): |
214 | @@ -29,7 +32,7 @@ |
215 | |
216 | next_result = None |
217 | exposed_methods = ['connect_to_signal', |
218 | - 'generate_captcha'] |
219 | + 'generate_captcha', 'request_password_reset_token'] |
220 | |
221 | def __init__(self, *args, **kwargs): |
222 | self._args = args |
223 | @@ -384,6 +387,23 @@ |
224 | """Store 'args' and 'kwargs' for test assertions.""" |
225 | self._called = (args, kwargs) |
226 | |
227 | + # pylint: disable=E1101, W0212 |
228 | + def assert_backend_called(self, method, *args, **kwargs): |
229 | + """Check that 'method(*args, **kwargs)' was called in the backend.""" |
230 | + self.assertIn(method, self.ui.backend._called) |
231 | + |
232 | + call = self.ui.backend._called[method] |
233 | + self.assertEqual(call[0], args) |
234 | + |
235 | + reply_handler = call[1].pop('reply_handler') |
236 | + self.assertEqual(reply_handler, NO_OP) |
237 | + |
238 | + error_handler = call[1].pop('error_handler') |
239 | + self.assertEqual(error_handler.func, self.ui._handle_error) |
240 | + |
241 | + self.assertEqual(call[1], kwargs) |
242 | + # pylint: enable=E1101, W0212 |
243 | + |
244 | |
245 | class BaseTestCaseUI(TestCase): |
246 | """Base Test Case.""" |
247 | |
248 | === modified file 'ubuntu_sso/qt/tests/test_current_user_sign_in_page.py' |
249 | --- ubuntu_sso/qt/tests/test_current_user_sign_in_page.py 2012-02-13 17:19:05 +0000 |
250 | +++ ubuntu_sso/qt/tests/test_current_user_sign_in_page.py 2012-02-17 14:21:18 +0000 |
251 | @@ -48,18 +48,20 @@ |
252 | "passwordForgotten", FakeSignal()) |
253 | self.patch(current_user_sign_in_page.CurrentUserSignInPage, |
254 | "userNotValidated", FakeSignal()) |
255 | + self.app_name = 'my_app' |
256 | self.ui = current_user_sign_in_page.CurrentUserSignInPage( |
257 | current_user_sign_in_ui.Ui_CurrentUserSignInPage(), |
258 | '', |
259 | + app_name=self.app_name, |
260 | parent=None) |
261 | self.wizard = FakeWizard() |
262 | self.patch(self.ui, 'wizard', lambda: self.wizard) |
263 | |
264 | def test_init(self): |
265 | """Test the construction of the object.""" |
266 | - self.assertTrue('LoggedIn' in self.ui._signals) |
267 | - self.assertTrue('LoginError' in self.ui._signals) |
268 | - self.assertTrue('UserNotValidated' in self.ui._signals) |
269 | + self.assertIn('LoggedIn', self.ui._signals) |
270 | + self.assertIn('LoginError', self.ui._signals) |
271 | + self.assertIn('UserNotValidated', self.ui._signals) |
272 | self.assertTrue(callable(self.ui._signals['LoggedIn'])) |
273 | self.assertTrue(callable(self.ui._signals['LoginError'])) |
274 | self.assertTrue(callable(self.ui._signals['UserNotValidated'])) |
275 | @@ -81,9 +83,9 @@ |
276 | self.patch(self.ui, "_connect_ui", |
277 | faked_object._connect_ui) |
278 | self.ui.setup_page() |
279 | - self.assertTrue('_set_translated_strings' in faked_object._called) |
280 | - self.assertTrue('_setup_signals' in faked_object._called) |
281 | - self.assertTrue('_connect_ui' in faked_object._called) |
282 | + self.assertIn('_set_translated_strings', faked_object._called) |
283 | + self.assertIn('_setup_signals', faked_object._called) |
284 | + self.assertIn('_connect_ui', faked_object._called) |
285 | # pylint: enable=E1101 |
286 | |
287 | def test_on_user_not_validated(self): |
288 | @@ -98,7 +100,7 @@ |
289 | self.signals_results.append((email, password)) |
290 | self.ui.userNotValidated.connect(slot) |
291 | self.ui.on_user_not_validated() |
292 | - self.assertTrue((email, password) in self.signals_results) |
293 | + self.assertIn((email, password), self.signals_results) |
294 | |
295 | def test_initialize_page(self): |
296 | """Test the initialization method.""" |
297 | @@ -110,8 +112,8 @@ |
298 | self.ui.initializePage() |
299 | self.assertEqual(wizard.buttons_text[QtGui.QWizard.CancelButton], |
300 | "Cancel") |
301 | - self.assertTrue(('setButtonLayout', |
302 | - (([QtGui.QWizard.BackButton, QtGui.QWizard.Stretch],), {})) in |
303 | + self.assertIn(('setButtonLayout', |
304 | + (([QtGui.QWizard.BackButton, QtGui.QWizard.Stretch],), {})), |
305 | wizard.called) |
306 | self.assertTrue(button.properties['default']) |
307 | self.assertFalse(button.isEnabled()) |
308 | @@ -178,12 +180,13 @@ |
309 | self.patch(FakedObject, "exposed_methods", exposed_methods) |
310 | faked_object = FakedObject() |
311 | self.patch(self.ui, "backend", faked_object) |
312 | - self.ui.ui.email_edit.setText('valid@email') |
313 | - self.ui.ui.password_edit.setText('123456') |
314 | + email = 'valid@email' |
315 | + password = '123456' |
316 | + self.ui.ui.email_edit.setText(email) |
317 | + self.ui.ui.password_edit.setText(password) |
318 | self.ui.login() |
319 | - self.assertTrue('login_and_ping' in self.ui.backend._called) |
320 | - self.assertEqual(self.ui.backend._called['login_and_ping'], |
321 | - ((None, u'valid@email', u'123456', ping), {})) |
322 | + self.assert_backend_called('login_and_ping', |
323 | + self.app_name, email, password, ping) |
324 | |
325 | def test_login_without_ping(self): |
326 | """Test the login method.""" |
327 | @@ -192,12 +195,13 @@ |
328 | self.patch(FakedObject, "exposed_methods", exposed_methods) |
329 | faked_object = FakedObject() |
330 | self.patch(self.ui, "backend", faked_object) |
331 | - self.ui.ui.email_edit.setText('valid@email') |
332 | - self.ui.ui.password_edit.setText('123456') |
333 | + email = 'valid@email' |
334 | + password = '123456' |
335 | + self.ui.ui.email_edit.setText(email) |
336 | + self.ui.ui.password_edit.setText(password) |
337 | self.ui.login() |
338 | - self.assertTrue('login' in self.ui.backend._called) |
339 | - self.assertEqual(self.ui.backend._called['login'], |
340 | - ((None, u'valid@email', u'123456'), {})) |
341 | + self.assert_backend_called('login', |
342 | + self.app_name, email, password) |
343 | |
344 | def test_on_login_error(self): |
345 | """Test the on_login_error method.""" |
346 | @@ -221,7 +225,7 @@ |
347 | self.signals_results.append((app, email)) |
348 | self.ui.userLoggedIn.connect(slot) |
349 | self.ui.on_logged_in(app_name, None) |
350 | - self.assertTrue((app_name, email) in self.signals_results) |
351 | + self.assertIn((app_name, email), self.signals_results) |
352 | |
353 | def test_on_forgotten_password(self): |
354 | """Test the on_forgotten_password method.""" |
355 | @@ -231,7 +235,7 @@ |
356 | self.signals_results.append(1) |
357 | self.ui.passwordForgotten.connect(slot) |
358 | self.ui.on_forgotten_password() |
359 | - self.assertTrue(1 in self.signals_results) |
360 | + self.assertIn(1, self.signals_results) |
361 | |
362 | def test_on_forgotten_password_link_clicked(self): |
363 | """Test the on_forgotten_password method.""" |
364 | @@ -241,4 +245,4 @@ |
365 | self.signals_results.append(1) |
366 | self.ui.passwordForgotten.connect(slot) |
367 | self.ui.ui.forgot_password_label.linkActivated.emit("link") |
368 | - self.assertTrue(1 in self.signals_results) |
369 | + self.assertIn(1, self.signals_results) |
370 | |
371 | === modified file 'ubuntu_sso/qt/tests/test_email_verification.py' |
372 | --- ubuntu_sso/qt/tests/test_email_verification.py 2012-02-13 14:04:27 +0000 |
373 | +++ ubuntu_sso/qt/tests/test_email_verification.py 2012-02-17 14:21:18 +0000 |
374 | @@ -51,8 +51,8 @@ |
375 | |
376 | def test_init(self): |
377 | """Test the construction of the object.""" |
378 | - self.assertTrue('EmailValidated' in self.ui._signals) |
379 | - self.assertTrue('EmailValidationError' in self.ui._signals) |
380 | + self.assertIn('EmailValidated', self.ui._signals) |
381 | + self.assertIn('EmailValidationError', self.ui._signals) |
382 | self.assertTrue(callable(self.ui._signals['EmailValidated'])) |
383 | self.assertTrue(callable(self.ui._signals['EmailValidationError'])) |
384 | self.assertEqual(self.ui.backend, FakedBackend.sso_login) |
385 | @@ -70,8 +70,8 @@ |
386 | self.patch(self.ui, "_connect_ui_elements", |
387 | faked_object._connect_ui_elements) |
388 | self.ui.setup_page() |
389 | - self.assertTrue('_setup_signals' in faked_object._called) |
390 | - self.assertTrue('_connect_ui_elements' in faked_object._called) |
391 | + self.assertIn('_setup_signals', faked_object._called) |
392 | + self.assertIn('_connect_ui_elements', faked_object._called) |
393 | # pylint: enable=E1101 |
394 | |
395 | def test_verification_code(self): |
396 | @@ -166,7 +166,7 @@ |
397 | self.signals_results.append((app, email)) |
398 | self.ui.registrationSuccess.connect(slot) |
399 | self.ui.on_email_validated(app_name) |
400 | - self.assertTrue((app_name, email) in self.signals_results) |
401 | + self.assertIn((app_name, email), self.signals_results) |
402 | |
403 | def test_validate_email_with_ping(self): |
404 | """Test the login method.""" |
405 | @@ -185,9 +185,8 @@ |
406 | faked_object = FakedObject() |
407 | self.patch(self.ui, "backend", faked_object) |
408 | self.ui.validate_email() |
409 | - self.assertTrue('validate_email_and_ping' in self.ui.backend._called) |
410 | - self.assertEqual(self.ui.backend._called['validate_email_and_ping'], |
411 | - ((app_name, email, password, code, ping), {})) |
412 | + self.assert_backend_called('validate_email_and_ping', |
413 | + app_name, email, password, code, ping) |
414 | |
415 | def test_validate_email_without_ping(self): |
416 | """Test the login method.""" |
417 | @@ -206,6 +205,5 @@ |
418 | faked_object = FakedObject() |
419 | self.patch(self.ui, "backend", faked_object) |
420 | self.ui.validate_email() |
421 | - self.assertTrue('validate_email' in self.ui.backend._called) |
422 | - self.assertEqual(self.ui.backend._called['validate_email'], |
423 | - ((app_name, email, password, code), {})) |
424 | + self.assert_backend_called('validate_email', |
425 | + app_name, email, password, code) |
426 | |
427 | === modified file 'ubuntu_sso/qt/tests/test_forgotten_password.py' |
428 | --- ubuntu_sso/qt/tests/test_forgotten_password.py 2012-02-13 21:50:16 +0000 |
429 | +++ ubuntu_sso/qt/tests/test_forgotten_password.py 2012-02-17 14:21:18 +0000 |
430 | @@ -40,19 +40,20 @@ |
431 | def setUp(self): |
432 | yield super(ForgottenPasswordTestCase, self).setUp() |
433 | self.signals_results = [] |
434 | + self.patch(gui.main, "get_sso_client", FakedBackend) |
435 | self.patch(forgotten_password_page.ForgottenPasswordPage, |
436 | "passwordResetTokenSent", FakeSignal()) |
437 | - self.patch(gui.main, "get_sso_client", FakedBackend) |
438 | + self.app_name = 'my_app' |
439 | self.ui = forgotten_password_page.ForgottenPasswordPage( |
440 | forgotten_password_ui.Ui_ForgottenPasswordPage(), |
441 | - parent=None) |
442 | + app_name=self.app_name, parent=None) |
443 | self.wizard = FakeWizard() |
444 | self.patch(self.ui, 'wizard', lambda: self.wizard) |
445 | |
446 | def test_init(self): |
447 | """Test the construction of the object.""" |
448 | - self.assertTrue('PasswordResetTokenSent' in self.ui._signals) |
449 | - self.assertTrue('PasswordResetError' in self.ui._signals) |
450 | + self.assertIn('PasswordResetTokenSent', self.ui._signals) |
451 | + self.assertIn('PasswordResetError', self.ui._signals) |
452 | self.assertTrue(callable(self.ui._signals['PasswordResetTokenSent'])) |
453 | self.assertTrue(callable(self.ui._signals['PasswordResetError'])) |
454 | self.assertEqual(self.ui.backend, FakedBackend.sso_login) |
455 | @@ -78,11 +79,11 @@ |
456 | self.patch(self.ui, "_register_fields", |
457 | faked_object._register_fields) |
458 | self.ui.setup_page() |
459 | - self.assertTrue('_setup_signals' in faked_object._called) |
460 | - self.assertTrue('_set_translated_strings' in faked_object._called) |
461 | - self.assertTrue('_connect_ui' in faked_object._called) |
462 | - self.assertTrue('_set_enhanced_line_edit' in faked_object._called) |
463 | - self.assertTrue('_register_fields' in faked_object._called) |
464 | + self.assertIn('_setup_signals', faked_object._called) |
465 | + self.assertIn('_set_translated_strings', faked_object._called) |
466 | + self.assertIn('_connect_ui', faked_object._called) |
467 | + self.assertIn('_set_enhanced_line_edit', faked_object._called) |
468 | + self.assertIn('_register_fields', faked_object._called) |
469 | |
470 | def test_email_widget(self): |
471 | """Test the email_widget property.""" |
472 | @@ -120,6 +121,12 @@ |
473 | self.assertEqual(value, self.ui.ui.send_button) |
474 | self.assertTrue(isinstance(value, QtGui.QPushButton)) |
475 | |
476 | + def test_send_button_clicked(self): |
477 | + """Test the send_button property.""" |
478 | + self.ui.send_button.clicked.emit(True) |
479 | + self.assert_backend_called('request_password_reset_token', |
480 | + self.app_name, '') |
481 | + |
482 | def test_try_again_widget(self): |
483 | """Test the try_again_widget property.""" |
484 | value = self.ui.try_again_widget |
485 | |
486 | === modified file 'ubuntu_sso/qt/tests/test_network_detection.py' |
487 | --- ubuntu_sso/qt/tests/test_network_detection.py 2012-02-02 15:44:18 +0000 |
488 | +++ ubuntu_sso/qt/tests/test_network_detection.py 2012-02-17 14:21:18 +0000 |
489 | @@ -60,10 +60,8 @@ |
490 | "wizard", FakeWizardButtonStyle) |
491 | self.network_detection.initializePage() |
492 | self.assertTrue(self.network_detection.btn_try_again.isDefault()) |
493 | - self.assertTrue( |
494 | - 'polish' in self.network_detection.btn_try_again.data) |
495 | - self.assertTrue( |
496 | - 'unpolish' in self.network_detection.btn_try_again.data) |
497 | + self.assertIn('polish', self.network_detection.btn_try_again.data) |
498 | + self.assertIn('unpolish', self.network_detection.btn_try_again.data) |
499 | self.assertEqual( |
500 | self.network_detection.btn_try_again.data['polish'], |
501 | self.network_detection.btn_try_again) |
502 | |
503 | === modified file 'ubuntu_sso/qt/tests/test_reset_password.py' |
504 | --- ubuntu_sso/qt/tests/test_reset_password.py 2012-02-09 18:09:29 +0000 |
505 | +++ ubuntu_sso/qt/tests/test_reset_password.py 2012-02-17 14:21:18 +0000 |
506 | @@ -19,7 +19,6 @@ |
507 | |
508 | from PyQt4 import QtGui, QtCore |
509 | from twisted.internet import defer |
510 | -from twisted.trial.unittest import TestCase |
511 | |
512 | from ubuntu_sso.utils.ui import ( |
513 | PASSWORD1_ENTRY, |
514 | @@ -33,7 +32,12 @@ |
515 | RESET_TITLE, |
516 | ) |
517 | from ubuntu_sso.qt.ui.reset_password_ui import Ui_ResetPasswordPage |
518 | -from ubuntu_sso.qt.tests import FakedBackend |
519 | +from ubuntu_sso.qt.tests import ( |
520 | + BaseTestCase, |
521 | + FakedBackend, |
522 | + FakedObject, |
523 | + FakeWizard, |
524 | +) |
525 | |
526 | |
527 | class FakePasswordAssistance(object): |
528 | @@ -50,52 +54,76 @@ |
529 | FakePasswordAssistance._called = False |
530 | |
531 | |
532 | -class ResetPasswordTestCase(TestCase): |
533 | +# We need this Fake until a future refactor. |
534 | +class FakeForgottenPage(object): |
535 | + |
536 | + """Fake Forgotten Page.""" |
537 | + |
538 | + def __init__(self): |
539 | + self.ui = self |
540 | + self.email_line_edit = self |
541 | + self.line_text = '' |
542 | + |
543 | + # pylint: disable=C0103 |
544 | + def setText(self, text): |
545 | + """Fake setText for Line edit.""" |
546 | + self.line_text = text |
547 | + # pylint: enable=C0103 |
548 | + |
549 | + def text(self): |
550 | + """Fake text for line edit.""" |
551 | + return self.line_text |
552 | + |
553 | + |
554 | +class ResetPasswordTestCase(BaseTestCase): |
555 | """Test the ResetPasswordPage code.""" |
556 | |
557 | @defer.inlineCallbacks |
558 | def setUp(self): |
559 | yield super(ResetPasswordTestCase, self).setUp() |
560 | self.patch(gui.main, "get_sso_client", FakedBackend) |
561 | - self.page = ResetPasswordPage(Ui_ResetPasswordPage(), |
562 | - 'app_name', |
563 | - None) |
564 | + self.app_name = 'my_app' |
565 | + self.ui = ResetPasswordPage(Ui_ResetPasswordPage(), |
566 | + app_name=self.app_name, |
567 | + parent=None) |
568 | + self.wizard = FakeWizard() |
569 | + self.patch(self.ui, 'wizard', lambda: self.wizard) |
570 | self.fake = FakePasswordAssistance() |
571 | |
572 | def test_init(self): |
573 | """Check the initial state of ResetPassword.""" |
574 | - self.assertEqual(self.page.ui.password_line_edit.receivers( |
575 | + self.assertEqual(self.ui.ui.password_line_edit.receivers( |
576 | QtCore.SIGNAL('textEdited(QString)')), 1) |
577 | - self.assertEqual(self.page.ui.confirm_password_line_edit.receivers( |
578 | + self.assertEqual(self.ui.ui.confirm_password_line_edit.receivers( |
579 | QtCore.SIGNAL('textEdited(QString)')), 1) |
580 | |
581 | def test_initialize(self): |
582 | """Check the Title and Subtitle.""" |
583 | - self.page.show() |
584 | - self.page.initializePage() |
585 | - self.addCleanup(self.page.hide) |
586 | - self.assertEqual(self.page.header.title_label.text(), RESET_TITLE) |
587 | - self.assertEqual(self.page.header.subtitle_label.text(), |
588 | + self.ui.show() |
589 | + self.ui.initializePage() |
590 | + self.addCleanup(self.ui.hide) |
591 | + self.assertEqual(self.ui.header.title_label.text(), RESET_TITLE) |
592 | + self.assertEqual(self.ui.header.subtitle_label.text(), |
593 | RESET_SUBTITLE) |
594 | - self.assertEqual(self.page.ui.password_label.text(), PASSWORD1_ENTRY) |
595 | - self.assertEqual(self.page.ui.confirm_password_label.text(), |
596 | + self.assertEqual(self.ui.ui.password_label.text(), PASSWORD1_ENTRY) |
597 | + self.assertEqual(self.ui.ui.confirm_password_label.text(), |
598 | PASSWORD2_ENTRY) |
599 | - self.assertEqual(self.page.ui.reset_code.text(), RESET_CODE_ENTRY) |
600 | + self.assertEqual(self.ui.ui.reset_code.text(), RESET_CODE_ENTRY) |
601 | |
602 | def test_focus_changed_password_visibility(self): |
603 | """Check visibility changes when focus_changed() is executed.""" |
604 | - self.page.show() |
605 | - self.addCleanup(self.page.hide) |
606 | - self.page.focus_changed(None, self.page.ui.password_line_edit) |
607 | - self.assertTrue(self.page.ui.password_assistance.isVisible()) |
608 | + self.ui.show() |
609 | + self.addCleanup(self.ui.hide) |
610 | + self.ui.focus_changed(None, self.ui.ui.password_line_edit) |
611 | + self.assertTrue(self.ui.ui.password_assistance.isVisible()) |
612 | |
613 | def test_show_hide_event(self): |
614 | """Check connections to focusChanged on show and hide event.""" |
615 | - self.page.show() |
616 | - self.addCleanup(self.page.hide) |
617 | + self.ui.show() |
618 | + self.addCleanup(self.ui.hide) |
619 | self.assertEqual(QtGui.QApplication.instance().receivers( |
620 | QtCore.SIGNAL("focusChanged(QWidget*, QWidget*)")), 1) |
621 | - self.page.hide() |
622 | + self.ui.hide() |
623 | self.assertEqual(QtGui.QApplication.instance().receivers( |
624 | QtCore.SIGNAL("focusChanged(QWidget*, QWidget*)")), 0) |
625 | |
626 | @@ -105,22 +133,40 @@ |
627 | """Check functions execution when focus_changed() is executed.""" |
628 | self.patch(common, 'password_default_assistance', self.fake.call) |
629 | self.addCleanup(self.fake.clenaup) |
630 | - self.page.show() |
631 | - self.addCleanup(self.page.hide) |
632 | + self.ui.show() |
633 | + self.addCleanup(self.ui.hide) |
634 | self.assertFalse(FakePasswordAssistance._called) |
635 | - self.page.focus_changed(None, self.page.ui.password_line_edit) |
636 | - self.assertTrue(self.page.ui.password_assistance.isVisible()) |
637 | + self.ui.focus_changed(None, self.ui.ui.password_line_edit) |
638 | + self.assertTrue(self.ui.ui.password_assistance.isVisible()) |
639 | self.assertTrue(FakePasswordAssistance._called) |
640 | |
641 | def test_focus_changed_2(self): |
642 | """Check functions execution when focus_changed() is executed.""" |
643 | self.patch(common, 'password_check_match', self.fake.call) |
644 | self.addCleanup(self.fake.clenaup) |
645 | - self.page.show() |
646 | - self.addCleanup(self.page.hide) |
647 | + self.ui.show() |
648 | + self.addCleanup(self.ui.hide) |
649 | self.assertFalse(FakePasswordAssistance._called) |
650 | - self.page.focus_changed(None, self.page.ui.confirm_password_line_edit) |
651 | - self.assertTrue(self.page.ui.password_assistance.isVisible()) |
652 | + self.ui.focus_changed(None, self.ui.ui.confirm_password_line_edit) |
653 | + self.assertTrue(self.ui.ui.password_assistance.isVisible()) |
654 | self.assertTrue(FakePasswordAssistance._called) |
655 | |
656 | # pylint: enable=W0212 |
657 | + |
658 | + def test_set_new_password(self): |
659 | + """Test set_new_password method.""" |
660 | + email = 'email@example.com' |
661 | + code = 'code' |
662 | + password = 'password' |
663 | + forgotten = FakeForgottenPage() |
664 | + forgotten.setText(email) |
665 | + self.patch(self.wizard, "forgotten", forgotten) |
666 | + exposed_methods = ['set_new_password'] |
667 | + self.patch(FakedObject, "exposed_methods", exposed_methods) |
668 | + faked_object = FakedObject() |
669 | + self.patch(self.ui, "backend", faked_object) |
670 | + self.ui.ui.reset_code_line_edit.setText(code) |
671 | + self.ui.ui.password_line_edit.setText(password) |
672 | + self.ui.set_new_password() |
673 | + self.assert_backend_called('set_new_password', |
674 | + self.app_name, email, code, password) |
675 | |
676 | === modified file 'ubuntu_sso/qt/tests/test_setup_account.py' |
677 | --- ubuntu_sso/qt/tests/test_setup_account.py 2012-02-10 21:09:38 +0000 |
678 | +++ ubuntu_sso/qt/tests/test_setup_account.py 2012-02-17 14:21:18 +0000 |
679 | @@ -44,11 +44,13 @@ |
680 | self.signals_results = [] |
681 | self.patch(setup_account_page.SetupAccountPage, |
682 | "userRegistered", FakeSignal()) |
683 | + self.app_name = 'my_app' |
684 | self.ui = setup_account_page.SetupAccountPage( |
685 | setup_account_ui.Ui_SetUpAccountPage(), |
686 | 'subtitle', |
687 | 'toc_link', |
688 | 'policy_link', |
689 | + app_name=self.app_name, |
690 | parent=None) |
691 | self.wizard = FakeWizard() |
692 | self.patch(self.ui, 'wizard', lambda: self.wizard) |
693 | @@ -155,7 +157,10 @@ |
694 | self.signals_results.append((email, password)) |
695 | self.ui.userRegistered.connect(slot) |
696 | self.ui.set_next_validation() |
697 | - self.assertTrue((email, password) in self.signals_results) |
698 | + self.assertIn((email, password), self.signals_results) |
699 | + self.assert_backend_called('register_user', |
700 | + self.app_name, email, password, name, captcha_id, |
701 | + captcha_solution) |
702 | |
703 | def test_set_next_validation(self): |
704 | """Test on_user_registered method.""" |
705 | @@ -169,7 +174,13 @@ |
706 | self.signals_results.append((email, password)) |
707 | self.ui.userRegistered.connect(slot) |
708 | self.ui.on_user_registered('app_name', None) |
709 | - self.assertTrue((email, password) in self.signals_results) |
710 | + self.assertIn((email, password), self.signals_results) |
711 | + |
712 | + def test_captcha_image_is_requested_as_startup(self): |
713 | + """The captcha image is requested at startup.""" |
714 | + # assert generate_captcha was called |
715 | + self.assert_backend_called('generate_captcha', |
716 | + self.app_name, self.ui.captcha_file) |
717 | |
718 | |
719 | class SetupAccountFakeWizardTestCase(BaseTestCase): |
720 | |
721 | === modified file 'ubuntu_sso/qt/tests/test_sign_in_page.py' |
722 | --- ubuntu_sso/qt/tests/test_sign_in_page.py 2012-02-10 21:09:38 +0000 |
723 | +++ ubuntu_sso/qt/tests/test_sign_in_page.py 2012-02-17 14:21:18 +0000 |
724 | @@ -55,7 +55,7 @@ |
725 | self.signals_results.append(1) |
726 | self.ui.existingAccountSelected.connect(slot) |
727 | self.ui._set_next_existing() |
728 | - self.assertTrue(1 in self.signals_results) |
729 | + self.assertIn(1, self.signals_results) |
730 | |
731 | def test_set_next_new(self): |
732 | """Test _set_next_existing method.""" |
733 | @@ -65,5 +65,5 @@ |
734 | self.signals_results.append(1) |
735 | self.ui.newAccountSelected.connect(slot) |
736 | self.ui._set_next_new() |
737 | - self.assertTrue(1 in self.signals_results) |
738 | + self.assertIn(1, self.signals_results) |
739 | # pylint: enable=W0212 |
740 | |
741 | === modified file 'ubuntu_sso/qt/tests/test_ubuntu_sso_wizard.py' |
742 | --- ubuntu_sso/qt/tests/test_ubuntu_sso_wizard.py 2012-02-13 20:37:57 +0000 |
743 | +++ ubuntu_sso/qt/tests/test_ubuntu_sso_wizard.py 2012-02-17 14:21:18 +0000 |
744 | @@ -89,6 +89,6 @@ |
745 | self.ui.show() |
746 | self.addCleanup(self.ui.hide) |
747 | self.ui.sign_in_page.ui.cancel_button.clicked.emit(True) |
748 | - self.assertTrue('close' in faked_object._called) |
749 | - self.assertTrue('reject' not in faked_object._called) |
750 | + self.assertIn('close', faked_object._called) |
751 | + self.assertNotIn('reject', faked_object._called) |
752 | # pylint: enable=W0212, E1101 |
Nice use of functools.partial
The only change I would suggest is fairly minor: Your test conditions are always assertTrue(x in y). You could instead do assertIn(x, y).