Merge lp:~nataliabidart/ubuntu-sso-client/warning_messages_within_entry into lp:ubuntu-sso-client

Proposed by Natalia Bidart
Status: Merged
Approved by: Vincenzo Di Somma
Approved revision: 592
Merged at revision: 591
Proposed branch: lp:~nataliabidart/ubuntu-sso-client/warning_messages_within_entry
Merge into: lp:ubuntu-sso-client
Diff against target: 503 lines (+121/-106)
3 files modified
data/ui.glade (+5/-49)
ubuntu_sso/gui.py (+34/-22)
ubuntu_sso/tests/test_gui.py (+82/-35)
To merge this branch: bzr merge lp:~nataliabidart/ubuntu-sso-client/warning_messages_within_entry
Reviewer Review Type Date Requested Status
Vincenzo Di Somma (community) Approve
Rodrigo Moya (community) Approve
Review via email: mp+33714@code.launchpad.net

Commit message

Warnings for entries are shown as secondary icons (LP: #624336).

Description of the change

Warnings for entries are shown as secondary icons.

To post a comment you must log in.
592. By Natalia Bidart

Pep8 fixes.

Revision history for this message
Rodrigo Moya (rodrigo-moya) wrote :

Works ok for me

review: Approve
Revision history for this message
Vincenzo Di Somma (vds) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'data/ui.glade'
2--- data/ui.glade 2010-08-25 18:12:58 +0000
3+++ data/ui.glade 2010-08-25 23:47:45 +0000
4@@ -62,14 +62,7 @@
5 <placeholder/>
6 </child>
7 <child>
8- <object class="GtkLabel" id="name_warning_label">
9- <property name="visible">True</property>
10- <property name="wrap">True</property>
11- </object>
12- <packing>
13- <property name="expand">False</property>
14- <property name="position">1</property>
15- </packing>
16+ <placeholder/>
17 </child>
18 <child>
19 <object class="GtkHBox" id="emails_hbox">
20@@ -89,14 +82,7 @@
21 </packing>
22 </child>
23 <child>
24- <object class="GtkLabel" id="email_warning_label">
25- <property name="visible">True</property>
26- <property name="wrap">True</property>
27- </object>
28- <packing>
29- <property name="expand">False</property>
30- <property name="position">3</property>
31- </packing>
32+ <placeholder/>
33 </child>
34 <child>
35 <object class="GtkHBox" id="passwords_hbox">
36@@ -126,13 +112,7 @@
37 </packing>
38 </child>
39 <child>
40- <object class="GtkLabel" id="password_warning_label">
41- <property name="visible">True</property>
42- <property name="wrap">True</property>
43- </object>
44- <packing>
45- <property name="position">6</property>
46- </packing>
47+ <placeholder/>
48 </child>
49 <child>
50 <placeholder/>
51@@ -169,13 +149,7 @@
52 <placeholder/>
53 </child>
54 <child>
55- <object class="GtkLabel" id="captcha_solution_warning_label">
56- <property name="visible">True</property>
57- <property name="wrap">True</property>
58- </object>
59- <packing>
60- <property name="position">1</property>
61- </packing>
62+ <placeholder/>
63 </child>
64 </object>
65 <packing>
66@@ -413,24 +387,6 @@
67 <placeholder/>
68 </child>
69 <child>
70- <object class="GtkLabel" id="login_email_warning_label">
71- <property name="visible">True</property>
72- <property name="label" translatable="yes">label</property>
73- </object>
74- <packing>
75- <property name="position">2</property>
76- </packing>
77- </child>
78- <child>
79- <object class="GtkLabel" id="login_password_warning_label">
80- <property name="visible">True</property>
81- <property name="label" translatable="yes">label</property>
82- </object>
83- <packing>
84- <property name="position">4</property>
85- </packing>
86- </child>
87- <child>
88 <object class="GtkLinkButton" id="forgotten_password_button">
89 <property name="label" translatable="yes">button</property>
90 <property name="visible">True</property>
91@@ -441,7 +397,7 @@
92 <signal name="clicked" handler="on_forgotten_password_button_clicked"/>
93 </object>
94 <packing>
95- <property name="position">5</property>
96+ <property name="position">2</property>
97 </packing>
98 </child>
99 </object>
100
101=== modified file 'ubuntu_sso/gui.py'
102--- ubuntu_sso/gui.py 2010-08-25 18:12:58 +0000
103+++ ubuntu_sso/gui.py 2010-08-25 23:47:45 +0000
104@@ -120,7 +120,7 @@
105 def __init__(self, label, is_password=False, *args, **kwargs):
106 self.label = label
107 self.is_password = is_password
108- self._user_input = None
109+ self.warning = None
110
111 super(LabeledEntry, self).__init__(*args, **kwargs)
112
113@@ -129,6 +129,7 @@
114 self.set_tooltip_text(self.label)
115 self.connect('focus-in-event', self._clear_text)
116 self.connect('focus-out-event', self._set_label)
117+ self.clear_warning()
118 self.show()
119
120 def _clear_text(self, *args, **kwargs):
121@@ -162,6 +163,20 @@
122 result = ''
123 return result
124
125+ def set_warning(self, warning_msg):
126+ """Display warning as secondary icon, set 'warning_msg' as tooltip."""
127+ self.warning = warning_msg
128+ self.set_property('secondary-icon-stock', gtk.STOCK_DIALOG_WARNING)
129+ self.set_property('secondary-icon-sensitive', True)
130+ self.set_property('secondary-icon-tooltip-text', warning_msg)
131+
132+ def clear_warning(self):
133+ """Remove any warning."""
134+ self.warning = None
135+ self.set_property('secondary-icon-stock', None)
136+ self.set_property('secondary-icon-sensitive', False)
137+ self.set_property('secondary-icon-tooltip-text', None)
138+
139
140 class UbuntuSSOClientGUI(object):
141 """Ubuntu single sign on GUI."""
142@@ -397,6 +412,8 @@
143 for widget in self.warnings:
144 widget.set_text('')
145 widget.hide()
146+ for widget in self.entries:
147+ getattr(self, widget).clear_warning()
148
149 def _non_empty_input(self, widget):
150 """Return weather widget has non empty content."""
151@@ -533,7 +550,7 @@
152 self.login_details_vbox.pack_start(self.login_email_entry)
153 self.login_details_vbox.reorder_child(self.login_email_entry, 0)
154 self.login_details_vbox.pack_start(self.login_password_entry)
155- self.login_details_vbox.reorder_child(self.login_password_entry, 2)
156+ self.login_details_vbox.reorder_child(self.login_password_entry, 1)
157
158 msg = self.FORGOTTEN_PASSWORD_BUTTON
159 self.forgotten_password_button.set_label(msg)
160@@ -628,41 +645,40 @@
161
162 name = self.name_entry.get_text()
163 if not name:
164- self._set_warning_message(self.name_warning_label,
165- self.FIELD_REQUIRED)
166+ self.name_entry.set_warning(self.FIELD_REQUIRED)
167 error |= True
168
169 # check email
170 email1 = self.email1_entry.get_text()
171 email2 = self.email2_entry.get_text()
172 if email1 != email2:
173- self._set_warning_message(self.email_warning_label,
174- self.EMAIL_MISMATCH)
175+ self.email1_entry.set_warning(self.EMAIL_MISMATCH)
176+ self.email2_entry.set_warning(self.EMAIL_MISMATCH)
177 error |= True
178
179 if '@' not in email1:
180- self._set_warning_message(self.email_warning_label,
181- self.EMAIL_INVALID)
182+ self.email1_entry.set_warning(self.EMAIL_INVALID)
183+ self.email2_entry.set_warning(self.EMAIL_INVALID)
184 error |= True
185
186 if not email1:
187- self._set_warning_message(self.email_warning_label,
188- self.FIELD_REQUIRED)
189+ self.email1_entry.set_warning(self.FIELD_REQUIRED)
190+ self.email2_entry.set_warning(self.FIELD_REQUIRED)
191 error |= True
192
193 # check password
194 password1 = self.password1_entry.get_text()
195 password2 = self.password2_entry.get_text()
196 if password1 != password2:
197- self._set_warning_message(self.password_warning_label,
198- self.PASSWORD_MISMATCH)
199+ self.password1_entry.set_warning(self.PASSWORD_MISMATCH)
200+ self.password2_entry.set_warning(self.PASSWORD_MISMATCH)
201 error |= True
202
203 if (len(password1) < 8 or
204 re.search('[A-Z]', password1) is None or
205 re.search('\d+', password1) is None):
206- self._set_warning_message(self.password_warning_label,
207- self.PASSWORD_TOO_WEAK)
208+ self.password1_entry.set_warning(self.PASSWORD_TOO_WEAK)
209+ self.password2_entry.set_warning(self.PASSWORD_TOO_WEAK)
210 error |= True
211
212 # check T&C
213@@ -673,8 +689,7 @@
214
215 captcha_solution = self.captcha_solution_entry.get_text()
216 if not captcha_solution:
217- self._set_warning_message(self.captcha_solution_warning_label,
218- self.FIELD_REQUIRED)
219+ self.captcha_solution_entry.set_warning(self.FIELD_REQUIRED)
220 error |= True
221
222 if error:
223@@ -721,20 +736,17 @@
224 email = self.login_email_entry.get_text()
225
226 if '@' not in email:
227- self._set_warning_message(self.login_email_warning_label,
228- self.EMAIL_INVALID)
229+ self.login_email_entry.set_warning(self.EMAIL_INVALID)
230 error |= True
231
232 if not email:
233- self._set_warning_message(self.login_email_warning_label,
234- self.FIELD_REQUIRED)
235+ self.login_email_entry.set_warning(self.FIELD_REQUIRED)
236 error |= True
237
238 password = self.login_password_entry.get_text()
239
240 if not password:
241- self._set_warning_message(self.login_password_warning_label,
242- self.FIELD_REQUIRED)
243+ self.login_password_entry.set_warning(self.FIELD_REQUIRED)
244 error |= True
245
246 if error:
247
248=== modified file 'ubuntu_sso/tests/test_gui.py'
249--- ubuntu_sso/tests/test_gui.py 2010-08-25 18:12:58 +0000
250+++ ubuntu_sso/tests/test_gui.py 2010-08-25 23:47:45 +0000
251@@ -262,6 +262,39 @@
252 self.entry.set_text('a')
253 self.assertEqual(self.entry.get_text(), 'a')
254
255+ def test_no_warning_by_default(self):
256+ """No secondary icon by default."""
257+ self.assertEqual(self.entry.warning, None)
258+ self.assertEqual(self.entry.get_property('secondary-icon-stock'),
259+ None)
260+ self.assertEqual(self.entry.get_property('secondary-icon-sensitive'),
261+ False)
262+ prop = self.entry.get_property('secondary-icon-tooltip-text')
263+ self.assertEqual(prop, None)
264+
265+ def test_set_warning(self):
266+ """Setting a warning show the proper secondary icon."""
267+ msg = 'You failed!'
268+ self.entry.set_warning(msg)
269+ self.assertEqual(self.entry.warning, msg)
270+ self.assertEqual(self.entry.get_property('secondary-icon-stock'),
271+ gtk.STOCK_DIALOG_WARNING)
272+ self.assertEqual(self.entry.get_property('secondary-icon-sensitive'),
273+ True)
274+ prop = self.entry.get_property('secondary-icon-tooltip-text')
275+ self.assertEqual(prop, msg)
276+
277+ def test_clear_warning(self):
278+ """Clearing a warning no longer show the secondary icon."""
279+ self.entry.clear_warning()
280+ self.assertEqual(self.entry.warning, None)
281+ self.assertEqual(self.entry.get_property('secondary-icon-stock'),
282+ None)
283+ self.assertEqual(self.entry.get_property('secondary-icon-sensitive'),
284+ False)
285+ prop = self.entry.get_property('secondary-icon-tooltip-text')
286+ self.assertEqual(prop, None)
287+
288
289 class PasswordLabeledEntryTestCase(LabeledEntryTestCase):
290 """Test suite for the labeled entry when is_password is True."""
291@@ -331,7 +364,7 @@
292 self.assertEqual(visible, widget.get_property('visible'),
293 msg % (name, '' if visible else 'not '))
294
295- def assert_correct_warning(self, label, message):
296+ def assert_correct_label_warning(self, label, message):
297 """Check that a warning is shown displaying 'message'."""
298 # warning label is visible
299 self.assertTrue(label.get_property('visible'))
300@@ -345,6 +378,10 @@
301 actual = label.style.fg[gtk.STATE_NORMAL]
302 self.assertEqual(expected, actual) # until realized this will fail
303
304+ def assert_correct_entry_warning(self, entry, message):
305+ """Check that a warning is shown displaying 'message'."""
306+ self.assertEqual(entry.warning, message)
307+
308 def assert_pages_visibility(self, **kwargs):
309 """The pages has the correct visibility."""
310 for i in self.pages:
311@@ -800,8 +837,8 @@
312
313 def test_warning_label_is_shown(self):
314 """On UserRegistrationError the warning label is shown."""
315- self.assert_correct_warning(self.ui.warning_label,
316- self.ui.UNKNOWN_ERROR)
317+ self.assert_correct_label_warning(self.ui.warning_label,
318+ self.ui.UNKNOWN_ERROR)
319
320
321 class VerifyEmailTestCase(UbuntuSSOClientTestCase):
322@@ -867,8 +904,8 @@
323 """On email validation error, the verify_email page is shown."""
324 self.ui.on_email_validation_error(app_name=APP_NAME, error=ERROR)
325 self.assert_pages_visibility(verify_email=True)
326- self.assert_correct_warning(self.ui.warning_label,
327- self.ui.UNKNOWN_ERROR)
328+ self.assert_correct_label_warning(self.ui.warning_label,
329+ self.ui.UNKNOWN_ERROR)
330
331 def test_success_label_is_correct(self):
332 """The success message is correct."""
333@@ -891,8 +928,8 @@
334
335 self.ui.join_ok_button.clicked() # submit form
336
337- self.assert_correct_warning(self.ui.name_warning_label,
338- self.ui.FIELD_REQUIRED)
339+ self.assert_correct_entry_warning(self.ui.name_entry,
340+ self.ui.FIELD_REQUIRED)
341 self.assertNotIn('register_user', self.ui.backend._called)
342
343 def test_warning_is_shown_if_empty_email(self):
344@@ -902,8 +939,10 @@
345
346 self.ui.join_ok_button.clicked() # submit form
347
348- self.assert_correct_warning(self.ui.email_warning_label,
349- self.ui.FIELD_REQUIRED)
350+ self.assert_correct_entry_warning(self.ui.email1_entry,
351+ self.ui.FIELD_REQUIRED)
352+ self.assert_correct_entry_warning(self.ui.email2_entry,
353+ self.ui.FIELD_REQUIRED)
354 self.assertNotIn('register_user', self.ui.backend._called)
355
356 def test_warning_is_shown_if_email_mismatch(self):
357@@ -913,8 +952,10 @@
358
359 self.ui.join_ok_button.clicked() # submit form
360
361- self.assert_correct_warning(self.ui.email_warning_label,
362- self.ui.EMAIL_MISMATCH)
363+ self.assert_correct_entry_warning(self.ui.email1_entry,
364+ self.ui.EMAIL_MISMATCH)
365+ self.assert_correct_entry_warning(self.ui.email2_entry,
366+ self.ui.EMAIL_MISMATCH)
367 self.assertNotIn('register_user', self.ui.backend._called)
368
369 def test_warning_is_shown_if_invalid_email(self):
370@@ -924,8 +965,10 @@
371
372 self.ui.join_ok_button.clicked() # submit form
373
374- self.assert_correct_warning(self.ui.email_warning_label,
375- self.ui.EMAIL_INVALID)
376+ self.assert_correct_entry_warning(self.ui.email1_entry,
377+ self.ui.EMAIL_INVALID)
378+ self.assert_correct_entry_warning(self.ui.email2_entry,
379+ self.ui.EMAIL_INVALID)
380 self.assertNotIn('register_user', self.ui.backend._called)
381
382 def test_password_help_is_always_shown(self):
383@@ -943,8 +986,10 @@
384
385 self.ui.join_ok_button.clicked() # submit form
386
387- self.assert_correct_warning(self.ui.password_warning_label,
388- self.ui.PASSWORD_MISMATCH)
389+ self.assert_correct_entry_warning(self.ui.password1_entry,
390+ self.ui.PASSWORD_MISMATCH)
391+ self.assert_correct_entry_warning(self.ui.password2_entry,
392+ self.ui.PASSWORD_MISMATCH)
393 self.assertNotIn('register_user', self.ui.backend._called)
394
395 def test_warning_is_shown_if_password_too_weak(self):
396@@ -956,8 +1001,10 @@
397
398 self.ui.join_ok_button.clicked() # submit form
399
400- self.assert_correct_warning(self.ui.password_warning_label,
401- self.ui.PASSWORD_TOO_WEAK)
402+ self.assert_correct_entry_warning(self.ui.password1_entry,
403+ self.ui.PASSWORD_TOO_WEAK)
404+ self.assert_correct_entry_warning(self.ui.password2_entry,
405+ self.ui.PASSWORD_TOO_WEAK)
406 self.assertNotIn('register_user', self.ui.backend._called)
407
408 def test_warning_is_shown_if_tc_not_accepted(self):
409@@ -967,8 +1014,8 @@
410
411 self.ui.join_ok_button.clicked() # submit form
412
413- self.assert_correct_warning(self.ui.tc_warning_label,
414- self.ui.TC_NOT_ACCEPTED)
415+ self.assert_correct_label_warning(self.ui.tc_warning_label,
416+ self.ui.TC_NOT_ACCEPTED)
417 self.assertNotIn('register_user', self.ui.backend._called)
418
419 def test_warning_is_shown_if_not_captcha_solution(self):
420@@ -978,8 +1025,8 @@
421
422 self.ui.join_ok_button.clicked() # submit form
423
424- self.assert_correct_warning(self.ui.captcha_solution_warning_label,
425- self.ui.FIELD_REQUIRED)
426+ self.assert_correct_entry_warning(self.ui.captcha_solution_entry,
427+ self.ui.FIELD_REQUIRED)
428 self.assertNotIn('register_user', self.ui.backend._called)
429
430 def test_no_warning_messages_if_valid_data_on_enter_details(self):
431@@ -1080,8 +1127,8 @@
432 """On user login error, a warning is shown with proper wording."""
433 self.click_connect_with_valid_data()
434 self.ui.on_login_error(app_name=APP_NAME, error=ERROR)
435- self.assert_correct_warning(self.ui.warning_label,
436- self.ui.UNKNOWN_ERROR)
437+ self.assert_correct_label_warning(self.ui.warning_label,
438+ self.ui.UNKNOWN_ERROR)
439
440 def test_back_to_registration_hides_warning(self):
441 """After user login error, warning is hidden when clicking 'Back'."""
442@@ -1105,8 +1152,8 @@
443
444 self.ui.login_ok_button.clicked() # submit form
445
446- self.assert_correct_warning(self.ui.login_email_warning_label,
447- self.ui.FIELD_REQUIRED)
448+ self.assert_correct_entry_warning(self.ui.login_email_entry,
449+ self.ui.FIELD_REQUIRED)
450 self.assertNotIn('login', self.ui.backend._called)
451
452 def test_warning_is_shown_if_invalid_email(self):
453@@ -1115,8 +1162,8 @@
454
455 self.ui.login_ok_button.clicked() # submit form
456
457- self.assert_correct_warning(self.ui.login_email_warning_label,
458- self.ui.EMAIL_INVALID)
459+ self.assert_correct_entry_warning(self.ui.login_email_entry,
460+ self.ui.EMAIL_INVALID)
461 self.assertNotIn('login', self.ui.backend._called)
462
463 def test_warning_is_shown_if_empty_password(self):
464@@ -1125,8 +1172,8 @@
465
466 self.ui.login_ok_button.clicked() # submit form
467
468- self.assert_correct_warning(self.ui.login_password_warning_label,
469- self.ui.FIELD_REQUIRED)
470+ self.assert_correct_entry_warning(self.ui.login_password_entry,
471+ self.ui.FIELD_REQUIRED)
472 self.assertNotIn('login', self.ui.backend._called)
473
474 def test_no_warning_messages_if_valid_data(self):
475@@ -1239,8 +1286,8 @@
476 def test_on_password_reset_error_shows_login_page(self):
477 """When reset token wasn't successfuly sent the login page is shown."""
478 self.ui.on_password_reset_error(app_name=APP_NAME, error=ERROR)
479- self.assert_correct_warning(self.ui.warning_label,
480- self.ui.UNKNOWN_ERROR)
481+ self.assert_correct_label_warning(self.ui.warning_label,
482+ self.ui.UNKNOWN_ERROR)
483 self.assert_pages_visibility(login=True)
484
485
486@@ -1289,15 +1336,15 @@
487 def test_on_password_changed_shows_success_page(self):
488 """When password was successfuly changed the success page is shown."""
489 self.ui.on_password_changed(app_name=APP_NAME, email=EMAIL)
490- self.assert_correct_warning(self.ui.warning_label,
491- self.ui.PASSWORD_CHANGED)
492+ self.assert_correct_label_warning(self.ui.warning_label,
493+ self.ui.PASSWORD_CHANGED)
494 self.assert_pages_visibility(login=True)
495
496 def test_on_password_change_error_shows_login_page(self):
497 """When password wasn't changed the reset password page is shown."""
498 self.ui.on_password_change_error(app_name=APP_NAME, error=ERROR)
499- self.assert_correct_warning(self.ui.warning_label,
500- self.ui.UNKNOWN_ERROR)
501+ self.assert_correct_label_warning(self.ui.warning_label,
502+ self.ui.UNKNOWN_ERROR)
503 self.assert_pages_visibility(request_password_token=True)
504
505

Subscribers

People subscribed via source and target branches