76
77
super(ChooseSignInControllerTestCase, self).setUp()
77
78
self.view = self.mocker.mock()
78
self.backend = self.mocker.mock()
79
79
self.controller = ChooseSignInController()
80
self.controller.view = self.view
81
self.controller.backend = self.backend
83
81
def test_set_up_translated_strings(self):
84
82
"""Ensure that the translations are used."""
85
self.view.ui.existing_account_button.setText(
83
self.view.existing_account_button.setText(
86
84
EXISTING_ACCOUNT_CHOICE_BUTTON)
87
self.view.ui.setup_account_button.setText(SET_UP_ACCOUNT_CHOICE_BUTTON)
85
self.view.new_account_button.setText(SET_UP_ACCOUNT_CHOICE_BUTTON)
88
86
self.mocker.replay()
89
self.controller._set_up_translated_strings()
87
self.controller._set_up_translated_strings(self.view)
91
89
def test_connect_buttons(self):
92
90
"""Ensure that all the buttons are correcly connected."""
93
self.view.ui.existing_account_button.clicked.connect(
94
self.controller._set_next_existing)
95
self.view.ui.setup_account_button.clicked.connect(
96
self.controller._set_next_new)
91
self.view.existing_account_button.clicked.connect(MATCH(callable))
92
self.view.new_account_button.clicked.connect(MATCH(callable))
97
93
self.mocker.replay()
98
self.controller._connect_buttons()
94
self.controller._connect_buttons(self.view)
100
96
def test_set_next_existing(self):
101
97
"""Test the execution of the callback."""
128
124
self.backend = self.mocker.mock()
129
125
self.connect = self.mocker.mock()
130
126
self.signal = self.mocker.replace('PyQt4.QtCore.SIGNAL')
131
self.controller = CurrentUserController(title='the title')
132
self.controller.view = self.view
133
self.controller.backend = self.backend
127
self.controller = CurrentUserController(title='the title',
128
backend=self.backend)
135
130
def test_translated_strings(self):
136
131
"""test that the ui is correctly set up."""
137
self.view.ui.email_edit.setPlaceholderText(EMAIL1_ENTRY)
138
self.view.ui.password_edit.setPlaceholderText(PASSWORD1_ENTRY)
139
self.view.ui.forgot_password_label.setText(
132
self.view.email_edit.setPlaceholderText(EMAIL1_ENTRY)
133
self.view.password_edit.setPlaceholderText(PASSWORD1_ENTRY)
134
self.view.forgot_password_label.setText(
140
135
FAKE_URL % FORGOTTEN_PASSWORD_BUTTON)
141
self.view.ui.sign_in_button.setText(SIGN_IN_BUTTON)
136
self.view.sign_in_button.setText(SIGN_IN_BUTTON)
142
137
self.mocker.replay()
143
self.controller._set_translated_strings()
138
self.controller._set_translated_strings(self.view)
145
140
def test_connect_ui(self):
146
141
"""test that the ui is correctly set up."""
147
self.view.ui.sign_in_button.clicked.connect(self.controller.login)
142
self.view.sign_in_button.clicked.connect(MATCH(callable))
148
143
self.backend.on_login_error_cb = MATCH(callable)
149
144
self.backend.on_logged_in_cb = MATCH(callable)
150
self.view.ui.forgot_password_label.linkActivated.connect(
145
self.view.forgot_password_label.linkActivated.connect(MATCH(callable))
152
146
self.mocker.replay()
153
self.controller._connect_ui()
147
self.controller._connect_ui(self.view, self.backend)
156
150
class SetUpAccountControllerTestCase(MockerTestCase):
160
154
"""Set the different tests."""
161
155
super(SetUpAccountControllerTestCase, self).setUp()
162
156
self.view = self.mocker.mock()
163
self.backend = self.mocker.mock()
164
157
self.get_password_strength = self.mocker.replace(
165
158
'ubuntu_sso.utils.ui.get_password_strength')
166
159
self.app_name = 'test'
167
160
self.help = 'help'
168
161
self.message_box = self.mocker.mock()
169
162
self.controller = SetUpAccountController(message_box=self.message_box)
170
self.controller.backend = self.backend
171
self.controller.view = self.view
173
164
def test_set_translated_strings(self):
174
165
"""Ensure all the strings are set."""
175
166
self.view.wizard().app_name
176
167
self.mocker.result(self.app_name)
177
self.view.ui.name_label.setText(NAME_ENTRY)
178
self.view.ui.email_label.setText(EMAIL1_ENTRY)
179
self.view.ui.confirm_email_label.setText(EMAIL2_ENTRY)
180
self.view.ui.password_label.setText(PASSWORD1_ENTRY)
181
self.view.ui.confirm_password_label.setText(PASSWORD2_ENTRY)
182
self.view.ui.password_info_label.setText(PASSWORD_HELP)
183
self.view.ui.captcha_solution_edit.setPlaceholderText(
168
self.view.name_edit.setPlaceholderText(NAME_ENTRY)
169
self.view.last_name_edit.setPlaceholderText(SURNAME_ENTRY)
170
self.view.email_edit.setPlaceholderText(EMAIL1_ENTRY)
171
self.view.confirm_email_edit.setPlaceholderText(EMAIL2_ENTRY)
172
self.view.password_edit.setPlaceholderText(PASSWORD1_ENTRY)
173
self.view.confirm_password_edit.setPlaceholderText(PASSWORD2_ENTRY)
174
self.view.password_info_label.setText(PASSWORD_HELP)
175
self.view.captcha_solution_edit.setPlaceholderText(
184
176
CAPTCHA_SOLUTION_ENTRY)
185
self.view.ui.terms_checkbox.setText(
177
self.view.terms_and_conditions_check_box.setText(
186
178
YES_TO_TC % {'app_name': self.app_name})
187
self.view.ui.terms_button.setText(TC_BUTTON)
188
self.view.ui.set_up_button.setText(SET_UP_ACCOUNT_BUTTON)
179
self.view.terms_and_conditions_button.setText(TC_BUTTON)
180
self.view.set_up_button.setText(SET_UP_ACCOUNT_BUTTON)
189
181
self.mocker.replay()
190
self.controller._set_translated_strings()
182
self.controller._set_translated_strings(self.view)
192
184
def test_set_titles(self):
193
185
"""Test how the different titles are set."""
200
192
self.view.setTitle(JOIN_HEADER_LABEL % {'app_name': self.app_name})
201
193
self.view.setSubTitle(self.help)
202
194
self.mocker.replay()
203
self.controller._set_titles()
195
self.controller._set_titles(self.view)
205
197
def test_connect_ui_elements(self):
206
198
"""Test that the ui elements are correctly connect."""
207
self.view.ui.terms_button.clicked.connect(self.controller.set_next_tos)
208
self.view.ui.set_up_button.clicked.connect(
209
self.controller.set_next_validation)
210
self.view.ui.set_up_button.setEnabled
199
backend = self.mocker.mock()
200
self.view.terms_and_conditions_button.clicked.connect(MATCH(callable))
201
self.view.set_up_button.clicked.connect(MATCH(callable))
202
self.view.password_edit.textChanged.connect(MATCH(callable))
203
self.view.set_up_button.setEnabled
211
204
self.mocker.result(lambda: None)
212
self.view.ui.terms_checkbox.stateChanged.connect(MATCH(callable))
213
self.view.ui.refresh_label.linkActivated.connect(MATCH(callable))
205
self.view.terms_and_conditions_check_box.stateChanged.connect(
207
self.view.captcha_refresh_label.linkActivated.connect(MATCH(callable))
214
208
# set the callbacks for the captcha generatio
215
self.backend.on_captcha_generated_cb = MATCH(callable)
216
self.backend.on_captcha_generation_error_cb = MATCH(callable)
217
self.backend.on_user_registration_error_cb = MATCH(callable)
218
self.backend.on_user_registered_cb = MATCH(callable)
209
backend.on_captcha_generated_cb = MATCH(callable)
210
backend.on_captcha_generation_error_cb = MATCH(callable)
211
backend.on_user_registration_error_cb = MATCH(callable)
212
backend.on_user_registered_cb = MATCH(callable)
219
213
self.mocker.replay()
220
self.controller._connect_ui_elements()
214
self.controller._connect_ui_elements(self.view, backend)
222
216
def test_is_correct_password_confirmation_false(self):
223
217
"""Test when the password is not correct."""
224
218
password = 'test'
225
self.view.ui.password_edit.text()
219
self.view.password_edit.text()
226
220
self.mocker.result('other')
227
221
self.mocker.replay()
228
222
self.assertFalse(
229
self.controller.is_correct_password_confirmation(password))
223
self.controller.is_correct_password_confirmation(password,
231
226
def test_is_correct_password_confirmation_true(self):
232
227
"""Test when the password is correct."""
233
228
password = 'test'
234
self.view.ui.password_edit.text()
229
self.view.password_edit.text()
235
230
self.mocker.result(password)
236
231
self.mocker.replay()
238
self.controller.is_correct_password_confirmation(password))
233
self.controller.is_correct_password_confirmation(password,
240
236
def test_is_correct_email_confirmation_false(self):
241
237
"""Test when the emails are not the same."""
242
238
email_address = 'address'
243
self.view.ui.email_edit.text()
239
self.view.email_edit.text()
244
240
self.mocker.result('other')
245
241
self.mocker.replay()
246
242
self.assertFalse(
247
self.controller.is_correct_email_confirmation(email_address))
243
self.controller.is_correct_email_confirmation(email_address,
249
246
def test_is_correct_email_confirmation_true(self):
250
247
"""Test when the emails are the same."""
251
248
email_address = 'address'
252
self.view.ui.email_edit.text()
249
self.view.email_edit.text()
253
250
self.mocker.result(email_address)
254
251
self.mocker.replay()
256
self.controller.is_correct_email_confirmation(email_address))
253
self.controller.is_correct_email_confirmation(email_address,
258
256
def test_set_next_tos(self):
259
257
"""Test the callback."""
263
261
self.view.next = next_id
264
262
self.view.wizard().next()
265
263
self.mocker.replay()
266
self.controller.set_next_tos()
264
self.controller.set_next_tos(self.view)
268
266
def test_set_next_validation(self):
269
267
"""Test the callback."""
271
269
email = 'email@example.com'
272
270
password = 'Qwerty9923'
273
271
captcha_id = 'captcha_id'
274
272
captcha_solution = 'captcha_solution'
275
273
self.view.wizard().app_name
276
274
self.mocker.result(self.app_name)
277
self.view.ui.name_edit.text()
278
self.mocker.result(name)
279
self.view.ui.email_edit.text()
280
self.mocker.result(email)
281
self.view.ui.email_edit.text()
282
self.mocker.result(email)
283
self.view.ui.confirm_email_edit.text()
284
self.mocker.result(email)
285
self.view.ui.password_edit.text()
286
self.mocker.result(password)
287
self.view.ui.password_edit.text()
288
self.mocker.result(password)
289
self.view.ui.confirm_password_edit.text()
276
self.mocker.result(email)
277
self.view.email_edit.text()
278
self.mocker.result(email)
279
self.view.confirm_email_edit.text()
280
self.mocker.result(email)
281
self.view.password_edit.text()
282
self.mocker.result(password)
283
self.view.password_edit.text()
284
self.mocker.result(password)
285
self.view.confirm_password_edit.text()
286
self.mocker.result(password)
288
self.mocker.result(email)
290
290
self.mocker.result(password)
291
291
self.view.captcha_id
292
292
self.mocker.result(captcha_id)
293
self.view.ui.captcha_solution_edit.text()
293
self.view.captcha_solution
294
294
self.mocker.result(captcha_solution)
295
self.backend.register_user(self.app_name, email, password, name,
296
captcha_id, captcha_solution)
295
backend = self.mocker.mock()
296
backend.register_user(self.app_name, email, password, captcha_id,
298
self.view.wizard().email_verification_page_id
299
self.mocker.result(next_id)
300
self.view.next = next_id
301
self.view.wizard().next()
297
302
self.mocker.replay()
298
self.controller.set_next_validation()
303
self.controller.set_next_validation(self.view, backend)
300
305
def test_set_next_validation_wrong_email(self):
301
306
"""Test the callback when there is a wrong email."""
302
307
email = 'email@example.com'
303
password = 'Qwerty9923'
304
308
self.view.wizard().app_name
305
309
self.mocker.result(self.app_name)
306
self.view.ui.email_edit.text()
307
311
self.mocker.result(email)
308
self.view.ui.confirm_email_edit.text()
312
self.view.email_edit.text()
313
self.mocker.result('email')
314
self.view.confirm_email_edit.text()
309
315
self.mocker.result('email2')
310
self.view.ui.password_edit.text()
311
self.mocker.result(password)
312
self.view.ui.confirm_password_edit.text()
313
self.mocker.result(password)
314
316
self.message_box.critical(self.view, self.app_name, EMAIL_MISMATCH)
315
317
self.mocker.replay()
316
self.assertFalse(self.controller.validate_form())
318
self.assertFalse(self.controller.validate_form(self.view))
318
320
def test_set_next_validation_not_min_password(self):
319
321
"""Test the callback with a weak password."""
321
323
email = 'email@example.com'
322
324
self.view.wizard().app_name
323
325
self.mocker.result(self.app_name)
324
self.view.ui.email_edit.text()
325
self.mocker.result(email)
326
self.view.ui.confirm_email_edit.text()
327
self.mocker.result(email)
328
self.view.ui.password_edit.text()
329
self.mocker.result(weak_password)
330
self.view.ui.confirm_password_edit.text()
327
self.mocker.result(email)
328
self.view.email_edit.text()
329
self.mocker.result(email)
330
self.view.confirm_email_edit.text()
331
self.mocker.result(email)
332
self.view.password_edit.text()
331
333
self.mocker.result(weak_password)
332
334
self.message_box.critical(self.view, self.app_name, PASSWORD_TOO_WEAK)
333
335
self.mocker.replay()
334
self.assertFalse(self.controller.validate_form())
336
self.assertFalse(self.controller.validate_form(self.view))
336
338
def test_set_next_validation_wrong_password(self):
337
339
"""Test the callback where the password is wrong."""
339
341
email = 'email@example.com'
340
342
self.view.wizard().app_name
341
343
self.mocker.result(self.app_name)
342
self.view.ui.email_edit.text()
343
self.mocker.result(email)
344
self.view.ui.confirm_email_edit.text()
345
self.mocker.result(email)
346
self.view.ui.password_edit.text()
347
self.mocker.result(password)
348
self.view.ui.confirm_password_edit.text()
345
self.mocker.result(email)
346
self.view.email_edit.text()
347
self.mocker.result(email)
348
self.view.confirm_email_edit.text()
349
self.mocker.result(email)
350
self.view.password_edit.text()
351
self.mocker.result(password)
352
self.view.password_edit.text()
353
self.mocker.result(password)
354
self.view.confirm_password_edit.text()
349
355
self.mocker.result('other_password')
350
356
self.message_box.critical(self.view, self.app_name, PASSWORD_MISMATCH)
351
357
self.mocker.replay()
352
self.assertFalse(self.controller.validate_form())
358
self.assertFalse(self.controller.validate_form(self.view))
360
def test_update_password_strength(self):
361
"""Test the callback."""
364
self.get_password_strength(password)
365
self.mocker.result(strength)
366
self.view.set_strength_level(strength, password)
368
self.controller.update_password_strength(password, self.view)
354
370
def test_set_line_edits_validations(self):
355
371
"""Set the validations to be performed on the edits."""
356
self.view.ui.email_edit
357
373
self.mocker.result(self.view)
358
374
self.view.set_line_edit_validation_rule(self.view, is_correct_email)
359
self.view.ui.confirm_email_edit
375
self.view.confirm_email_edit
360
376
self.mocker.result(self.view)
361
377
self.view.set_line_edit_validation_rule(self.view, MATCH(callable))
362
self.view.ui.confirm_email_edit.textChanged.emit
378
self.view.confirm_email_edit.textChanged.emit
363
379
self.mocker.result(lambda: None)
364
self.view.ui.email_edit.textChanged.connect(MATCH(callable))
365
self.view.ui.password_edit
380
self.view.email_edit.textChanged.connect(MATCH(callable))
381
self.view.password_edit
366
382
self.mocker.result(self.view)
367
383
self.view.set_line_edit_validation_rule(self.view,
368
384
is_min_required_password)
369
self.view.ui.confirm_password_edit
385
self.view.confirm_password_edit
370
386
self.mocker.result(self.view)
371
387
self.view.set_line_edit_validation_rule(self.view, MATCH(callable))
372
self.view.ui.confirm_password_edit.textChanged.emit
388
self.view.confirm_password_edit.textChanged.emit
373
389
self.mocker.result(lambda: None)
374
self.view.ui.password_edit.textChanged.connect(MATCH(callable))
390
self.view.password_edit.textChanged.connect(MATCH(callable))
375
391
self.mocker.replay()
376
self.controller._set_line_edits_validations()
392
self.controller._set_line_edits_validations(self.view)
379
395
class TosControllerTestCase(MockerTestCase):
383
399
"""Set the tests."""
384
400
super(TosControllerTestCase, self).setUp()
385
401
self.view = self.mocker.mock()
386
self.backend = self.mocker.mock()
387
402
self.title = 'title'
388
403
self.subtitle = 'sub'
390
405
self.controller = TosController(title=self.title,
391
406
subtitle=self.subtitle,
392
407
tos_url=self.url)
393
self.controller.view = self.view
395
409
def test_setup_ui(self):
396
410
"""Test the set up of the ui."""
397
411
self.view.setTitle(self.title)
398
412
self.view.setSubTitle(self.subtitle)
399
self.view.ui.terms_webkit.load(ANY)
413
self.view.webkit.load(ANY)
400
414
self.mocker.replay()
401
415
self.controller.setupUi(self.view)
409
423
super(EmailVerificationControllerTestCase, self).setUp()
410
424
self.view = self.mocker.mock()
411
self.backend = self.mocker.mock()
412
425
self.controller = EmailVerificationController()
413
self.controller.view = self.view
414
self.controller.backend = self.backend
416
427
def test_set_translated_strings(self):
417
428
"""Test that strings are translated."""
418
self.view.ui.verification_code_edit.setPlaceholderText(
429
self.view.verification_code_edit.setPlaceholderText(VERIFY_EMAIL_TITLE)
420
430
self.mocker.replay()
421
self.controller._set_translated_strings()
431
self.controller._set_translated_strings(self.view)
423
433
def test_connect_ui_elements(self):
424
434
"""Set the ui connections."""
425
self.view.next_button.clicked.connect(self.controller.validate_email)
426
self.backend.on_email_validated_cb = MATCH(callable)
427
self.backend.on_email_validation_error_cb = \
428
self.controller.on_email_validation_error
435
self.view.next_button.clicked.connect(MATCH(callable))
429
436
self.mocker.replay()
430
self.controller._connect_ui_elements()
437
self.controller._connect_ui_elements(self.view)
432
439
def test_set_titles(self):
433
440
"""Test that the titles are set."""
434
441
self.view.setTitle(VERIFY_EMAIL_TITLE)
435
442
self.view.setSubTitle(VERIFY_EMAIL_CONTENT)
436
443
self.mocker.replay()
437
self.controller._set_titles()
444
self.controller._set_titles(self.view)
439
def test_validate_email(self):
446
def test_next_page(self):
440
447
"""Test the callback."""
441
email_address = 'email@test.com'
442
password = 'password'
443
app_name = 'app_name'
445
self.view.wizard().field('email_address').toString()
446
self.mocker.result(email_address)
447
self.view.wizard().field('password').toString()
448
self.mocker.result(password)
449
self.view.wizard().app_name
450
self.mocker.result(app_name)
451
self.view.ui.verification_code_edit.text()
452
self.mocker.result(code)
453
self.backend.validate_email(app_name, email_address, password, code)
448
self.view.wizard().next()
454
449
self.mocker.replay()
455
self.controller.validate_email()
450
self.controller.next_page(self.view)
458
453
class ErrorControllerTestCase(MockerTestCase):
462
457
"""Set the tests."""
463
458
super(ErrorControllerTestCase, self).setUp()
464
self.view = self.mocker.mock()
465
self.backend = self.mocker.mock()
466
459
self.controller = ErrorController()
467
self.controller.view = self.view
468
self.controller.backend = self.backend
460
self.view = self.mocker.mock()
470
462
def test_set_ui(self):
471
463
"""Test the process that sets the ui."""
472
464
self.view.next = -1
473
self.view.ui.error_message_label
465
self.view.error_message_label
474
466
self.mocker.result(self.view)
475
467
self.view.setText(ERROR)
476
468
self.mocker.replay()
484
476
"""Set the tests."""
485
477
super(SuccessControllerTestCase, self).setUp()
486
self.view = self.mocker.mock()
487
self.backend = self.mocker.mock()
488
478
self.controller = SuccessController()
489
self.controller.view = self.view
490
self.controller.backend = self.backend
479
self.view = self.mocker.mock()
492
481
def test_set_ui(self):
493
482
"""Test the process that sets the ui."""
494
483
self.view.next = -1
495
self.view.ui.success_message_label
484
self.view.success_message_label
496
485
self.mocker.result(self.view)
497
486
self.view.setText(SUCCESS)
498
487
self.mocker.replay()
507
496
super(UbuntuSSOWizardControllerTestCase, self).setUp()
508
497
self.app_name = 'test'
509
self.view = self.mocker.mock()
510
self.backend = self.mocker.mock()
498
self.controller = UbuntuSSOWizardController()
511
499
self.callback = self.mocker.mock()
512
self.controller = UbuntuSSOWizardController()
513
self.controller.view = self.view
514
self.controller.backend = self.backend
500
self.view = self.mocker.mock()
516
502
def test_on_user_cancelation(self):
517
503
"""Test that the callback is indeed called."""
574
560
self.view.setButtonLayout(buttons_layout)
575
561
self.mocker.replay()
576
self.controller.show_error_message()
562
self.controller.show_error_message(self.view)
578
564
def test_setup_ui(self):
579
565
"""Test that the ui is connect."""
580
566
self.view.setWizardStyle(QWizard.ModernStyle)
581
567
self.view.button(QWizard.CancelButton)
582
568
self.mocker.result(self.view)
583
self.view.clicked.connect(self.controller.on_user_cancelation)
584
self.view.loginSuccess.connect(self.controller.on_login_success)
585
self.view.registrationSuccess.connect(
586
self.controller.on_registration_success)
569
self.view.clicked.connect(MATCH(callable))
570
self.view.loginSuccess.connect(MATCH(callable))
571
self.view.registrationSuccess.connect(MATCH(callable))
587
572
self.mocker.replay()
588
573
self.controller.setupUi(self.view)
630
612
self.mocker.result(line_edit)
631
613
self.view.set_line_edit_validation_rule(line_edit, is_correct_email)
632
614
self.mocker.replay()
633
self.controller._set_enhanced_line_edit()
615
self.controller._set_enhanced_line_edit(self.view)
635
617
def test_connect_ui(self):
636
618
"""Test that the correct ui signals are connected."""
619
backend = self.mocker.mock()
637
620
self.view.send_button.clicked.connect(MATCH(callable))
638
self.view.try_again_button.clicked.connect(
639
self.controller.on_try_again)
640
self.backend.on_password_reset_token_sent_cb = MATCH(callable)
641
self.backend.on_password_reset_error_cb = \
642
self.controller.on_password_reset_error
621
self.view.try_again_button.clicked.connect(MATCH(callable))
622
backend.on_password_reset_token_sent_cb = MATCH(callable)
623
backend.on_password_reset_error_cb = MATCH(callable)
643
624
self.mocker.replay()
644
self.controller._connect_ui()
625
self.controller._connect_ui(self.view, backend)
646
627
def test_on_try_again(self):
647
628
"""Test that the on_try_again callback does work as expected."""
687
670
"""Setup the tests."""
688
671
super(ResetPasswordControllerTestCase, self).setUp()
689
672
self.view = self.mocker.mock()
690
self.backend = self.mocker.mock()
691
673
self.controller = ResetPasswordController()
692
self.controller.view = self.view
693
self.controller.backend = self.backend
695
675
def test_set_translated_strings(self):
696
676
"""Ensure that the correct strings are set."""
697
self.view.ui.reset_code_line_edit.setPlaceholderText(RESET_CODE_ENTRY)
698
self.view.ui.password_line_edit.setPlaceholderText(PASSWORD1_ENTRY)
699
self.view.ui.confirm_password_line_edit.setPlaceholderText(
677
self.view.reset_code_line_edit.setPlaceholderText(RESET_CODE_ENTRY)
678
self.view.password_line_edit.setPlaceholderText(PASSWORD1_ENTRY)
679
self.view.confirm_password_line_edit.setPlaceholderText(
701
self.view.ui.reset_password_button.setText(RESET_PASSWORD)
681
self.view.reset_password_button.setText(RESET_PASSWORD)
702
682
self.view.setSubTitle(PASSWORD_HELP)
703
683
self.mocker.replay()
704
self.controller._set_translated_strings()
684
self.controller._set_translated_strings(self.view)
706
686
def test_connect_ui(self):
707
687
"""Ensure that the diffent signals from the ui are connected."""
708
self.view.ui.reset_password_button.clicked.connect(
709
self.controller.set_new_password)
710
self.backend.on_password_changed_cb = \
711
self.controller.on_password_changed
712
self.backend.on_password_change_error_cb = \
713
self.controller.on_password_change_error
688
backend = self.mocker.mock()
689
self.view.reset_password_button.clicked.connect(MATCH(callable))
690
backend.on_password_changed_cb = MATCH(callable)
691
backend.on_password_change_error_cb = MATCH(callable)
714
692
self.mocker.replay()
715
self.controller._connect_ui()
693
self.controller._connect_ui(self.view, backend)
717
695
def test_add_line_edits_validations(self):
718
696
"""Ensure that the line validation have been added."""
719
697
line_edit = 'line_edit'
721
self.view.ui.password_line_edit
699
self.view.password_line_edit
722
700
self.mocker.result('line_edit')
723
701
self.view.set_line_edit_validation_rule(line_edit,
724
702
is_min_required_password)
725
self.view.ui.confirm_password_line_edit
703
self.view.confirm_password_line_edit
726
704
self.mocker.result('line_edit')
727
705
self.view.set_line_edit_validation_rule(line_edit, MATCH(callable))
728
self.view.ui.confirm_password_line_edit.textChanged.emit
706
self.view.confirm_password_line_edit.textChanged.emit
729
707
self.mocker.result(emit)
730
self.view.ui.password_line_edit.textChanged.connect(emit)
708
self.view.password_line_edit.textChanged.connect(emit)
731
709
self.mocker.replay()
732
self.controller._add_line_edits_validations()
710
self.controller._add_line_edits_validations(self.view)
734
712
def test_set_new_password(self):
735
713
"""Test that the correct action is performed."""
739
717
password = 'password'
718
backend = self.mocker.mock()
740
719
self.view.wizard().app_name
741
720
self.mocker.result(app_name)
742
721
self.view.wizard().field('email_address').toString()
743
722
self.mocker.result(email)
744
self.view.ui.reset_code_line_edit.text()
745
724
self.mocker.result(code)
746
self.view.ui.password_line_edit.text()
747
726
self.mocker.result(password)
748
self.backend.set_new_password(app_name, email, code, password)
727
backend.set_new_password(app_name, email, code, password)
749
728
self.mocker.replay()
750
self.controller.set_new_password()
729
self.controller.set_new_password(self.view, backend)
752
731
def test_is_correct_password_confirmation_true(self):
753
732
"""Test that the correct password confirmation is used."""
754
733
password = 'password'
755
self.view.ui.password_line_edit.text()
734
self.view.password_line_edit.text()
756
735
self.mocker.result(password)
757
736
self.mocker.replay()
758
737
self.assertTrue(self.controller.is_correct_password_confirmation(
761
741
def test_is_correct_password_confirmation_false(self):
762
742
"""Test that the correct password confirmation is used."""
763
743
password = 'password'
764
self.view.ui.password_line_edit.text()
744
self.view.password_line_edit.text()
765
745
self.mocker.result(password + password)
766
746
self.mocker.replay()
767
747
self.assertFalse(self.controller.is_correct_password_confirmation(