~mvo/ubuntu-sso-client/strawman-lp711413

« back to all changes in this revision

Viewing changes to ubuntu_sso/qt/tests/test_windows.py

  • Committer: Tarmac
  • Author(s): Manuel de la Pena, ralsina, Roberto Alsina
  • Date: 2011-04-14 17:01:56 UTC
  • mfrom: (705.2.2 forgotten_password)
  • Revision ID: tarmac-20110414170156-4k8s1708gzgj5oi2
Fixes lp:753281

Adds the required UI and backend to allow a windows user to reset his sso password from the Windows client. Tests have been added to ensure that the backend is correctly called.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
    CurrentUserController,
25
25
    EmailVerificationController,
26
26
    ErrorController,
 
27
    ForgottenPasswordController,
 
28
    FAKE_URL,
 
29
    ResetPasswordController,
27
30
    SetUpAccountController,
28
31
    SuccessController,
29
32
    TosController,
33
36
    EMAIL1_ENTRY,
34
37
    EMAIL2_ENTRY,
35
38
    EMAIL_MISMATCH,
 
39
    EMAIL_LABEL,
36
40
    ERROR,
37
41
    EXISTING_ACCOUNT_CHOICE_BUTTON,
38
42
    FORGOTTEN_PASSWORD_BUTTON,
43
47
    PASSWORD_HELP,
44
48
    PASSWORD_TOO_WEAK,
45
49
    PASSWORD_MISMATCH,
 
50
    RESET_PASSWORD,
 
51
    RESET_CODE_ENTRY,
 
52
    REQUEST_PASSWORD_TOKEN_LABEL,
46
53
    SET_UP_ACCOUNT_CHOICE_BUTTON,
47
54
    SET_UP_ACCOUNT_BUTTON,
48
55
    SIGN_IN_BUTTON,
49
56
    SURNAME_ENTRY,
50
57
    SUCCESS,
 
58
    REQUEST_PASSWORD_TOKEN_WRONG_EMAIL,
 
59
    REQUEST_PASSWORD_TOKEN_TECH_ERROR,
51
60
    TC_BUTTON,
 
61
    TRY_AGAIN_BUTTON,
52
62
    VERIFY_EMAIL_TITLE,
53
63
    VERIFY_EMAIL_CONTENT,
54
64
    YES_TO_TC,
55
 
    is_min_required_password)
 
65
    is_min_required_password,
 
66
    is_correct_email)
56
67
 
57
68
#ignore the comon mocker issues with lint
58
 
# pylint: disable=W0212,W0104
 
69
# pylint: disable=W0212,W0104,W0106
59
70
 
60
71
 
61
72
class ChooseSignInControllerTestCase(MockerTestCase):
84
95
 
85
96
    def test_set_next_existing(self):
86
97
        """Test the execution of the callback."""
87
 
        self.view.next = self.controller._existing_account_id
 
98
        next_id = 4
 
99
        self.view.wizard().current_user_page_id
 
100
        self.mocker.result(next_id)
 
101
        self.view.next = next_id
88
102
        self.view.wizard().next()
89
103
        self.mocker.replay()
90
104
        self.controller._set_next_existing(self.view)
91
105
 
92
106
    def test_set_next_new(self):
93
107
        """Test the execution of the callback."""
94
 
        self.view.next = self.controller._new_account_id
 
108
        next_id = 5
 
109
        self.view.wizard().setup_account_page_id
 
110
        self.mocker.result(next_id)
 
111
        self.view.next = next_id
95
112
        self.view.wizard().next()
96
113
        self.mocker.replay()
97
114
        self.controller._set_next_new(self.view)
114
131
        """test that the ui is correctly set up."""
115
132
        self.view.email_edit.setPlaceholderText(EMAIL1_ENTRY)
116
133
        self.view.password_edit.setPlaceholderText(PASSWORD1_ENTRY)
117
 
        self.view.forgot_password_label.setText(FORGOTTEN_PASSWORD_BUTTON)
 
134
        self.view.forgot_password_label.setText(
 
135
                                        FAKE_URL % FORGOTTEN_PASSWORD_BUTTON)
118
136
        self.view.sign_in_button.setText(SIGN_IN_BUTTON)
119
137
        self.mocker.replay()
120
138
        self.controller._set_translated_strings(self.view)
124
142
        self.view.sign_in_button.clicked.connect(MATCH(callable))
125
143
        self.backend.on_login_error_cb = MATCH(callable)
126
144
        self.backend.on_logged_in_cb = MATCH(callable)
 
145
        self.view.forgot_password_label.linkActivated.connect(MATCH(callable))
127
146
        self.mocker.replay()
128
 
        self.controller._connect_buttons(self.view, self.backend)
 
147
        self.controller._connect_ui(self.view, self.backend)
129
148
 
130
149
 
131
150
class SetUpAccountControllerTestCase(MockerTestCase):
140
159
        self.app_name = 'test'
141
160
        self.help = 'help'
142
161
        self.message_box = self.mocker.mock()
143
 
        self.controller = SetUpAccountController(app_name=self.app_name,
144
 
                                                 help_message=self.help,
145
 
                                                 message_box=self.message_box)
 
162
        self.controller = SetUpAccountController(message_box=self.message_box)
146
163
 
147
164
    def test_set_translated_strings(self):
148
165
        """Ensure all the strings are set."""
 
166
        self.view.wizard().app_name
 
167
        self.mocker.result(self.app_name)
149
168
        self.view.name_edit.setPlaceholderText(NAME_ENTRY)
150
169
        self.view.last_name_edit.setPlaceholderText(SURNAME_ENTRY)
151
170
        self.view.email_edit.setPlaceholderText(EMAIL1_ENTRY)
164
183
 
165
184
    def test_set_titles(self):
166
185
        """Test how the different titles are set."""
 
186
        self.view.wizard()
 
187
        self.mocker.result(self.view)
 
188
        self.view.app_name
 
189
        self.mocker.result(self.app_name)
 
190
        self.view.help_text
 
191
        self.mocker.result(self.help)
167
192
        self.view.setTitle(JOIN_HEADER_LABEL % {'app_name': self.app_name})
168
193
        self.view.setSubTitle(self.help)
169
194
        self.mocker.replay()
228
253
                self.controller.is_correct_email_confirmation(email_address,
229
254
                                                              self.view))
230
255
 
231
 
    def test_is_correct_email_true(self):
232
 
        """Test when the email is correct."""
233
 
        email = 'manuel@canonical.com'
234
 
        self.mocker.replay()
235
 
        self.assertTrue(self.controller.is_correct_email(email))
236
 
 
237
 
    def test_is_correct_email_false(self):
238
 
        """Test when the email is not correct."""
239
 
        email = 'manuelcanonical.com'
240
 
        self.mocker.replay()
241
 
        self.assertFalse(self.controller.is_correct_email(email))
242
 
 
243
256
    def test_set_next_tos(self):
244
257
        """Test the callback."""
245
 
        self.view.next = self.controller._tos_id
 
258
        next_id = 2
 
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)
249
265
 
250
266
    def test_set_next_validation(self):
251
267
        """Test the callback."""
 
268
        next_id = 4
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)
256
275
        self.view.email
257
276
        self.mocker.result(email)
258
277
        self.view.email_edit.text()
276
295
        backend = self.mocker.mock()
277
296
        backend.register_user(self.app_name, email, password, captcha_id,
278
297
                              captcha_solution)
279
 
        self.view.next = self.controller._validation_id
 
298
        self.view.wizard().email_verification_page_id
 
299
        self.mocker.result(next_id)
 
300
        self.view.next = next_id
280
301
        self.view.wizard().next()
281
302
        self.mocker.replay()
282
303
        self.controller.set_next_validation(self.view, backend)
284
305
    def test_set_next_validation_wrong_email(self):
285
306
        """Test the callback when there is a wrong email."""
286
307
        email = 'email@example.com'
 
308
        self.view.wizard().app_name
 
309
        self.mocker.result(self.app_name)
287
310
        self.view.email
288
311
        self.mocker.result(email)
289
312
        self.view.email_edit.text()
298
321
        """Test the callback with a weak password."""
299
322
        weak_password = 'weak'
300
323
        email = 'email@example.com'
 
324
        self.view.wizard().app_name
 
325
        self.mocker.result(self.app_name)
301
326
        self.view.email
302
327
        self.mocker.result(email)
303
328
        self.view.email_edit.text()
314
339
        """Test the callback where the password is wrong."""
315
340
        password = 'Qwerty9923'
316
341
        email = 'email@example.com'
 
342
        self.view.wizard().app_name
 
343
        self.mocker.result(self.app_name)
317
344
        self.view.email
318
345
        self.mocker.result(email)
319
346
        self.view.email_edit.text()
344
371
        """Set the validations to be performed on the edits."""
345
372
        self.view.email_edit
346
373
        self.mocker.result(self.view)
347
 
        self.view.set_line_edit_validation_rule(self.view,
348
 
                                            self.controller.is_correct_email)
 
374
        self.view.set_line_edit_validation_rule(self.view, is_correct_email)
349
375
        self.view.confirm_email_edit
350
376
        self.mocker.result(self.view)
351
377
        self.view.set_line_edit_validation_rule(self.view, MATCH(callable))
469
495
        """Set tests."""
470
496
        super(UbuntuSSOWizardControllerTestCase, self).setUp()
471
497
        self.app_name = 'test'
472
 
        self.controller = UbuntuSSOWizardController(app_name=self.app_name)
 
498
        self.controller = UbuntuSSOWizardController()
473
499
        self.callback = self.mocker.mock()
474
500
        self.view = self.mocker.mock()
475
501
 
476
502
    def test_on_user_cancelation(self):
477
503
        """Test that the callback is indeed called."""
 
504
        self.view.app_name
 
505
        self.mocker.result(self.app_name)
478
506
        self.controller.user_cancellation_callback = self.callback
479
507
        self.callback(self.app_name)
480
508
        self.view.close()
543
571
        self.view.registrationSuccess.connect(MATCH(callable))
544
572
        self.mocker.replay()
545
573
        self.controller.setupUi(self.view)
 
574
 
 
575
 
 
576
class ForgottenPasswordControllerTestCase(MockerTestCase):
 
577
    """Test the controller of the fogotten password page."""
 
578
 
 
579
    def setUp(self):
 
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'
 
585
 
 
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)
 
592
        self.mocker.replay()
 
593
        self.controller._register_fields(self.view)
 
594
 
 
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':
 
601
                                    self.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)
 
605
        self.mocker.replay()
 
606
        self.controller._set_translated_strings(self.view)
 
607
 
 
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)
 
614
        self.mocker.replay()
 
615
        self.controller._set_enhanced_line_edit(self.view)
 
616
 
 
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)
 
624
        self.mocker.replay()
 
625
        self.controller._connect_ui(self.view, backend)
 
626
 
 
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)
 
632
        self.mocker.replay()
 
633
        self.controller.on_try_again(self.view)
 
634
 
 
635
    def test_on_password_reset_token_sent(self):
 
636
        """Test that the on_password_token_sent callback works as expected."""
 
637
        page_id = 3
 
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()
 
642
        self.mocker.replay()
 
643
        self.controller.on_password_reset_token_sent(self.view)
 
644
 
 
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)
 
650
        self.mocker.replay()
 
651
        self.controller.on_password_reset_error(self.app_name, error,
 
652
                                                self.view)
 
653
 
 
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)
 
661
        self.mocker.replay()
 
662
        self.controller.on_password_reset_error(self.app_name, error,
 
663
                                                self.view)
 
664
 
 
665
 
 
666
class ResetPasswordControllerTestCase(MockerTestCase):
 
667
    """Ensure that the reset password works as expected."""
 
668
 
 
669
    def setUp(self):
 
670
        """Setup the tests."""
 
671
        super(ResetPasswordControllerTestCase, self).setUp()
 
672
        self.view = self.mocker.mock()
 
673
        self.controller = ResetPasswordController()
 
674
 
 
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(
 
680
                                                            PASSWORD2_ENTRY)
 
681
        self.view.reset_password_button.setText(RESET_PASSWORD)
 
682
        self.view.setSubTitle(PASSWORD_HELP)
 
683
        self.mocker.replay()
 
684
        self.controller._set_translated_strings(self.view)
 
685
 
 
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)
 
692
        self.mocker.replay()
 
693
        self.controller._connect_ui(self.view, backend)
 
694
 
 
695
    def test_add_line_edits_validations(self):
 
696
        """Ensure that the line validation have been added."""
 
697
        line_edit = 'line_edit'
 
698
        emit = 'emit'
 
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)
 
709
        self.mocker.replay()
 
710
        self.controller._add_line_edits_validations(self.view)
 
711
 
 
712
    def test_set_new_password(self):
 
713
        """Test that the correct action is performed."""
 
714
        app_name = 'app_name'
 
715
        email = 'email'
 
716
        code = 'code'
 
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)
 
723
        self.view.reset_code
 
724
        self.mocker.result(code)
 
725
        self.view.password
 
726
        self.mocker.result(password)
 
727
        backend.set_new_password(app_name, email, code, password)
 
728
        self.mocker.replay()
 
729
        self.controller.set_new_password(self.view, backend)
 
730
 
 
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)
 
736
        self.mocker.replay()
 
737
        self.assertTrue(self.controller.is_correct_password_confirmation(
 
738
                                                                    password,
 
739
                                                                    self.view))
 
740
 
 
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)
 
746
        self.mocker.replay()
 
747
        self.assertFalse(self.controller.is_correct_password_confirmation(
 
748
                                                                    password,
 
749
                                                                    self.view))