1
# -*- coding: utf-8 -*-
3
# Authors: Manuel de la Pena <manuel@canonical.com>
4
# Natalia B. Bidart <natalia.bidart@canonical.com>
6
# Copyright 2011 Canonical Ltd.
8
# This program is free software: you can redistribute it and/or modify it
9
# under the terms of the GNU General Public License version 3, as published
10
# by the Free Software Foundation.
12
# This program is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranties of
14
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
15
# PURPOSE. See the GNU General Public License for more details.
17
# You should have received a copy of the GNU General Public License along
18
# with this program. If not, see <http://www.gnu.org/licenses/>.
20
"""Test the ui controllers."""
24
from twisted.internet import defer
26
# pylint: disable=F0401,E0611
28
from PyQt4.QtCore import QString, SIGNAL
29
from PyQt4.QtGui import QCheckBox, QLabel, QLineEdit, QWizard
35
# pylint: enable=F0401,E0611
37
from ubuntu_sso.qt.controllers import (
39
ChooseSignInController,
40
CurrentUserController,
41
EmailVerificationController,
43
ForgottenPasswordController,
44
ResetPasswordController,
45
SetUpAccountController,
47
UbuntuSSOWizardController,
49
from ubuntu_sso.qt.tests import BaseTestCase, FakePageUiStyle
50
from ubuntu_sso.utils.ui import (
51
CAPTCHA_REQUIRED_ERROR,
52
CAPTCHA_SOLUTION_ENTRY,
59
EXISTING_ACCOUNT_CHOICE_BUTTON,
60
FORGOTTEN_PASSWORD_BUTTON,
71
REQUEST_PASSWORD_TOKEN_LABEL,
72
SET_UP_ACCOUNT_CHOICE_BUTTON,
75
REQUEST_PASSWORD_TOKEN_WRONG_EMAIL,
76
REQUEST_PASSWORD_TOKEN_TECH_ERROR,
82
#ignore the comon mocker issues with lint
83
# pylint: disable=W0212,W0104,W0106,E1103
86
class FakeButton(FakePageUiStyle):
91
"""Initialize object."""
92
super(FakeButton, self).__init__()
96
def connect(self, function):
97
"""Receive the function that should be connected to this button."""
98
self.function = function
101
class FakeField(object):
103
"""Fake Field for text input."""
105
def __init__(self, text):
108
# pylint: disable=C0103
110
"""Fake toString method for input fields."""
112
# pylint: enable=C0103
115
class FakeWizard(object):
119
current_user_page_id = 1
120
setup_account_page_id = 2
121
forgotten_password_page_id = 3
122
reset_password_page_id = 4
124
def __init__(self, view):
125
"""Initialize object."""
127
self.app_name = 'app_name'
128
self.help_text = 'help'
131
# pylint: disable=C0103
132
self.loginSuccess = self
133
self.registrationSuccess = self
134
# pylint: enable=C0103
135
self.forgotten = self
137
self.email_line_edit = QLineEdit()
139
# pylint: disable=C0103
140
def registerField(self, key, text):
141
"""Fake registerField from wizard."""
142
self.properties['field_%s' % key] = FakeField(text)
143
# pylint: enable=C0103
145
def field(self, key):
146
"""Fake field from wizard"""
147
return self.properties['field_%s' % key]
150
"""Fake next method to move to to next page in the wizard."""
151
self.view.properties['wizard_next'] = True
153
def emit(self, name, email):
155
self.properties['emit'] = (name, email)
158
class FakeGenericView(object):
160
"""Fake Generic page."""
163
"""Initialize object."""
167
self.properties['currentId'] = -1
169
self.fake_wizard = FakeWizard(self)
171
def set_title(self, title):
172
"""Fake set_title for the page."""
173
self.properties['title'] = title
175
def set_subtitle(self, subtitle):
176
"""Fake set_subtitle for the page"""
177
self.properties['subtitle'] = subtitle
179
# pylint: disable=C0103
180
def setTitle(self, title):
182
self.set_title(title)
184
def setSubTitle(self, subtitle):
186
self.set_subtitle(subtitle)
187
# pylint: enable=C0103
190
"""Fake wizard is returned."""
191
return self.fake_wizard
194
class FakeChooseSignInView(FakeGenericView):
196
"""Fake ChooseSignIn page."""
199
"""Initialize object."""
200
super(FakeChooseSignInView, self).__init__()
201
self.existing_account_button = FakeButton()
202
self.setup_account_button = FakeButton()
205
class FakeCurrentUserView(FakeGenericView):
207
"""Fake Current User view."""
210
super(FakeCurrentUserView, self).__init__()
211
self.email_label = QLabel()
212
self.password_label = QLabel()
213
self.forgot_password_label = QLabel()
214
self.sign_in_button = FakeButton()
215
self.email_edit = QLineEdit()
216
self.password_edit = QLineEdit()
217
self.on_logged_in_cb = None
218
self.on_login_error_cb = None
220
def fake_backend(self):
221
"""Fake get_backend."""
224
def login(self, appname, email, password):
225
"""Fake backend login."""
226
self.properties['backend_login'] = (appname, email, password)
229
# pylint: disable=C0103
230
def addErrback(self, function):
231
"""Fake defer addErrback."""
232
self.properties['login-addErrback'] = function
233
# pylint: enable=C0103
236
class FakeLineEdit(object):
238
"""A fake QLineEdit."""
240
def __init__(self, *args):
248
# setText is inherited
249
# pylint: disable=C0103
250
def setText(self, text):
251
"""Return saved text."""
255
class FakePage(object):
257
"""A fake wizard page."""
266
class FakeCurrentUserPage(FakePageUiStyle):
268
"""Fake CurrentuserPage."""
270
def __init__(self, *args):
272
super(FakeCurrentUserPage, self).__init__(*args)
273
self.ui.email_edit = FakeLineEdit()
274
self.ui.password_edit = FakeLineEdit()
275
self.sign_in_button = self
278
class FakeSetupAccountPageView(FakeGenericView):
280
"""Fake SetupAccount view."""
283
super(FakeSetupAccountPageView, self).__init__()
286
self.name_label = QLabel()
287
self.email_label = QLabel()
288
self.confirm_email_label = QLabel()
289
self.password_label = QLabel()
290
self.confirm_password_label = QLabel()
291
self.password_info_label = QLabel()
292
self.refresh_label = QLabel()
293
self.name_assistance = QLabel()
294
self.email_assistance = QLabel()
295
self.confirm_email_assistance = QLabel()
297
self.captcha_solution_edit = QLineEdit()
298
self.name_edit = QLineEdit()
299
self.email_edit = QLineEdit()
300
self.confirm_email_edit = QLineEdit()
301
self.password_edit = QLineEdit()
302
self.confirm_password_edit = QLineEdit()
303
self.captcha_solution_edit = QLineEdit()
305
self.terms_checkbox = QCheckBox()
307
self.set_up_button = FakeButton()
309
self.on_captcha_generated_cb = None
310
self.on_captcha_generation_error_cb = None
311
self.on_user_registered_cb = None
312
self.on_user_registration_error_cb = None
314
def fake_backend(self):
315
"""Fake get_backend."""
318
def set_line_edit_validation_rule(self, edit, function):
319
"""Fake set_line_edit_validation_rule from view."""
320
elements = self.properties.get('validation_rule', None)
323
elements.append((edit, function))
324
self.properties['validation_rule'] = elements
326
# pylint: disable=C0103
327
def registerField(self, key, edit):
328
"""Fake registerField from page."""
329
self.properties[key] = edit
330
# pylint: enable=C0103
332
def set_error_message(self, label, message):
333
"""Fake set_error_message."""
334
label.setText(message)
337
class FakeMessageBox(object):
339
"""A fake message box."""
344
def __init__(self, *args, **kwargs):
345
self.args = (args, kwargs)
347
def critical(self, *args, **kwargs):
348
"""Fake critical popup."""
349
self.critical_args = (args, kwargs)
352
class FakeSetupAccountUi(object):
353
"""Fake ui variable for FakeView."""
355
email_assistance = None
358
class FakeView(object):
363
ui = FakeSetupAccountUi()
366
"""Use itself as a fake wizard, too."""
369
def set_error_message(self, label, msg):
370
"""Simulate to add the message to the label as SetupAccount do."""
373
class FakeSetupAccountView(FakeView):
379
captcha_refresh_executed = False
380
captcha_refreshing_value = False
382
def on_captcha_refresh_complete(self):
383
"""Fake the call to refresh finished."""
384
self.captcha_refresh_executed = True
386
def on_captcha_refreshing(self):
387
"""Fake the call to refreshing."""
388
self.captcha_refreshing_value = True
390
def fake_open(self, filename):
391
"""Fake open for Image."""
394
# pylint: disable=W0622
395
def save(self, io, format):
396
"""Fake save for Image."""
397
# pylint: enable=W0622
400
class FakeControllerForCaptcha(object):
402
"""Fake controller to test refresh_captcha method."""
405
"""Initialize FakeControllerForCaptcha."""
406
self.callback_error = False
408
def generate_captcha(self, *args):
409
"""Fake generate deferred for captcha."""
412
# pylint: disable=C0103
413
def addErrback(self, call):
414
"""Fake addErrback."""
415
self.callback_error = call is not None
416
# pylint: enable=C0103
419
class FakeEmailVerificationView(FakePageUiStyle):
420
"""Fake EmailVerification Page."""
422
def __init__(self, *args):
424
super(FakeEmailVerificationView, self).__init__(*args)
425
self.verification_code = ''
426
self.next_button = self
429
class EmailVerificationView(FakeGenericView):
431
"""Fake Email Verification view."""
434
super(EmailVerificationView, self).__init__()
437
self.verification_code_edit = QLineEdit()
438
self.verification_code = ''
440
self.next_button = FakeButton()
442
self.on_email_validated_cb = None
443
self.on_email_validation_error_cb = None
445
def fake_backend(self):
446
"""Fake get_backend."""
449
def validate_email(self, *args, **kwargs):
450
"""Fake validate_email method from backend"""
451
self.properties['validate_email'] = (args, kwargs)
454
class ErrorPageView(FakeGenericView):
456
"""Fake Error Page view."""
459
super(ErrorPageView, self).__init__()
461
self.error_message_label = QLabel()
464
class SuccessPageView(FakeGenericView):
466
"""Fake Success Page view."""
469
super(SuccessPageView, self).__init__()
471
self.success_message_body = QLabel()
474
class UbuntuSSOView(object):
476
"""Fake view for UbuntuSSO."""
484
self.app_name = 'app_name'
485
self.success_message_label = QLabel()
487
# pylint: disable=C0103
488
self.loginSuccess = FakeButton()
489
self.registrationSuccess = FakeButton()
490
# pylint: enable=C0103
491
self.page = FakeGenericView()
493
def button(self, *args):
495
self.properties['button_method'] = args
496
self.properties['button'] = FakeButton()
497
return self.properties['button']
499
def callback(self, *args, **kwargs):
501
self.properties['callback'] = (args, kwargs)
506
self.properties['close'] = True
508
# pylint: disable=C0103
509
def setButtonLayout(self, layout):
510
"""Fake setButtonLayout."""
511
self.properties['buttons_layout'] = layout
513
def currentPage(self):
514
"""Fake currentPage."""
517
def setWizardStyle(self, style):
518
"""Fake setWizardStyle."""
519
self.properties['wizard_style'] = style
520
# pylint: enable=C0103
523
"""Fake next method to move to to next page in the wizard."""
524
self.properties['wizard_next'] = True
527
class FakeLineEditForForgottenPage(object):
532
"""Initilize object."""
533
self.email_text = QString()
536
"""Fake text for QLineEdit."""
537
return self.email_text
539
# setText is inherited
540
# pylint: disable=C0103
541
def setText(self, text):
542
"""Fake setText for QLineEdit."""
543
self.email_text = QString(text)
544
# pylint: enable=C0103
547
class FakeForgottenPasswordPage(FakePageUiStyle):
551
super(FakeForgottenPasswordPage, self).__init__()
552
self.email_address_line_edit = self
553
self.send_button = self
554
self.email_widget = FakePageUiStyle()
555
self.forgotted_password_intro_label = FakePageUiStyle()
556
self.try_again_widget = FakePageUiStyle()
557
self.email_line_edit = FakeLineEditForForgottenPage()
559
def fake_backend(self):
560
"""Fake get_backend."""
564
class FakeForgottenPasswordPageView(FakeGenericView):
568
super(FakeForgottenPasswordPageView, self).__init__()
569
self.email_address_line_edit = QLineEdit()
570
self.send_button = FakeButton()
571
self.try_again_button = FakeButton()
572
self.email_widget = FakePageUiStyle()
573
self.forgotted_password_intro_label = QLabel()
574
self.email_address_label = QLabel()
575
self.try_again_widget = FakePageUiStyle()
576
self.email_line_edit = QLineEdit()
578
self.on_password_reset_error_cb = None
579
self.on_password_reset_token_sent_cb = None
581
def fake_backend(self):
582
"""Fake get_backend."""
585
# pylint: disable=C0103
586
def registerField(self, key, item):
587
"""Fake registerField from wizard."""
588
self.properties['field_%s' % key] = item
589
# pylint: enable=C0103
591
def field(self, key):
592
"""Fake field from wizard"""
593
return self.properties['field_%s' % key]
595
def set_line_edit_validation_rule(self, edit, function):
596
"""Fake set_line_edit_validation_rule from view."""
597
elements = self.properties.get('validation_rule', None)
600
elements.append((edit, function))
601
self.properties['validation_rule'] = elements
604
class ResetPasswordPageView(FakeGenericView):
608
super(ResetPasswordPageView, self).__init__()
609
self.reset_password_button = FakeButton()
610
self.reset_code_line_edit = QLineEdit()
611
self.password_line_edit = QLineEdit()
612
self.confirm_password_line_edit = QLineEdit()
614
self.on_password_changed_cb = None
615
self.on_password_change_error_cb = None
617
def fake_backend(self):
618
"""Fake get_backend."""
621
# pylint: disable=C0103
622
def registerField(self, key, item):
623
"""Fake registerField from wizard."""
624
self.properties['field_%s' % key] = item
625
# pylint: enable=C0103
627
def field(self, key):
628
"""Fake field from wizard"""
629
return self.properties['field_%s' % key]
631
def set_line_edit_validation_rule(self, edit, function):
632
"""Fake set_line_edit_validation_rule from view."""
633
elements = self.properties.get('validation_rule', None)
636
elements.append((edit, function))
637
self.properties['validation_rule'] = elements
639
def set_new_password(self, *args, **kwargs):
640
"""Fake set_new_password from backend."""
641
self.properties['backend_new_password'] = (args, kwargs)
644
class FakeResetPasswordPage(FakePageUiStyle):
646
"""Fake ResetPasswordPage."""
648
def __init__(self, *args):
650
super(FakeResetPasswordPage, self).__init__()
651
self.ui.reset_code_line_edit = FakeLineEdit()
652
self.ui.password_line_edit = FakeLineEdit()
653
self.ui.confirm_password_line_edit = FakeLineEdit()
654
self.reset_password_button = self
655
self._enabled = 9 # Intentionally wrong.
658
class FakeWizardForResetPassword(object):
660
"""Fake Wizard for ResetPasswordController."""
663
self.current_user = self
665
self.email_edit = self
666
self.email_line_edit = self
667
self.forgotten = self
670
self.hide_value = False
671
self.text_value = 'mail@mail.com'
672
self.current_user_page_id = 4
675
"""Fake wizard function for view."""
679
"""Fake back for wizard."""
683
"""Fake hide for overlay."""
684
self.hide_value = True
687
"""Fake text for QLineEdit."""
688
return self.text_value
690
# pylint: disable=C0103
691
def setText(self, text):
692
"""Fake setText for QLineEdit."""
693
self.text_value = text
695
def visitedPages(self):
696
"""Return an int list of fake visited pages."""
698
# pylint: enable=C0103
701
class BackendControllerTestCase(BaseTestCase):
702
"""The test case for the BackendController."""
704
@defer.inlineCallbacks
706
yield super(BackendControllerTestCase, self).setUp()
707
self.backend = BackendController()
709
@defer.inlineCallbacks
710
def test_get_backend(self):
711
"""The backend is properly retrieved."""
712
result = yield self.backend.get_backend()
713
self.assertTrue(self.sso_login_backend is result)
716
class ChooseSignInControllerTestCase(BaseTestCase):
717
"""Test the choose sign in controller."""
719
@defer.inlineCallbacks
722
yield super(ChooseSignInControllerTestCase, self).setUp()
724
self.subtitle = 'subtitle'
725
self.controller = ChooseSignInController(self.title, self.subtitle)
726
self.view = FakeChooseSignInView()
727
self.controller.view = self.view
729
def test_setup_ui(self):
730
"""Test the set up of the ui."""
731
self.controller.setupUi(self.view)
732
self.assertEqual(self.view.properties['title'], self.title)
733
self.assertEqual(self.view.properties['subtitle'], self.subtitle)
734
self.assertEqual(self.view.existing_account_button.text(),
735
EXISTING_ACCOUNT_CHOICE_BUTTON)
736
self.assertEqual(self.view.setup_account_button.text(),
737
SET_UP_ACCOUNT_CHOICE_BUTTON)
738
self.assertIsInstance(self.view.existing_account_button.function,
739
collections.Callable)
740
self.assertIsInstance(self.view.setup_account_button.function,
741
collections.Callable)
743
def test_set_up_translated_strings(self):
744
"""Ensure that the translations are used."""
745
self.controller._set_up_translated_strings()
746
self.assertEqual(self.view.existing_account_button.text(),
747
EXISTING_ACCOUNT_CHOICE_BUTTON)
748
self.assertEqual(self.view.setup_account_button.text(),
749
SET_UP_ACCOUNT_CHOICE_BUTTON)
751
def test_connect_buttons(self):
752
"""Ensure that all the buttons are correcly connected."""
753
self.controller._connect_buttons()
754
self.assertIsInstance(self.view.existing_account_button.function,
755
collections.Callable)
756
self.assertIsInstance(self.view.setup_account_button.function,
757
collections.Callable)
759
def test_set_next_existing(self):
760
"""Test the execution of the callback."""
761
self.controller._set_next_existing()
762
self.assertEqual(self.view.next,
763
self.view.fake_wizard.current_user_page_id)
765
def test_set_next_new(self):
766
"""Test the execution of the callback."""
767
self.controller._set_next_new()
768
self.assertEqual(self.view.next,
769
self.view.fake_wizard.setup_account_page_id)
772
class CurrentUserControllerTestCase(BaseTestCase):
773
"""Test the current user controller."""
775
@defer.inlineCallbacks
778
yield super(CurrentUserControllerTestCase, self).setUp()
779
self.controller = CurrentUserController(title='the title',
780
subtitle='the subtitle')
781
self.view = FakeCurrentUserView()
782
self.controller.view = self.view
783
self.patch(self.controller, "get_backend", self.view.fake_backend)
784
self.controller.setupUi(self.view)
786
def test_translated_strings(self):
787
"""test that the ui is correctly set up."""
788
self.controller._set_translated_strings()
789
self.assertEqual(self.view.email_label.text(), EMAIL_LABEL)
790
self.assertEqual(self.view.password_label.text(), LOGIN_PASSWORD_LABEL)
791
self.assertEqual(self.view.forgot_password_label.text(),
792
FORGOTTEN_PASSWORD_BUTTON)
793
self.assertEqual(self.view.sign_in_button.text(), SIGN_IN_BUTTON)
795
def test_connect_ui(self):
796
"""test that the ui is correctly set up."""
797
self.controller._connect_ui()
798
self.assertIsInstance(self.view.sign_in_button.function,
799
collections.Callable)
800
# Check if receivers is 2 because _connect_ui was called on setUp
801
self.assertEqual(self.view.forgot_password_label.receivers(
802
SIGNAL('linkActivated(QString)')), 2)
803
self.assertEqual(self.view.email_edit.receivers(
804
SIGNAL('textChanged(QString)')), 2)
805
self.assertEqual(self.view.password_edit.receivers(
806
SIGNAL('textChanged(QString)')), 2)
807
self.assertFalse(self.view.on_login_error_cb is None)
808
self.assertFalse(self.view.on_logged_in_cb is None)
810
def test_title_subtitle(self):
811
"""Ensure we are storing the title and subtitle correctly."""
812
self.assertEqual(self.view.properties['title'], 'the title')
813
self.assertEqual(self.view.properties['subtitle'], 'the subtitle')
815
def test_on_logged_in(self):
816
"""Test on_logged_in method."""
817
self.view.email_edit.setText('email@email.com')
818
self.controller.on_logged_in('app-name', {})
819
self.assertEqual(self.view.fake_wizard.properties['emit'],
820
('app-name', 'email@email.com'))
822
def test_login(self):
823
"""Test login method."""
824
email = 'email@email.com'
825
password = 'password'
826
self.view.email_edit.setText(email)
827
self.view.password_edit.setText(password)
828
self.controller.login()
829
self.assertEqual(self.view.properties['backend_login'],
830
(self.view.fake_wizard.app_name, email, password))
831
self.assertIsInstance(self.view.properties['login-addErrback'],
832
collections.Callable)
834
def test_on_forgotten_password(self):
835
"""Test on_forgotten_password flow."""
836
email = 'email@email.com'
837
self.view.email_edit.setText(email)
838
self.controller.on_forgotten_password()
839
self.assertEqual(self.view.next,
840
self.view.fake_wizard.forgotten_password_page_id)
841
self.assertTrue(self.view.properties['wizard_next'])
843
def test_setup_ui(self):
844
"""Test the set up of the ui."""
845
self.controller._title = 'title_setup'
846
self.controller._subtitle = 'subtitle_setup'
847
self.controller.setupUi(self.view)
848
self.assertEqual(self.view.properties['title'], 'title_setup')
849
self.assertEqual(self.view.properties['subtitle'], 'subtitle_setup')
850
self.assertIsInstance(self.view.sign_in_button.function,
851
collections.Callable)
852
# Check if receivers is 2 because _connect_ui was called on setUp
853
self.assertEqual(self.view.forgot_password_label.receivers(
854
SIGNAL('linkActivated(QString)')), 2)
855
self.assertEqual(self.view.email_edit.receivers(
856
SIGNAL('textChanged(QString)')), 2)
857
self.assertEqual(self.view.password_edit.receivers(
858
SIGNAL('textChanged(QString)')), 2)
859
self.assertFalse(self.view.on_login_error_cb is None)
860
self.assertFalse(self.view.on_logged_in_cb is None)
861
self.assertEqual(self.view.email_label.text(), EMAIL_LABEL)
862
self.assertEqual(self.view.password_label.text(), LOGIN_PASSWORD_LABEL)
863
self.assertEqual(self.view.forgot_password_label.text(),
864
FORGOTTEN_PASSWORD_BUTTON)
865
self.assertEqual(self.view.sign_in_button.text(), SIGN_IN_BUTTON)
868
class CurrentUserControllerErrorTestCase(BaseTestCase):
870
"""Tests for CurrentUserController's error handler."""
872
on_error_method_name = "on_login_error"
873
controller_class = CurrentUserController
875
@defer.inlineCallbacks
878
yield super(CurrentUserControllerErrorTestCase, self).setUp()
879
self.message_box = FakeMessageBox()
880
self.controller = self.controller_class(
881
message_box=self.message_box)
882
self.controller.view = FakePage()
883
self.on_error_method = getattr(
884
self.controller, self.on_error_method_name)
886
def test_error_message_key(self):
887
"""Test that on_login_error reacts to errors with "error_message"."""
888
self.on_error_method({"error_message": "WORRY!"})
889
self.assertEqual(self.message_box.critical_args, (('WORRY!',
890
self.controller.view), {}))
892
def test_message_key(self):
893
"""Test that on_login_error reacts to errors with "message"."""
894
self.on_error_method({"message": "WORRY!"})
895
self.assertEqual(self.message_box.critical_args, (('WORRY!',
896
self.controller.view), {}))
898
def test_broken_error(self):
899
"""Test that on_login_error reacts to broken errors."""
900
self.on_error_method({"boo!": "WORRY!"})
902
[('%s: %s' % (k, v)) for k, v in \
903
{"boo!": "WORRY!"}.iteritems()])
904
self.assertEqual(self.message_box.critical_args,
905
((result, self.controller.view), {}))
907
def test_all_and_message(self):
908
"""Test that on_login_error reacts to broken errors."""
909
self.on_error_method(
910
{"message": "WORRY!", "__all__": "MORE!"})
911
self.assertEqual(self.message_box.critical_args,
912
(('MORE!\nWORRY!', self.controller.view), {}))
914
def test_all_and_error_message(self):
915
"""Test that on_login_error reacts to broken errors."""
916
self.on_error_method(
917
{"error_message": "WORRY!", "__all__": "MORE!"})
918
self.assertEqual(self.message_box.critical_args,
919
(('MORE!\nWORRY!', self.controller.view), {}))
921
def test_only_all(self):
922
"""Test that on_login_error reacts to broken errors."""
923
self.on_error_method(
924
{"__all__": "MORE!"})
925
self.assertEqual(self.message_box.critical_args,
926
(('MORE!', self.controller.view), {}))
929
class EmailVerificationControllerErrorTestCase(
930
CurrentUserControllerErrorTestCase):
932
"""Tests for EmailVerificationController's error handler."""
934
on_error_method_name = "on_email_validation_error"
935
controller_class = EmailVerificationController
937
@defer.inlineCallbacks
940
yield super(EmailVerificationControllerErrorTestCase, self).setUp()
941
# This error handler takes one extra argument.
942
self.on_error_method = lambda error: getattr(
943
self.controller, self.on_error_method_name)('APP', error)
946
class SetUpAccountControllerErrorTestCase(
947
EmailVerificationControllerErrorTestCase):
949
"""Tests for SetUpAccountController's error handler."""
951
on_error_method_name = "on_user_registration_error"
952
controller_class = SetUpAccountController
954
@defer.inlineCallbacks
957
yield super(SetUpAccountControllerErrorTestCase, self).setUp()
958
self.patch(self.controller, "_refresh_captcha", lambda *args: None)
961
class ResetPasswordControllerErrorTestCase(
962
EmailVerificationControllerErrorTestCase):
964
"""Tests for ResetPasswordController's error handler."""
966
on_error_method_name = "on_password_change_error"
967
controller_class = ResetPasswordController
970
class CurrentUserControllerValidationTest(BaseTestCase):
972
"""Tests for CurrentUserController, but without Mocker."""
974
@defer.inlineCallbacks
977
yield super(CurrentUserControllerValidationTest, self).setUp()
978
self.message_box = FakeMessageBox()
979
self.controller = CurrentUserController(
980
message_box=self.message_box)
981
self.controller.view = FakeCurrentUserPage()
983
def test_valid(self):
984
"""Enable the button with a valid email/password."""
985
self.controller.view.email_edit.setText("a@b")
986
self.controller.view.password_edit.setText("pass")
987
self.controller._validate()
988
self.assertTrue(self.controller.view.sign_in_button.enabled())
989
self.assertTrue(self.controller.view.properties.get('unpolish', False))
990
self.assertTrue(self.controller.view.properties.get('polish', False))
991
self.assertTrue("DisabledState" in self.controller.view.properties)
992
self.assertEqual(self.controller.view.properties["DisabledState"],
993
not self.controller.view.sign_in_button.enabled())
995
def test_invalid_email(self):
996
"""The submit button should be disabled with an invalid email."""
997
self.controller.view.email_edit.setText("ab")
998
self.controller.view.password_edit.setText("pass")
999
self.controller._validate()
1000
self.assertFalse(self.controller.view.sign_in_button.enabled())
1001
self.assertTrue("DisabledState" in self.controller.view.properties)
1002
self.assertEqual(self.controller.view.properties["DisabledState"],
1003
not self.controller.view.sign_in_button.enabled())
1004
self.assertTrue(self.controller.view.properties.get('unpolish', False))
1005
self.assertTrue(self.controller.view.properties.get('polish', False))
1007
def test_invalid_password(self):
1008
"""The submit button should be disabled with an invalid password."""
1009
self.controller.view.email_edit.setText("a@b")
1010
self.controller.view.password_edit.setText("")
1011
self.controller._validate()
1012
self.assertFalse(self.controller.view.sign_in_button.enabled())
1013
self.assertTrue(self.controller.view.properties.get('unpolish', False))
1014
self.assertTrue(self.controller.view.properties.get('polish', False))
1015
self.assertTrue("DisabledState" in self.controller.view.properties)
1016
self.assertEqual(self.controller.view.properties["DisabledState"],
1017
not self.controller.view.sign_in_button.enabled())
1019
def test_invalid_both(self):
1020
"""The submit button should be disabled with invalid data."""
1021
self.controller.view.email_edit.setText("ab")
1022
self.controller.view.password_edit.setText("")
1023
self.controller._validate()
1024
self.assertFalse(self.controller.view.sign_in_button.enabled())
1025
self.assertTrue(self.controller.view.properties.get('unpolish', False))
1026
self.assertTrue(self.controller.view.properties.get('polish', False))
1027
self.assertTrue("DisabledState" in self.controller.view.properties)
1028
self.assertEqual(self.controller.view.properties["DisabledState"],
1029
not self.controller.view.sign_in_button.enabled())
1032
class SetUpAccountControllerTestCase(BaseTestCase):
1033
"""test the controller used to setup a new account."""
1035
@defer.inlineCallbacks
1037
"""Set the different tests."""
1038
yield super(SetUpAccountControllerTestCase, self).setUp()
1039
self.view = FakeSetupAccountPageView()
1040
self.message_box = FakeMessageBox()
1041
self.controller = SetUpAccountController(message_box=self.message_box)
1042
self.patch(self.controller, "get_backend", self.view.fake_backend)
1043
self.controller.view = self.view
1044
self.controller.backend = self.view
1046
def test_set_translated_strings(self):
1047
"""Ensure all the strings are set."""
1048
self.controller._set_translated_strings()
1049
self.assertEqual(self.view.name_label.text(), NAME_ENTRY)
1050
self.assertEqual(self.view.email_label.text(), EMAIL1_ENTRY)
1051
self.assertEqual(self.view.confirm_email_label.text(), EMAIL2_ENTRY)
1052
self.assertEqual(self.view.password_label.text(), PASSWORD1_ENTRY)
1053
self.assertEqual(self.view.confirm_password_label.text(),
1055
self.assertEqual(self.view.password_info_label.text(), PASSWORD_HELP)
1056
self.assertEqual(self.view.captcha_solution_edit.placeholderText(),
1057
CAPTCHA_SOLUTION_ENTRY)
1059
def test_set_titles(self):
1060
"""Test how the different titles are set."""
1061
self.controller._set_titles()
1062
self.assertEqual(self.view.properties['title'],
1063
JOIN_HEADER_LABEL % {'app_name': self.view.fake_wizard.app_name})
1064
self.assertEqual(self.view.properties['subtitle'],
1065
self.view.fake_wizard.help_text)
1067
def test_connect_ui_elements(self):
1068
"""Test that the ui elements are correctly connect."""
1069
self.controller._connect_ui_elements()
1070
self.assertEqual(self.view.name_edit.receivers(
1071
SIGNAL('textEdited(QString)')), 1)
1072
self.assertEqual(self.view.email_edit.receivers(
1073
SIGNAL('textEdited(QString)')), 1)
1074
self.assertEqual(self.view.confirm_email_edit.receivers(
1075
SIGNAL('textEdited(QString)')), 1)
1076
self.assertEqual(self.view.password_edit.receivers(
1077
SIGNAL('textEdited(QString)')), 1)
1078
self.assertEqual(self.view.confirm_password_edit.receivers(
1079
SIGNAL('textEdited(QString)')), 1)
1080
self.assertEqual(self.view.captcha_solution_edit.receivers(
1081
SIGNAL('textEdited(QString)')), 1)
1082
self.assertEqual(self.view.refresh_label.receivers(
1083
SIGNAL('linkActivated(QString)')), 1)
1084
self.assertEqual(self.view.terms_checkbox.receivers(
1085
SIGNAL('stateChanged(int)')), 1)
1086
# set the callbacks for the captcha generation
1087
self.assertIsInstance(self.view.on_captcha_generated_cb,
1088
collections.Callable)
1089
self.assertIsInstance(self.view.on_captcha_generation_error_cb,
1090
collections.Callable)
1091
self.assertIsInstance(self.view.on_user_registration_error_cb,
1092
collections.Callable)
1093
self.assertIsInstance(self.view.on_user_registered_cb,
1094
collections.Callable)
1096
def test_set_line_edits_validations(self):
1097
"""Test _set_line_validations from controller."""
1098
self.controller._set_line_edits_validations()
1099
elements = self.view.properties['validation_rule']
1100
self.assertFalse(elements is None)
1102
self.assertTrue(type(e[0]) is QLineEdit)
1103
self.assertIsInstance(e[1], collections.Callable)
1105
def all_valid(self):
1106
"""Set all the widgets to a valid state."""
1107
self.view.name_edit.setText('Name')
1108
self.view.email_edit.setText('email@email.com')
1109
self.view.confirm_email_edit.setText('email@email.com')
1110
self.view.password_edit.setText('T3st3rqw')
1111
self.view.confirm_password_edit.setText('T3st3rqw')
1112
self.view.captcha_solution_edit.setText('captcha solution')
1113
self.view.terms_checkbox.setChecked(True)
1115
def all_invalid(self):
1116
"""Set all the widgets to an invalid state."""
1117
self.view.name_edit.setText('')
1118
self.view.email_edit.setText('')
1119
self.view.confirm_email_edit.setText('email')
1120
self.view.password_edit.setText('')
1121
self.view.confirm_password_edit.setText('t')
1122
self.view.captcha_solution_edit.setText('')
1123
self.view.terms_checkbox.setChecked(False)
1125
def test_enable_setup_button_only_checkbox_ok(self):
1126
"""Test enable button only name valid."""
1128
self.view.terms_checkbox.setChecked(True)
1129
self.controller._enable_setup_button()
1131
self.assertFalse(self.view.set_up_button.enabled())
1132
self.assertTrue(self.view.set_up_button.property('DisabledState'))
1133
self.assertTrue(self.view.set_up_button.properties['polish'])
1134
self.assertTrue(self.view.set_up_button.properties['unpolish'])
1136
def test_enable_setup_button_only_name_ok(self):
1137
"""Test enable button only name valid."""
1139
self.view.name_edit.setText('Name')
1140
self.controller._enable_setup_button()
1142
self.assertFalse(self.view.set_up_button.enabled())
1143
self.assertTrue(self.view.set_up_button.property('DisabledState'))
1144
self.assertTrue(self.view.set_up_button.properties['polish'])
1145
self.assertTrue(self.view.set_up_button.properties['unpolish'])
1147
def test_enable_setup_button_only_email_ok(self):
1148
"""Test enable button only name valid."""
1150
self.view.email_edit.setText('email@email.com')
1151
self.controller._enable_setup_button()
1153
self.assertFalse(self.view.set_up_button.enabled())
1154
self.assertTrue(self.view.set_up_button.property('DisabledState'))
1155
self.assertTrue(self.view.set_up_button.properties['polish'])
1156
self.assertTrue(self.view.set_up_button.properties['unpolish'])
1158
def test_enable_setup_button_only_confirm_email_ok(self):
1159
"""Test enable button only name valid."""
1161
self.view.confirm_email_edit.setText('email@email.com')
1162
self.controller._enable_setup_button()
1164
self.assertFalse(self.view.set_up_button.enabled())
1165
self.assertTrue(self.view.set_up_button.property('DisabledState'))
1166
self.assertTrue(self.view.set_up_button.properties['polish'])
1167
self.assertTrue(self.view.set_up_button.properties['unpolish'])
1169
def test_enable_setup_button_only_email_and_confirm_ok(self):
1170
"""Test enable button only name valid."""
1172
self.view.email_edit.setText('email@email.com')
1173
self.view.confirm_email_edit.setText('email@email.com')
1174
self.controller._enable_setup_button()
1176
self.assertFalse(self.view.set_up_button.enabled())
1177
self.assertTrue(self.view.set_up_button.property('DisabledState'))
1178
self.assertTrue(self.view.set_up_button.properties['polish'])
1179
self.assertTrue(self.view.set_up_button.properties['unpolish'])
1181
def test_enable_setup_button_only_password_ok(self):
1182
"""Test enable button only name valid."""
1184
self.view.password_edit.setText('T3st3rqw')
1185
self.controller._enable_setup_button()
1187
self.assertFalse(self.view.set_up_button.enabled())
1188
self.assertTrue(self.view.set_up_button.property('DisabledState'))
1189
self.assertTrue(self.view.set_up_button.properties['polish'])
1190
self.assertTrue(self.view.set_up_button.properties['unpolish'])
1192
def test_enable_setup_button_only_password_confirm_ok(self):
1193
"""Test enable button only name valid."""
1195
self.view.confirm_password_edit.setText('T3st3rqw')
1196
self.controller._enable_setup_button()
1198
self.assertFalse(self.view.set_up_button.enabled())
1199
self.assertTrue(self.view.set_up_button.property('DisabledState'))
1200
self.assertTrue(self.view.set_up_button.properties['polish'])
1201
self.assertTrue(self.view.set_up_button.properties['unpolish'])
1203
def test_enable_setup_button_only_password_and_confirm_ok(self):
1204
"""Test enable button only name valid."""
1206
self.view.password_edit.setText('T3st3rqw')
1207
self.view.confirm_password_edit.setText('T3st3rqw')
1208
self.controller._enable_setup_button()
1210
self.assertFalse(self.view.set_up_button.enabled())
1211
self.assertTrue(self.view.set_up_button.property('DisabledState'))
1212
self.assertTrue(self.view.set_up_button.properties['polish'])
1213
self.assertTrue(self.view.set_up_button.properties['unpolish'])
1215
def test_enable_setup_button_only_captcha_ok(self):
1216
"""Test enable button only name valid."""
1218
self.view.captcha_solution_edit.setText('captcha solution')
1219
self.controller._enable_setup_button()
1221
self.assertFalse(self.view.set_up_button.enabled())
1222
self.assertTrue(self.view.set_up_button.property('DisabledState'))
1223
self.assertTrue(self.view.set_up_button.properties['polish'])
1224
self.assertTrue(self.view.set_up_button.properties['unpolish'])
1226
def test_enable_setup_button_only_all_ok(self):
1227
"""Test enable button only name valid."""
1229
self.controller._enable_setup_button()
1231
self.assertTrue(self.view.set_up_button.enabled())
1232
self.assertFalse(self.view.set_up_button.property('DisabledState'))
1233
self.assertTrue(self.view.set_up_button.properties['polish'])
1234
self.assertTrue(self.view.set_up_button.properties['unpolish'])
1236
def test_enable_setup_button_all_wrong(self):
1237
"""Test enable button only name valid."""
1239
self.controller._enable_setup_button()
1241
self.assertFalse(self.view.set_up_button.enabled())
1242
self.assertTrue(self.view.set_up_button.property('DisabledState'))
1243
self.assertTrue(self.view.set_up_button.properties['polish'])
1244
self.assertTrue(self.view.set_up_button.properties['unpolish'])
1246
def test_enable_setup_button_name_wrong(self):
1247
"""Test enable button only name valid."""
1249
self.view.name_edit.setText('')
1250
self.controller._enable_setup_button()
1252
self.assertFalse(self.view.set_up_button.enabled())
1253
self.assertTrue(self.view.set_up_button.property('DisabledState'))
1254
self.assertTrue(self.view.set_up_button.properties['polish'])
1255
self.assertTrue(self.view.set_up_button.properties['unpolish'])
1257
def test_enable_setup_button_email_wrong(self):
1258
"""Test enable button only name valid."""
1260
self.view.email_edit.setText('')
1261
self.controller._enable_setup_button()
1263
self.assertFalse(self.view.set_up_button.enabled())
1264
self.assertTrue(self.view.set_up_button.property('DisabledState'))
1265
self.assertTrue(self.view.set_up_button.properties['polish'])
1266
self.assertTrue(self.view.set_up_button.properties['unpolish'])
1268
def test_enable_setup_button_confirm_email_wrong(self):
1269
"""Test enable button only name valid."""
1271
self.view.confirm_email_edit.setText('')
1272
self.controller._enable_setup_button()
1274
self.assertFalse(self.view.set_up_button.enabled())
1275
self.assertTrue(self.view.set_up_button.property('DisabledState'))
1276
self.assertTrue(self.view.set_up_button.properties['polish'])
1277
self.assertTrue(self.view.set_up_button.properties['unpolish'])
1279
def test_enable_setup_button_password_wrong(self):
1280
"""Test enable button only name valid."""
1282
self.view.password_edit.setText('')
1283
self.controller._enable_setup_button()
1285
self.assertFalse(self.view.set_up_button.enabled())
1286
self.assertTrue(self.view.set_up_button.property('DisabledState'))
1287
self.assertTrue(self.view.set_up_button.properties['polish'])
1288
self.assertTrue(self.view.set_up_button.properties['unpolish'])
1290
def test_enable_setup_button_confirm_password_wrong(self):
1291
"""Test enable button only name valid."""
1293
self.view.confirm_password_edit.setText('')
1294
self.controller._enable_setup_button()
1296
self.assertFalse(self.view.set_up_button.enabled())
1297
self.assertTrue(self.view.set_up_button.property('DisabledState'))
1298
self.assertTrue(self.view.set_up_button.properties['polish'])
1299
self.assertTrue(self.view.set_up_button.properties['unpolish'])
1301
def test_enable_setup_button_captcha_wrong(self):
1302
"""Test enable button only name valid."""
1304
self.view.captcha_solution_edit.setText('')
1305
self.controller._enable_setup_button()
1307
self.assertFalse(self.view.set_up_button.enabled())
1308
self.assertTrue(self.view.set_up_button.property('DisabledState'))
1309
self.assertTrue(self.view.set_up_button.properties['polish'])
1310
self.assertTrue(self.view.set_up_button.properties['unpolish'])
1312
def test_enable_setup_button_checkbox_wrong(self):
1313
"""Test enable button only name valid."""
1315
self.view.terms_checkbox.setChecked(False)
1316
self.controller._enable_setup_button()
1318
self.assertFalse(self.view.set_up_button.enabled())
1319
self.assertTrue(self.view.set_up_button.property('DisabledState'))
1320
self.assertTrue(self.view.set_up_button.properties['polish'])
1321
self.assertTrue(self.view.set_up_button.properties['unpolish'])
1323
def test_register_fields(self):
1324
"""Test _register_fields."""
1325
self.controller._register_fields()
1326
self.assertTrue('email_address' in self.view.properties)
1327
self.assertTrue('password' in self.view.properties)
1328
self.assertTrue(type(self.view.properties['email_address']) is \
1330
self.assertTrue(type(self.view.properties['password']) is \
1333
def test_validate_form_all_ok(self):
1334
"""Test the result of validate_form."""
1336
self.assertTrue(self.controller.validate_form())
1337
self.assertNotEqual(self.view.name_assistance.text(), NAME_INVALID)
1338
self.assertNotEqual(self.view.email_assistance.text(), EMAIL_INVALID)
1339
self.assertNotEqual(self.view.confirm_email_assistance.text(),
1341
messages = '\n'.join([PASSWORD_TOO_WEAK, PASSWORD_MISMATCH,
1342
CAPTCHA_REQUIRED_ERROR])
1343
self.assertNotEqual(self.message_box.critical_args,
1344
((messages, self.view), {}))
1346
def test_validate_form_all_wrong(self):
1347
"""Test the result of validate_form."""
1349
self.assertFalse(self.controller.validate_form())
1350
self.assertEqual(self.view.name_assistance.text(), NAME_INVALID)
1351
self.assertEqual(self.view.email_assistance.text(), EMAIL_INVALID)
1352
self.assertEqual(self.view.confirm_email_assistance.text(),
1354
messages = '\n'.join([PASSWORD_TOO_WEAK, PASSWORD_MISMATCH,
1355
CAPTCHA_REQUIRED_ERROR])
1356
self.assertEqual(self.message_box.critical_args,
1357
((messages, self.view), {}))
1359
def test_validate_form_name_ok(self):
1360
"""Test the result of validate_form."""
1362
self.view.name_edit.setText('Name')
1363
self.assertFalse(self.controller.validate_form())
1364
self.assertEqual(self.view.email_assistance.text(), EMAIL_INVALID)
1365
self.assertEqual(self.view.confirm_email_assistance.text(),
1367
messages = '\n'.join([PASSWORD_TOO_WEAK, PASSWORD_MISMATCH,
1368
CAPTCHA_REQUIRED_ERROR])
1369
self.assertEqual(self.message_box.critical_args,
1370
((messages, self.view), {}))
1372
def test_validate_form_email_ok(self):
1373
"""Test the result of validate_form."""
1375
self.view.email_edit.setText('email@email.com')
1376
self.assertFalse(self.controller.validate_form())
1377
self.assertEqual(self.view.name_assistance.text(), NAME_INVALID)
1378
self.assertEqual(self.view.confirm_email_assistance.text(),
1380
messages = '\n'.join([PASSWORD_TOO_WEAK, PASSWORD_MISMATCH,
1381
CAPTCHA_REQUIRED_ERROR])
1382
self.assertEqual(self.message_box.critical_args,
1383
((messages, self.view), {}))
1385
def test_validate_form_confirm_email_ok(self):
1386
"""Test the result of validate_form."""
1388
self.view.email_edit.setText('email@email.com')
1389
self.view.confirm_email_edit.setText('email@email.com')
1390
self.assertFalse(self.controller.validate_form())
1391
self.assertEqual(self.view.name_assistance.text(), NAME_INVALID)
1392
messages = '\n'.join([PASSWORD_TOO_WEAK, PASSWORD_MISMATCH,
1393
CAPTCHA_REQUIRED_ERROR])
1394
self.assertEqual(self.message_box.critical_args,
1395
((messages, self.view), {}))
1397
def test_validate_form_password_weak(self):
1398
"""Test the result of validate_form."""
1400
self.view.password_edit.setText('Test')
1401
self.view.confirm_password_edit.setText('Test')
1402
self.assertFalse(self.controller.validate_form())
1403
messages = '\n'.join([PASSWORD_TOO_WEAK])
1404
self.assertEqual(self.message_box.critical_args,
1405
((messages, self.view), {}))
1407
def test_validate_form_password_mismatch(self):
1408
"""Test the result of validate_form."""
1410
self.view.password_edit.setText('T3st3rqw')
1411
self.view.confirm_password_edit.setText('test')
1412
self.assertFalse(self.controller.validate_form())
1413
messages = '\n'.join([PASSWORD_MISMATCH])
1414
self.assertEqual(self.message_box.critical_args,
1415
((messages, self.view), {}))
1417
def test_validate_form_captcha_required(self):
1418
"""Test the result of validate_form."""
1420
self.view.captcha_solution_edit.setText('')
1421
self.assertFalse(self.controller.validate_form())
1422
messages = '\n'.join([CAPTCHA_REQUIRED_ERROR])
1423
self.assertEqual(self.message_box.critical_args,
1424
((messages, self.view), {}))
1426
def test_is_correct_email(self):
1427
"""Test if the email is correct."""
1428
self.assertTrue(self.controller.is_correct_email('email@'))
1429
self.assertFalse(self.controller.is_correct_email('email'))
1431
def test_is_correct_email_confirmation(self):
1432
"""Test if the email confirmation is correct."""
1433
self.view.email_edit.setText('email@email.com')
1434
self.controller.is_correct_email_confirmation('email.@email.com')
1436
def test_is_correct_password_confirmation(self):
1437
"""Test is_correct_password_confirmation method."""
1438
self.view.password_edit.setText('T3st3rqw')
1439
self.controller.is_correct_password_confirmation('T3st3rqw')
1442
class SetupAccountControllerCaptchaTest(BaseTestCase):
1443
"""Tests for SetupAccountController, but without Mocker."""
1445
@defer.inlineCallbacks
1447
"""Set the different tests."""
1448
yield super(SetupAccountControllerCaptchaTest, self).setUp()
1449
self.message_box = FakeMessageBox()
1450
self.controller = SetUpAccountController(message_box=self.message_box)
1451
self.patch(self.controller, 'view', FakeSetupAccountView())
1452
self.fake_backend = FakeControllerForCaptcha()
1453
self.patch(self.controller, 'backend', self.fake_backend)
1455
def test_refresh_captcha(self):
1456
"""Test the Refresh Captcha function."""
1457
self.assertFalse(self.controller.view.captcha_refreshing_value)
1458
self.controller._refresh_captcha()
1459
self.assertTrue(self.controller.view.captcha_refreshing_value)
1460
self.assertTrue(self.fake_backend.callback_error)
1463
class SetupAccountControllerValidationTest(BaseTestCase):
1464
"""Tests for SetupAccountController, but without Mocker."""
1466
@defer.inlineCallbacks
1468
"""Set the different tests."""
1469
yield super(SetupAccountControllerValidationTest, self).setUp()
1470
self.message_box = FakeMessageBox()
1471
self.controller = SetUpAccountController(message_box=self.message_box)
1472
self.patch(self.controller, '_refresh_captcha', self._set_called)
1473
self.patch(self.controller, 'view', FakeSetupAccountView())
1475
def test_on_user_registration_refresh_captcha(self):
1476
"""If there is a user reg. error, captcha should refresh."""
1477
self.controller.on_user_registration_error('TestApp', {})
1478
self.assertEqual(self._called, ((), {}))
1480
def test_on_user_registration_all_only(self):
1481
"""Pass only a __all__ error key."""
1482
self.controller.on_user_registration_error('TestApp',
1483
{'__all__': "Error in All"})
1484
self.assertEqual(self.message_box.critical_args, ((
1485
"Error in All", self.controller.view), {}))
1487
def test_on_user_registration_all_fields(self):
1488
"""Pass all known error keys, plus unknown one."""
1489
self.controller.on_user_registration_error('TestApp',
1490
{'__all__': "Error in All",
1491
'email': "Error in email",
1492
'pasword': "Error in password",
1493
'unknownfield': "Error in unknown",
1495
self.assertEqual(self.message_box.critical_args, ((
1496
"Error in All", self.controller.view), {}))
1498
def test_registration_errors_without_message_or_all(self):
1499
"""Pass only a email error key."""
1500
errdict = {'errtype': "RegistrationError",
1501
'email': "Error in email"}
1502
self.controller.on_user_registration_error('TestApp', errdict)
1504
expected = (('', self.controller.view), {})
1505
self.assertEqual(self.message_box.critical_args, expected)
1507
def test_on_captcha_generated(self):
1508
"""Test if the method that shows the overlay is executed."""
1509
self.patch(Image, "open", self.controller.view.fake_open)
1510
self.assertFalse(self.controller.view.captcha_refresh_executed)
1511
self.controller.on_captcha_generated('app_name', 'captcha_id')
1512
self.assertTrue(self.controller.view.captcha_refresh_executed)
1514
def test_on_captcha_generation_error(self):
1515
"""Test if the method that hides the overlay is executed."""
1516
self.assertFalse(self.controller.view.captcha_refresh_executed)
1517
self.controller.on_captcha_generation_error({})
1518
self.assertTrue(self.controller.view.captcha_refresh_executed)
1521
class EmailVerificationControllerTestCase(BaseTestCase):
1522
"""Test the controller."""
1524
@defer.inlineCallbacks
1527
yield super(EmailVerificationControllerTestCase, self).setUp()
1528
self.view = EmailVerificationView()
1529
self.backend = self.view
1530
self.controller = EmailVerificationController(
1531
message_box=FakeMessageBox())
1532
self.controller.view = self.view
1533
self.controller.backend = self.backend
1534
self.patch(self.controller, "get_backend", self.view.fake_backend)
1535
self.email = 'email@email.com'
1536
self.password = 'T3st3rqw'
1537
self.view.fake_wizard.registerField('email_address', self.email)
1538
self.view.fake_wizard.registerField('password', self.password)
1540
def test_connect_ui_elements(self):
1541
"""Set the ui connections."""
1542
self.controller._connect_ui_elements()
1543
self.assertEqual(self.view.verification_code_edit.receivers(
1544
SIGNAL('textChanged(QString)')), 1)
1545
self.assertIsInstance(self.view.next_button.function,
1546
collections.Callable)
1547
self.assertIsInstance(self.view.on_email_validated_cb,
1548
collections.Callable)
1549
self.assertIsInstance(self.view.on_email_validation_error_cb,
1550
collections.Callable)
1552
def test_set_titles(self):
1553
"""Test that the titles are set."""
1554
self.controller.set_titles()
1555
self.assertEqual(self.view.properties['title'], VERIFY_EMAIL_TITLE)
1556
self.assertEqual(self.view.properties['subtitle'],
1557
VERIFY_EMAIL_CONTENT % {
1558
"app_name": self.view.fake_wizard.app_name,
1559
"email": self.email,
1562
def test_validate_email(self):
1563
"""Test the callback."""
1565
self.view.verification_code_edit.setText(code)
1566
self.controller.validate_email()
1567
self.assertEqual(self.view.properties['validate_email'],
1568
((self.view.fake_wizard.app_name, self.email, self.password,
1571
def test_validate_form(self):
1572
"""Test validate_form."""
1573
self.view.verification_code = 'qwe123'
1574
self.controller.validate_form()
1575
self.assertTrue(self.view.next_button.enabled())
1576
self.assertFalse(self.view.next_button.property('DisabledState'))
1577
self.assertTrue(self.view.next_button.properties['polish'])
1578
self.assertTrue(self.view.next_button.properties['unpolish'])
1580
self.view.verification_code = ''
1581
self.controller.validate_form()
1582
self.assertFalse(self.view.next_button.enabled())
1583
self.assertTrue(self.view.next_button.property('DisabledState'))
1584
self.assertTrue(self.view.next_button.properties['polish'])
1585
self.assertTrue(self.view.next_button.properties['unpolish'])
1587
def test_page_initialized(self):
1588
"""test pageInitialized to check the initial state of the page."""
1589
self.controller.pageInitialized()
1590
self.assertTrue(self.view.next_button.properties['default'])
1591
self.assertFalse(self.view.next_button.enabled())
1592
self.assertTrue(self.view.next_button.property('DisabledState'))
1593
self.assertTrue(self.view.next_button.properties['polish'])
1594
self.assertTrue(self.view.next_button.properties['unpolish'])
1596
def test_on_email_validation_error(self):
1597
"""Test on_email_validation_error."""
1598
error = dict(error='email error')
1599
self.controller.on_email_validation_error('app', error)
1601
[('%s: %s' % (k, v)) for k, v in error.iteritems()])
1602
self.assertEqual(self.controller.message_box.critical_args,
1603
((result, self.view), {}))
1605
def test_on_email_validated(self):
1606
"""Test on_email_validated."""
1607
self.controller.on_email_validated('app_name')
1608
self.assertEqual(self.view.fake_wizard.properties['emit'],
1609
('app_name', self.email))
1612
class EmailVerificationControllerValidationTestCase(BaseTestCase):
1613
"""Tests for EmailVerificationController, but without Mocker."""
1615
@defer.inlineCallbacks
1617
"""Set the different tests."""
1618
yield super(EmailVerificationControllerValidationTestCase,
1620
self.message_box = FakeMessageBox()
1621
self.controller = EmailVerificationController(
1622
message_box=self.message_box)
1623
self.patch(self.controller, 'view', FakeEmailVerificationView())
1625
def test_on_email_validation_error(self):
1626
"""Test that on_email_validation_error callback works as expected."""
1627
# Error type is removed from the final message
1628
error = dict(errtype='BadTokenError')
1629
app_name = 'app_name'
1630
self.controller.on_email_validation_error(app_name, error)
1631
self.assertEqual(self.message_box.critical_args,
1632
(('', self.controller.view), {}))
1634
def test_validate_form_wrong(self):
1635
"""Check the state of the next button."""
1636
self.controller.view.verification_code = ''
1637
self.controller.validate_form()
1638
self.assertFalse(self.controller.view.next_button.isEnabled())
1639
self.assertTrue(self.controller.view.properties.get('unpolish', False))
1640
self.assertTrue(self.controller.view.properties.get('polish', False))
1641
self.assertTrue("DisabledState" in self.controller.view.properties)
1642
self.assertEqual(self.controller.view.properties["DisabledState"],
1643
not self.controller.view.next_button.enabled())
1645
def test_validate_form_ok(self):
1646
"""Check the state of the next button."""
1647
self.controller.view.verification_code = 'as322fdw'
1648
self.controller.validate_form()
1649
self.assertTrue(self.controller.view.next_button.isEnabled)
1650
self.assertTrue(self.controller.view.properties.get('unpolish', False))
1651
self.assertTrue(self.controller.view.properties.get('polish', False))
1652
self.assertTrue("DisabledState" in self.controller.view.properties)
1653
self.assertEqual(self.controller.view.properties["DisabledState"],
1654
not self.controller.view.next_button.enabled())
1657
class ErrorControllerTestCase(BaseTestCase):
1658
"""Test the success page controller."""
1660
@defer.inlineCallbacks
1662
yield super(ErrorControllerTestCase, self).setUp()
1663
self.view = ErrorPageView()
1664
self.backend = self.view
1665
self.controller = ErrorController()
1666
self.controller.view = self.view
1667
self.controller.backend = self.backend
1669
def test_set_ui(self):
1670
"""Test the process that sets the ui."""
1671
self.controller._title = ERROR
1672
self.controller._subtitle = ERROR
1673
self.controller.setupUi(self.view)
1674
self.assertEqual(self.view.error_message_label.text(), ERROR)
1675
self.assertEqual(self.view.properties['title'], ERROR)
1676
self.assertEqual(self.view.properties['subtitle'], ERROR)
1677
self.assertEqual(self.view.next, -1)
1680
class SuccessControllerTestCase(BaseTestCase):
1681
"""Test the success page controller."""
1683
@defer.inlineCallbacks
1685
yield super(SuccessControllerTestCase, self).setUp()
1686
self.view = SuccessPageView()
1687
self.backend = self.view
1688
self.controller = SuccessController()
1689
self.controller.view = self.view
1690
self.controller.backend = self.backend
1692
def test_set_ui(self):
1693
"""Test the process that sets the ui."""
1694
self.controller._title = SUCCESS
1695
self.controller._subtitle = SUCCESS
1696
self.controller.setupUi(self.view)
1697
self.assertEqual(self.view.properties['title'], SUCCESS)
1698
self.assertEqual(self.view.properties['subtitle'], SUCCESS)
1699
self.assertEqual(self.view.next, -1)
1702
class UbuntuSSOWizardControllerTestCase(BaseTestCase):
1703
"""Test the wizard controller."""
1705
@defer.inlineCallbacks
1708
yield super(UbuntuSSOWizardControllerTestCase, self).setUp()
1709
self.view = UbuntuSSOView()
1710
self.backend = self.view
1711
self.callback = self.view.callback
1712
self.controller = UbuntuSSOWizardController()
1713
self.controller.view = self.view
1714
self.controller.backend = self.backend
1716
def test_on_user_cancelation(self):
1717
"""Test that the callback is indeed called."""
1718
self.controller.user_cancellation_callback = self.callback
1719
self.controller.on_user_cancelation()
1720
self.assertTrue(self.view.properties.get('close', False))
1721
self.assertEqual(self.view.properties['callback'],
1722
((self.view.app_name, ), {}))
1724
def test_on_login_success(self):
1725
"""Test that the callback is indeed called."""
1728
self.controller.login_success_callback = self.callback
1729
self.controller.login_success_callback(app_name, email)
1730
self.assertEqual(self.view.properties['callback'],
1731
((app_name, email), {}))
1733
def test_on_registration_success(self):
1734
"""Test that the callback is indeed called."""
1737
self.controller.registration_success_callback = self.callback
1738
self.controller.registration_success_callback(app_name, email)
1739
self.assertEqual(self.view.properties['callback'],
1740
((app_name, email), {}))
1742
def test_show_success_message(self):
1743
"""Test that the correct page will be shown."""
1744
self.controller.show_success_message()
1745
# the buttons layout we expect to have
1747
layout.append(QWizard.Stretch)
1748
layout.append(QWizard.FinishButton)
1750
self.assertEqual(self.view.page.next, self.view.success_page_id)
1751
self.assertTrue(self.view.properties['wizard_next'])
1752
self.assertEqual(self.view.properties['buttons_layout'], layout)
1754
def test_show_error_message(self):
1755
"""Test that the correct page will be shown."""
1756
self.controller.show_error_message()
1757
# the buttons layout we expect to have
1759
layout.append(QWizard.Stretch)
1760
layout.append(QWizard.FinishButton)
1762
self.assertEqual(self.view.page.next, self.view.error_page_id)
1763
self.assertTrue(self.view.properties['wizard_next'])
1764
self.assertEqual(self.view.properties['buttons_layout'], layout)
1766
def test_setup_ui(self):
1767
"""Test that the ui is connect."""
1768
self.controller.setupUi(self.view)
1769
self.assertEqual(self.view.properties['wizard_style'],
1770
QWizard.ModernStyle)
1771
self.assertIsInstance(self.view.properties['button'].function,
1772
collections.Callable)
1773
self.assertIsInstance(self.view.loginSuccess.function,
1774
collections.Callable)
1775
self.assertIsInstance(self.view.registrationSuccess.function,
1776
collections.Callable)
1779
class ForgottenPasswordControllerValidationTest(BaseTestCase):
1781
"""Tests for ForgottenPasswordController, but without Mocker."""
1783
@defer.inlineCallbacks
1785
"""Set the different tests."""
1786
yield super(ForgottenPasswordControllerValidationTest, self).setUp()
1787
self.message_box = FakeMessageBox()
1788
self.controller = ForgottenPasswordController(
1789
message_box=self.message_box)
1790
self.view = FakeForgottenPasswordPage()
1791
self.controller.view = self.view
1792
self.patch(self.controller, "get_backend", self.view.fake_backend)
1794
def test_page_initialized(self):
1795
"""Test the initial state of the page when it is loaded."""
1796
self.controller.pageInitialized()
1797
self.assertFalse(self.controller.view.send_button.enabled())
1798
self.assertTrue(self.controller.view.send_button.properties['default'])
1799
self.assertTrue("DisabledState" in self.controller.view.properties)
1800
self.assertEqual(self.controller.view.properties["DisabledState"],
1801
not self.controller.view.send_button.enabled())
1802
self.assertTrue(self.controller.view.properties.get('unpolish', False))
1803
self.assertTrue(self.controller.view.properties.get('polish', False))
1805
def test_page_initialized_with_text(self):
1806
"""Test the initial state of the page when it is loaded."""
1807
self.controller.view.email_line_edit.setText('mail@mail.com')
1808
self.controller.pageInitialized()
1809
self.assertTrue(self.controller.view.send_button.enabled())
1811
self.controller.view.send_button.properties['default'])
1812
self.assertTrue("DisabledState" in self.controller.view.properties)
1813
self.assertEqual(self.controller.view.properties["DisabledState"],
1814
not self.controller.view.send_button.enabled())
1815
self.assertTrue(self.controller.view.properties.get('unpolish', False))
1816
self.assertTrue(self.controller.view.properties.get('polish', False))
1818
def test_valid(self):
1819
"""The submit button should be enabled with a valid email."""
1820
self.controller.view.email_address_line_edit.setText("a@b")
1821
self.assertNotEqual(unicode(
1822
self.controller.view.email_address_line_edit.text()), u"")
1823
self.controller._validate()
1824
self.assertTrue(self.controller.view.send_button.enabled())
1825
self.assertTrue("DisabledState" in self.controller.view.properties)
1826
self.assertEqual(self.controller.view.properties["DisabledState"],
1827
not self.controller.view.send_button.enabled())
1828
self.assertTrue(self.controller.view.properties.get('unpolish', False))
1829
self.assertTrue(self.controller.view.properties.get('polish', False))
1831
def test_invalid(self):
1832
"""The submit button should be disabled with an invalid email."""
1833
self.controller.view.email_address_line_edit.setText("ab")
1834
self.assertNotEqual(
1835
unicode(self.controller.view.email_address_line_edit.text()), u"")
1836
self.controller._validate()
1837
self.assertFalse(self.controller.view.send_button.enabled())
1838
self.assertTrue("DisabledState" in self.controller.view.properties)
1839
self.assertEqual(self.controller.view.properties["DisabledState"],
1840
not self.controller.view.send_button.enabled())
1841
self.assertTrue(self.controller.view.properties.get('unpolish', False))
1842
self.assertTrue(self.controller.view.properties.get('polish', False))
1844
def test_empty(self):
1845
"""The submit button should be disabled without email."""
1847
unicode(self.controller.view.email_address_line_edit.text()), u"")
1848
self.assertFalse(self.controller.view.send_button.enabled())
1850
def test_on_password_reset_error_token_error(self):
1851
"""Test that the on_password_reset_error callback works as expected."""
1852
error = dict(errtype='ResetPasswordTokenError')
1853
app_name = 'app_name'
1854
self.controller.on_password_reset_error(app_name, error)
1855
msg = REQUEST_PASSWORD_TOKEN_WRONG_EMAIL
1856
self.assertEqual(self.controller.message_box.critical_args,
1857
((msg, self.controller.view), {}))
1859
def test_on_password_reset_error_general_error(self):
1860
"""Test that the on_password_reset_error callback works as expected."""
1861
error = dict(errtype='RandomError')
1862
app_name = 'app_name'
1863
msg = REQUEST_PASSWORD_TOKEN_TECH_ERROR
1864
self.controller.on_password_reset_error(app_name, error)
1865
self.assertFalse(self.controller.view.email_widget.isVisible())
1867
self.controller.view.forgotted_password_intro_label.isVisible())
1868
self.assertTrue(self.controller.view.try_again_widget.isVisible())
1869
self.assertEqual(self.controller.message_box.critical_args,
1870
((msg, self.controller.view), {}))
1873
class ForgottenPasswordControllerTestCase(BaseTestCase):
1874
"""Test the controller of the fogotten password page."""
1876
@defer.inlineCallbacks
1878
"""Setup the tests."""
1879
yield super(ForgottenPasswordControllerTestCase, self).setUp()
1880
self.view = FakeForgottenPasswordPageView()
1881
self.backend = self.view
1882
self.controller = ForgottenPasswordController(
1883
message_box=FakeMessageBox())
1884
self.controller.view = self.view
1885
self.controller.backend = self.backend
1887
def test_register_fields(self):
1888
"""Ensure that all the diff fields are registered."""
1889
self.controller._register_fields()
1890
self.assertEqual(self.view.field('email_address'),
1891
self.view.email_address_line_edit)
1893
def test_set_translated_strings(self):
1894
"""Ensure that the correct strings are translated."""
1895
self.controller._set_translated_strings()
1896
self.assertEqual(self.view.forgotted_password_intro_label.text(),
1897
REQUEST_PASSWORD_TOKEN_LABEL % {'app_name':
1898
self.view.fake_wizard.app_name})
1899
self.assertEqual(self.view.email_address_label.text(),
1901
self.assertEqual(self.view.send_button.text(),
1903
self.assertEqual(self.view.try_again_button.text(),
1906
def test_set_enhanced_line_edit(self):
1907
"""Test that the correct line enhancements have been added."""
1908
self.controller._set_enhanced_line_edit()
1909
elements = self.view.properties['validation_rule']
1910
self.assertFalse(elements is None)
1912
self.assertTrue(e[0] is self.view.email_address_line_edit)
1913
self.assertIsInstance(e[1], collections.Callable)
1915
def test_connect_ui(self):
1916
"""Test that the correct ui signals are connected."""
1917
self.controller._connect_ui()
1918
self.assertEqual(self.view.email_address_line_edit.receivers(
1919
SIGNAL('textChanged(QString)')), 1)
1920
self.assertIsInstance(self.view.send_button.function,
1921
collections.Callable)
1922
self.assertIsInstance(self.view.try_again_button.function,
1923
collections.Callable)
1924
self.assertIsInstance(self.view.on_password_reset_token_sent_cb,
1925
collections.Callable)
1926
self.assertIsInstance(self.view.on_password_reset_error_cb,
1927
collections.Callable)
1929
def test_on_try_again(self):
1930
"""Test that the on_try_again callback does work as expected."""
1931
self.controller.on_try_again()
1932
self.assertFalse(self.view.try_again_widget.isVisible())
1933
self.assertTrue(self.view.email_widget.isVisible())
1935
def test_on_password_reset_token_sent(self):
1936
"""Test that the on_password_token_sent callback works as expected."""
1937
self.controller.on_password_reset_token_sent()
1938
self.assertTrue(self.view.properties['wizard_next'])
1939
self.assertEqual(self.view.next,
1940
self.view.fake_wizard.reset_password_page_id)
1943
class ResetPasswordControllerTestCase(BaseTestCase):
1944
"""Ensure that the reset password works as expected."""
1946
@defer.inlineCallbacks
1948
"""Setup the tests."""
1949
yield super(ResetPasswordControllerTestCase, self).setUp()
1950
self.view = ResetPasswordPageView()
1951
self.backend = self.view
1952
self.controller = ResetPasswordController()
1953
self.controller.view = self.view
1954
self.controller.backend = self.backend
1956
def test_set_translated_strings(self):
1957
"""Ensure that the correct strings are set."""
1958
self.controller._set_translated_strings()
1959
self.assertEqual(self.view.reset_password_button.text(),
1961
self.assertEqual(self.view.properties['subtitle'],
1964
def test_connect_ui(self):
1965
"""Ensure that the diffent signals from the ui are connected."""
1966
self.controller._connect_ui()
1967
self.assertIsInstance(self.view.reset_password_button.function,
1968
collections.Callable)
1969
self.assertIsInstance(self.view.on_password_changed_cb,
1970
collections.Callable)
1971
self.assertIsInstance(self.view.on_password_change_error_cb,
1972
collections.Callable)
1973
self.assertEqual(self.view.reset_code_line_edit.receivers(
1974
SIGNAL('textChanged(QString)')), 1)
1975
self.assertEqual(self.view.password_line_edit.receivers(
1976
SIGNAL('textChanged(QString)')), 1)
1977
self.assertEqual(self.view.confirm_password_line_edit.receivers(
1978
SIGNAL('textChanged(QString)')), 1)
1980
def test_add_line_edits_validations(self):
1981
"""Ensure that the line validation have been added."""
1982
self.controller._add_line_edits_validations()
1983
self.assertEqual(self.view.password_line_edit.receivers(
1984
SIGNAL('textChanged(QString)')), 1)
1985
elements = self.view.properties['validation_rule']
1986
self.assertFalse(elements is None)
1988
self.assertTrue(type(e[0]) is QLineEdit)
1989
self.assertIsInstance(e[1], collections.Callable)
1991
def test_set_new_password(self):
1992
"""Test that the correct action is performed."""
1993
email = 'email@email.com'
1995
password = 'T3st3rqw'
1996
self.view.wizard().forgotten.ui.email_line_edit.setText(email)
1997
self.view.reset_code_line_edit.setText(code)
1998
self.view.password_line_edit.setText(password)
1999
self.controller.set_new_password()
2000
self.assertEqual(self.view.properties['backend_new_password'],
2001
((self.view.fake_wizard.app_name, email, code, password), {}))
2003
def test_is_correct_password_confirmation_true(self):
2004
"""Test that the correct password confirmation is used."""
2005
password = 'password'
2006
self.view.password_line_edit.setText(password)
2007
self.assertTrue(self.controller.is_correct_password_confirmation(
2010
def test_is_correct_password_confirmation_false(self):
2011
"""Test that the correct password confirmation is used."""
2012
password = 'password'
2013
self.view.password_line_edit.setText(password + password)
2014
self.assertFalse(self.controller.is_correct_password_confirmation(
2018
class ResetPasswordControllerValidationTest(BaseTestCase):
2020
"""Tests for ResetPasswordController, but without Mocker."""
2022
@defer.inlineCallbacks
2025
yield super(ResetPasswordControllerValidationTest, self).setUp()
2026
self.controller = ResetPasswordController()
2027
self.controller.view = FakeResetPasswordPage()
2029
def test_page_initialized(self):
2030
"""Test the initial state of the page when it is loaded."""
2031
self.controller.pageInitialized()
2033
self.controller.view.reset_password_button.enabled())
2035
self.controller.view.reset_password_button.properties['default'])
2036
self.assertTrue("DisabledState" in self.controller.view.properties)
2037
self.assertEqual(self.controller.view.properties["DisabledState"],
2038
not self.controller.view.reset_password_button.enabled())
2039
self.assertTrue(self.controller.view.properties.get('unpolish', False))
2040
self.assertTrue(self.controller.view.properties.get('polish', False))
2042
def test_valid(self):
2043
"""Enable the button with valid data."""
2044
self.controller.view.reset_code_line_edit.setText("ABCD")
2045
self.controller.view.password_line_edit.setText("1234567A")
2046
self.controller.view.confirm_password_line_edit.setText("1234567A")
2047
self.controller._validate()
2048
self.assertTrue(self.controller.view.reset_password_button.enabled())
2049
self.assertTrue("DisabledState" in self.controller.view.properties)
2050
self.assertEqual(self.controller.view.properties["DisabledState"],
2051
not self.controller.view.reset_password_button.enabled())
2052
self.assertTrue(self.controller.view.properties.get('unpolish', False))
2053
self.assertTrue(self.controller.view.properties.get('polish', False))
2055
def test_invalid_code(self):
2056
"""Disable the button with an invalid code."""
2057
self.controller.view.reset_code_line_edit.setText("")
2058
self.controller.view.password_line_edit.setText("1234567A")
2059
self.controller.view.confirm_password_line_edit.setText("1234567A")
2060
self.controller._validate()
2061
self.assertFalse(self.controller.view.reset_password_button.enabled())
2062
self.assertTrue("DisabledState" in self.controller.view.properties)
2063
self.assertEqual(self.controller.view.properties["DisabledState"],
2064
not self.controller.view.reset_password_button.enabled())
2065
self.assertTrue(self.controller.view.properties.get('unpolish', False))
2066
self.assertTrue(self.controller.view.properties.get('polish', False))
2068
def test_invalid_password(self):
2069
"""Disable the button with an invalid password."""
2070
self.controller.view.reset_code_line_edit.setText("")
2071
self.controller.view.password_line_edit.setText("1234567")
2072
self.controller.view.confirm_password_line_edit.setText("1234567")
2073
self.controller._validate()
2074
self.assertFalse(self.controller.view.reset_password_button.enabled())
2076
def test_invalid_confirm(self):
2077
"""Disable the button with an invalid password confirm."""
2078
self.controller.view.reset_code_line_edit.setText("")
2079
self.controller.view.password_line_edit.setText("1234567A")
2080
self.controller.view.confirm_password_line_edit.setText("1234567")
2081
self.controller._validate()
2082
self.assertFalse(self.controller.view.reset_password_button.enabled())
2085
class ResetPasswordControllerRealControllerTest(BaseTestCase):
2087
"""Tests for ResetPasswordController, but without Mocker."""
2089
@defer.inlineCallbacks
2092
yield super(ResetPasswordControllerRealControllerTest, self).setUp()
2093
self.controller = ResetPasswordController()
2094
self.controller.view = FakeWizardForResetPassword()
2096
def test_on_password_changed(self):
2097
"""Test that on_password_changed execute the proper operation."""
2098
self.controller.on_password_changed('app_name', '')
2099
self.assertTrue(self.controller.view.hide_value)
2101
self.assertEqual(self.controller.view.count_back, times_visited)
2102
self.assertEqual(self.controller.view.text_value, 'mail@mail.com')
2104
def test_on_password_changed_not_visited(self):
2105
"""Test that on_password_changed execute the proper operation."""
2106
current_user_page_id = 20
2107
self.patch(self.controller.view, "current_user_page_id",
2108
current_user_page_id)
2109
self.controller.on_password_changed('app_name', '')
2110
self.assertTrue(self.controller.view.hide_value)
2112
self.assertEqual(self.controller.view.count_back, times_visited)
2113
self.assertEqual(self.controller.view.text_value, 'mail@mail.com')