~nataliabidart/ubuntu-sso-client/find-me-bin-dir

« back to all changes in this revision

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

- Refactor the pages and controller in sso (LP: #929686).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- coding: utf-8 -*-
2
 
 
3
 
# Authors: Manuel de la Pena <manuel@canonical.com>
4
 
#          Natalia B. Bidart <natalia.bidart@canonical.com>
5
 
#
6
 
# Copyright 2011 Canonical Ltd.
7
 
#
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.
11
 
#
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.
16
 
#
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/>.
19
 
 
20
 
"""Test the ui controllers."""
21
 
 
22
 
import collections
23
 
 
24
 
from twisted.internet import defer
25
 
 
26
 
# pylint: disable=F0401,E0611
27
 
 
28
 
from PyQt4.QtCore import QString, SIGNAL
29
 
from PyQt4.QtGui import QCheckBox, QLabel, QLineEdit, QWizard
30
 
 
31
 
try:
32
 
    from PIL import Image
33
 
except ImportError:
34
 
    import Image
35
 
# pylint: enable=F0401,E0611
36
 
 
37
 
from ubuntu_sso.qt.controllers import (
38
 
    BackendController,
39
 
    ChooseSignInController,
40
 
    CurrentUserController,
41
 
    EmailVerificationController,
42
 
    ErrorController,
43
 
    ForgottenPasswordController,
44
 
    ResetPasswordController,
45
 
    SetUpAccountController,
46
 
    SuccessController,
47
 
    UbuntuSSOWizardController,
48
 
)
49
 
from ubuntu_sso.qt.tests import BaseTestCase, FakePageUiStyle
50
 
from ubuntu_sso.utils.ui import (
51
 
    CAPTCHA_REQUIRED_ERROR,
52
 
    CAPTCHA_SOLUTION_ENTRY,
53
 
    EMAIL1_ENTRY,
54
 
    EMAIL2_ENTRY,
55
 
    EMAIL_INVALID,
56
 
    EMAIL_MISMATCH,
57
 
    ERROR,
58
 
    EMAIL_LABEL,
59
 
    EXISTING_ACCOUNT_CHOICE_BUTTON,
60
 
    FORGOTTEN_PASSWORD_BUTTON,
61
 
    JOIN_HEADER_LABEL,
62
 
    LOGIN_PASSWORD_LABEL,
63
 
    NAME_ENTRY,
64
 
    NAME_INVALID,
65
 
    PASSWORD1_ENTRY,
66
 
    PASSWORD2_ENTRY,
67
 
    PASSWORD_HELP,
68
 
    PASSWORD_TOO_WEAK,
69
 
    PASSWORD_MISMATCH,
70
 
    RESET_PASSWORD,
71
 
    REQUEST_PASSWORD_TOKEN_LABEL,
72
 
    SET_UP_ACCOUNT_CHOICE_BUTTON,
73
 
    SIGN_IN_BUTTON,
74
 
    SUCCESS,
75
 
    REQUEST_PASSWORD_TOKEN_WRONG_EMAIL,
76
 
    REQUEST_PASSWORD_TOKEN_TECH_ERROR,
77
 
    TRY_AGAIN_BUTTON,
78
 
    VERIFY_EMAIL_CONTENT,
79
 
    VERIFY_EMAIL_TITLE,
80
 
)
81
 
 
82
 
#ignore the comon mocker issues with lint
83
 
# pylint: disable=W0212,W0104,W0106,E1103
84
 
 
85
 
 
86
 
class FakeButton(FakePageUiStyle):
87
 
 
88
 
    """Fake Button."""
89
 
 
90
 
    def __init__(self):
91
 
        """Initialize object."""
92
 
        super(FakeButton, self).__init__()
93
 
        self.function = None
94
 
        self.clicked = self
95
 
 
96
 
    def connect(self, function):
97
 
        """Receive the function that should be connected to this button."""
98
 
        self.function = function
99
 
 
100
 
 
101
 
class FakeField(object):
102
 
 
103
 
    """Fake Field for text input."""
104
 
 
105
 
    def __init__(self, text):
106
 
        self.text = text
107
 
 
108
 
    # pylint: disable=C0103
109
 
    def toString(self):
110
 
        """Fake toString method for input fields."""
111
 
        return self.text
112
 
    # pylint: enable=C0103
113
 
 
114
 
 
115
 
class FakeWizard(object):
116
 
 
117
 
    """Fake Wizard."""
118
 
 
119
 
    current_user_page_id = 1
120
 
    setup_account_page_id = 2
121
 
    forgotten_password_page_id = 3
122
 
    reset_password_page_id = 4
123
 
 
124
 
    def __init__(self, view):
125
 
        """Initialize object."""
126
 
        self.properties = {}
127
 
        self.app_name = 'app_name'
128
 
        self.help_text = 'help'
129
 
        self.view = view
130
 
        self.next_id = 0
131
 
        # pylint: disable=C0103
132
 
        self.loginSuccess = self
133
 
        self.registrationSuccess = self
134
 
        # pylint: enable=C0103
135
 
        self.forgotten = self
136
 
        self.ui = self
137
 
        self.email_line_edit = QLineEdit()
138
 
 
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
144
 
 
145
 
    def field(self, key):
146
 
        """Fake field from wizard"""
147
 
        return self.properties['field_%s' % key]
148
 
 
149
 
    def next(self):
150
 
        """Fake next method to move to to next page in the wizard."""
151
 
        self.view.properties['wizard_next'] = True
152
 
 
153
 
    def emit(self, name, email):
154
 
        """Fake emit."""
155
 
        self.properties['emit'] = (name, email)
156
 
 
157
 
 
158
 
class FakeGenericView(object):
159
 
 
160
 
    """Fake Generic page."""
161
 
 
162
 
    def __init__(self):
163
 
        """Initialize object."""
164
 
        self.properties = {}
165
 
        self.ui = self
166
 
        self.header = self
167
 
        self.properties['currentId'] = -1
168
 
        self.next = 0
169
 
        self.fake_wizard = FakeWizard(self)
170
 
 
171
 
    def set_title(self, title):
172
 
        """Fake set_title for the page."""
173
 
        self.properties['title'] = title
174
 
 
175
 
    def set_subtitle(self, subtitle):
176
 
        """Fake set_subtitle for the page"""
177
 
        self.properties['subtitle'] = subtitle
178
 
 
179
 
    # pylint: disable=C0103
180
 
    def setTitle(self, title):
181
 
        """Fake setTitle."""
182
 
        self.set_title(title)
183
 
 
184
 
    def setSubTitle(self, subtitle):
185
 
        """Fake setTitle."""
186
 
        self.set_subtitle(subtitle)
187
 
    # pylint: enable=C0103
188
 
 
189
 
    def wizard(self):
190
 
        """Fake wizard is returned."""
191
 
        return self.fake_wizard
192
 
 
193
 
 
194
 
class FakeChooseSignInView(FakeGenericView):
195
 
 
196
 
    """Fake ChooseSignIn page."""
197
 
 
198
 
    def __init__(self):
199
 
        """Initialize object."""
200
 
        super(FakeChooseSignInView, self).__init__()
201
 
        self.existing_account_button = FakeButton()
202
 
        self.setup_account_button = FakeButton()
203
 
 
204
 
 
205
 
class FakeCurrentUserView(FakeGenericView):
206
 
 
207
 
    """Fake Current User view."""
208
 
 
209
 
    def __init__(self):
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
219
 
 
220
 
    def fake_backend(self):
221
 
        """Fake get_backend."""
222
 
        return self
223
 
 
224
 
    def login(self, appname, email, password):
225
 
        """Fake backend login."""
226
 
        self.properties['backend_login'] = (appname, email, password)
227
 
        return self
228
 
 
229
 
    # pylint: disable=C0103
230
 
    def addErrback(self, function):
231
 
        """Fake defer addErrback."""
232
 
        self.properties['login-addErrback'] = function
233
 
    # pylint: enable=C0103
234
 
 
235
 
 
236
 
class FakeLineEdit(object):
237
 
 
238
 
    """A fake QLineEdit."""
239
 
 
240
 
    def __init__(self, *args):
241
 
        """Initialize."""
242
 
        self._text = u""
243
 
 
244
 
    def text(self):
245
 
        """Save text."""
246
 
        return self._text
247
 
 
248
 
    # setText is inherited
249
 
    # pylint: disable=C0103
250
 
    def setText(self, text):
251
 
        """Return saved text."""
252
 
        self._text = text
253
 
 
254
 
 
255
 
class FakePage(object):
256
 
 
257
 
    """A fake wizard page."""
258
 
 
259
 
    app_name = "APP"
260
 
 
261
 
    def wizard(self):
262
 
        """Fake wizard."""
263
 
        return self
264
 
 
265
 
 
266
 
class FakeCurrentUserPage(FakePageUiStyle):
267
 
 
268
 
    """Fake CurrentuserPage."""
269
 
 
270
 
    def __init__(self, *args):
271
 
        """Initialize."""
272
 
        super(FakeCurrentUserPage, self).__init__(*args)
273
 
        self.ui.email_edit = FakeLineEdit()
274
 
        self.ui.password_edit = FakeLineEdit()
275
 
        self.sign_in_button = self
276
 
 
277
 
 
278
 
class FakeSetupAccountPageView(FakeGenericView):
279
 
 
280
 
    """Fake SetupAccount view."""
281
 
 
282
 
    def __init__(self):
283
 
        super(FakeSetupAccountPageView, self).__init__()
284
 
        self.ui = self
285
 
        # Labels
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()
296
 
        # Line Edits
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()
304
 
        # Check Box
305
 
        self.terms_checkbox = QCheckBox()
306
 
        # Setup Button
307
 
        self.set_up_button = FakeButton()
308
 
        # Backend
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
313
 
 
314
 
    def fake_backend(self):
315
 
        """Fake get_backend."""
316
 
        return self
317
 
 
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)
321
 
        if elements is None:
322
 
            elements = []
323
 
        elements.append((edit, function))
324
 
        self.properties['validation_rule'] = elements
325
 
 
326
 
    # pylint: disable=C0103
327
 
    def registerField(self, key, edit):
328
 
        """Fake registerField from page."""
329
 
        self.properties[key] = edit
330
 
    # pylint: enable=C0103
331
 
 
332
 
    def set_error_message(self, label, message):
333
 
        """Fake set_error_message."""
334
 
        label.setText(message)
335
 
 
336
 
 
337
 
class FakeMessageBox(object):
338
 
 
339
 
    """A fake message box."""
340
 
 
341
 
    args = None
342
 
    critical_args = None
343
 
 
344
 
    def __init__(self, *args, **kwargs):
345
 
        self.args = (args, kwargs)
346
 
 
347
 
    def critical(self, *args, **kwargs):
348
 
        """Fake critical popup."""
349
 
        self.critical_args = (args, kwargs)
350
 
 
351
 
 
352
 
class FakeSetupAccountUi(object):
353
 
    """Fake ui variable for FakeView."""
354
 
 
355
 
    email_assistance = None
356
 
 
357
 
 
358
 
class FakeView(object):
359
 
 
360
 
    """A fake view."""
361
 
 
362
 
    app_name = "TestApp"
363
 
    ui = FakeSetupAccountUi()
364
 
 
365
 
    def wizard(self):
366
 
        """Use itself as a fake wizard, too."""
367
 
        return self
368
 
 
369
 
    def set_error_message(self, label, msg):
370
 
        """Simulate to add the message to the label as SetupAccount do."""
371
 
 
372
 
 
373
 
class FakeSetupAccountView(FakeView):
374
 
 
375
 
    """A Fake view."""
376
 
 
377
 
    captcha_file = None
378
 
    captcha_image = None
379
 
    captcha_refresh_executed = False
380
 
    captcha_refreshing_value = False
381
 
 
382
 
    def on_captcha_refresh_complete(self):
383
 
        """Fake the call to refresh finished."""
384
 
        self.captcha_refresh_executed = True
385
 
 
386
 
    def on_captcha_refreshing(self):
387
 
        """Fake the call to refreshing."""
388
 
        self.captcha_refreshing_value = True
389
 
 
390
 
    def fake_open(self, filename):
391
 
        """Fake open for Image."""
392
 
        return self
393
 
 
394
 
    # pylint: disable=W0622
395
 
    def save(self, io, format):
396
 
        """Fake save for Image."""
397
 
    # pylint: enable=W0622
398
 
 
399
 
 
400
 
class FakeControllerForCaptcha(object):
401
 
 
402
 
    """Fake controller to test refresh_captcha method."""
403
 
 
404
 
    def __init__(self):
405
 
        """Initialize FakeControllerForCaptcha."""
406
 
        self.callback_error = False
407
 
 
408
 
    def generate_captcha(self, *args):
409
 
        """Fake generate deferred for captcha."""
410
 
        return self
411
 
 
412
 
    # pylint: disable=C0103
413
 
    def addErrback(self, call):
414
 
        """Fake addErrback."""
415
 
        self.callback_error = call is not None
416
 
    # pylint: enable=C0103
417
 
 
418
 
 
419
 
class FakeEmailVerificationView(FakePageUiStyle):
420
 
    """Fake EmailVerification Page."""
421
 
 
422
 
    def __init__(self, *args):
423
 
        """Initialize."""
424
 
        super(FakeEmailVerificationView, self).__init__(*args)
425
 
        self.verification_code = ''
426
 
        self.next_button = self
427
 
 
428
 
 
429
 
class EmailVerificationView(FakeGenericView):
430
 
 
431
 
    """Fake Email Verification view."""
432
 
 
433
 
    def __init__(self):
434
 
        super(EmailVerificationView, self).__init__()
435
 
        self.ui = self
436
 
        # Line Edits
437
 
        self.verification_code_edit = QLineEdit()
438
 
        self.verification_code = ''
439
 
        # Setup Button
440
 
        self.next_button = FakeButton()
441
 
        # Backend
442
 
        self.on_email_validated_cb = None
443
 
        self.on_email_validation_error_cb = None
444
 
 
445
 
    def fake_backend(self):
446
 
        """Fake get_backend."""
447
 
        return self
448
 
 
449
 
    def validate_email(self, *args, **kwargs):
450
 
        """Fake validate_email method from backend"""
451
 
        self.properties['validate_email'] = (args, kwargs)
452
 
 
453
 
 
454
 
class ErrorPageView(FakeGenericView):
455
 
 
456
 
    """Fake Error Page view."""
457
 
 
458
 
    def __init__(self):
459
 
        super(ErrorPageView, self).__init__()
460
 
        self.ui = self
461
 
        self.error_message_label = QLabel()
462
 
 
463
 
 
464
 
class SuccessPageView(FakeGenericView):
465
 
 
466
 
    """Fake Success Page view."""
467
 
 
468
 
    def __init__(self):
469
 
        super(SuccessPageView, self).__init__()
470
 
        self.ui = self
471
 
        self.success_message_body = QLabel()
472
 
 
473
 
 
474
 
class UbuntuSSOView(object):
475
 
 
476
 
    """Fake view for UbuntuSSO."""
477
 
 
478
 
    success_page_id = 5
479
 
    error_page_id = 6
480
 
 
481
 
    def __init__(self):
482
 
        self.properties = {}
483
 
        self.ui = self
484
 
        self.app_name = 'app_name'
485
 
        self.success_message_label = QLabel()
486
 
        self.result = 0
487
 
        # pylint: disable=C0103
488
 
        self.loginSuccess = FakeButton()
489
 
        self.registrationSuccess = FakeButton()
490
 
        # pylint: enable=C0103
491
 
        self.page = FakeGenericView()
492
 
 
493
 
    def button(self, *args):
494
 
        """Fake button."""
495
 
        self.properties['button_method'] = args
496
 
        self.properties['button'] = FakeButton()
497
 
        return self.properties['button']
498
 
 
499
 
    def callback(self, *args, **kwargs):
500
 
        """Fake callback."""
501
 
        self.properties['callback'] = (args, kwargs)
502
 
        return self.result
503
 
 
504
 
    def close(self):
505
 
        """Fake close."""
506
 
        self.properties['close'] = True
507
 
 
508
 
    # pylint: disable=C0103
509
 
    def setButtonLayout(self, layout):
510
 
        """Fake setButtonLayout."""
511
 
        self.properties['buttons_layout'] = layout
512
 
 
513
 
    def currentPage(self):
514
 
        """Fake currentPage."""
515
 
        return self.page
516
 
 
517
 
    def setWizardStyle(self, style):
518
 
        """Fake setWizardStyle."""
519
 
        self.properties['wizard_style'] = style
520
 
    # pylint: enable=C0103
521
 
 
522
 
    def next(self):
523
 
        """Fake next method to move to to next page in the wizard."""
524
 
        self.properties['wizard_next'] = True
525
 
 
526
 
 
527
 
class FakeLineEditForForgottenPage(object):
528
 
 
529
 
    """Fake Line Edit"""
530
 
 
531
 
    def __init__(self):
532
 
        """Initilize object."""
533
 
        self.email_text = QString()
534
 
 
535
 
    def text(self):
536
 
        """Fake text for QLineEdit."""
537
 
        return self.email_text
538
 
 
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
545
 
 
546
 
 
547
 
class FakeForgottenPasswordPage(FakePageUiStyle):
548
 
    """Fake the page."""
549
 
 
550
 
    def __init__(self):
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()
558
 
 
559
 
    def fake_backend(self):
560
 
        """Fake get_backend."""
561
 
        return self
562
 
 
563
 
 
564
 
class FakeForgottenPasswordPageView(FakeGenericView):
565
 
    """Fake the page."""
566
 
 
567
 
    def __init__(self):
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()
577
 
        # Backend
578
 
        self.on_password_reset_error_cb = None
579
 
        self.on_password_reset_token_sent_cb = None
580
 
 
581
 
    def fake_backend(self):
582
 
        """Fake get_backend."""
583
 
        return self
584
 
 
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
590
 
 
591
 
    def field(self, key):
592
 
        """Fake field from wizard"""
593
 
        return self.properties['field_%s' % key]
594
 
 
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)
598
 
        if elements is None:
599
 
            elements = []
600
 
        elements.append((edit, function))
601
 
        self.properties['validation_rule'] = elements
602
 
 
603
 
 
604
 
class ResetPasswordPageView(FakeGenericView):
605
 
    """Fake the page."""
606
 
 
607
 
    def __init__(self):
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()
613
 
        # Backend
614
 
        self.on_password_changed_cb = None
615
 
        self.on_password_change_error_cb = None
616
 
 
617
 
    def fake_backend(self):
618
 
        """Fake get_backend."""
619
 
        return self
620
 
 
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
626
 
 
627
 
    def field(self, key):
628
 
        """Fake field from wizard"""
629
 
        return self.properties['field_%s' % key]
630
 
 
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)
634
 
        if elements is None:
635
 
            elements = []
636
 
        elements.append((edit, function))
637
 
        self.properties['validation_rule'] = elements
638
 
 
639
 
    def set_new_password(self, *args, **kwargs):
640
 
        """Fake set_new_password from backend."""
641
 
        self.properties['backend_new_password'] = (args, kwargs)
642
 
 
643
 
 
644
 
class FakeResetPasswordPage(FakePageUiStyle):
645
 
 
646
 
    """Fake ResetPasswordPage."""
647
 
 
648
 
    def __init__(self, *args):
649
 
        """Initialize."""
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.
656
 
 
657
 
 
658
 
class FakeWizardForResetPassword(object):
659
 
 
660
 
    """Fake Wizard for ResetPasswordController."""
661
 
 
662
 
    def __init__(self):
663
 
        self.current_user = self
664
 
        self.ui = self
665
 
        self.email_edit = self
666
 
        self.email_line_edit = self
667
 
        self.forgotten = self
668
 
        self.overlay = self
669
 
        self.count_back = 0
670
 
        self.hide_value = False
671
 
        self.text_value = 'mail@mail.com'
672
 
        self.current_user_page_id = 4
673
 
 
674
 
    def wizard(self):
675
 
        """Fake wizard function for view."""
676
 
        return self
677
 
 
678
 
    def back(self):
679
 
        """Fake back for wizard."""
680
 
        self.count_back += 1
681
 
 
682
 
    def hide(self):
683
 
        """Fake hide for overlay."""
684
 
        self.hide_value = True
685
 
 
686
 
    def text(self):
687
 
        """Fake text for QLineEdit."""
688
 
        return self.text_value
689
 
 
690
 
    # pylint: disable=C0103
691
 
    def setText(self, text):
692
 
        """Fake setText for QLineEdit."""
693
 
        self.text_value = text
694
 
 
695
 
    def visitedPages(self):
696
 
        """Return an int list of fake visited pages."""
697
 
        return [1, 4, 6, 8]
698
 
    # pylint: enable=C0103
699
 
 
700
 
 
701
 
class BackendControllerTestCase(BaseTestCase):
702
 
    """The test case for the BackendController."""
703
 
 
704
 
    @defer.inlineCallbacks
705
 
    def setUp(self):
706
 
        yield super(BackendControllerTestCase, self).setUp()
707
 
        self.backend = BackendController()
708
 
 
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)
714
 
 
715
 
 
716
 
class ChooseSignInControllerTestCase(BaseTestCase):
717
 
    """Test the choose sign in controller."""
718
 
 
719
 
    @defer.inlineCallbacks
720
 
    def setUp(self):
721
 
        """Set tests."""
722
 
        yield super(ChooseSignInControllerTestCase, self).setUp()
723
 
        self.title = 'title'
724
 
        self.subtitle = 'subtitle'
725
 
        self.controller = ChooseSignInController(self.title, self.subtitle)
726
 
        self.view = FakeChooseSignInView()
727
 
        self.controller.view = self.view
728
 
 
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)
742
 
 
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)
750
 
 
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)
758
 
 
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)
764
 
 
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)
770
 
 
771
 
 
772
 
class CurrentUserControllerTestCase(BaseTestCase):
773
 
    """Test the current user controller."""
774
 
 
775
 
    @defer.inlineCallbacks
776
 
    def setUp(self):
777
 
        """Setup tests."""
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)
785
 
 
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)
794
 
 
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)
809
 
 
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')
814
 
 
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'))
821
 
 
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)
833
 
 
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'])
842
 
 
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)
866
 
 
867
 
 
868
 
class CurrentUserControllerErrorTestCase(BaseTestCase):
869
 
 
870
 
    """Tests for CurrentUserController's error handler."""
871
 
 
872
 
    on_error_method_name = "on_login_error"
873
 
    controller_class = CurrentUserController
874
 
 
875
 
    @defer.inlineCallbacks
876
 
    def setUp(self):
877
 
        """Setup test."""
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)
885
 
 
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), {}))
891
 
 
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), {}))
897
 
 
898
 
    def test_broken_error(self):
899
 
        """Test that on_login_error reacts to broken errors."""
900
 
        self.on_error_method({"boo!": "WORRY!"})
901
 
        result = '\n'.join(
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), {}))
906
 
 
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), {}))
913
 
 
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), {}))
920
 
 
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), {}))
927
 
 
928
 
 
929
 
class EmailVerificationControllerErrorTestCase(
930
 
    CurrentUserControllerErrorTestCase):
931
 
 
932
 
    """Tests for EmailVerificationController's error handler."""
933
 
 
934
 
    on_error_method_name = "on_email_validation_error"
935
 
    controller_class = EmailVerificationController
936
 
 
937
 
    @defer.inlineCallbacks
938
 
    def setUp(self):
939
 
        """Setup test."""
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)
944
 
 
945
 
 
946
 
class SetUpAccountControllerErrorTestCase(
947
 
    EmailVerificationControllerErrorTestCase):
948
 
 
949
 
    """Tests for SetUpAccountController's error handler."""
950
 
 
951
 
    on_error_method_name = "on_user_registration_error"
952
 
    controller_class = SetUpAccountController
953
 
 
954
 
    @defer.inlineCallbacks
955
 
    def setUp(self):
956
 
        """Setup test."""
957
 
        yield super(SetUpAccountControllerErrorTestCase, self).setUp()
958
 
        self.patch(self.controller, "_refresh_captcha", lambda *args: None)
959
 
 
960
 
 
961
 
class ResetPasswordControllerErrorTestCase(
962
 
    EmailVerificationControllerErrorTestCase):
963
 
 
964
 
    """Tests for ResetPasswordController's error handler."""
965
 
 
966
 
    on_error_method_name = "on_password_change_error"
967
 
    controller_class = ResetPasswordController
968
 
 
969
 
 
970
 
class CurrentUserControllerValidationTest(BaseTestCase):
971
 
 
972
 
    """Tests for CurrentUserController, but without Mocker."""
973
 
 
974
 
    @defer.inlineCallbacks
975
 
    def setUp(self):
976
 
        """Setup test."""
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()
982
 
 
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())
994
 
 
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))
1006
 
 
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())
1018
 
 
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())
1030
 
 
1031
 
 
1032
 
class SetUpAccountControllerTestCase(BaseTestCase):
1033
 
    """test the controller used to setup a new account."""
1034
 
 
1035
 
    @defer.inlineCallbacks
1036
 
    def setUp(self):
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
1045
 
 
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(),
1054
 
            PASSWORD2_ENTRY)
1055
 
        self.assertEqual(self.view.password_info_label.text(), PASSWORD_HELP)
1056
 
        self.assertEqual(self.view.captcha_solution_edit.placeholderText(),
1057
 
            CAPTCHA_SOLUTION_ENTRY)
1058
 
 
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)
1066
 
 
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)
1095
 
 
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)
1101
 
        for e in elements:
1102
 
            self.assertTrue(type(e[0]) is QLineEdit)
1103
 
            self.assertIsInstance(e[1], collections.Callable)
1104
 
 
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)
1114
 
 
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)
1124
 
 
1125
 
    def test_enable_setup_button_only_checkbox_ok(self):
1126
 
        """Test enable button only name valid."""
1127
 
        self.all_invalid()
1128
 
        self.view.terms_checkbox.setChecked(True)
1129
 
        self.controller._enable_setup_button()
1130
 
 
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'])
1135
 
 
1136
 
    def test_enable_setup_button_only_name_ok(self):
1137
 
        """Test enable button only name valid."""
1138
 
        self.all_invalid()
1139
 
        self.view.name_edit.setText('Name')
1140
 
        self.controller._enable_setup_button()
1141
 
 
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'])
1146
 
 
1147
 
    def test_enable_setup_button_only_email_ok(self):
1148
 
        """Test enable button only name valid."""
1149
 
        self.all_invalid()
1150
 
        self.view.email_edit.setText('email@email.com')
1151
 
        self.controller._enable_setup_button()
1152
 
 
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'])
1157
 
 
1158
 
    def test_enable_setup_button_only_confirm_email_ok(self):
1159
 
        """Test enable button only name valid."""
1160
 
        self.all_invalid()
1161
 
        self.view.confirm_email_edit.setText('email@email.com')
1162
 
        self.controller._enable_setup_button()
1163
 
 
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'])
1168
 
 
1169
 
    def test_enable_setup_button_only_email_and_confirm_ok(self):
1170
 
        """Test enable button only name valid."""
1171
 
        self.all_invalid()
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()
1175
 
 
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'])
1180
 
 
1181
 
    def test_enable_setup_button_only_password_ok(self):
1182
 
        """Test enable button only name valid."""
1183
 
        self.all_invalid()
1184
 
        self.view.password_edit.setText('T3st3rqw')
1185
 
        self.controller._enable_setup_button()
1186
 
 
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'])
1191
 
 
1192
 
    def test_enable_setup_button_only_password_confirm_ok(self):
1193
 
        """Test enable button only name valid."""
1194
 
        self.all_invalid()
1195
 
        self.view.confirm_password_edit.setText('T3st3rqw')
1196
 
        self.controller._enable_setup_button()
1197
 
 
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'])
1202
 
 
1203
 
    def test_enable_setup_button_only_password_and_confirm_ok(self):
1204
 
        """Test enable button only name valid."""
1205
 
        self.all_invalid()
1206
 
        self.view.password_edit.setText('T3st3rqw')
1207
 
        self.view.confirm_password_edit.setText('T3st3rqw')
1208
 
        self.controller._enable_setup_button()
1209
 
 
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'])
1214
 
 
1215
 
    def test_enable_setup_button_only_captcha_ok(self):
1216
 
        """Test enable button only name valid."""
1217
 
        self.all_invalid()
1218
 
        self.view.captcha_solution_edit.setText('captcha solution')
1219
 
        self.controller._enable_setup_button()
1220
 
 
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'])
1225
 
 
1226
 
    def test_enable_setup_button_only_all_ok(self):
1227
 
        """Test enable button only name valid."""
1228
 
        self.all_valid()
1229
 
        self.controller._enable_setup_button()
1230
 
 
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'])
1235
 
 
1236
 
    def test_enable_setup_button_all_wrong(self):
1237
 
        """Test enable button only name valid."""
1238
 
        self.all_invalid()
1239
 
        self.controller._enable_setup_button()
1240
 
 
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'])
1245
 
 
1246
 
    def test_enable_setup_button_name_wrong(self):
1247
 
        """Test enable button only name valid."""
1248
 
        self.all_valid()
1249
 
        self.view.name_edit.setText('')
1250
 
        self.controller._enable_setup_button()
1251
 
 
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'])
1256
 
 
1257
 
    def test_enable_setup_button_email_wrong(self):
1258
 
        """Test enable button only name valid."""
1259
 
        self.all_valid()
1260
 
        self.view.email_edit.setText('')
1261
 
        self.controller._enable_setup_button()
1262
 
 
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'])
1267
 
 
1268
 
    def test_enable_setup_button_confirm_email_wrong(self):
1269
 
        """Test enable button only name valid."""
1270
 
        self.all_valid()
1271
 
        self.view.confirm_email_edit.setText('')
1272
 
        self.controller._enable_setup_button()
1273
 
 
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'])
1278
 
 
1279
 
    def test_enable_setup_button_password_wrong(self):
1280
 
        """Test enable button only name valid."""
1281
 
        self.all_valid()
1282
 
        self.view.password_edit.setText('')
1283
 
        self.controller._enable_setup_button()
1284
 
 
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'])
1289
 
 
1290
 
    def test_enable_setup_button_confirm_password_wrong(self):
1291
 
        """Test enable button only name valid."""
1292
 
        self.all_valid()
1293
 
        self.view.confirm_password_edit.setText('')
1294
 
        self.controller._enable_setup_button()
1295
 
 
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'])
1300
 
 
1301
 
    def test_enable_setup_button_captcha_wrong(self):
1302
 
        """Test enable button only name valid."""
1303
 
        self.all_valid()
1304
 
        self.view.captcha_solution_edit.setText('')
1305
 
        self.controller._enable_setup_button()
1306
 
 
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'])
1311
 
 
1312
 
    def test_enable_setup_button_checkbox_wrong(self):
1313
 
        """Test enable button only name valid."""
1314
 
        self.all_valid()
1315
 
        self.view.terms_checkbox.setChecked(False)
1316
 
        self.controller._enable_setup_button()
1317
 
 
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'])
1322
 
 
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 \
1329
 
            QLineEdit)
1330
 
        self.assertTrue(type(self.view.properties['password']) is \
1331
 
            QLineEdit)
1332
 
 
1333
 
    def test_validate_form_all_ok(self):
1334
 
        """Test the result of validate_form."""
1335
 
        self.all_valid()
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(),
1340
 
            EMAIL_MISMATCH)
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), {}))
1345
 
 
1346
 
    def test_validate_form_all_wrong(self):
1347
 
        """Test the result of validate_form."""
1348
 
        self.all_invalid()
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(),
1353
 
            EMAIL_MISMATCH)
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), {}))
1358
 
 
1359
 
    def test_validate_form_name_ok(self):
1360
 
        """Test the result of validate_form."""
1361
 
        self.all_invalid()
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(),
1366
 
            EMAIL_MISMATCH)
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), {}))
1371
 
 
1372
 
    def test_validate_form_email_ok(self):
1373
 
        """Test the result of validate_form."""
1374
 
        self.all_invalid()
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(),
1379
 
            EMAIL_MISMATCH)
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), {}))
1384
 
 
1385
 
    def test_validate_form_confirm_email_ok(self):
1386
 
        """Test the result of validate_form."""
1387
 
        self.all_invalid()
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), {}))
1396
 
 
1397
 
    def test_validate_form_password_weak(self):
1398
 
        """Test the result of validate_form."""
1399
 
        self.all_valid()
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), {}))
1406
 
 
1407
 
    def test_validate_form_password_mismatch(self):
1408
 
        """Test the result of validate_form."""
1409
 
        self.all_valid()
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), {}))
1416
 
 
1417
 
    def test_validate_form_captcha_required(self):
1418
 
        """Test the result of validate_form."""
1419
 
        self.all_valid()
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), {}))
1425
 
 
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'))
1430
 
 
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')
1435
 
 
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')
1440
 
 
1441
 
 
1442
 
class SetupAccountControllerCaptchaTest(BaseTestCase):
1443
 
    """Tests for SetupAccountController, but without Mocker."""
1444
 
 
1445
 
    @defer.inlineCallbacks
1446
 
    def setUp(self):
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)
1454
 
 
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)
1461
 
 
1462
 
 
1463
 
class SetupAccountControllerValidationTest(BaseTestCase):
1464
 
    """Tests for SetupAccountController, but without Mocker."""
1465
 
 
1466
 
    @defer.inlineCallbacks
1467
 
    def setUp(self):
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())
1474
 
 
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, ((), {}))
1479
 
 
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), {}))
1486
 
 
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",
1494
 
            })
1495
 
        self.assertEqual(self.message_box.critical_args, ((
1496
 
            "Error in All", self.controller.view), {}))
1497
 
 
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)
1503
 
 
1504
 
        expected = (('', self.controller.view), {})
1505
 
        self.assertEqual(self.message_box.critical_args, expected)
1506
 
 
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)
1513
 
 
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)
1519
 
 
1520
 
 
1521
 
class EmailVerificationControllerTestCase(BaseTestCase):
1522
 
    """Test the controller."""
1523
 
 
1524
 
    @defer.inlineCallbacks
1525
 
    def setUp(self):
1526
 
        """Set tests."""
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)
1539
 
 
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)
1551
 
 
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,
1560
 
            })
1561
 
 
1562
 
    def test_validate_email(self):
1563
 
        """Test the callback."""
1564
 
        code = 'qwe123'
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,
1569
 
            code), {}))
1570
 
 
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'])
1579
 
 
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'])
1586
 
 
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'])
1595
 
 
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)
1600
 
        result = '\n'.join(
1601
 
                [('%s: %s' % (k, v)) for k, v in error.iteritems()])
1602
 
        self.assertEqual(self.controller.message_box.critical_args,
1603
 
            ((result, self.view), {}))
1604
 
 
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))
1610
 
 
1611
 
 
1612
 
class EmailVerificationControllerValidationTestCase(BaseTestCase):
1613
 
    """Tests for EmailVerificationController, but without Mocker."""
1614
 
 
1615
 
    @defer.inlineCallbacks
1616
 
    def setUp(self):
1617
 
        """Set the different tests."""
1618
 
        yield super(EmailVerificationControllerValidationTestCase,
1619
 
            self).setUp()
1620
 
        self.message_box = FakeMessageBox()
1621
 
        self.controller = EmailVerificationController(
1622
 
            message_box=self.message_box)
1623
 
        self.patch(self.controller, 'view', FakeEmailVerificationView())
1624
 
 
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), {}))
1633
 
 
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())
1644
 
 
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())
1655
 
 
1656
 
 
1657
 
class ErrorControllerTestCase(BaseTestCase):
1658
 
    """Test the success page controller."""
1659
 
 
1660
 
    @defer.inlineCallbacks
1661
 
    def setUp(self):
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
1668
 
 
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)
1678
 
 
1679
 
 
1680
 
class SuccessControllerTestCase(BaseTestCase):
1681
 
    """Test the success page controller."""
1682
 
 
1683
 
    @defer.inlineCallbacks
1684
 
    def setUp(self):
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
1691
 
 
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)
1700
 
 
1701
 
 
1702
 
class UbuntuSSOWizardControllerTestCase(BaseTestCase):
1703
 
    """Test the wizard controller."""
1704
 
 
1705
 
    @defer.inlineCallbacks
1706
 
    def setUp(self):
1707
 
        """Set tests."""
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
1715
 
 
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, ), {}))
1723
 
 
1724
 
    def test_on_login_success(self):
1725
 
        """Test that the callback is indeed called."""
1726
 
        app_name = 'app'
1727
 
        email = 'email'
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), {}))
1732
 
 
1733
 
    def test_on_registration_success(self):
1734
 
        """Test that the callback is indeed called."""
1735
 
        app_name = 'app'
1736
 
        email = 'email'
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), {}))
1741
 
 
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
1746
 
        layout = []
1747
 
        layout.append(QWizard.Stretch)
1748
 
        layout.append(QWizard.FinishButton)
1749
 
 
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)
1753
 
 
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
1758
 
        layout = []
1759
 
        layout.append(QWizard.Stretch)
1760
 
        layout.append(QWizard.FinishButton)
1761
 
 
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)
1765
 
 
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)
1777
 
 
1778
 
 
1779
 
class ForgottenPasswordControllerValidationTest(BaseTestCase):
1780
 
 
1781
 
    """Tests for ForgottenPasswordController, but without Mocker."""
1782
 
 
1783
 
    @defer.inlineCallbacks
1784
 
    def setUp(self):
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)
1793
 
 
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))
1804
 
 
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())
1810
 
        self.assertTrue(
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))
1817
 
 
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))
1830
 
 
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))
1843
 
 
1844
 
    def test_empty(self):
1845
 
        """The submit button should be disabled without email."""
1846
 
        self.assertEqual(
1847
 
            unicode(self.controller.view.email_address_line_edit.text()), u"")
1848
 
        self.assertFalse(self.controller.view.send_button.enabled())
1849
 
 
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), {}))
1858
 
 
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())
1866
 
        self.assertFalse(
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), {}))
1871
 
 
1872
 
 
1873
 
class ForgottenPasswordControllerTestCase(BaseTestCase):
1874
 
    """Test the controller of the fogotten password page."""
1875
 
 
1876
 
    @defer.inlineCallbacks
1877
 
    def setUp(self):
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
1886
 
 
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)
1892
 
 
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(),
1900
 
            EMAIL_LABEL)
1901
 
        self.assertEqual(self.view.send_button.text(),
1902
 
            RESET_PASSWORD)
1903
 
        self.assertEqual(self.view.try_again_button.text(),
1904
 
            TRY_AGAIN_BUTTON)
1905
 
 
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)
1911
 
        for e in elements:
1912
 
            self.assertTrue(e[0] is self.view.email_address_line_edit)
1913
 
            self.assertIsInstance(e[1], collections.Callable)
1914
 
 
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)
1928
 
 
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())
1934
 
 
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)
1941
 
 
1942
 
 
1943
 
class ResetPasswordControllerTestCase(BaseTestCase):
1944
 
    """Ensure that the reset password works as expected."""
1945
 
 
1946
 
    @defer.inlineCallbacks
1947
 
    def setUp(self):
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
1955
 
 
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(),
1960
 
            RESET_PASSWORD)
1961
 
        self.assertEqual(self.view.properties['subtitle'],
1962
 
            PASSWORD_HELP)
1963
 
 
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)
1979
 
 
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)
1987
 
        for e in elements:
1988
 
            self.assertTrue(type(e[0]) is QLineEdit)
1989
 
            self.assertIsInstance(e[1], collections.Callable)
1990
 
 
1991
 
    def test_set_new_password(self):
1992
 
        """Test that the correct action is performed."""
1993
 
        email = 'email@email.com'
1994
 
        code = 'qwe123'
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), {}))
2002
 
 
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(
2008
 
                                                                    password))
2009
 
 
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(
2015
 
                                                                    password))
2016
 
 
2017
 
 
2018
 
class ResetPasswordControllerValidationTest(BaseTestCase):
2019
 
 
2020
 
    """Tests for ResetPasswordController, but without Mocker."""
2021
 
 
2022
 
    @defer.inlineCallbacks
2023
 
    def setUp(self):
2024
 
        """Setup test."""
2025
 
        yield super(ResetPasswordControllerValidationTest, self).setUp()
2026
 
        self.controller = ResetPasswordController()
2027
 
        self.controller.view = FakeResetPasswordPage()
2028
 
 
2029
 
    def test_page_initialized(self):
2030
 
        """Test the initial state of the page when it is loaded."""
2031
 
        self.controller.pageInitialized()
2032
 
        self.assertFalse(
2033
 
            self.controller.view.reset_password_button.enabled())
2034
 
        self.assertTrue(
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))
2041
 
 
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))
2054
 
 
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))
2067
 
 
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())
2075
 
 
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())
2083
 
 
2084
 
 
2085
 
class ResetPasswordControllerRealControllerTest(BaseTestCase):
2086
 
 
2087
 
    """Tests for ResetPasswordController, but without Mocker."""
2088
 
 
2089
 
    @defer.inlineCallbacks
2090
 
    def setUp(self):
2091
 
        """Setup test."""
2092
 
        yield super(ResetPasswordControllerRealControllerTest, self).setUp()
2093
 
        self.controller = ResetPasswordController()
2094
 
        self.controller.view = FakeWizardForResetPassword()
2095
 
 
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)
2100
 
        times_visited = 2
2101
 
        self.assertEqual(self.controller.view.count_back, times_visited)
2102
 
        self.assertEqual(self.controller.view.text_value, 'mail@mail.com')
2103
 
 
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)
2111
 
        times_visited = 4
2112
 
        self.assertEqual(self.controller.view.count_back, times_visited)
2113
 
        self.assertEqual(self.controller.view.text_value, 'mail@mail.com')