Merge lp:~diegosarmentero/ubuntuone-windows-installer/ui-form into lp:ubuntuone-windows-installer
- ui-form
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Natalia Bidart |
Approved revision: | 60 |
Merged at revision: | 37 |
Proposed branch: | lp:~diegosarmentero/ubuntuone-windows-installer/ui-form |
Merge into: | lp:ubuntuone-windows-installer |
Diff against target: |
1312 lines (+570/-471) 4 files modified
data/qt/ubuntuone.qss (+15/-16) ubuntuone_installer/gui/qt/setup_account.py (+55/-32) ubuntuone_installer/gui/qt/tests/test_gui.py (+18/-423) ubuntuone_installer/gui/qt/tests/test_setup_account.py (+482/-0) |
To merge this branch: | bzr merge lp:~diegosarmentero/ubuntuone-windows-installer/ui-form |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Natalia Bidart (community) | Approve | ||
Roberto Alsina (community) | Approve | ||
Review via email:
|
Commit message
Fixed Bug #829652
(About Setup Account Page Styling and text field validation)
Description of the change
Fixed Bug #829652
(About Setup Account Page Styling and text field validation)
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Natalia Bidart (nataliabidart) wrote : | # |
So, I see that in validate_
So, I think we can change this block
if until > len(self.
return
for i in xrange(until):
by:
for func in validation_
func()
I know they are not equivalents, since the latter will execute all the validation functions even if 'until' is too big, but I still don't see why we would have that case happening. Would you please confirm why you're checking "until > len(self.
* Pleas eunify these 2 imports into one:
+from ubuntuone_
+from ubuntuone_
* I think it will be better to skip globally # pylint: disable=C0103 in the test_setup_
* FakeValidationDict and its methods have no docstrings. Also, this class has a lot of duplication in its definitions, so I advice replacing all that using some metaprogramming, something like:
1 class FakeValidationD
2
3 def __init__(self):
4 for i in xrange(4):
5 # set all the instance variables
6 setattr(
7 setattr(self, 'validate_%s' %i, self.wrapper(i))
8
9 def __getitem__(self, i):
10 return getattr(self, 'validate_%s' % i)
11
12 def wrapper(self, i):
13
14 def inner(*args, **kwargs):
15 for j in xrange(i+1):
16 setattr(
17 return inner
* This block is not needed:
+ def setUp(self):
+ """Initialize this test instance."""
+ super(SetupAcco
(remember, no need to define setUp and tearDown if you're not customizing anything)
* Since we're adding changes in every line in the new tets file, can you please change all the self.assertEqua
Thanks!
- 54. By Diego Sarmentero
-
Fixed some tests.
- 55. By Diego Sarmentero
-
Removed __len__ method.
- 56. By Diego Sarmentero
-
Fixed some tests.
- 57. By Diego Sarmentero
-
Added missing docstrings.
- 58. By Diego Sarmentero
-
Remove unused variable and group together some imports in test_gui
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Natalia Bidart (nataliabidart) wrote : | # |
* Can you please add a docstring for the FakeValidationDict class?
* This code:
1103 + temp_function = self.ui.
1104 + self.ui.
1105 + self.ui.
1106 + self.assertTrue
1107 + self.assertFals
1108 + self.assertFals
1109 + self.assertFals
1110 + self.ui.
does not guarantee that the validation_
1104 + self.patch(self.ui, 'validation_
if for some reason you can't use this, add a cleanup statement right after the assignment:
1103 + temp_function = self.ui.
1104 + self.ui.
1105 + self.addCleanup
* No need to change the following, but you should notice that all the calls to self.ui.hide will not be executed if the test fails. So, ideally, the hide() call should be right next to the show() call, as a cleanup call:
+ self.ui.show()
+ self.addCleanup
- 59. By Diego Sarmentero
-
Tests improved to apply needs fixing comments.
- 60. By Diego Sarmentero
-
Added missing docstrings.
Removed FakeWizard from test_gui
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Natalia Bidart (nataliabidart) wrote : | # |
Looks good!
Preview Diff
1 | === modified file 'data/qt/ubuntuone.qss' |
2 | --- data/qt/ubuntuone.qss 2011-08-23 13:41:04 +0000 |
3 | +++ data/qt/ubuntuone.qss 2011-08-25 19:47:24 +0000 |
4 | @@ -1,4 +1,4 @@ |
5 | -QWidget{ |
6 | +QWidget { |
7 | font-family: "Ubuntu"; |
8 | color: #333333; |
9 | } |
10 | @@ -14,16 +14,15 @@ |
11 | } |
12 | |
13 | QWizard, |
14 | -QDialog{ |
15 | +QDialog { |
16 | background-color: white; |
17 | } |
18 | |
19 | -QLabel#password_assistance, |
20 | -QLabel#refresh_label{ |
21 | +QLabel#password_assistance { |
22 | border-image: url(":/balloon_shape.png"); |
23 | } |
24 | |
25 | -QLineEdit{ |
26 | +QLineEdit { |
27 | border: 1px solid #aea79f; |
28 | } |
29 | |
30 | @@ -31,16 +30,16 @@ |
31 | QLabel#sign_in_label, |
32 | QLabel#choose_services_label, |
33 | QLabel#select_folders_label, |
34 | -QLabel#sync_label{ |
35 | +QLabel#sync_label { |
36 | font-size: 14px; |
37 | } |
38 | |
39 | -QTextEdit{ |
40 | +QTextEdit { |
41 | background-color: #ffffff; |
42 | border: none; |
43 | } |
44 | |
45 | -QPushButton{ |
46 | +QPushButton { |
47 | border-radius: 5px; |
48 | border-style: solid; |
49 | padding: 6px; |
50 | @@ -130,18 +129,18 @@ |
51 | min-height: 100px; |
52 | } |
53 | |
54 | -QFrame#frm_box > QLabel{ |
55 | +QFrame#frm_box > QLabel { |
56 | font-size: 24px; |
57 | } |
58 | |
59 | -QLabel#image_label{ |
60 | +QLabel#image_label { |
61 | border-style: dotted; |
62 | border-color: #939389; |
63 | border-bottom-width: 1px; |
64 | border-top-width: 1px; |
65 | } |
66 | |
67 | -QLabel#title_label{ |
68 | +QLabel#title_label { |
69 | font-size: 20px; |
70 | } |
71 | |
72 | @@ -156,7 +155,7 @@ |
73 | color: #333333; |
74 | } |
75 | |
76 | -QGroupBox#bandwidth_settings{ |
77 | +QGroupBox#bandwidth_settings { |
78 | border-style: dotted; |
79 | border-color: #939389; |
80 | border-bottom-width: 1px; |
81 | @@ -167,15 +166,15 @@ |
82 | alternate-background-color: #efedec; |
83 | } |
84 | |
85 | -QLabel#form_errors{ |
86 | +QLabel#form_errors { |
87 | font: bold 14px; |
88 | - color: #dd4814; |
89 | + color: #df2d1f; |
90 | } |
91 | |
92 | -QLineEdit[formError="true"]{ |
93 | +QLineEdit[formError="true"] { |
94 | background-color: #ffe5e5; |
95 | } |
96 | |
97 | -QLineEdit[formError="false"]{ |
98 | +QLineEdit[formError="false"] { |
99 | background-color: white; |
100 | } |
101 | |
102 | === modified file 'ubuntuone_installer/gui/qt/setup_account.py' |
103 | --- ubuntuone_installer/gui/qt/setup_account.py 2011-08-23 13:41:04 +0000 |
104 | +++ ubuntuone_installer/gui/qt/setup_account.py 2011-08-25 19:47:24 +0000 |
105 | @@ -29,18 +29,30 @@ |
106 | |
107 | # pylint: disable=C0103 |
108 | BAD = u'<img src=":/password_hint_warning.png" /><font> %s </font>' |
109 | -ERROR = u'<font color="#dd4814"><b> %s </b></font>' |
110 | +ERROR = u'<font color="#df2d1f"><b> %s </b></font>' |
111 | GOOD = u'<img src=":/password_hint_ok.png" /><font> %s </font>' |
112 | NORMAL = u'<font> %s </font>' |
113 | TITLE_STYLE = "<span style=\"font-size:24px\">%s</span>" |
114 | |
115 | +EMAIL = _("Email") |
116 | EMPTY_NAME = _("Please enter your name") |
117 | INVALID_EMAIL = _("Please enter a valid email address") |
118 | EMAIL_MATCH = _("The email addresses do not match") |
119 | +NAME = _("Name") |
120 | +PASSWORD = _("Create a password") |
121 | PASSWORD_LENGTH = _("At least 8 characters") |
122 | PASSWORD_DIGIT = _("At least one number") |
123 | PASSWORD_UPPER = _("At least one uppercase letter") |
124 | PASSWORD_MATCH = _("Passwords don't match") |
125 | +PASSWORD_MUST_CONTAIN = _("Your password must contain") |
126 | +RETYPE_EMAIL = _("Retype email") |
127 | +RETYPE_PASSWORD = _("Retype password") |
128 | +SHOW_TERMS = _("Show Terms of Service") |
129 | +SUBTITLE = _("You only need to set up your account " \ |
130 | + "once to get access to Ubuntu One across your devices.") |
131 | +TERMS = _("By signing up to Ubuntu One you agree to our Terms " |
132 | + "of Service and Privacy Policy") |
133 | +TITLE = _("Sign Up to Ubuntu One") |
134 | |
135 | |
136 | class SetupAccountPage(sso_gui.SetupAccountPage): |
137 | @@ -48,15 +60,15 @@ |
138 | |
139 | def __init__(self, *args, **kwargs): |
140 | super(SetupAccountPage, self).__init__(*args, **kwargs) |
141 | - self.ui.name_edit.textEdited.connect(self.name_assistance) |
142 | - self.ui.email_edit.textEdited.connect(self.email_assistance) |
143 | - self.ui.email_edit.textEdited.connect(self.confirm_email_assistance) |
144 | - self.ui.confirm_email_edit.textEdited.connect( |
145 | - self.confirm_email_assistance) |
146 | self.ui.password_edit.textEdited.connect( |
147 | lambda: self.password_assistance(NORMAL)) |
148 | - self.ui.confirm_password_edit.textEdited.connect( |
149 | - self.password_assistance) |
150 | + |
151 | + # The functions are placed based on the focus order of the widgets. |
152 | + self.validation_functions = [ |
153 | + self.name_assistance, |
154 | + self.email_assistance, |
155 | + self.confirm_email_assistance, |
156 | + self.password_check_match] |
157 | |
158 | # Invalid name "initializePage" |
159 | # pylint: disable=C0103 |
160 | @@ -65,20 +77,17 @@ |
161 | """Setup UI details.""" |
162 | # We need to override some texts from SSO |
163 | # to match our spec |
164 | - title_page = TITLE_STYLE % _("Sign Up to Ubuntu One") |
165 | + title_page = TITLE_STYLE % TITLE |
166 | self.setTitle(title_page) |
167 | - self.setSubTitle(_("You only need to set up your account " |
168 | - "once to get access to Ubuntu One across your devices.")) |
169 | + self.setSubTitle(SUBTITLE) |
170 | |
171 | - self.ui.name_label.setText(_("Name")) |
172 | - self.ui.email_label.setText(_("Email")) |
173 | - self.ui.confirm_email_label.setText(_("Retype email")) |
174 | - self.ui.password_label.setText(_("Create a password")) |
175 | - self.ui.confirm_password_label.setText(_("Retype password")) |
176 | - self.ui.terms_checkbox.setText( |
177 | - _("By signing up to Ubuntu One you agree to our Terms " |
178 | - "of Service and Privacy Policy")) |
179 | - self.ui.terms_button.setText(_("Show Terms of Service")) |
180 | + self.ui.name_label.setText(NAME) |
181 | + self.ui.email_label.setText(EMAIL) |
182 | + self.ui.confirm_email_label.setText(RETYPE_EMAIL) |
183 | + self.ui.password_label.setText(PASSWORD) |
184 | + self.ui.confirm_password_label.setText(RETYPE_PASSWORD) |
185 | + self.ui.terms_checkbox.setText(TERMS) |
186 | + self.ui.terms_button.setText(SHOW_TERMS) |
187 | self.ui.password_info_label.hide() |
188 | |
189 | # Button setup |
190 | @@ -96,12 +105,20 @@ |
191 | |
192 | def focus_changed(self, old, now): |
193 | """Check who has the focus to activate password popups if necessary.""" |
194 | - if now == self.ui.password_edit: |
195 | - self.ui.password_assistance.setVisible(True) |
196 | - elif old == self.ui.password_edit or \ |
197 | - now == self.ui.confirm_password_edit: |
198 | - self.ui.password_assistance.setVisible(True) |
199 | - self.password_assistance() |
200 | + if now == self.ui.email_edit: |
201 | + self.validate_data_on_focus_changed(1) |
202 | + elif now == self.ui.confirm_email_edit: |
203 | + self.validate_data_on_focus_changed(2) |
204 | + elif now == self.ui.password_edit: |
205 | + self.validate_data_on_focus_changed(3) |
206 | + self.ui.password_assistance.setVisible(True) |
207 | + elif now == self.ui.captcha_solution_edit: |
208 | + self.validate_data_on_focus_changed(4) |
209 | + |
210 | + def validate_data_on_focus_changed(self, until): |
211 | + """Validate the all the text fields until the given index.""" |
212 | + for func in self.validation_functions[:until]: |
213 | + func() |
214 | |
215 | def name_assistance(self): |
216 | """Show help for the name field.""" |
217 | @@ -140,8 +157,7 @@ |
218 | def password_assistance(self, icon_type=BAD): |
219 | """Show help for the password field.""" |
220 | text1 = unicode(self.ui.password_edit.text()) |
221 | - text2 = unicode(self.ui.confirm_password_edit.text()) |
222 | - label_text = ["<b>%s</b>" % _("Your password must contain"), ] |
223 | + label_text = ["<b>%s</b>" % PASSWORD_MUST_CONTAIN, ] |
224 | |
225 | if len(text1) < 8: |
226 | sign = icon_type |
227 | @@ -161,14 +177,21 @@ |
228 | sign = GOOD |
229 | label_text.append(sign % PASSWORD_DIGIT) |
230 | |
231 | + self.ui.password_assistance.setText("<br>".join(label_text)) |
232 | + |
233 | + def password_check_match(self): |
234 | + """Check if passwords match, otherwise show a message.""" |
235 | + self.password_assistance() |
236 | + label_text = unicode(self.ui.password_assistance.text()) |
237 | + text1 = unicode(self.ui.password_edit.text()) |
238 | + text2 = unicode(self.ui.confirm_password_edit.text()) |
239 | if text1 != text2: |
240 | - label_text.append(icon_type % PASSWORD_MATCH) |
241 | - |
242 | - self.ui.password_assistance.setText("<br>".join(label_text)) |
243 | + label_text += "<br>" + BAD % PASSWORD_MATCH |
244 | + self.ui.password_assistance.setText(label_text) |
245 | |
246 | def password_default_assistance(self): |
247 | """Show default help for the password field.""" |
248 | - label_text = ["<b>%s</b>" % _("Your password must contain"), ] |
249 | + label_text = ["<b>%s</b>" % PASSWORD_MUST_CONTAIN, ] |
250 | |
251 | label_text.append(NORMAL % PASSWORD_LENGTH) |
252 | label_text.append(NORMAL % PASSWORD_UPPER) |
253 | |
254 | === modified file 'ubuntuone_installer/gui/qt/tests/test_gui.py' |
255 | --- ubuntuone_installer/gui/qt/tests/test_gui.py 2011-08-25 00:31:08 +0000 |
256 | +++ ubuntuone_installer/gui/qt/tests/test_gui.py 2011-08-25 19:47:24 +0000 |
257 | @@ -27,14 +27,8 @@ |
258 | from ubuntuone.platform.credentials import APP_NAME |
259 | from ubuntuone.controlpanel.gui import qt |
260 | |
261 | -from ubuntuone_installer.gui.qt import gui |
262 | +from ubuntuone_installer.gui.qt import gui, forgotten, utils |
263 | from ubuntuone_installer.gui.qt.tests import BaseTestCase |
264 | -from ubuntuone_installer.gui.qt import forgotten |
265 | -from ubuntuone_installer.gui.qt import setup_account |
266 | -from ubuntuone_installer.gui.qt.ui import ( |
267 | - setup_account_ui, |
268 | -) |
269 | -from ubuntuone_installer.gui.qt import utils |
270 | |
271 | |
272 | TOKEN = {u'consumer_key': u'xQ7xDAz', |
273 | @@ -180,6 +174,7 @@ |
274 | self.ui.setStartId(self.ui.LICENSE_PAGE_ID) |
275 | self.ui.restart() |
276 | self.ui.show() |
277 | + self.addCleanup(self.ui.hide) |
278 | gui.AreYouSure.result = 0 |
279 | self.patch(utils, "uninstall_application", self._set_called) |
280 | self.ui.done(result=0) |
281 | @@ -190,6 +185,7 @@ |
282 | self.ui.setStartId(self.ui.LICENSE_PAGE_ID) |
283 | self.ui.restart() |
284 | self.ui.show() |
285 | + self.addCleanup(self.ui.hide) |
286 | gui.AreYouSure.result = 0 |
287 | self.patch(utils, "uninstall_application", self._set_called) |
288 | self.ui.done(result=0) |
289 | @@ -203,6 +199,7 @@ |
290 | self.ui.setStartId(self.ui.preferences_page_id) |
291 | self.ui.restart() |
292 | self.ui.show() |
293 | + self.addCleanup(self.ui.hide) |
294 | |
295 | btn_pref = preferences_page.preferences_widget.ui.apply_changes_button |
296 | self.assertEqual(btn_pref.isVisible(), False) |
297 | @@ -218,6 +215,7 @@ |
298 | self.ui.setStartId(self.ui.preferences_page_id) |
299 | self.ui.restart() |
300 | self.ui.show() |
301 | + self.addCleanup(self.ui.hide) |
302 | |
303 | btn_pref = preferences_page.wizard().button( |
304 | QtGui.QWizard.CustomButton1) |
305 | @@ -234,6 +232,7 @@ |
306 | self.ui.setStartId(self.ui.preferences_page_id) |
307 | self.ui.restart() |
308 | self.ui.show() |
309 | + self.addCleanup(self.ui.hide) |
310 | |
311 | # pylint: disable=W0212 |
312 | preferences_page._button_clicked(QtGui.QWizard.CustomButton2) |
313 | @@ -255,6 +254,7 @@ |
314 | self.ui.setStartId(self.ui.folders_page_id) |
315 | self.ui.restart() |
316 | self.ui.show() |
317 | + self.addCleanup(self.ui.hide) |
318 | |
319 | btn_folders = folders_page.folders_widget.ui.share_publish_button |
320 | self.assertEqual(btn_folders.isVisible(), False) |
321 | @@ -275,6 +275,7 @@ |
322 | self.ui.setStartId(self.ui.folders_page_id) |
323 | self.ui.restart() |
324 | self.ui.show() |
325 | + self.addCleanup(self.ui.hide) |
326 | |
327 | folders_page.on_check_settings_button_clicked() |
328 | self.assertEqual(self.ui.currentId(), self.ui.preferences_page_id) |
329 | @@ -333,6 +334,7 @@ |
330 | self.ui.setStartId(self.ui.LICENSE_PAGE_ID) |
331 | self.ui.restart() |
332 | self.ui.show() |
333 | + self.addCleanup(self.ui.hide) |
334 | self.ui.next() |
335 | # This is 2 because we hide it once on __init__() |
336 | # and then again on next() |
337 | @@ -343,6 +345,7 @@ |
338 | self.ui.setStartId(self.ui.LICENSE_PAGE_ID) |
339 | self.ui.restart() |
340 | self.ui.show() |
341 | + self.addCleanup(self.ui.hide) |
342 | license_page = self.ui.page(self.ui.LICENSE_PAGE_ID) |
343 | self.assertEqual(self.ui.form_errors_label.parentWidget(), None) |
344 | self.ui.critical("test critical message") |
345 | @@ -390,6 +393,7 @@ |
346 | self.ui.setStartId(self.ui.SYNC_NOW_OR_LATER_PAGE) |
347 | self.ui.restart() |
348 | self.ui.show() |
349 | + self.addCleanup(self.ui.hide) |
350 | gui.AreYouSure.result = 0 |
351 | # I can't patch sys because frozen is not there by default |
352 | gui.sys.frozen = True |
353 | @@ -410,12 +414,14 @@ |
354 | gui.AreYouSure.result = 1 |
355 | self.patch(gui.subprocess, "Popen", self._set_called) |
356 | self.ui.show() |
357 | + self.addCleanup(self.ui.hide) |
358 | self.ui.done(result=0) |
359 | self.assertEqual(self.ui.isVisible(), True) |
360 | |
361 | def test_user_is_sure_in_last_page(self): |
362 | """Cancelling on the last page is ok.""" |
363 | self.ui.show() |
364 | + self.addCleanup(self.ui.hide) |
365 | self.patch(self.ui, 'currentId', lambda: self.ui.CONGRATULATIONS_PAGE) |
366 | self.patch(gui.subprocess, "Popen", self._set_called) |
367 | self.ui.done(result=0) |
368 | @@ -427,8 +433,10 @@ |
369 | self.ui.setStartId(self.ui.SYNC_NOW_OR_LATER_PAGE) |
370 | self.ui.restart() |
371 | self.ui.show() |
372 | + self.addCleanup(self.ui.hide) |
373 | gui.AreYouSure.result = 0 |
374 | self.ui.show() |
375 | + self.addCleanup(self.ui.hide) |
376 | self.ui.done(result=0) |
377 | self.assertEqual(self.ui.isVisible(), False) |
378 | |
379 | @@ -441,6 +449,7 @@ |
380 | self.ui.setStartId(self.ui.CONGRATULATIONS_PAGE) |
381 | self.ui.restart() |
382 | self.ui.show() |
383 | + self.addCleanup(self.ui.hide) |
384 | |
385 | # Check the properties have the right values |
386 | self.assertEqual(congrats_page.field("sync_later").toBool(), |
387 | @@ -457,6 +466,7 @@ |
388 | self.ui.setStartId(self.ui.SYNC_NOW_OR_LATER_PAGE) |
389 | self.ui.restart() |
390 | self.ui.show() |
391 | + self.addCleanup(self.ui.hide) |
392 | |
393 | # Check the navigation is correct |
394 | self.assertEqual(sync_page.nextId(), self.ui.folders_page_id) |
395 | @@ -470,6 +480,7 @@ |
396 | self.ui.setStartId(self.ui.CONGRATULATIONS_PAGE) |
397 | self.ui.restart() |
398 | self.ui.show() |
399 | + self.addCleanup(self.ui.hide) |
400 | |
401 | # Check the properties have the right values |
402 | self.assertEqual(congrats_page.field("sync_now").toBool(), |
403 | @@ -598,422 +609,6 @@ |
404 | self.shown = True |
405 | |
406 | |
407 | -class FakeWizard(object): |
408 | - """Replace wizard() function on wizard pages.""" |
409 | - |
410 | - params = None |
411 | - |
412 | - # Invalid name "setButtonLayout" |
413 | - # pylint: disable=C0103 |
414 | - |
415 | - def setButtonLayout(self, *args, **kwargs): |
416 | - """Fake the functionality of setButtonLayout on QWizard class.""" |
417 | - FakeWizard.params = (args, kwargs) |
418 | - |
419 | - # pylint: enable=C0103 |
420 | - |
421 | - |
422 | -class FakeWizard(object): |
423 | - """Replace wizard() function on wizard pages.""" |
424 | - |
425 | - params = None |
426 | - |
427 | - # Invalid name "setButtonLayout" |
428 | - # pylint: disable=C0103 |
429 | - |
430 | - def setButtonLayout(self, *args, **kwargs): |
431 | - """Fake the functionality of setButtonLayout on QWizard class.""" |
432 | - FakeWizard.params = (args, kwargs) |
433 | - |
434 | - # pylint: enable=C0103 |
435 | - |
436 | - |
437 | -class SetupAccountTestCase(BaseTestCase): |
438 | - """Test the SetupAccountPage code.""" |
439 | - |
440 | - class_ui = setup_account.SetupAccountPage |
441 | - kwargs = dict( |
442 | - ui=setup_account_ui.Ui_SetUpAccountPage(), |
443 | - controller=FakeController(), |
444 | - parent=None, |
445 | - ) |
446 | - |
447 | - def setUp(self): |
448 | - """Initialize this test instance.""" |
449 | - super(SetupAccountTestCase, self).setUp() |
450 | - |
451 | - def test_init(self): |
452 | - """Check the initial state of SetupAccount.""" |
453 | - self.assertEqual(self.ui.ui.name_edit.receivers( |
454 | - QtCore.SIGNAL('textEdited(QString)')), 1) |
455 | - self.assertEqual(self.ui.ui.email_edit.receivers( |
456 | - QtCore.SIGNAL('textEdited(QString)')), 2) |
457 | - self.assertEqual(self.ui.ui.confirm_email_edit.receivers( |
458 | - QtCore.SIGNAL('textEdited(QString)')), 1) |
459 | - self.assertEqual(self.ui.ui.password_edit.receivers( |
460 | - QtCore.SIGNAL('textEdited(QString)')), 1) |
461 | - self.assertEqual(self.ui.ui.confirm_password_edit.receivers( |
462 | - QtCore.SIGNAL('textEdited(QString)')), 1) |
463 | - |
464 | - def test_initialize_page(self): |
465 | - """Check the initializePage to ensure proper widgets visibility.""" |
466 | - self.ui.show() |
467 | - self.patch(self.ui, 'wizard', FakeWizard) |
468 | - self.ui.initializePage() |
469 | - self.assertEqual(FakeWizard.params, (([ |
470 | - QtGui.QWizard.BackButton, |
471 | - QtGui.QWizard.Stretch],), {})) |
472 | - self.assertFalse(self.ui.ui.name_assistance.isVisible()) |
473 | - self.assertFalse(self.ui.ui.email_assistance.isVisible()) |
474 | - self.assertFalse(self.ui.ui.confirm_email_assistance.isVisible()) |
475 | - self.assertFalse(self.ui.ui.password_assistance.isVisible()) |
476 | - |
477 | - def test_empty_name(self): |
478 | - """Status when the name field is empty. |
479 | - |
480 | - * Name Assistance label visible. |
481 | - * Correct error message in it. |
482 | - """ |
483 | - self.ui.ui.name_edit.setText("") |
484 | - self.ui.name_assistance() |
485 | - self.ui.show() |
486 | - self.assertEqual(self.ui.ui.name_assistance.isVisible(), True) |
487 | - self.assertEqual( |
488 | - unicode(self.ui.ui.name_assistance.text()), |
489 | - setup_account.ERROR % setup_account.EMPTY_NAME) |
490 | - self.ui.hide() |
491 | - |
492 | - def test_blank_name(self): |
493 | - """Status when the name field is blank (spaces). |
494 | - |
495 | - * Name Assistance label visible. |
496 | - * Correct error message in it. |
497 | - """ |
498 | - self.ui.ui.name_edit.setText(" ") |
499 | - self.ui.name_assistance() |
500 | - self.ui.show() |
501 | - self.assertEqual(self.ui.ui.name_assistance.isVisible(), True) |
502 | - self.assertEqual( |
503 | - unicode(self.ui.ui.name_assistance.text()), |
504 | - setup_account.ERROR % setup_account.EMPTY_NAME) |
505 | - self.ui.hide() |
506 | - |
507 | - def test_valid_name(self): |
508 | - """Status when the name field is valid. |
509 | - |
510 | - * Name Assistance label invisible. |
511 | - """ |
512 | - self.ui.ui.name_edit.setText("John Doe") |
513 | - self.ui.name_assistance() |
514 | - self.ui.show() |
515 | - self.assertEqual(self.ui.ui.name_assistance.isVisible(), False) |
516 | - self.ui.hide() |
517 | - |
518 | - def test_invalid_email(self): |
519 | - """Status when the email field has no @. |
520 | - |
521 | - * Email Assistance label visible. |
522 | - * Correct error message in it. |
523 | - """ |
524 | - self.ui.ui.email_edit.setText("foobar") |
525 | - self.ui.email_assistance() |
526 | - self.ui.show() |
527 | - self.assertEqual(self.ui.ui.email_assistance.isVisible(), True) |
528 | - self.assertEqual( |
529 | - unicode(self.ui.ui.email_assistance.text()), |
530 | - setup_account.ERROR % setup_account.INVALID_EMAIL) |
531 | - self.ui.hide() |
532 | - |
533 | - def test_valid_email(self): |
534 | - """Status when the email field has a @. |
535 | - |
536 | - * Email Assistance label invisible. |
537 | - """ |
538 | - self.ui.ui.email_edit.setText("foo@bar") |
539 | - self.ui.email_assistance() |
540 | - self.ui.show() |
541 | - self.assertEqual(self.ui.ui.email_assistance.isVisible(), False) |
542 | - self.ui.hide() |
543 | - |
544 | - def test_matching_emails(self): |
545 | - """Status when the email fields match. |
546 | - |
547 | - * Email Assistance label invisible. |
548 | - """ |
549 | - self.ui.ui.email_edit.setText("foo@bar") |
550 | - self.ui.ui.confirm_email_edit.setText("foo@bar") |
551 | - self.ui.confirm_email_assistance() |
552 | - self.ui.show() |
553 | - self.assertEqual( |
554 | - self.ui.ui.confirm_email_assistance.isVisible(), False) |
555 | - self.ui.hide() |
556 | - |
557 | - def test_not_matching_emails(self): |
558 | - """Status when the email fields don't match. |
559 | - |
560 | - * Email Assistance label visible. |
561 | - * Correct error message. |
562 | - """ |
563 | - self.ui.ui.email_edit.setText("foo@bar") |
564 | - self.ui.ui.confirm_email_edit.setText("foo@baz") |
565 | - self.ui.confirm_email_assistance() |
566 | - self.ui.show() |
567 | - self.assertEqual(self.ui.ui.confirm_email_assistance.isVisible(), True) |
568 | - self.assertEqual( |
569 | - unicode(self.ui.ui.confirm_email_assistance.text()), |
570 | - setup_account.ERROR % setup_account.EMAIL_MATCH) |
571 | - self.ui.hide() |
572 | - |
573 | - def test_short_password(self): |
574 | - """Status with short password. |
575 | - |
576 | - * Password assistance contains the right message. |
577 | - """ |
578 | - self.ui.ui.password_edit.setText("foobar") |
579 | - self.ui.password_assistance() |
580 | - self.assertIn( |
581 | - setup_account.BAD % setup_account.PASSWORD_LENGTH, |
582 | - unicode(self.ui.ui.password_assistance.text()), |
583 | - ) |
584 | - |
585 | - def test_long_password(self): |
586 | - """Status with long password. |
587 | - |
588 | - * Password assistance contains the right message. |
589 | - """ |
590 | - self.ui.ui.password_edit.setText("foobarbaz") |
591 | - self.ui.password_assistance() |
592 | - self.assertIn( |
593 | - setup_account.GOOD % setup_account.PASSWORD_LENGTH, |
594 | - unicode(self.ui.ui.password_assistance.text()), |
595 | - ) |
596 | - |
597 | - def test_no_number_password(self): |
598 | - """Status with password without a number. |
599 | - |
600 | - * Password assistance contains the right message. |
601 | - """ |
602 | - self.ui.ui.password_edit.setText("foobarbaz") |
603 | - self.ui.password_assistance() |
604 | - self.assertIn( |
605 | - setup_account.BAD % setup_account.PASSWORD_DIGIT, |
606 | - unicode(self.ui.ui.password_assistance.text()), |
607 | - ) |
608 | - |
609 | - def test_number_password(self): |
610 | - """Status with password with a number. |
611 | - |
612 | - * Password assistance contains the right message. |
613 | - """ |
614 | - self.ui.ui.password_edit.setText("foobarba7") |
615 | - self.ui.password_assistance() |
616 | - self.assertIn( |
617 | - setup_account.GOOD % setup_account.PASSWORD_DIGIT, |
618 | - unicode(self.ui.ui.password_assistance.text()), |
619 | - ) |
620 | - |
621 | - def test_no_uppercase_password(self): |
622 | - """Status with password without uppercase letters. |
623 | - |
624 | - * Password assistance contains the right message. |
625 | - """ |
626 | - self.ui.ui.password_edit.setText("foobarbaz") |
627 | - self.ui.password_assistance() |
628 | - self.assertIn( |
629 | - setup_account.BAD % setup_account.PASSWORD_UPPER, |
630 | - unicode(self.ui.ui.password_assistance.text()), |
631 | - ) |
632 | - |
633 | - def test_upper_password(self): |
634 | - """Status with password with uppercase letters. |
635 | - |
636 | - * Password assistance contains the right message. |
637 | - """ |
638 | - self.ui.ui.password_edit.setText("Foobarba7") |
639 | - self.ui.password_assistance() |
640 | - self.assertIn( |
641 | - setup_account.GOOD % setup_account.PASSWORD_UPPER, |
642 | - unicode(self.ui.ui.password_assistance.text()), |
643 | - ) |
644 | - |
645 | - def test_matching_passwords(self): |
646 | - """Status when the passwords match. |
647 | - |
648 | - * Password assistance doesn't contain the message. |
649 | - """ |
650 | - self.ui.ui.password_edit.setText("Foobarba7") |
651 | - self.ui.ui.confirm_password_edit.setText("Foobarba7") |
652 | - self.ui.password_assistance() |
653 | - self.assertNotIn( |
654 | - setup_account.PASSWORD_MATCH, |
655 | - unicode(self.ui.ui.password_assistance.text()), |
656 | - ) |
657 | - |
658 | - def test_not_matching_passwords(self): |
659 | - """Status when the passwords not match. |
660 | - |
661 | - * Password assistance contains the right message. |
662 | - """ |
663 | - self.ui.ui.password_edit.setText("Foobarba7") |
664 | - self.ui.ui.confirm_password_edit.setText("BazBarFo0") |
665 | - self.ui.password_assistance() |
666 | - self.assertIn( |
667 | - setup_account.BAD % setup_account.PASSWORD_MATCH, |
668 | - unicode(self.ui.ui.password_assistance.text()), |
669 | - ) |
670 | - |
671 | - def test_password_default_assistance(self): |
672 | - """Status when the password line edit receive focus and shows popup. |
673 | - |
674 | - * Password assistance contains the right message. |
675 | - """ |
676 | - self.ui.ui.password_edit.setText("") |
677 | - self.ui.ui.confirm_password_edit.setText("") |
678 | - self.ui.password_assistance() |
679 | - self.ui.focus_changed(None, self.ui.ui.password_edit) |
680 | - self.assertIn( |
681 | - setup_account.NORMAL % setup_account.PASSWORD_LENGTH, |
682 | - unicode(self.ui.ui.password_assistance.text()), |
683 | - ) |
684 | - self.assertIn( |
685 | - setup_account.NORMAL % setup_account.PASSWORD_UPPER, |
686 | - unicode(self.ui.ui.password_assistance.text()), |
687 | - ) |
688 | - self.assertIn( |
689 | - setup_account.NORMAL % setup_account.PASSWORD_DIGIT, |
690 | - unicode(self.ui.ui.password_assistance.text()), |
691 | - ) |
692 | - |
693 | - def test_password_assistance_in_focus_length_correct(self): |
694 | - """Check the QLineEdit for password when the length is correct.""" |
695 | - self.ui.ui.password_edit.setText("aaaaaaaaa") |
696 | - self.ui.ui.confirm_password_edit.setText("") |
697 | - self.ui.password_assistance(setup_account.NORMAL) |
698 | - self.assertIn( |
699 | - setup_account.GOOD % setup_account.PASSWORD_LENGTH, |
700 | - unicode(self.ui.ui.password_assistance.text()), |
701 | - ) |
702 | - self.assertIn( |
703 | - setup_account.NORMAL % setup_account.PASSWORD_UPPER, |
704 | - unicode(self.ui.ui.password_assistance.text()), |
705 | - ) |
706 | - self.assertIn( |
707 | - setup_account.NORMAL % setup_account.PASSWORD_DIGIT, |
708 | - unicode(self.ui.ui.password_assistance.text()), |
709 | - ) |
710 | - self.assertIn( |
711 | - setup_account.NORMAL % setup_account.PASSWORD_MATCH, |
712 | - unicode(self.ui.ui.password_assistance.text()), |
713 | - ) |
714 | - |
715 | - def test_password_assistance_in_focus_with_upper(self): |
716 | - """Check the QLineEdit for password when it has an upper case char.""" |
717 | - self.ui.ui.password_edit.setText("AAa") |
718 | - self.ui.ui.confirm_password_edit.setText("") |
719 | - self.ui.password_assistance(setup_account.NORMAL) |
720 | - self.assertIn( |
721 | - setup_account.NORMAL % setup_account.PASSWORD_LENGTH, |
722 | - unicode(self.ui.ui.password_assistance.text()), |
723 | - ) |
724 | - self.assertIn( |
725 | - setup_account.GOOD % setup_account.PASSWORD_UPPER, |
726 | - unicode(self.ui.ui.password_assistance.text()), |
727 | - ) |
728 | - self.assertIn( |
729 | - setup_account.NORMAL % setup_account.PASSWORD_DIGIT, |
730 | - unicode(self.ui.ui.password_assistance.text()), |
731 | - ) |
732 | - self.assertIn( |
733 | - setup_account.NORMAL % setup_account.PASSWORD_MATCH, |
734 | - unicode(self.ui.ui.password_assistance.text()), |
735 | - ) |
736 | - |
737 | - def test_password_assistance_in_focus_with_number(self): |
738 | - """Check the QLineEdit for password when it contains numbers.""" |
739 | - self.ui.ui.password_edit.setText("a123") |
740 | - self.ui.ui.confirm_password_edit.setText("") |
741 | - self.ui.password_assistance(setup_account.NORMAL) |
742 | - self.assertIn( |
743 | - setup_account.NORMAL % setup_account.PASSWORD_LENGTH, |
744 | - unicode(self.ui.ui.password_assistance.text()), |
745 | - ) |
746 | - self.assertIn( |
747 | - setup_account.NORMAL % setup_account.PASSWORD_UPPER, |
748 | - unicode(self.ui.ui.password_assistance.text()), |
749 | - ) |
750 | - self.assertIn( |
751 | - setup_account.GOOD % setup_account.PASSWORD_DIGIT, |
752 | - unicode(self.ui.ui.password_assistance.text()), |
753 | - ) |
754 | - self.assertIn( |
755 | - setup_account.NORMAL % setup_account.PASSWORD_MATCH, |
756 | - unicode(self.ui.ui.password_assistance.text()), |
757 | - ) |
758 | - |
759 | - def test_password_assistance_in_focus_all_ok(self): |
760 | - """Check the QLineEdit for password when all the condition are ok.""" |
761 | - self.ui.ui.password_edit.setText("T3st3rqw") |
762 | - self.ui.ui.confirm_password_edit.setText("T3st3rqw") |
763 | - self.ui.password_assistance(setup_account.NORMAL) |
764 | - self.assertIn( |
765 | - setup_account.GOOD % setup_account.PASSWORD_LENGTH, |
766 | - unicode(self.ui.ui.password_assistance.text()), |
767 | - ) |
768 | - self.assertIn( |
769 | - setup_account.GOOD % setup_account.PASSWORD_UPPER, |
770 | - unicode(self.ui.ui.password_assistance.text()), |
771 | - ) |
772 | - self.assertIn( |
773 | - setup_account.GOOD % setup_account.PASSWORD_DIGIT, |
774 | - unicode(self.ui.ui.password_assistance.text()), |
775 | - ) |
776 | - self.assertNotIn( |
777 | - setup_account.NORMAL % setup_account.PASSWORD_MATCH, |
778 | - unicode(self.ui.ui.password_assistance.text()), |
779 | - ) |
780 | - |
781 | - def test_side_widget_state(self): |
782 | - """Test if the side widget of the wizard has state frame visible.""" |
783 | - if type(self.ui) != gui.MainWindow: |
784 | - return |
785 | - self.ui.on_currentIdChanged(self.ui.LICENSE_PAGE) |
786 | - self.assertEqual( |
787 | - True, |
788 | - self.ui.sideWidget().ui.states_frame.isVisible()) |
789 | - self.ui.on_currentIdChanged(self.ui.SIGNIN_PAGE) |
790 | - self.assertEqual( |
791 | - True, |
792 | - self.ui.sideWidget().ui.states_frame.isVisible()) |
793 | - self.ui.on_currentIdChanged(self.ui.local_folders_page_id) |
794 | - self.assertEqual( |
795 | - True, |
796 | - self.ui.sideWidget().ui.states_frame.isVisible()) |
797 | - self.ui.on_currentIdChanged(self.ui.CONGRATULATIONS_PAGE) |
798 | - self.assertEqual( |
799 | - True, |
800 | - self.ui.sideWidget().ui.states_frame.isVisible()) |
801 | - |
802 | - def test_check_valid(self): |
803 | - """Check the propery value of a QLineEdit marked as valid.""" |
804 | - self.ui.check_as_valid(self.ui.ui.name_edit) |
805 | - self.assertEqual(self.ui.ui.name_edit.property("formError"), |
806 | - False) |
807 | - |
808 | - def test_check_invalid(self): |
809 | - """Check the propery value of a QLineEdit marked as invalid.""" |
810 | - self.ui.check_as_invalid(self.ui.ui.name_edit) |
811 | - self.assertEqual(self.ui.ui.name_edit.property("formError"), |
812 | - True) |
813 | - |
814 | - def test_focus_changed(self): |
815 | - """Check visibility changes when focus_changed() is executed.""" |
816 | - self.ui.show() |
817 | - self.ui.focus_changed(None, self.ui.ui.password_edit) |
818 | - self.assertTrue(self.ui.ui.password_assistance.isVisible()) |
819 | - self.ui.focus_changed(None, self.ui.ui.captcha_solution_edit) |
820 | - self.assertTrue(self.ui.ui.refresh_label.isVisible()) |
821 | - |
822 | - |
823 | class FakeFailingCredentialsManagementTool(object): |
824 | |
825 | """A fake CredentialsManagementTool that fails.""" |
826 | |
827 | === added file 'ubuntuone_installer/gui/qt/tests/test_setup_account.py' |
828 | --- ubuntuone_installer/gui/qt/tests/test_setup_account.py 1970-01-01 00:00:00 +0000 |
829 | +++ ubuntuone_installer/gui/qt/tests/test_setup_account.py 2011-08-25 19:47:24 +0000 |
830 | @@ -0,0 +1,482 @@ |
831 | +# -*- coding: utf-8 -*- |
832 | + |
833 | +# Authors: Alejandro J. Cura <alecu@canonical.com> |
834 | +# Roberto Alsina <roberto.alsina@canonical.com> |
835 | +# Diego Sarmentero <diego.sarmentero@canonical.com> |
836 | +# |
837 | +# Copyright 2011 Canonical Ltd. |
838 | +# |
839 | +# This program is free software: you can redistribute it and/or modify it |
840 | +# under the terms of the GNU General Public License version 3, as published |
841 | +# by the Free Software Foundation. |
842 | +# |
843 | +# This program is distributed in the hope that it will be useful, but |
844 | +# WITHOUT ANY WARRANTY; without even the implied warranties of |
845 | +# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
846 | +# PURPOSE. See the GNU General Public License for more details. |
847 | +# |
848 | +# You should have received a copy of the GNU General Public License along |
849 | +# with this program. If not, see <http://www.gnu.org/licenses/>. |
850 | + |
851 | +"""Tests for the Setup Account page Qt UI.""" |
852 | + |
853 | +from PyQt4 import QtGui, QtCore |
854 | + |
855 | +from ubuntuone_installer.gui.qt import gui, setup_account |
856 | +from ubuntuone_installer.gui.qt.tests import BaseTestCase |
857 | +from ubuntuone_installer.gui.qt.ui import ( |
858 | + setup_account_ui, |
859 | +) |
860 | + |
861 | + |
862 | +class FakeController(object): |
863 | + |
864 | + """A fake controller for the tests.""" |
865 | + |
866 | + def __init__(self, *args, **kwargs): |
867 | + self.args = (args, kwargs) |
868 | + |
869 | + # pylint: disable=C0103 |
870 | + def setupUi(self, view): |
871 | + """Fake the setup.""" |
872 | + # pylint: enable=C0103 |
873 | + |
874 | + |
875 | +class FakeWizard(object): |
876 | + """Replace wizard() function on wizard pages.""" |
877 | + |
878 | + params = None |
879 | + |
880 | + # Invalid name "setButtonLayout" |
881 | + # pylint: disable=C0103 |
882 | + |
883 | + def setButtonLayout(self, *args, **kwargs): |
884 | + """Fake the functionality of setButtonLayout on QWizard class.""" |
885 | + FakeWizard.params = (args, kwargs) |
886 | + |
887 | + # pylint: enable=C0103 |
888 | + |
889 | + |
890 | +class FakeValidationDict(object): |
891 | + """A Fake dictionary to replace validation_functions on Setup Account.""" |
892 | + |
893 | + def __init__(self): |
894 | + for i in xrange(len(self)): |
895 | + # set all the instance variables |
896 | + setattr(FakeValidationDict, 'valid%s' % i, False) |
897 | + setattr(self, 'validate_%s' % i, self.wrapper(i)) |
898 | + |
899 | + def __getitem__(self, i): |
900 | + """Get the proper function depending on the index received.""" |
901 | + return getattr(self, 'validate_%s' % i) |
902 | + |
903 | + def __getslice__(self, i, j): |
904 | + """Check that the class length is not exceded and return the funcs.""" |
905 | + j = j if j <= len(self) else len(self) |
906 | + return [self[q] for q in xrange(j)] |
907 | + |
908 | + def __len__(self): |
909 | + """Return the number of functions in this class.""" |
910 | + return 4 |
911 | + |
912 | + def wrapper(self, i): |
913 | + """Change the state of the attributes based on the index.""" |
914 | + def inner(*args, **kwargs): |
915 | + """Replace the value of the attributes depending on the index.""" |
916 | + for j in xrange(i + 1): |
917 | + setattr(FakeValidationDict, 'valid%s' % j, True) |
918 | + return inner |
919 | + |
920 | + |
921 | +class SetupAccountTestCase(BaseTestCase): |
922 | + """Test the SetupAccountPage code.""" |
923 | + |
924 | + class_ui = setup_account.SetupAccountPage |
925 | + kwargs = dict( |
926 | + ui=setup_account_ui.Ui_SetUpAccountPage(), |
927 | + controller=FakeController(), |
928 | + parent=None, |
929 | + ) |
930 | + |
931 | + def test_init(self): |
932 | + """Check the initial state of SetupAccount.""" |
933 | + self.assertEqual(self.ui.ui.password_edit.receivers( |
934 | + QtCore.SIGNAL('textEdited(QString)')), 1) |
935 | + self.assertTrue(self.ui.validation_functions) |
936 | + |
937 | + def test_initialize_page(self): |
938 | + """Check the initializePage to ensure proper widgets visibility.""" |
939 | + self.ui.show() |
940 | + self.addCleanup(self.ui.hide) |
941 | + self.patch(self.ui, 'wizard', FakeWizard) |
942 | + self.ui.initializePage() |
943 | + self.assertEqual(FakeWizard.params, (([ |
944 | + QtGui.QWizard.BackButton, |
945 | + QtGui.QWizard.Stretch],), {})) |
946 | + self.assertFalse(self.ui.ui.name_assistance.isVisible()) |
947 | + self.assertFalse(self.ui.ui.email_assistance.isVisible()) |
948 | + self.assertFalse(self.ui.ui.confirm_email_assistance.isVisible()) |
949 | + self.assertFalse(self.ui.ui.password_assistance.isVisible()) |
950 | + |
951 | + def test_empty_name(self): |
952 | + """Status when the name field is empty. |
953 | + |
954 | + * Name Assistance label visible. |
955 | + * Correct error message in it. |
956 | + """ |
957 | + self.ui.ui.name_edit.setText("") |
958 | + self.ui.name_assistance() |
959 | + self.ui.show() |
960 | + self.addCleanup(self.ui.hide) |
961 | + self.assertTrue(self.ui.ui.name_assistance.isVisible()) |
962 | + self.assertEqual( |
963 | + unicode(self.ui.ui.name_assistance.text()), |
964 | + setup_account.ERROR % setup_account.EMPTY_NAME) |
965 | + self.ui.hide() |
966 | + |
967 | + def test_blank_name(self): |
968 | + """Status when the name field is blank (spaces). |
969 | + |
970 | + * Name Assistance label visible. |
971 | + * Correct error message in it. |
972 | + """ |
973 | + self.ui.ui.name_edit.setText(" ") |
974 | + self.ui.name_assistance() |
975 | + self.ui.show() |
976 | + self.addCleanup(self.ui.hide) |
977 | + self.assertTrue(self.ui.ui.name_assistance.isVisible()) |
978 | + self.assertEqual( |
979 | + unicode(self.ui.ui.name_assistance.text()), |
980 | + setup_account.ERROR % setup_account.EMPTY_NAME) |
981 | + self.ui.hide() |
982 | + |
983 | + def test_valid_name(self): |
984 | + """Status when the name field is valid. |
985 | + |
986 | + * Name Assistance label invisible. |
987 | + """ |
988 | + self.ui.ui.name_edit.setText("John Doe") |
989 | + self.ui.name_assistance() |
990 | + self.ui.show() |
991 | + self.addCleanup(self.ui.hide) |
992 | + self.assertFalse(self.ui.ui.name_assistance.isVisible()) |
993 | + self.ui.hide() |
994 | + |
995 | + def test_invalid_email(self): |
996 | + """Status when the email field has no @. |
997 | + |
998 | + * Email Assistance label visible. |
999 | + * Correct error message in it. |
1000 | + """ |
1001 | + self.ui.ui.email_edit.setText("foobar") |
1002 | + self.ui.email_assistance() |
1003 | + self.ui.show() |
1004 | + self.addCleanup(self.ui.hide) |
1005 | + self.assertTrue(self.ui.ui.email_assistance.isVisible()) |
1006 | + self.assertEqual( |
1007 | + unicode(self.ui.ui.email_assistance.text()), |
1008 | + setup_account.ERROR % setup_account.INVALID_EMAIL) |
1009 | + self.ui.hide() |
1010 | + |
1011 | + def test_valid_email(self): |
1012 | + """Status when the email field has a @. |
1013 | + |
1014 | + * Email Assistance label invisible. |
1015 | + """ |
1016 | + self.ui.ui.email_edit.setText("foo@bar") |
1017 | + self.ui.email_assistance() |
1018 | + self.ui.show() |
1019 | + self.addCleanup(self.ui.hide) |
1020 | + self.assertFalse(self.ui.ui.email_assistance.isVisible()) |
1021 | + self.ui.hide() |
1022 | + |
1023 | + def test_matching_emails(self): |
1024 | + """Status when the email fields match. |
1025 | + |
1026 | + * Email Assistance label invisible. |
1027 | + """ |
1028 | + self.ui.ui.email_edit.setText("foo@bar") |
1029 | + self.ui.ui.confirm_email_edit.setText("foo@bar") |
1030 | + self.ui.confirm_email_assistance() |
1031 | + self.ui.show() |
1032 | + self.addCleanup(self.ui.hide) |
1033 | + self.assertFalse(self.ui.ui.confirm_email_assistance.isVisible()) |
1034 | + self.ui.hide() |
1035 | + |
1036 | + def test_not_matching_emails(self): |
1037 | + """Status when the email fields don't match. |
1038 | + |
1039 | + * Email Assistance label visible. |
1040 | + * Correct error message. |
1041 | + """ |
1042 | + self.ui.ui.email_edit.setText("foo@bar") |
1043 | + self.ui.ui.confirm_email_edit.setText("foo@baz") |
1044 | + self.ui.confirm_email_assistance() |
1045 | + self.ui.show() |
1046 | + self.addCleanup(self.ui.hide) |
1047 | + self.assertTrue(self.ui.ui.confirm_email_assistance.isVisible()) |
1048 | + self.assertEqual( |
1049 | + unicode(self.ui.ui.confirm_email_assistance.text()), |
1050 | + setup_account.ERROR % setup_account.EMAIL_MATCH) |
1051 | + self.ui.hide() |
1052 | + |
1053 | + def test_short_password(self): |
1054 | + """Status with short password. |
1055 | + |
1056 | + * Password assistance contains the right message. |
1057 | + """ |
1058 | + self.ui.ui.password_edit.setText("foobar") |
1059 | + self.ui.password_assistance() |
1060 | + self.assertIn( |
1061 | + setup_account.BAD % setup_account.PASSWORD_LENGTH, |
1062 | + unicode(self.ui.ui.password_assistance.text()), |
1063 | + ) |
1064 | + |
1065 | + def test_long_password(self): |
1066 | + """Status with long password. |
1067 | + |
1068 | + * Password assistance contains the right message. |
1069 | + """ |
1070 | + self.ui.ui.password_edit.setText("foobarbaz") |
1071 | + self.ui.password_assistance() |
1072 | + self.assertIn( |
1073 | + setup_account.GOOD % setup_account.PASSWORD_LENGTH, |
1074 | + unicode(self.ui.ui.password_assistance.text()), |
1075 | + ) |
1076 | + |
1077 | + def test_no_number_password(self): |
1078 | + """Status with password without a number. |
1079 | + |
1080 | + * Password assistance contains the right message. |
1081 | + """ |
1082 | + self.ui.ui.password_edit.setText("foobarbaz") |
1083 | + self.ui.password_assistance() |
1084 | + self.assertIn( |
1085 | + setup_account.BAD % setup_account.PASSWORD_DIGIT, |
1086 | + unicode(self.ui.ui.password_assistance.text()), |
1087 | + ) |
1088 | + |
1089 | + def test_number_password(self): |
1090 | + """Status with password with a number. |
1091 | + |
1092 | + * Password assistance contains the right message. |
1093 | + """ |
1094 | + self.ui.ui.password_edit.setText("foobarba7") |
1095 | + self.ui.password_assistance() |
1096 | + self.assertIn( |
1097 | + setup_account.GOOD % setup_account.PASSWORD_DIGIT, |
1098 | + unicode(self.ui.ui.password_assistance.text()), |
1099 | + ) |
1100 | + |
1101 | + def test_no_uppercase_password(self): |
1102 | + """Status with password without uppercase letters. |
1103 | + |
1104 | + * Password assistance contains the right message. |
1105 | + """ |
1106 | + self.ui.ui.password_edit.setText("foobarbaz") |
1107 | + self.ui.password_assistance() |
1108 | + self.assertIn( |
1109 | + setup_account.BAD % setup_account.PASSWORD_UPPER, |
1110 | + unicode(self.ui.ui.password_assistance.text()), |
1111 | + ) |
1112 | + |
1113 | + def test_upper_password(self): |
1114 | + """Status with password with uppercase letters. |
1115 | + |
1116 | + * Password assistance contains the right message. |
1117 | + """ |
1118 | + self.ui.ui.password_edit.setText("Foobarba7") |
1119 | + self.ui.password_assistance() |
1120 | + self.assertIn( |
1121 | + setup_account.GOOD % setup_account.PASSWORD_UPPER, |
1122 | + unicode(self.ui.ui.password_assistance.text()), |
1123 | + ) |
1124 | + |
1125 | + def test_matching_passwords(self): |
1126 | + """Status when the passwords match. |
1127 | + |
1128 | + * Password assistance doesn't contain the message. |
1129 | + """ |
1130 | + self.ui.ui.password_edit.setText("Foobarba7") |
1131 | + self.ui.ui.confirm_password_edit.setText("Foobarba7") |
1132 | + self.ui.password_check_match() |
1133 | + self.assertNotIn( |
1134 | + setup_account.BAD % setup_account.PASSWORD_MATCH, |
1135 | + unicode(self.ui.ui.password_assistance.text())) |
1136 | + |
1137 | + def test_not_matching_passwords(self): |
1138 | + """Status when the passwords not match. |
1139 | + |
1140 | + * Password assistance contains the right message. |
1141 | + """ |
1142 | + self.ui.ui.password_edit.setText("Foobarba7") |
1143 | + self.ui.ui.confirm_password_edit.setText("BazBarFo0") |
1144 | + self.ui.password_check_match() |
1145 | + self.assertIn( |
1146 | + setup_account.BAD % setup_account.PASSWORD_MATCH, |
1147 | + unicode(self.ui.ui.password_assistance.text()), |
1148 | + ) |
1149 | + |
1150 | + def test_password_default_assistance(self): |
1151 | + """Status when the password line edit receive focus and shows popup. |
1152 | + |
1153 | + * Password assistance contains the right message. |
1154 | + """ |
1155 | + self.ui.ui.password_edit.setText("") |
1156 | + self.ui.ui.confirm_password_edit.setText("") |
1157 | + self.ui.validate_data_on_focus_changed(4) |
1158 | + self.ui.focus_changed(None, self.ui.ui.password_edit) |
1159 | + self.assertIn( |
1160 | + setup_account.NORMAL % setup_account.PASSWORD_LENGTH, |
1161 | + unicode(self.ui.ui.password_assistance.text()), |
1162 | + ) |
1163 | + self.assertIn( |
1164 | + setup_account.NORMAL % setup_account.PASSWORD_UPPER, |
1165 | + unicode(self.ui.ui.password_assistance.text()), |
1166 | + ) |
1167 | + self.assertIn( |
1168 | + setup_account.NORMAL % setup_account.PASSWORD_DIGIT, |
1169 | + unicode(self.ui.ui.password_assistance.text()), |
1170 | + ) |
1171 | + |
1172 | + def test_password_assistance_in_focus_length_correct(self): |
1173 | + """Check the QLineEdit for password when the length is correct.""" |
1174 | + self.ui.ui.password_edit.setText("aaaaaaaaa") |
1175 | + self.ui.ui.confirm_password_edit.setText("") |
1176 | + self.ui.password_assistance(setup_account.NORMAL) |
1177 | + self.assertIn( |
1178 | + setup_account.GOOD % setup_account.PASSWORD_LENGTH, |
1179 | + unicode(self.ui.ui.password_assistance.text()), |
1180 | + ) |
1181 | + self.assertIn( |
1182 | + setup_account.NORMAL % setup_account.PASSWORD_UPPER, |
1183 | + unicode(self.ui.ui.password_assistance.text()), |
1184 | + ) |
1185 | + self.assertIn( |
1186 | + setup_account.NORMAL % setup_account.PASSWORD_DIGIT, |
1187 | + unicode(self.ui.ui.password_assistance.text()), |
1188 | + ) |
1189 | + |
1190 | + def test_password_assistance_in_focus_with_upper(self): |
1191 | + """Check the QLineEdit for password when it has an upper case char.""" |
1192 | + self.ui.ui.password_edit.setText("AAa") |
1193 | + self.ui.ui.confirm_password_edit.setText("") |
1194 | + self.ui.password_assistance(setup_account.NORMAL) |
1195 | + self.assertIn( |
1196 | + setup_account.NORMAL % setup_account.PASSWORD_LENGTH, |
1197 | + unicode(self.ui.ui.password_assistance.text()), |
1198 | + ) |
1199 | + self.assertIn( |
1200 | + setup_account.GOOD % setup_account.PASSWORD_UPPER, |
1201 | + unicode(self.ui.ui.password_assistance.text()), |
1202 | + ) |
1203 | + self.assertIn( |
1204 | + setup_account.NORMAL % setup_account.PASSWORD_DIGIT, |
1205 | + unicode(self.ui.ui.password_assistance.text()), |
1206 | + ) |
1207 | + |
1208 | + def test_password_assistance_in_focus_with_number(self): |
1209 | + """Check the QLineEdit for password when it contains numbers.""" |
1210 | + self.ui.ui.password_edit.setText("a123") |
1211 | + self.ui.ui.confirm_password_edit.setText("") |
1212 | + self.ui.password_assistance(setup_account.NORMAL) |
1213 | + self.assertIn( |
1214 | + setup_account.NORMAL % setup_account.PASSWORD_LENGTH, |
1215 | + unicode(self.ui.ui.password_assistance.text()), |
1216 | + ) |
1217 | + self.assertIn( |
1218 | + setup_account.NORMAL % setup_account.PASSWORD_UPPER, |
1219 | + unicode(self.ui.ui.password_assistance.text()), |
1220 | + ) |
1221 | + self.assertIn( |
1222 | + setup_account.GOOD % setup_account.PASSWORD_DIGIT, |
1223 | + unicode(self.ui.ui.password_assistance.text()), |
1224 | + ) |
1225 | + |
1226 | + def test_password_assistance_in_focus_all_ok(self): |
1227 | + """Check the QLineEdit for password when all the condition are ok.""" |
1228 | + self.ui.ui.password_edit.setText("T3st3rqw") |
1229 | + self.ui.ui.confirm_password_edit.setText("T3st3rqw") |
1230 | + self.ui.password_assistance(setup_account.NORMAL) |
1231 | + self.assertIn( |
1232 | + setup_account.GOOD % setup_account.PASSWORD_LENGTH, |
1233 | + unicode(self.ui.ui.password_assistance.text()), |
1234 | + ) |
1235 | + self.assertIn( |
1236 | + setup_account.GOOD % setup_account.PASSWORD_UPPER, |
1237 | + unicode(self.ui.ui.password_assistance.text()), |
1238 | + ) |
1239 | + self.assertIn( |
1240 | + setup_account.GOOD % setup_account.PASSWORD_DIGIT, |
1241 | + unicode(self.ui.ui.password_assistance.text()), |
1242 | + ) |
1243 | + self.assertNotIn( |
1244 | + setup_account.NORMAL % setup_account.PASSWORD_MATCH, |
1245 | + unicode(self.ui.ui.password_assistance.text()), |
1246 | + ) |
1247 | + |
1248 | + def test_side_widget_state(self): |
1249 | + """Test if the side widget of the wizard has state frame visible.""" |
1250 | + if type(self.ui) != gui.MainWindow: |
1251 | + return |
1252 | + self.ui.on_currentIdChanged(self.ui.LICENSE_PAGE) |
1253 | + self.assertTrue(self.ui.sideWidget().ui.states_frame.isVisible()) |
1254 | + self.ui.on_currentIdChanged(self.ui.SIGNIN_PAGE) |
1255 | + self.assertTrue(self.ui.sideWidget().ui.states_frame.isVisible()) |
1256 | + self.ui.on_currentIdChanged(self.ui.local_folders_page_id) |
1257 | + self.assertTrue(self.ui.sideWidget().ui.states_frame.isVisible()) |
1258 | + self.ui.on_currentIdChanged(self.ui.CONGRATULATIONS_PAGE) |
1259 | + self.assertTrue(self.ui.sideWidget().ui.states_frame.isVisible()) |
1260 | + |
1261 | + def test_check_valid(self): |
1262 | + """Check the propery value of a QLineEdit marked as valid.""" |
1263 | + self.ui.check_as_valid(self.ui.ui.name_edit) |
1264 | + self.assertFalse(self.ui.ui.name_edit.property("formError").toBool()) |
1265 | + |
1266 | + def test_check_invalid(self): |
1267 | + """Check the propery value of a QLineEdit marked as invalid.""" |
1268 | + self.ui.check_as_invalid(self.ui.ui.name_edit) |
1269 | + self.assertTrue(self.ui.ui.name_edit.property("formError").toBool()) |
1270 | + |
1271 | + def test_focus_changed_1(self): |
1272 | + """Check functions execution when focus_changed() is executed.""" |
1273 | + self.patch(self.ui, 'validation_functions', FakeValidationDict()) |
1274 | + self.ui.validate_data_on_focus_changed(1) |
1275 | + self.assertTrue(getattr(FakeValidationDict, "valid0")) |
1276 | + self.assertFalse(getattr(FakeValidationDict, "valid1")) |
1277 | + self.assertFalse(getattr(FakeValidationDict, "valid2")) |
1278 | + self.assertFalse(getattr(FakeValidationDict, "valid3")) |
1279 | + |
1280 | + def test_focus_changed_2(self): |
1281 | + """Check functions execution when focus_changed() is executed.""" |
1282 | + self.patch(self.ui, 'validation_functions', FakeValidationDict()) |
1283 | + self.ui.validate_data_on_focus_changed(2) |
1284 | + self.assertTrue(getattr(FakeValidationDict, "valid0")) |
1285 | + self.assertTrue(getattr(FakeValidationDict, "valid1")) |
1286 | + self.assertFalse(getattr(FakeValidationDict, "valid2")) |
1287 | + self.assertFalse(getattr(FakeValidationDict, "valid3")) |
1288 | + |
1289 | + def test_focus_changed_3(self): |
1290 | + """Check functions execution when focus_changed() is executed.""" |
1291 | + self.patch(self.ui, 'validation_functions', FakeValidationDict()) |
1292 | + self.ui.validate_data_on_focus_changed(3) |
1293 | + self.assertTrue(getattr(FakeValidationDict, "valid0")) |
1294 | + self.assertTrue(getattr(FakeValidationDict, "valid1")) |
1295 | + self.assertTrue(getattr(FakeValidationDict, "valid2")) |
1296 | + self.assertFalse(getattr(FakeValidationDict, "valid3")) |
1297 | + |
1298 | + def test_focus_changed_4(self): |
1299 | + """Check functions execution when focus_changed() is executed.""" |
1300 | + self.patch(self.ui, 'validation_functions', FakeValidationDict()) |
1301 | + self.ui.validate_data_on_focus_changed(4) |
1302 | + self.assertTrue(getattr(FakeValidationDict, "valid0")) |
1303 | + self.assertTrue(getattr(FakeValidationDict, "valid1")) |
1304 | + self.assertTrue(getattr(FakeValidationDict, "valid2")) |
1305 | + self.assertTrue(getattr(FakeValidationDict, "valid3")) |
1306 | + |
1307 | + def test_focus_changed_password_visibility(self): |
1308 | + """Check visibility changes when focus_changed() is executed.""" |
1309 | + self.ui.show() |
1310 | + self.addCleanup(self.ui.hide) |
1311 | + self.ui.focus_changed(None, self.ui.ui.password_edit) |
1312 | + self.assertTrue(self.ui.ui.password_assistance.isVisible()) |
Please try to put the strings in constants, and not in the code like "Your password must contain" (line 171 of the diff), which is also used in two places.
Also, since the logic now depends on the tab order, you should add a test that verifies the tab order is the right one. We should also check that the tab order agrees with the vertical order of the fields, but that's probably overkill.