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

« back to all changes in this revision

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

  • Committer: Natalia B. Bidart
  • Date: 2011-12-20 16:29:34 UTC
  • Revision ID: natalia.bidart@canonical.com-20111220162934-2s5xou06v3usxyr6
Tags: ubuntu-sso-client-2_99_0
- Release v2.99.0.

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