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
from PyQt4.QtGui import QCheckBox, QLabel, QLineEdit, QWizard
27
from PyQt4.QtCore import QString, SIGNAL
29
# pylint: disable=F0401
34
# pylint: enable=F0401
36
from ubuntu_sso.qt.controllers import (
38
ChooseSignInController,
39
CurrentUserController,
40
EmailVerificationController,
42
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.assertTrue(self.view.properties['wizard_next'])
763
self.assertEqual(self.view.next,
764
self.view.fake_wizard.current_user_page_id)
766
def test_set_next_new(self):
767
"""Test the execution of the callback."""
768
self.controller._set_next_new()
769
self.assertTrue(self.view.properties['wizard_next'])
770
self.assertEqual(self.view.next,
771
self.view.fake_wizard.setup_account_page_id)
774
class CurrentUserControllerTestCase(BaseTestCase):
775
"""Test the current user controller."""
777
@defer.inlineCallbacks
780
yield super(CurrentUserControllerTestCase, self).setUp()
781
self.controller = CurrentUserController(title='the title',
782
subtitle='the subtitle')
783
self.view = FakeCurrentUserView()
784
self.controller.view = self.view
785
self.patch(self.controller, "get_backend", self.view.fake_backend)
786
self.controller.setupUi(self.view)
788
def test_translated_strings(self):
789
"""test that the ui is correctly set up."""
790
self.controller._set_translated_strings()
791
self.assertEqual(self.view.email_label.text(), EMAIL_LABEL)
792
self.assertEqual(self.view.password_label.text(), LOGIN_PASSWORD_LABEL)
793
self.assertEqual(self.view.forgot_password_label.text(),
794
FAKE_URL % FORGOTTEN_PASSWORD_BUTTON)
795
self.assertEqual(self.view.sign_in_button.text(), SIGN_IN_BUTTON)
797
def test_connect_ui(self):
798
"""test that the ui is correctly set up."""
799
self.controller._connect_ui()
800
self.assertIsInstance(self.view.sign_in_button.function,
801
collections.Callable)
802
# Check if receivers is 2 because _connect_ui was called on setUp
803
self.assertEqual(self.view.forgot_password_label.receivers(
804
SIGNAL('linkActivated(QString)')), 2)
805
self.assertEqual(self.view.email_edit.receivers(
806
SIGNAL('textChanged(QString)')), 2)
807
self.assertEqual(self.view.password_edit.receivers(
808
SIGNAL('textChanged(QString)')), 2)
809
self.assertFalse(self.view.on_login_error_cb is None)
810
self.assertFalse(self.view.on_logged_in_cb is None)
812
def test_title_subtitle(self):
813
"""Ensure we are storing the title and subtitle correctly."""
814
self.assertEqual(self.view.properties['title'], 'the title')
815
self.assertEqual(self.view.properties['subtitle'], 'the subtitle')
817
def test_on_logged_in(self):
818
"""Test on_logged_in method."""
819
self.view.email_edit.setText('email@email.com')
820
self.controller.on_logged_in('app-name', {})
821
self.assertEqual(self.view.fake_wizard.properties['emit'],
822
('app-name', 'email@email.com'))
824
def test_login(self):
825
"""Test login method."""
826
email = 'email@email.com'
827
password = 'password'
828
self.view.email_edit.setText(email)
829
self.view.password_edit.setText(password)
830
self.controller.login()
831
self.assertEqual(self.view.properties['backend_login'],
832
(self.view.fake_wizard.app_name, email, password))
833
self.assertIsInstance(self.view.properties['login-addErrback'],
834
collections.Callable)
836
def test_on_forgotten_password(self):
837
"""Test on_forgotten_password flow."""
838
email = 'email@email.com'
839
self.view.email_edit.setText(email)
840
self.controller.on_forgotten_password()
841
self.assertEqual(self.view.next,
842
self.view.fake_wizard.forgotten_password_page_id)
843
self.assertTrue(self.view.properties['wizard_next'])
845
def test_setup_ui(self):
846
"""Test the set up of the ui."""
847
self.controller._title = 'title_setup'
848
self.controller._subtitle = 'subtitle_setup'
849
self.controller.setupUi(self.view)
850
self.assertEqual(self.view.properties['title'], 'title_setup')
851
self.assertEqual(self.view.properties['subtitle'], 'subtitle_setup')
852
self.assertIsInstance(self.view.sign_in_button.function,
853
collections.Callable)
854
# Check if receivers is 2 because _connect_ui was called on setUp
855
self.assertEqual(self.view.forgot_password_label.receivers(
856
SIGNAL('linkActivated(QString)')), 2)
857
self.assertEqual(self.view.email_edit.receivers(
858
SIGNAL('textChanged(QString)')), 2)
859
self.assertEqual(self.view.password_edit.receivers(
860
SIGNAL('textChanged(QString)')), 2)
861
self.assertFalse(self.view.on_login_error_cb is None)
862
self.assertFalse(self.view.on_logged_in_cb is None)
863
self.assertEqual(self.view.email_label.text(), EMAIL_LABEL)
864
self.assertEqual(self.view.password_label.text(), LOGIN_PASSWORD_LABEL)
865
self.assertEqual(self.view.forgot_password_label.text(),
866
FAKE_URL % FORGOTTEN_PASSWORD_BUTTON)
867
self.assertEqual(self.view.sign_in_button.text(), SIGN_IN_BUTTON)
870
class CurrentUserControllerErrorTestCase(BaseTestCase):
872
"""Tests for CurrentUserController's error handler."""
874
on_error_method_name = "on_login_error"
875
controller_class = CurrentUserController
877
@defer.inlineCallbacks
880
yield super(CurrentUserControllerErrorTestCase, self).setUp()
881
self.message_box = FakeMessageBox()
882
self.controller = self.controller_class(
883
message_box=self.message_box)
884
self.controller.view = FakePage()
885
self.on_error_method = getattr(
886
self.controller, self.on_error_method_name)
888
def test_error_message_key(self):
889
"""Test that on_login_error reacts to errors with "error_message"."""
890
self.on_error_method({"error_message": "WORRY!"})
891
self.assertEqual(self.message_box.critical_args, (('WORRY!',
892
self.controller.view), {}))
894
def test_message_key(self):
895
"""Test that on_login_error reacts to errors with "message"."""
896
self.on_error_method({"message": "WORRY!"})
897
self.assertEqual(self.message_box.critical_args, (('WORRY!',
898
self.controller.view), {}))
900
def test_broken_error(self):
901
"""Test that on_login_error reacts to broken errors."""
902
self.on_error_method({"boo!": "WORRY!"})
904
[('%s: %s' % (k, v)) for k, v in \
905
{"boo!": "WORRY!"}.iteritems()])
906
self.assertEqual(self.message_box.critical_args,
907
((result, self.controller.view), {}))
909
def test_all_and_message(self):
910
"""Test that on_login_error reacts to broken errors."""
911
self.on_error_method(
912
{"message": "WORRY!", "__all__": "MORE!"})
913
self.assertEqual(self.message_box.critical_args,
914
(('MORE!\nWORRY!', self.controller.view), {}))
916
def test_all_and_error_message(self):
917
"""Test that on_login_error reacts to broken errors."""
918
self.on_error_method(
919
{"error_message": "WORRY!", "__all__": "MORE!"})
920
self.assertEqual(self.message_box.critical_args,
921
(('MORE!\nWORRY!', self.controller.view), {}))
923
def test_only_all(self):
924
"""Test that on_login_error reacts to broken errors."""
925
self.on_error_method(
926
{"__all__": "MORE!"})
927
self.assertEqual(self.message_box.critical_args,
928
(('MORE!', self.controller.view), {}))
931
class EmailVerificationControllerErrorTestCase(
932
CurrentUserControllerErrorTestCase):
934
"""Tests for EmailVerificationController's error handler."""
936
on_error_method_name = "on_email_validation_error"
937
controller_class = EmailVerificationController
939
@defer.inlineCallbacks
942
yield super(EmailVerificationControllerErrorTestCase, self).setUp()
943
# This error handler takes one extra argument.
944
self.on_error_method = lambda error: getattr(
945
self.controller, self.on_error_method_name)('APP', error)
948
class SetUpAccountControllerErrorTestCase(
949
EmailVerificationControllerErrorTestCase):
951
"""Tests for SetUpAccountController's error handler."""
953
on_error_method_name = "on_user_registration_error"
954
controller_class = SetUpAccountController
956
@defer.inlineCallbacks
959
yield super(SetUpAccountControllerErrorTestCase, self).setUp()
960
self.patch(self.controller, "_refresh_captcha", lambda *args: None)
963
class ResetPasswordControllerErrorTestCase(
964
EmailVerificationControllerErrorTestCase):
966
"""Tests for ResetPasswordController's error handler."""
968
on_error_method_name = "on_password_change_error"
969
controller_class = ResetPasswordController
972
class CurrentUserControllerValidationTest(BaseTestCase):
974
"""Tests for CurrentUserController, but without Mocker."""
976
@defer.inlineCallbacks
979
yield super(CurrentUserControllerValidationTest, self).setUp()
980
self.message_box = FakeMessageBox()
981
self.controller = CurrentUserController(
982
message_box=self.message_box)
983
self.controller.view = FakeCurrentUserPage()
985
def test_valid(self):
986
"""Enable the button with a valid email/password."""
987
self.controller.view.email_edit.setText("a@b")
988
self.controller.view.password_edit.setText("pass")
989
self.controller._validate()
990
self.assertTrue(self.controller.view.sign_in_button.enabled())
991
self.assertTrue(self.controller.view.properties.get('unpolish', False))
992
self.assertTrue(self.controller.view.properties.get('polish', False))
993
self.assertTrue("DisabledState" in self.controller.view.properties)
994
self.assertEqual(self.controller.view.properties["DisabledState"],
995
not self.controller.view.sign_in_button.enabled())
997
def test_invalid_email(self):
998
"""The submit button should be disabled with an invalid email."""
999
self.controller.view.email_edit.setText("ab")
1000
self.controller.view.password_edit.setText("pass")
1001
self.controller._validate()
1002
self.assertFalse(self.controller.view.sign_in_button.enabled())
1003
self.assertTrue("DisabledState" in self.controller.view.properties)
1004
self.assertEqual(self.controller.view.properties["DisabledState"],
1005
not self.controller.view.sign_in_button.enabled())
1006
self.assertTrue(self.controller.view.properties.get('unpolish', False))
1007
self.assertTrue(self.controller.view.properties.get('polish', False))
1009
def test_invalid_password(self):
1010
"""The submit button should be disabled with an invalid password."""
1011
self.controller.view.email_edit.setText("a@b")
1012
self.controller.view.password_edit.setText("")
1013
self.controller._validate()
1014
self.assertFalse(self.controller.view.sign_in_button.enabled())
1015
self.assertTrue(self.controller.view.properties.get('unpolish', False))
1016
self.assertTrue(self.controller.view.properties.get('polish', False))
1017
self.assertTrue("DisabledState" in self.controller.view.properties)
1018
self.assertEqual(self.controller.view.properties["DisabledState"],
1019
not self.controller.view.sign_in_button.enabled())
1021
def test_invalid_both(self):
1022
"""The submit button should be disabled with invalid data."""
1023
self.controller.view.email_edit.setText("ab")
1024
self.controller.view.password_edit.setText("")
1025
self.controller._validate()
1026
self.assertFalse(self.controller.view.sign_in_button.enabled())
1027
self.assertTrue(self.controller.view.properties.get('unpolish', False))
1028
self.assertTrue(self.controller.view.properties.get('polish', False))
1029
self.assertTrue("DisabledState" in self.controller.view.properties)
1030
self.assertEqual(self.controller.view.properties["DisabledState"],
1031
not self.controller.view.sign_in_button.enabled())
1034
class SetUpAccountControllerTestCase(BaseTestCase):
1035
"""test the controller used to setup a new account."""
1037
@defer.inlineCallbacks
1039
"""Set the different tests."""
1040
yield super(SetUpAccountControllerTestCase, self).setUp()
1041
self.view = FakeSetupAccountPageView()
1042
self.message_box = FakeMessageBox()
1043
self.controller = SetUpAccountController(message_box=self.message_box)
1044
self.patch(self.controller, "get_backend", self.view.fake_backend)
1045
self.controller.view = self.view
1046
self.controller.backend = self.view
1048
def test_set_translated_strings(self):
1049
"""Ensure all the strings are set."""
1050
self.controller._set_translated_strings()
1051
self.assertEqual(self.view.name_label.text(), NAME_ENTRY)
1052
self.assertEqual(self.view.email_label.text(), EMAIL1_ENTRY)
1053
self.assertEqual(self.view.confirm_email_label.text(), EMAIL2_ENTRY)
1054
self.assertEqual(self.view.password_label.text(), PASSWORD1_ENTRY)
1055
self.assertEqual(self.view.confirm_password_label.text(),
1057
self.assertEqual(self.view.password_info_label.text(), PASSWORD_HELP)
1058
self.assertEqual(self.view.captcha_solution_edit.placeholderText(),
1059
CAPTCHA_SOLUTION_ENTRY)
1061
def test_set_titles(self):
1062
"""Test how the different titles are set."""
1063
self.controller._set_titles()
1064
self.assertEqual(self.view.properties['title'],
1065
JOIN_HEADER_LABEL % {'app_name': self.view.fake_wizard.app_name})
1066
self.assertEqual(self.view.properties['subtitle'],
1067
self.view.fake_wizard.help_text)
1069
def test_connect_ui_elements(self):
1070
"""Test that the ui elements are correctly connect."""
1071
self.controller._connect_ui_elements()
1072
self.assertEqual(self.view.name_edit.receivers(
1073
SIGNAL('textEdited(QString)')), 1)
1074
self.assertEqual(self.view.email_edit.receivers(
1075
SIGNAL('textEdited(QString)')), 1)
1076
self.assertEqual(self.view.confirm_email_edit.receivers(
1077
SIGNAL('textEdited(QString)')), 1)
1078
self.assertEqual(self.view.password_edit.receivers(
1079
SIGNAL('textEdited(QString)')), 1)
1080
self.assertEqual(self.view.confirm_password_edit.receivers(
1081
SIGNAL('textEdited(QString)')), 1)
1082
self.assertEqual(self.view.captcha_solution_edit.receivers(
1083
SIGNAL('textEdited(QString)')), 1)
1084
self.assertEqual(self.view.refresh_label.receivers(
1085
SIGNAL('linkActivated(QString)')), 1)
1086
self.assertEqual(self.view.terms_checkbox.receivers(
1087
SIGNAL('stateChanged(int)')), 1)
1088
# set the callbacks for the captcha generation
1089
self.assertIsInstance(self.view.on_captcha_generated_cb,
1090
collections.Callable)
1091
self.assertIsInstance(self.view.on_captcha_generation_error_cb,
1092
collections.Callable)
1093
self.assertIsInstance(self.view.on_user_registration_error_cb,
1094
collections.Callable)
1095
self.assertIsInstance(self.view.on_user_registered_cb,
1096
collections.Callable)
1098
def test_set_line_edits_validations(self):
1099
"""Test _set_line_validations from controller."""
1100
self.controller._set_line_edits_validations()
1101
elements = self.view.properties['validation_rule']
1102
self.assertFalse(elements is None)
1104
self.assertTrue(type(e[0]) is QLineEdit)
1105
self.assertIsInstance(e[1], collections.Callable)
1107
def all_valid(self):
1108
"""Set all the widgets to a valid state."""
1109
self.view.name_edit.setText('Name')
1110
self.view.email_edit.setText('email@email.com')
1111
self.view.confirm_email_edit.setText('email@email.com')
1112
self.view.password_edit.setText('T3st3rqw')
1113
self.view.confirm_password_edit.setText('T3st3rqw')
1114
self.view.captcha_solution_edit.setText('captcha solution')
1115
self.view.terms_checkbox.setChecked(True)
1117
def all_invalid(self):
1118
"""Set all the widgets to an invalid state."""
1119
self.view.name_edit.setText('')
1120
self.view.email_edit.setText('')
1121
self.view.confirm_email_edit.setText('email')
1122
self.view.password_edit.setText('')
1123
self.view.confirm_password_edit.setText('t')
1124
self.view.captcha_solution_edit.setText('')
1125
self.view.terms_checkbox.setChecked(False)
1127
def test_enable_setup_button_only_checkbox_ok(self):
1128
"""Test enable button only name valid."""
1130
self.view.terms_checkbox.setChecked(True)
1131
self.controller._enable_setup_button()
1133
self.assertFalse(self.view.set_up_button.enabled())
1134
self.assertTrue(self.view.set_up_button.property('DisabledState'))
1135
self.assertTrue(self.view.set_up_button.properties['polish'])
1136
self.assertTrue(self.view.set_up_button.properties['unpolish'])
1138
def test_enable_setup_button_only_name_ok(self):
1139
"""Test enable button only name valid."""
1141
self.view.name_edit.setText('Name')
1142
self.controller._enable_setup_button()
1144
self.assertFalse(self.view.set_up_button.enabled())
1145
self.assertTrue(self.view.set_up_button.property('DisabledState'))
1146
self.assertTrue(self.view.set_up_button.properties['polish'])
1147
self.assertTrue(self.view.set_up_button.properties['unpolish'])
1149
def test_enable_setup_button_only_email_ok(self):
1150
"""Test enable button only name valid."""
1152
self.view.email_edit.setText('email@email.com')
1153
self.controller._enable_setup_button()
1155
self.assertFalse(self.view.set_up_button.enabled())
1156
self.assertTrue(self.view.set_up_button.property('DisabledState'))
1157
self.assertTrue(self.view.set_up_button.properties['polish'])
1158
self.assertTrue(self.view.set_up_button.properties['unpolish'])
1160
def test_enable_setup_button_only_confirm_email_ok(self):
1161
"""Test enable button only name valid."""
1163
self.view.confirm_email_edit.setText('email@email.com')
1164
self.controller._enable_setup_button()
1166
self.assertFalse(self.view.set_up_button.enabled())
1167
self.assertTrue(self.view.set_up_button.property('DisabledState'))
1168
self.assertTrue(self.view.set_up_button.properties['polish'])
1169
self.assertTrue(self.view.set_up_button.properties['unpolish'])
1171
def test_enable_setup_button_only_email_and_confirm_ok(self):
1172
"""Test enable button only name valid."""
1174
self.view.email_edit.setText('email@email.com')
1175
self.view.confirm_email_edit.setText('email@email.com')
1176
self.controller._enable_setup_button()
1178
self.assertFalse(self.view.set_up_button.enabled())
1179
self.assertTrue(self.view.set_up_button.property('DisabledState'))
1180
self.assertTrue(self.view.set_up_button.properties['polish'])
1181
self.assertTrue(self.view.set_up_button.properties['unpolish'])
1183
def test_enable_setup_button_only_password_ok(self):
1184
"""Test enable button only name valid."""
1186
self.view.password_edit.setText('T3st3rqw')
1187
self.controller._enable_setup_button()
1189
self.assertFalse(self.view.set_up_button.enabled())
1190
self.assertTrue(self.view.set_up_button.property('DisabledState'))
1191
self.assertTrue(self.view.set_up_button.properties['polish'])
1192
self.assertTrue(self.view.set_up_button.properties['unpolish'])
1194
def test_enable_setup_button_only_password_confirm_ok(self):
1195
"""Test enable button only name valid."""
1197
self.view.confirm_password_edit.setText('T3st3rqw')
1198
self.controller._enable_setup_button()
1200
self.assertFalse(self.view.set_up_button.enabled())
1201
self.assertTrue(self.view.set_up_button.property('DisabledState'))
1202
self.assertTrue(self.view.set_up_button.properties['polish'])
1203
self.assertTrue(self.view.set_up_button.properties['unpolish'])
1205
def test_enable_setup_button_only_password_and_confirm_ok(self):
1206
"""Test enable button only name valid."""
1208
self.view.password_edit.setText('T3st3rqw')
1209
self.view.confirm_password_edit.setText('T3st3rqw')
1210
self.controller._enable_setup_button()
1212
self.assertFalse(self.view.set_up_button.enabled())
1213
self.assertTrue(self.view.set_up_button.property('DisabledState'))
1214
self.assertTrue(self.view.set_up_button.properties['polish'])
1215
self.assertTrue(self.view.set_up_button.properties['unpolish'])
1217
def test_enable_setup_button_only_captcha_ok(self):
1218
"""Test enable button only name valid."""
1220
self.view.captcha_solution_edit.setText('captcha solution')
1221
self.controller._enable_setup_button()
1223
self.assertFalse(self.view.set_up_button.enabled())
1224
self.assertTrue(self.view.set_up_button.property('DisabledState'))
1225
self.assertTrue(self.view.set_up_button.properties['polish'])
1226
self.assertTrue(self.view.set_up_button.properties['unpolish'])
1228
def test_enable_setup_button_only_all_ok(self):
1229
"""Test enable button only name valid."""
1231
self.controller._enable_setup_button()
1233
self.assertTrue(self.view.set_up_button.enabled())
1234
self.assertFalse(self.view.set_up_button.property('DisabledState'))
1235
self.assertTrue(self.view.set_up_button.properties['polish'])
1236
self.assertTrue(self.view.set_up_button.properties['unpolish'])
1238
def test_enable_setup_button_all_wrong(self):
1239
"""Test enable button only name valid."""
1241
self.controller._enable_setup_button()
1243
self.assertFalse(self.view.set_up_button.enabled())
1244
self.assertTrue(self.view.set_up_button.property('DisabledState'))
1245
self.assertTrue(self.view.set_up_button.properties['polish'])
1246
self.assertTrue(self.view.set_up_button.properties['unpolish'])
1248
def test_enable_setup_button_name_wrong(self):
1249
"""Test enable button only name valid."""
1251
self.view.name_edit.setText('')
1252
self.controller._enable_setup_button()
1254
self.assertFalse(self.view.set_up_button.enabled())
1255
self.assertTrue(self.view.set_up_button.property('DisabledState'))
1256
self.assertTrue(self.view.set_up_button.properties['polish'])
1257
self.assertTrue(self.view.set_up_button.properties['unpolish'])
1259
def test_enable_setup_button_email_wrong(self):
1260
"""Test enable button only name valid."""
1262
self.view.email_edit.setText('')
1263
self.controller._enable_setup_button()
1265
self.assertFalse(self.view.set_up_button.enabled())
1266
self.assertTrue(self.view.set_up_button.property('DisabledState'))
1267
self.assertTrue(self.view.set_up_button.properties['polish'])
1268
self.assertTrue(self.view.set_up_button.properties['unpolish'])
1270
def test_enable_setup_button_confirm_email_wrong(self):
1271
"""Test enable button only name valid."""
1273
self.view.confirm_email_edit.setText('')
1274
self.controller._enable_setup_button()
1276
self.assertFalse(self.view.set_up_button.enabled())
1277
self.assertTrue(self.view.set_up_button.property('DisabledState'))
1278
self.assertTrue(self.view.set_up_button.properties['polish'])
1279
self.assertTrue(self.view.set_up_button.properties['unpolish'])
1281
def test_enable_setup_button_password_wrong(self):
1282
"""Test enable button only name valid."""
1284
self.view.password_edit.setText('')
1285
self.controller._enable_setup_button()
1287
self.assertFalse(self.view.set_up_button.enabled())
1288
self.assertTrue(self.view.set_up_button.property('DisabledState'))
1289
self.assertTrue(self.view.set_up_button.properties['polish'])
1290
self.assertTrue(self.view.set_up_button.properties['unpolish'])
1292
def test_enable_setup_button_confirm_password_wrong(self):
1293
"""Test enable button only name valid."""
1295
self.view.confirm_password_edit.setText('')
1296
self.controller._enable_setup_button()
1298
self.assertFalse(self.view.set_up_button.enabled())
1299
self.assertTrue(self.view.set_up_button.property('DisabledState'))
1300
self.assertTrue(self.view.set_up_button.properties['polish'])
1301
self.assertTrue(self.view.set_up_button.properties['unpolish'])
1303
def test_enable_setup_button_captcha_wrong(self):
1304
"""Test enable button only name valid."""
1306
self.view.captcha_solution_edit.setText('')
1307
self.controller._enable_setup_button()
1309
self.assertFalse(self.view.set_up_button.enabled())
1310
self.assertTrue(self.view.set_up_button.property('DisabledState'))
1311
self.assertTrue(self.view.set_up_button.properties['polish'])
1312
self.assertTrue(self.view.set_up_button.properties['unpolish'])
1314
def test_enable_setup_button_checkbox_wrong(self):
1315
"""Test enable button only name valid."""
1317
self.view.terms_checkbox.setChecked(False)
1318
self.controller._enable_setup_button()
1320
self.assertFalse(self.view.set_up_button.enabled())
1321
self.assertTrue(self.view.set_up_button.property('DisabledState'))
1322
self.assertTrue(self.view.set_up_button.properties['polish'])
1323
self.assertTrue(self.view.set_up_button.properties['unpolish'])
1325
def test_register_fields(self):
1326
"""Test _register_fields."""
1327
self.controller._register_fields()
1328
self.assertTrue('email_address' in self.view.properties)
1329
self.assertTrue('password' in self.view.properties)
1330
self.assertTrue(type(self.view.properties['email_address']) is \
1332
self.assertTrue(type(self.view.properties['password']) is \
1335
def test_validate_form_all_ok(self):
1336
"""Test the result of validate_form."""
1338
self.assertTrue(self.controller.validate_form())
1339
self.assertNotEqual(self.view.name_assistance.text(), NAME_INVALID)
1340
self.assertNotEqual(self.view.email_assistance.text(), EMAIL_INVALID)
1341
self.assertNotEqual(self.view.confirm_email_assistance.text(),
1343
messages = '\n'.join([PASSWORD_TOO_WEAK, PASSWORD_MISMATCH,
1344
CAPTCHA_REQUIRED_ERROR])
1345
self.assertNotEqual(self.message_box.critical_args,
1346
((messages, self.view), {}))
1348
def test_validate_form_all_wrong(self):
1349
"""Test the result of validate_form."""
1351
self.assertFalse(self.controller.validate_form())
1352
self.assertEqual(self.view.name_assistance.text(), NAME_INVALID)
1353
self.assertEqual(self.view.email_assistance.text(), EMAIL_INVALID)
1354
self.assertEqual(self.view.confirm_email_assistance.text(),
1356
messages = '\n'.join([PASSWORD_TOO_WEAK, PASSWORD_MISMATCH,
1357
CAPTCHA_REQUIRED_ERROR])
1358
self.assertEqual(self.message_box.critical_args,
1359
((messages, self.view), {}))
1361
def test_validate_form_name_ok(self):
1362
"""Test the result of validate_form."""
1364
self.view.name_edit.setText('Name')
1365
self.assertFalse(self.controller.validate_form())
1366
self.assertEqual(self.view.email_assistance.text(), EMAIL_INVALID)
1367
self.assertEqual(self.view.confirm_email_assistance.text(),
1369
messages = '\n'.join([PASSWORD_TOO_WEAK, PASSWORD_MISMATCH,
1370
CAPTCHA_REQUIRED_ERROR])
1371
self.assertEqual(self.message_box.critical_args,
1372
((messages, self.view), {}))
1374
def test_validate_form_email_ok(self):
1375
"""Test the result of validate_form."""
1377
self.view.email_edit.setText('email@email.com')
1378
self.assertFalse(self.controller.validate_form())
1379
self.assertEqual(self.view.name_assistance.text(), NAME_INVALID)
1380
self.assertEqual(self.view.confirm_email_assistance.text(),
1382
messages = '\n'.join([PASSWORD_TOO_WEAK, PASSWORD_MISMATCH,
1383
CAPTCHA_REQUIRED_ERROR])
1384
self.assertEqual(self.message_box.critical_args,
1385
((messages, self.view), {}))
1387
def test_validate_form_confirm_email_ok(self):
1388
"""Test the result of validate_form."""
1390
self.view.email_edit.setText('email@email.com')
1391
self.view.confirm_email_edit.setText('email@email.com')
1392
self.assertFalse(self.controller.validate_form())
1393
self.assertEqual(self.view.name_assistance.text(), NAME_INVALID)
1394
messages = '\n'.join([PASSWORD_TOO_WEAK, PASSWORD_MISMATCH,
1395
CAPTCHA_REQUIRED_ERROR])
1396
self.assertEqual(self.message_box.critical_args,
1397
((messages, self.view), {}))
1399
def test_validate_form_password_weak(self):
1400
"""Test the result of validate_form."""
1402
self.view.password_edit.setText('Test')
1403
self.view.confirm_password_edit.setText('Test')
1404
self.assertFalse(self.controller.validate_form())
1405
messages = '\n'.join([PASSWORD_TOO_WEAK])
1406
self.assertEqual(self.message_box.critical_args,
1407
((messages, self.view), {}))
1409
def test_validate_form_password_mismatch(self):
1410
"""Test the result of validate_form."""
1412
self.view.password_edit.setText('T3st3rqw')
1413
self.view.confirm_password_edit.setText('test')
1414
self.assertFalse(self.controller.validate_form())
1415
messages = '\n'.join([PASSWORD_MISMATCH])
1416
self.assertEqual(self.message_box.critical_args,
1417
((messages, self.view), {}))
1419
def test_validate_form_captcha_required(self):
1420
"""Test the result of validate_form."""
1422
self.view.captcha_solution_edit.setText('')
1423
self.assertFalse(self.controller.validate_form())
1424
messages = '\n'.join([CAPTCHA_REQUIRED_ERROR])
1425
self.assertEqual(self.message_box.critical_args,
1426
((messages, self.view), {}))
1428
def test_is_correct_email(self):
1429
"""Test if the email is correct."""
1430
self.assertTrue(self.controller.is_correct_email('email@'))
1431
self.assertFalse(self.controller.is_correct_email('email'))
1433
def test_is_correct_email_confirmation(self):
1434
"""Test if the email confirmation is correct."""
1435
self.view.email_edit.setText('email@email.com')
1436
self.controller.is_correct_email_confirmation('email.@email.com')
1438
def test_is_correct_password_confirmation(self):
1439
"""Test is_correct_password_confirmation method."""
1440
self.view.password_edit.setText('T3st3rqw')
1441
self.controller.is_correct_password_confirmation('T3st3rqw')
1444
class SetupAccountControllerCaptchaTest(BaseTestCase):
1445
"""Tests for SetupAccountController, but without Mocker."""
1447
@defer.inlineCallbacks
1449
"""Set the different tests."""
1450
yield super(SetupAccountControllerCaptchaTest, self).setUp()
1451
self.message_box = FakeMessageBox()
1452
self.controller = SetUpAccountController(message_box=self.message_box)
1453
self.patch(self.controller, 'view', FakeSetupAccountView())
1454
self.fake_backend = FakeControllerForCaptcha()
1455
self.patch(self.controller, 'backend', self.fake_backend)
1457
def test_refresh_captcha(self):
1458
"""Test the Refresh Captcha function."""
1459
self.assertFalse(self.controller.view.captcha_refreshing_value)
1460
self.controller._refresh_captcha()
1461
self.assertTrue(self.controller.view.captcha_refreshing_value)
1462
self.assertTrue(self.fake_backend.callback_error)
1465
class SetupAccountControllerValidationTest(BaseTestCase):
1466
"""Tests for SetupAccountController, but without Mocker."""
1468
@defer.inlineCallbacks
1470
"""Set the different tests."""
1471
yield super(SetupAccountControllerValidationTest, self).setUp()
1472
self.message_box = FakeMessageBox()
1473
self.controller = SetUpAccountController(message_box=self.message_box)
1474
self.patch(self.controller, '_refresh_captcha', self._set_called)
1475
self.patch(self.controller, 'view', FakeSetupAccountView())
1477
def test_on_user_registration_refresh_captcha(self):
1478
"""If there is a user reg. error, captcha should refresh."""
1479
self.controller.on_user_registration_error('TestApp', {})
1480
self.assertEqual(self._called, ((), {}))
1482
def test_on_user_registration_all_only(self):
1483
"""Pass only a __all__ error key."""
1484
self.controller.on_user_registration_error('TestApp',
1485
{'__all__': "Error in All"})
1486
self.assertEqual(self.message_box.critical_args, ((
1487
"Error in All", self.controller.view), {}))
1489
def test_on_user_registration_all_fields(self):
1490
"""Pass all known error keys, plus unknown one."""
1491
self.controller.on_user_registration_error('TestApp',
1492
{'__all__': "Error in All",
1493
'email': "Error in email",
1494
'pasword': "Error in password",
1495
'unknownfield': "Error in unknown",
1497
self.assertEqual(self.message_box.critical_args, ((
1498
"Error in All", self.controller.view), {}))
1500
def test_registration_errors_without_message_or_all(self):
1501
"""Pass only a email error key."""
1502
errdict = {'errtype': "RegistrationError",
1503
'email': "Error in email"}
1504
self.controller.on_user_registration_error('TestApp', errdict)
1506
expected = (('', self.controller.view), {})
1507
self.assertEqual(self.message_box.critical_args, expected)
1509
def test_on_captcha_generated(self):
1510
"""Test if the method that shows the overlay is executed."""
1511
self.patch(Image, "open", self.controller.view.fake_open)
1512
self.assertFalse(self.controller.view.captcha_refresh_executed)
1513
self.controller.on_captcha_generated('app_name', 'captcha_id')
1514
self.assertTrue(self.controller.view.captcha_refresh_executed)
1516
def test_on_captcha_generation_error(self):
1517
"""Test if the method that hides the overlay is executed."""
1518
self.assertFalse(self.controller.view.captcha_refresh_executed)
1519
self.controller.on_captcha_generation_error({})
1520
self.assertTrue(self.controller.view.captcha_refresh_executed)
1523
class EmailVerificationControllerTestCase(BaseTestCase):
1524
"""Test the controller."""
1526
@defer.inlineCallbacks
1529
yield super(EmailVerificationControllerTestCase, self).setUp()
1530
self.view = EmailVerificationView()
1531
self.backend = self.view
1532
self.controller = EmailVerificationController(
1533
message_box=FakeMessageBox())
1534
self.controller.view = self.view
1535
self.controller.backend = self.backend
1536
self.patch(self.controller, "get_backend", self.view.fake_backend)
1537
self.email = 'email@email.com'
1538
self.password = 'T3st3rqw'
1539
self.view.fake_wizard.registerField('email_address', self.email)
1540
self.view.fake_wizard.registerField('password', self.password)
1542
def test_connect_ui_elements(self):
1543
"""Set the ui connections."""
1544
self.controller._connect_ui_elements()
1545
self.assertEqual(self.view.verification_code_edit.receivers(
1546
SIGNAL('textChanged(QString)')), 1)
1547
self.assertIsInstance(self.view.next_button.function,
1548
collections.Callable)
1549
self.assertIsInstance(self.view.on_email_validated_cb,
1550
collections.Callable)
1551
self.assertIsInstance(self.view.on_email_validation_error_cb,
1552
collections.Callable)
1554
def test_set_titles(self):
1555
"""Test that the titles are set."""
1556
self.controller.set_titles()
1557
self.assertEqual(self.view.properties['title'], VERIFY_EMAIL_TITLE)
1558
self.assertEqual(self.view.properties['subtitle'],
1559
VERIFY_EMAIL_CONTENT % {
1560
"app_name": self.view.fake_wizard.app_name,
1561
"email": self.email,
1564
def test_validate_email(self):
1565
"""Test the callback."""
1567
self.view.verification_code_edit.setText(code)
1568
self.controller.validate_email()
1569
self.assertEqual(self.view.properties['validate_email'],
1570
((self.view.fake_wizard.app_name, self.email, self.password,
1573
def test_validate_form(self):
1574
"""Test validate_form."""
1575
self.view.verification_code = 'qwe123'
1576
self.controller.validate_form()
1577
self.assertTrue(self.view.next_button.enabled())
1578
self.assertFalse(self.view.next_button.property('DisabledState'))
1579
self.assertTrue(self.view.next_button.properties['polish'])
1580
self.assertTrue(self.view.next_button.properties['unpolish'])
1582
self.view.verification_code = ''
1583
self.controller.validate_form()
1584
self.assertFalse(self.view.next_button.enabled())
1585
self.assertTrue(self.view.next_button.property('DisabledState'))
1586
self.assertTrue(self.view.next_button.properties['polish'])
1587
self.assertTrue(self.view.next_button.properties['unpolish'])
1589
def test_page_initialized(self):
1590
"""test pageInitialized to check the initial state of the page."""
1591
self.controller.pageInitialized()
1592
self.assertTrue(self.view.next_button.properties['default'])
1593
self.assertFalse(self.view.next_button.enabled())
1594
self.assertTrue(self.view.next_button.property('DisabledState'))
1595
self.assertTrue(self.view.next_button.properties['polish'])
1596
self.assertTrue(self.view.next_button.properties['unpolish'])
1598
def test_on_email_validation_error(self):
1599
"""Test on_email_validation_error."""
1600
error = dict(error='email error')
1601
self.controller.on_email_validation_error('app', error)
1603
[('%s: %s' % (k, v)) for k, v in error.iteritems()])
1604
self.assertEqual(self.controller.message_box.critical_args,
1605
((result, self.view), {}))
1607
def test_on_email_validated(self):
1608
"""Test on_email_validated."""
1609
self.controller.on_email_validated('app_name')
1610
self.assertEqual(self.view.fake_wizard.properties['emit'],
1611
('app_name', self.email))
1614
class EmailVerificationControllerValidationTestCase(BaseTestCase):
1615
"""Tests for EmailVerificationController, but without Mocker."""
1617
@defer.inlineCallbacks
1619
"""Set the different tests."""
1620
yield super(EmailVerificationControllerValidationTestCase,
1622
self.message_box = FakeMessageBox()
1623
self.controller = EmailVerificationController(
1624
message_box=self.message_box)
1625
self.patch(self.controller, 'view', FakeEmailVerificationView())
1627
def test_on_email_validation_error(self):
1628
"""Test that on_email_validation_error callback works as expected."""
1629
# Error type is removed from the final message
1630
error = dict(errtype='BadTokenError')
1631
app_name = 'app_name'
1632
self.controller.on_email_validation_error(app_name, error)
1633
self.assertEqual(self.message_box.critical_args,
1634
(('', self.controller.view), {}))
1636
def test_validate_form_wrong(self):
1637
"""Check the state of the next button."""
1638
self.controller.view.verification_code = ''
1639
self.controller.validate_form()
1640
self.assertFalse(self.controller.view.next_button.isEnabled())
1641
self.assertTrue(self.controller.view.properties.get('unpolish', False))
1642
self.assertTrue(self.controller.view.properties.get('polish', False))
1643
self.assertTrue("DisabledState" in self.controller.view.properties)
1644
self.assertEqual(self.controller.view.properties["DisabledState"],
1645
not self.controller.view.next_button.enabled())
1647
def test_validate_form_ok(self):
1648
"""Check the state of the next button."""
1649
self.controller.view.verification_code = 'as322fdw'
1650
self.controller.validate_form()
1651
self.assertTrue(self.controller.view.next_button.isEnabled)
1652
self.assertTrue(self.controller.view.properties.get('unpolish', False))
1653
self.assertTrue(self.controller.view.properties.get('polish', False))
1654
self.assertTrue("DisabledState" in self.controller.view.properties)
1655
self.assertEqual(self.controller.view.properties["DisabledState"],
1656
not self.controller.view.next_button.enabled())
1659
class ErrorControllerTestCase(BaseTestCase):
1660
"""Test the success page controller."""
1662
@defer.inlineCallbacks
1664
yield super(ErrorControllerTestCase, self).setUp()
1665
self.view = ErrorPageView()
1666
self.backend = self.view
1667
self.controller = ErrorController()
1668
self.controller.view = self.view
1669
self.controller.backend = self.backend
1671
def test_set_ui(self):
1672
"""Test the process that sets the ui."""
1673
self.controller._title = ERROR
1674
self.controller._subtitle = ERROR
1675
self.controller.setupUi(self.view)
1676
self.assertEqual(self.view.error_message_label.text(), ERROR)
1677
self.assertEqual(self.view.properties['title'], ERROR)
1678
self.assertEqual(self.view.properties['subtitle'], ERROR)
1679
self.assertEqual(self.view.next, -1)
1682
class SuccessControllerTestCase(BaseTestCase):
1683
"""Test the success page controller."""
1685
@defer.inlineCallbacks
1687
yield super(SuccessControllerTestCase, self).setUp()
1688
self.view = SuccessPageView()
1689
self.backend = self.view
1690
self.controller = SuccessController()
1691
self.controller.view = self.view
1692
self.controller.backend = self.backend
1694
def test_set_ui(self):
1695
"""Test the process that sets the ui."""
1696
self.controller._title = SUCCESS
1697
self.controller._subtitle = SUCCESS
1698
self.controller.setupUi(self.view)
1699
self.assertEqual(self.view.properties['title'], SUCCESS)
1700
self.assertEqual(self.view.properties['subtitle'], SUCCESS)
1701
self.assertEqual(self.view.next, -1)
1704
class UbuntuSSOWizardControllerTestCase(BaseTestCase):
1705
"""Test the wizard controller."""
1707
@defer.inlineCallbacks
1710
yield super(UbuntuSSOWizardControllerTestCase, self).setUp()
1711
self.view = UbuntuSSOView()
1712
self.backend = self.view
1713
self.callback = self.view.callback
1714
self.controller = UbuntuSSOWizardController()
1715
self.controller.view = self.view
1716
self.controller.backend = self.backend
1718
def test_on_user_cancelation(self):
1719
"""Test that the callback is indeed called."""
1720
self.controller.user_cancellation_callback = self.callback
1721
self.controller.on_user_cancelation()
1722
self.assertTrue(self.view.properties.get('close', False))
1723
self.assertEqual(self.view.properties['callback'],
1724
((self.view.app_name, ), {}))
1726
def test_on_login_success(self):
1727
"""Test that the callback is indeed called."""
1730
self.controller.login_success_callback = self.callback
1731
self.controller.login_success_callback(app_name, email)
1732
self.assertEqual(self.view.properties['callback'],
1733
((app_name, email), {}))
1735
def test_on_registration_success(self):
1736
"""Test that the callback is indeed called."""
1739
self.controller.registration_success_callback = self.callback
1740
self.controller.registration_success_callback(app_name, email)
1741
self.assertEqual(self.view.properties['callback'],
1742
((app_name, email), {}))
1744
def test_show_success_message(self):
1745
"""Test that the correct page will be shown."""
1746
self.controller.show_success_message()
1747
# the buttons layout we expect to have
1749
layout.append(QWizard.Stretch)
1750
layout.append(QWizard.FinishButton)
1752
self.assertEqual(self.view.page.next, self.view.success_page_id)
1753
self.assertTrue(self.view.properties['wizard_next'])
1754
self.assertEqual(self.view.properties['buttons_layout'], layout)
1756
def test_show_error_message(self):
1757
"""Test that the correct page will be shown."""
1758
self.controller.show_error_message()
1759
# the buttons layout we expect to have
1761
layout.append(QWizard.Stretch)
1762
layout.append(QWizard.FinishButton)
1764
self.assertEqual(self.view.page.next, self.view.error_page_id)
1765
self.assertTrue(self.view.properties['wizard_next'])
1766
self.assertEqual(self.view.properties['buttons_layout'], layout)
1768
def test_setup_ui(self):
1769
"""Test that the ui is connect."""
1770
self.controller.setupUi(self.view)
1771
self.assertEqual(self.view.properties['wizard_style'],
1772
QWizard.ModernStyle)
1773
self.assertIsInstance(self.view.properties['button'].function,
1774
collections.Callable)
1775
self.assertIsInstance(self.view.loginSuccess.function,
1776
collections.Callable)
1777
self.assertIsInstance(self.view.registrationSuccess.function,
1778
collections.Callable)
1781
class ForgottenPasswordControllerValidationTest(BaseTestCase):
1783
"""Tests for ForgottenPasswordController, but without Mocker."""
1785
@defer.inlineCallbacks
1787
"""Set the different tests."""
1788
yield super(ForgottenPasswordControllerValidationTest, self).setUp()
1789
self.message_box = FakeMessageBox()
1790
self.controller = ForgottenPasswordController(
1791
message_box=self.message_box)
1792
self.view = FakeForgottenPasswordPage()
1793
self.controller.view = self.view
1794
self.patch(self.controller, "get_backend", self.view.fake_backend)
1796
def test_page_initialized(self):
1797
"""Test the initial state of the page when it is loaded."""
1798
self.controller.pageInitialized()
1799
self.assertFalse(self.controller.view.send_button.enabled())
1800
self.assertTrue(self.controller.view.send_button.properties['default'])
1801
self.assertTrue("DisabledState" in self.controller.view.properties)
1802
self.assertEqual(self.controller.view.properties["DisabledState"],
1803
not self.controller.view.send_button.enabled())
1804
self.assertTrue(self.controller.view.properties.get('unpolish', False))
1805
self.assertTrue(self.controller.view.properties.get('polish', False))
1807
def test_page_initialized_with_text(self):
1808
"""Test the initial state of the page when it is loaded."""
1809
self.controller.view.email_line_edit.setText('mail@mail.com')
1810
self.controller.pageInitialized()
1811
self.assertTrue(self.controller.view.send_button.enabled())
1813
self.controller.view.send_button.properties['default'])
1814
self.assertTrue("DisabledState" in self.controller.view.properties)
1815
self.assertEqual(self.controller.view.properties["DisabledState"],
1816
not self.controller.view.send_button.enabled())
1817
self.assertTrue(self.controller.view.properties.get('unpolish', False))
1818
self.assertTrue(self.controller.view.properties.get('polish', False))
1820
def test_valid(self):
1821
"""The submit button should be enabled with a valid email."""
1822
self.controller.view.email_address_line_edit.setText("a@b")
1823
self.assertNotEqual(unicode(
1824
self.controller.view.email_address_line_edit.text()), u"")
1825
self.controller._validate()
1826
self.assertTrue(self.controller.view.send_button.enabled())
1827
self.assertTrue("DisabledState" in self.controller.view.properties)
1828
self.assertEqual(self.controller.view.properties["DisabledState"],
1829
not self.controller.view.send_button.enabled())
1830
self.assertTrue(self.controller.view.properties.get('unpolish', False))
1831
self.assertTrue(self.controller.view.properties.get('polish', False))
1833
def test_invalid(self):
1834
"""The submit button should be disabled with an invalid email."""
1835
self.controller.view.email_address_line_edit.setText("ab")
1836
self.assertNotEqual(
1837
unicode(self.controller.view.email_address_line_edit.text()), u"")
1838
self.controller._validate()
1839
self.assertFalse(self.controller.view.send_button.enabled())
1840
self.assertTrue("DisabledState" in self.controller.view.properties)
1841
self.assertEqual(self.controller.view.properties["DisabledState"],
1842
not self.controller.view.send_button.enabled())
1843
self.assertTrue(self.controller.view.properties.get('unpolish', False))
1844
self.assertTrue(self.controller.view.properties.get('polish', False))
1846
def test_empty(self):
1847
"""The submit button should be disabled without email."""
1849
unicode(self.controller.view.email_address_line_edit.text()), u"")
1850
self.assertFalse(self.controller.view.send_button.enabled())
1852
def test_on_password_reset_error_token_error(self):
1853
"""Test that the on_password_reset_error callback works as expected."""
1854
error = dict(errtype='ResetPasswordTokenError')
1855
app_name = 'app_name'
1856
self.controller.on_password_reset_error(app_name, error)
1857
msg = REQUEST_PASSWORD_TOKEN_WRONG_EMAIL
1858
self.assertEqual(self.controller.message_box.critical_args,
1859
((msg, self.controller.view), {}))
1861
def test_on_password_reset_error_general_error(self):
1862
"""Test that the on_password_reset_error callback works as expected."""
1863
error = dict(errtype='RandomError')
1864
app_name = 'app_name'
1865
msg = REQUEST_PASSWORD_TOKEN_TECH_ERROR
1866
self.controller.on_password_reset_error(app_name, error)
1867
self.assertFalse(self.controller.view.email_widget.isVisible())
1869
self.controller.view.forgotted_password_intro_label.isVisible())
1870
self.assertTrue(self.controller.view.try_again_widget.isVisible())
1871
self.assertEqual(self.controller.message_box.critical_args,
1872
((msg, self.controller.view), {}))
1875
class ForgottenPasswordControllerTestCase(BaseTestCase):
1876
"""Test the controller of the fogotten password page."""
1878
@defer.inlineCallbacks
1880
"""Setup the tests."""
1881
yield super(ForgottenPasswordControllerTestCase, self).setUp()
1882
self.view = FakeForgottenPasswordPageView()
1883
self.backend = self.view
1884
self.controller = ForgottenPasswordController(
1885
message_box=FakeMessageBox())
1886
self.controller.view = self.view
1887
self.controller.backend = self.backend
1889
def test_register_fields(self):
1890
"""Ensure that all the diff fields are registered."""
1891
self.controller._register_fields()
1892
self.assertEqual(self.view.field('email_address'),
1893
self.view.email_address_line_edit)
1895
def test_set_translated_strings(self):
1896
"""Ensure that the correct strings are translated."""
1897
self.controller._set_translated_strings()
1898
self.assertEqual(self.view.forgotted_password_intro_label.text(),
1899
REQUEST_PASSWORD_TOKEN_LABEL % {'app_name':
1900
self.view.fake_wizard.app_name})
1901
self.assertEqual(self.view.email_address_label.text(),
1903
self.assertEqual(self.view.send_button.text(),
1905
self.assertEqual(self.view.try_again_button.text(),
1908
def test_set_enhanced_line_edit(self):
1909
"""Test that the correct line enhancements have been added."""
1910
self.controller._set_enhanced_line_edit()
1911
elements = self.view.properties['validation_rule']
1912
self.assertFalse(elements is None)
1914
self.assertTrue(e[0] is self.view.email_address_line_edit)
1915
self.assertIsInstance(e[1], collections.Callable)
1917
def test_connect_ui(self):
1918
"""Test that the correct ui signals are connected."""
1919
self.controller._connect_ui()
1920
self.assertEqual(self.view.email_address_line_edit.receivers(
1921
SIGNAL('textChanged(QString)')), 1)
1922
self.assertIsInstance(self.view.send_button.function,
1923
collections.Callable)
1924
self.assertIsInstance(self.view.try_again_button.function,
1925
collections.Callable)
1926
self.assertIsInstance(self.view.on_password_reset_token_sent_cb,
1927
collections.Callable)
1928
self.assertIsInstance(self.view.on_password_reset_error_cb,
1929
collections.Callable)
1931
def test_on_try_again(self):
1932
"""Test that the on_try_again callback does work as expected."""
1933
self.controller.on_try_again()
1934
self.assertFalse(self.view.try_again_widget.isVisible())
1935
self.assertTrue(self.view.email_widget.isVisible())
1937
def test_on_password_reset_token_sent(self):
1938
"""Test that the on_password_token_sent callback works as expected."""
1939
self.controller.on_password_reset_token_sent()
1940
self.assertTrue(self.view.properties['wizard_next'])
1941
self.assertEqual(self.view.next,
1942
self.view.fake_wizard.reset_password_page_id)
1945
class ResetPasswordControllerTestCase(BaseTestCase):
1946
"""Ensure that the reset password works as expected."""
1948
@defer.inlineCallbacks
1950
"""Setup the tests."""
1951
yield super(ResetPasswordControllerTestCase, self).setUp()
1952
self.view = ResetPasswordPageView()
1953
self.backend = self.view
1954
self.controller = ResetPasswordController()
1955
self.controller.view = self.view
1956
self.controller.backend = self.backend
1958
def test_set_translated_strings(self):
1959
"""Ensure that the correct strings are set."""
1960
self.controller._set_translated_strings()
1961
self.assertEqual(self.view.reset_password_button.text(),
1963
self.assertEqual(self.view.properties['subtitle'],
1966
def test_connect_ui(self):
1967
"""Ensure that the diffent signals from the ui are connected."""
1968
self.controller._connect_ui()
1969
self.assertIsInstance(self.view.reset_password_button.function,
1970
collections.Callable)
1971
self.assertIsInstance(self.view.on_password_changed_cb,
1972
collections.Callable)
1973
self.assertIsInstance(self.view.on_password_change_error_cb,
1974
collections.Callable)
1975
self.assertEqual(self.view.reset_code_line_edit.receivers(
1976
SIGNAL('textChanged(QString)')), 1)
1977
self.assertEqual(self.view.password_line_edit.receivers(
1978
SIGNAL('textChanged(QString)')), 1)
1979
self.assertEqual(self.view.confirm_password_line_edit.receivers(
1980
SIGNAL('textChanged(QString)')), 1)
1982
def test_add_line_edits_validations(self):
1983
"""Ensure that the line validation have been added."""
1984
self.controller._add_line_edits_validations()
1985
self.assertEqual(self.view.password_line_edit.receivers(
1986
SIGNAL('textChanged(QString)')), 1)
1987
elements = self.view.properties['validation_rule']
1988
self.assertFalse(elements is None)
1990
self.assertTrue(type(e[0]) is QLineEdit)
1991
self.assertIsInstance(e[1], collections.Callable)
1993
def test_set_new_password(self):
1994
"""Test that the correct action is performed."""
1995
email = 'email@email.com'
1997
password = 'T3st3rqw'
1998
self.view.wizard().forgotten.ui.email_line_edit.setText(email)
1999
self.view.reset_code_line_edit.setText(code)
2000
self.view.password_line_edit.setText(password)
2001
self.controller.set_new_password()
2002
self.assertEqual(self.view.properties['backend_new_password'],
2003
((self.view.fake_wizard.app_name, email, code, password), {}))
2005
def test_is_correct_password_confirmation_true(self):
2006
"""Test that the correct password confirmation is used."""
2007
password = 'password'
2008
self.view.password_line_edit.setText(password)
2009
self.assertTrue(self.controller.is_correct_password_confirmation(
2012
def test_is_correct_password_confirmation_false(self):
2013
"""Test that the correct password confirmation is used."""
2014
password = 'password'
2015
self.view.password_line_edit.setText(password + password)
2016
self.assertFalse(self.controller.is_correct_password_confirmation(
2020
class ResetPasswordControllerValidationTest(BaseTestCase):
2022
"""Tests for ResetPasswordController, but without Mocker."""
2024
@defer.inlineCallbacks
2027
yield super(ResetPasswordControllerValidationTest, self).setUp()
2028
self.controller = ResetPasswordController()
2029
self.controller.view = FakeResetPasswordPage()
2031
def test_page_initialized(self):
2032
"""Test the initial state of the page when it is loaded."""
2033
self.controller.pageInitialized()
2035
self.controller.view.reset_password_button.enabled())
2037
self.controller.view.reset_password_button.properties['default'])
2038
self.assertTrue("DisabledState" in self.controller.view.properties)
2039
self.assertEqual(self.controller.view.properties["DisabledState"],
2040
not self.controller.view.reset_password_button.enabled())
2041
self.assertTrue(self.controller.view.properties.get('unpolish', False))
2042
self.assertTrue(self.controller.view.properties.get('polish', False))
2044
def test_valid(self):
2045
"""Enable the button with valid data."""
2046
self.controller.view.reset_code_line_edit.setText("ABCD")
2047
self.controller.view.password_line_edit.setText("1234567A")
2048
self.controller.view.confirm_password_line_edit.setText("1234567A")
2049
self.controller._validate()
2050
self.assertTrue(self.controller.view.reset_password_button.enabled())
2051
self.assertTrue("DisabledState" in self.controller.view.properties)
2052
self.assertEqual(self.controller.view.properties["DisabledState"],
2053
not self.controller.view.reset_password_button.enabled())
2054
self.assertTrue(self.controller.view.properties.get('unpolish', False))
2055
self.assertTrue(self.controller.view.properties.get('polish', False))
2057
def test_invalid_code(self):
2058
"""Disable the button with an invalid code."""
2059
self.controller.view.reset_code_line_edit.setText("")
2060
self.controller.view.password_line_edit.setText("1234567A")
2061
self.controller.view.confirm_password_line_edit.setText("1234567A")
2062
self.controller._validate()
2063
self.assertFalse(self.controller.view.reset_password_button.enabled())
2064
self.assertTrue("DisabledState" in self.controller.view.properties)
2065
self.assertEqual(self.controller.view.properties["DisabledState"],
2066
not self.controller.view.reset_password_button.enabled())
2067
self.assertTrue(self.controller.view.properties.get('unpolish', False))
2068
self.assertTrue(self.controller.view.properties.get('polish', False))
2070
def test_invalid_password(self):
2071
"""Disable the button with an invalid password."""
2072
self.controller.view.reset_code_line_edit.setText("")
2073
self.controller.view.password_line_edit.setText("1234567")
2074
self.controller.view.confirm_password_line_edit.setText("1234567")
2075
self.controller._validate()
2076
self.assertFalse(self.controller.view.reset_password_button.enabled())
2078
def test_invalid_confirm(self):
2079
"""Disable the button with an invalid password confirm."""
2080
self.controller.view.reset_code_line_edit.setText("")
2081
self.controller.view.password_line_edit.setText("1234567A")
2082
self.controller.view.confirm_password_line_edit.setText("1234567")
2083
self.controller._validate()
2084
self.assertFalse(self.controller.view.reset_password_button.enabled())
2087
class ResetPasswordControllerRealControllerTest(BaseTestCase):
2089
"""Tests for ResetPasswordController, but without Mocker."""
2091
@defer.inlineCallbacks
2094
yield super(ResetPasswordControllerRealControllerTest, self).setUp()
2095
self.controller = ResetPasswordController()
2096
self.controller.view = FakeWizardForResetPassword()
2098
def test_on_password_changed(self):
2099
"""Test that on_password_changed execute the proper operation."""
2100
self.controller.on_password_changed('app_name', '')
2101
self.assertTrue(self.controller.view.hide_value)
2103
self.assertEqual(self.controller.view.count_back, times_visited)
2104
self.assertEqual(self.controller.view.text_value, 'mail@mail.com')
2106
def test_on_password_changed_not_visited(self):
2107
"""Test that on_password_changed execute the proper operation."""
2108
current_user_page_id = 20
2109
self.patch(self.controller.view, "current_user_page_id",
2110
current_user_page_id)
2111
self.controller.on_password_changed('app_name', '')
2112
self.assertTrue(self.controller.view.hide_value)
2114
self.assertEqual(self.controller.view.count_back, times_visited)
2115
self.assertEqual(self.controller.view.text_value, 'mail@mail.com')