228
253
self.controller.is_correct_email_confirmation(email_address,
231
def test_is_correct_email_true(self):
232
"""Test when the email is correct."""
233
email = 'manuel@canonical.com'
235
self.assertTrue(self.controller.is_correct_email(email))
237
def test_is_correct_email_false(self):
238
"""Test when the email is not correct."""
239
email = 'manuelcanonical.com'
241
self.assertFalse(self.controller.is_correct_email(email))
243
256
def test_set_next_tos(self):
244
257
"""Test the callback."""
245
self.view.next = self.controller._tos_id
259
self.view.wizard().tos_page_id
260
self.mocker.result(next_id)
261
self.view.next = next_id
246
262
self.view.wizard().next()
247
263
self.mocker.replay()
248
264
self.controller.set_next_tos(self.view)
250
266
def test_set_next_validation(self):
251
267
"""Test the callback."""
252
269
email = 'email@example.com'
253
270
password = 'Qwerty9923'
254
271
captcha_id = 'captcha_id'
255
272
captcha_solution = 'captcha_solution'
273
self.view.wizard().app_name
274
self.mocker.result(self.app_name)
257
276
self.mocker.result(email)
258
277
self.view.email_edit.text()
543
571
self.view.registrationSuccess.connect(MATCH(callable))
544
572
self.mocker.replay()
545
573
self.controller.setupUi(self.view)
576
class ForgottenPasswordControllerTestCase(MockerTestCase):
577
"""Test the controller of the fogotten password page."""
580
"""Setup the tests."""
581
super(ForgottenPasswordControllerTestCase, self).setUp()
582
self.view = self.mocker.mock()
583
self.controller = ForgottenPasswordController()
584
self.app_name = 'app_name'
586
def test_register_fields(self):
587
"""Ensure that all the diff fields are registered."""
588
line_edit = 'line_edit'
589
self.view.email_address_line_edit
590
self.mocker.result(line_edit)
591
self.view.registerField('email_address', line_edit)
593
self.controller._register_fields(self.view)
595
def test_set_translated_strings(self):
596
"""Ensure that the correct strings are translated."""
597
self.view.wizard().app_name
598
self.mocker.result(self.app_name)
599
self.view.forgotted_password_intro_label.setText(
600
REQUEST_PASSWORD_TOKEN_LABEL % {'app_name':
602
self.view.email_address_label.setText(EMAIL_LABEL)
603
self.view.send_button.setText(RESET_PASSWORD)
604
self.view.try_again_button.setText(TRY_AGAIN_BUTTON)
606
self.controller._set_translated_strings(self.view)
608
def test_set_enhanced_line_edit(self):
609
"""Test that the correct line enhancements have been added."""
610
line_edit = 'line_edit'
611
self.view.email_address_line_edit
612
self.mocker.result(line_edit)
613
self.view.set_line_edit_validation_rule(line_edit, is_correct_email)
615
self.controller._set_enhanced_line_edit(self.view)
617
def test_connect_ui(self):
618
"""Test that the correct ui signals are connected."""
619
backend = self.mocker.mock()
620
self.view.send_button.clicked.connect(MATCH(callable))
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)
625
self.controller._connect_ui(self.view, backend)
627
def test_on_try_again(self):
628
"""Test that the on_try_again callback does work as expected."""
629
self.view.error_label.setVisible(False)
630
self.view.try_again_widget.setVisible(False)
631
self.view.email_widget.setVisible(True)
633
self.controller.on_try_again(self.view)
635
def test_on_password_reset_token_sent(self):
636
"""Test that the on_password_token_sent callback works as expected."""
638
self.view.wizard().reset_password_page_id
639
self.mocker.result(page_id)
640
self.view.next = page_id
641
self.view.wizard().next()
643
self.controller.on_password_reset_token_sent(self.view)
645
def test_on_password_reset_error_token_error(self):
646
"""Test that the on_password_reset_error callback works as expected."""
647
error = dict(errtype='ResetPasswordTokenError')
648
self.view.error_label.setText(REQUEST_PASSWORD_TOKEN_WRONG_EMAIL)
649
self.view.error_label.setVisible(True)
651
self.controller.on_password_reset_error(self.app_name, error,
654
def test_on_password_reset_error_general_error(self):
655
"""Test that the on_password_reset_error callback works as expected."""
656
error = dict(errtype='RandomError')
657
self.view.email_widget.setVisible(False)
658
self.view.forgotted_password_intro_label.setVisible(False)
659
self.view.try_again_wisget.setVisible(True)
660
self.view.error_label.setText(REQUEST_PASSWORD_TOKEN_TECH_ERROR)
662
self.controller.on_password_reset_error(self.app_name, error,
666
class ResetPasswordControllerTestCase(MockerTestCase):
667
"""Ensure that the reset password works as expected."""
670
"""Setup the tests."""
671
super(ResetPasswordControllerTestCase, self).setUp()
672
self.view = self.mocker.mock()
673
self.controller = ResetPasswordController()
675
def test_set_translated_strings(self):
676
"""Ensure that the correct strings are set."""
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(
681
self.view.reset_password_button.setText(RESET_PASSWORD)
682
self.view.setSubTitle(PASSWORD_HELP)
684
self.controller._set_translated_strings(self.view)
686
def test_connect_ui(self):
687
"""Ensure that the diffent signals from the ui are connected."""
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)
693
self.controller._connect_ui(self.view, backend)
695
def test_add_line_edits_validations(self):
696
"""Ensure that the line validation have been added."""
697
line_edit = 'line_edit'
699
self.view.password_line_edit
700
self.mocker.result('line_edit')
701
self.view.set_line_edit_validation_rule(line_edit,
702
is_min_required_password)
703
self.view.confirm_password_line_edit
704
self.mocker.result('line_edit')
705
self.view.set_line_edit_validation_rule(line_edit, MATCH(callable))
706
self.view.confirm_password_line_edit.textChanged.emit
707
self.mocker.result(emit)
708
self.view.password_line_edit.textChanged.connect(emit)
710
self.controller._add_line_edits_validations(self.view)
712
def test_set_new_password(self):
713
"""Test that the correct action is performed."""
714
app_name = 'app_name'
717
password = 'password'
718
backend = self.mocker.mock()
719
self.view.wizard().app_name
720
self.mocker.result(app_name)
721
self.view.wizard().field('email_address').toString()
722
self.mocker.result(email)
724
self.mocker.result(code)
726
self.mocker.result(password)
727
backend.set_new_password(app_name, email, code, password)
729
self.controller.set_new_password(self.view, backend)
731
def test_is_correct_password_confirmation_true(self):
732
"""Test that the correct password confirmation is used."""
733
password = 'password'
734
self.view.password_line_edit.text()
735
self.mocker.result(password)
737
self.assertTrue(self.controller.is_correct_password_confirmation(
741
def test_is_correct_password_confirmation_false(self):
742
"""Test that the correct password confirmation is used."""
743
password = 'password'
744
self.view.password_line_edit.text()
745
self.mocker.result(password + password)
747
self.assertFalse(self.controller.is_correct_password_confirmation(