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

« back to all changes in this revision

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

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

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

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
    EMAIL1_ENTRY,
37
37
    EMAIL2_ENTRY,
38
38
    EMAIL_MISMATCH,
 
39
    EMAIL_LABEL,
39
40
    ERROR,
40
 
    EMAIL_LABEL,
41
41
    EXISTING_ACCOUNT_CHOICE_BUTTON,
42
42
    FORGOTTEN_PASSWORD_BUTTON,
43
43
    JOIN_HEADER_LABEL,
53
53
    SET_UP_ACCOUNT_CHOICE_BUTTON,
54
54
    SET_UP_ACCOUNT_BUTTON,
55
55
    SIGN_IN_BUTTON,
 
56
    SURNAME_ENTRY,
56
57
    SUCCESS,
57
58
    REQUEST_PASSWORD_TOKEN_WRONG_EMAIL,
58
59
    REQUEST_PASSWORD_TOKEN_TECH_ERROR,
75
76
        """Set tests."""
76
77
        super(ChooseSignInControllerTestCase, self).setUp()
77
78
        self.view = self.mocker.mock()
78
 
        self.backend = self.mocker.mock()
79
79
        self.controller = ChooseSignInController()
80
 
        self.controller.view = self.view
81
 
        self.controller.backend = self.backend
82
80
 
83
81
    def test_set_up_translated_strings(self):
84
82
        """Ensure that the translations are used."""
85
 
        self.view.ui.existing_account_button.setText(
 
83
        self.view.existing_account_button.setText(
86
84
                                            EXISTING_ACCOUNT_CHOICE_BUTTON)
87
 
        self.view.ui.setup_account_button.setText(SET_UP_ACCOUNT_CHOICE_BUTTON)
 
85
        self.view.new_account_button.setText(SET_UP_ACCOUNT_CHOICE_BUTTON)
88
86
        self.mocker.replay()
89
 
        self.controller._set_up_translated_strings()
 
87
        self.controller._set_up_translated_strings(self.view)
90
88
 
91
89
    def test_connect_buttons(self):
92
90
        """Ensure that all the buttons are correcly connected."""
93
 
        self.view.ui.existing_account_button.clicked.connect(
94
 
                                            self.controller._set_next_existing)
95
 
        self.view.ui.setup_account_button.clicked.connect(
96
 
                                                 self.controller._set_next_new)
 
91
        self.view.existing_account_button.clicked.connect(MATCH(callable))
 
92
        self.view.new_account_button.clicked.connect(MATCH(callable))
97
93
        self.mocker.replay()
98
 
        self.controller._connect_buttons()
 
94
        self.controller._connect_buttons(self.view)
99
95
 
100
96
    def test_set_next_existing(self):
101
97
        """Test the execution of the callback."""
105
101
        self.view.next = next_id
106
102
        self.view.wizard().next()
107
103
        self.mocker.replay()
108
 
        self.controller._set_next_existing()
 
104
        self.controller._set_next_existing(self.view)
109
105
 
110
106
    def test_set_next_new(self):
111
107
        """Test the execution of the callback."""
115
111
        self.view.next = next_id
116
112
        self.view.wizard().next()
117
113
        self.mocker.replay()
118
 
        self.controller._set_next_new()
 
114
        self.controller._set_next_new(self.view)
119
115
 
120
116
 
121
117
class CurrentUserControllerTestCase(MockerTestCase):
128
124
        self.backend = self.mocker.mock()
129
125
        self.connect = self.mocker.mock()
130
126
        self.signal = self.mocker.replace('PyQt4.QtCore.SIGNAL')
131
 
        self.controller = CurrentUserController(title='the title')
132
 
        self.controller.view = self.view
133
 
        self.controller.backend = self.backend
 
127
        self.controller = CurrentUserController(title='the title',
 
128
                                                backend=self.backend)
134
129
 
135
130
    def test_translated_strings(self):
136
131
        """test that the ui is correctly set up."""
137
 
        self.view.ui.email_edit.setPlaceholderText(EMAIL1_ENTRY)
138
 
        self.view.ui.password_edit.setPlaceholderText(PASSWORD1_ENTRY)
139
 
        self.view.ui.forgot_password_label.setText(
 
132
        self.view.email_edit.setPlaceholderText(EMAIL1_ENTRY)
 
133
        self.view.password_edit.setPlaceholderText(PASSWORD1_ENTRY)
 
134
        self.view.forgot_password_label.setText(
140
135
                                        FAKE_URL % FORGOTTEN_PASSWORD_BUTTON)
141
 
        self.view.ui.sign_in_button.setText(SIGN_IN_BUTTON)
 
136
        self.view.sign_in_button.setText(SIGN_IN_BUTTON)
142
137
        self.mocker.replay()
143
 
        self.controller._set_translated_strings()
 
138
        self.controller._set_translated_strings(self.view)
144
139
 
145
140
    def test_connect_ui(self):
146
141
        """test that the ui is correctly set up."""
147
 
        self.view.ui.sign_in_button.clicked.connect(self.controller.login)
 
142
        self.view.sign_in_button.clicked.connect(MATCH(callable))
148
143
        self.backend.on_login_error_cb = MATCH(callable)
149
144
        self.backend.on_logged_in_cb = MATCH(callable)
150
 
        self.view.ui.forgot_password_label.linkActivated.connect(
151
 
                                                        MATCH(callable))
 
145
        self.view.forgot_password_label.linkActivated.connect(MATCH(callable))
152
146
        self.mocker.replay()
153
 
        self.controller._connect_ui()
 
147
        self.controller._connect_ui(self.view, self.backend)
154
148
 
155
149
 
156
150
class SetUpAccountControllerTestCase(MockerTestCase):
160
154
        """Set the different tests."""
161
155
        super(SetUpAccountControllerTestCase, self).setUp()
162
156
        self.view = self.mocker.mock()
163
 
        self.backend = self.mocker.mock()
164
157
        self.get_password_strength = self.mocker.replace(
165
158
                                 'ubuntu_sso.utils.ui.get_password_strength')
166
159
        self.app_name = 'test'
167
160
        self.help = 'help'
168
161
        self.message_box = self.mocker.mock()
169
162
        self.controller = SetUpAccountController(message_box=self.message_box)
170
 
        self.controller.backend = self.backend
171
 
        self.controller.view = self.view
172
163
 
173
164
    def test_set_translated_strings(self):
174
165
        """Ensure all the strings are set."""
175
166
        self.view.wizard().app_name
176
167
        self.mocker.result(self.app_name)
177
 
        self.view.ui.name_label.setText(NAME_ENTRY)
178
 
        self.view.ui.email_label.setText(EMAIL1_ENTRY)
179
 
        self.view.ui.confirm_email_label.setText(EMAIL2_ENTRY)
180
 
        self.view.ui.password_label.setText(PASSWORD1_ENTRY)
181
 
        self.view.ui.confirm_password_label.setText(PASSWORD2_ENTRY)
182
 
        self.view.ui.password_info_label.setText(PASSWORD_HELP)
183
 
        self.view.ui.captcha_solution_edit.setPlaceholderText(
 
168
        self.view.name_edit.setPlaceholderText(NAME_ENTRY)
 
169
        self.view.last_name_edit.setPlaceholderText(SURNAME_ENTRY)
 
170
        self.view.email_edit.setPlaceholderText(EMAIL1_ENTRY)
 
171
        self.view.confirm_email_edit.setPlaceholderText(EMAIL2_ENTRY)
 
172
        self.view.password_edit.setPlaceholderText(PASSWORD1_ENTRY)
 
173
        self.view.confirm_password_edit.setPlaceholderText(PASSWORD2_ENTRY)
 
174
        self.view.password_info_label.setText(PASSWORD_HELP)
 
175
        self.view.captcha_solution_edit.setPlaceholderText(
184
176
                                                    CAPTCHA_SOLUTION_ENTRY)
185
 
        self.view.ui.terms_checkbox.setText(
 
177
        self.view.terms_and_conditions_check_box.setText(
186
178
                                       YES_TO_TC % {'app_name': self.app_name})
187
 
        self.view.ui.terms_button.setText(TC_BUTTON)
188
 
        self.view.ui.set_up_button.setText(SET_UP_ACCOUNT_BUTTON)
 
179
        self.view.terms_and_conditions_button.setText(TC_BUTTON)
 
180
        self.view.set_up_button.setText(SET_UP_ACCOUNT_BUTTON)
189
181
        self.mocker.replay()
190
 
        self.controller._set_translated_strings()
 
182
        self.controller._set_translated_strings(self.view)
191
183
 
192
184
    def test_set_titles(self):
193
185
        """Test how the different titles are set."""
200
192
        self.view.setTitle(JOIN_HEADER_LABEL % {'app_name': self.app_name})
201
193
        self.view.setSubTitle(self.help)
202
194
        self.mocker.replay()
203
 
        self.controller._set_titles()
 
195
        self.controller._set_titles(self.view)
204
196
 
205
197
    def test_connect_ui_elements(self):
206
198
        """Test that the ui elements are correctly connect."""
207
 
        self.view.ui.terms_button.clicked.connect(self.controller.set_next_tos)
208
 
        self.view.ui.set_up_button.clicked.connect(
209
 
                                           self.controller.set_next_validation)
210
 
        self.view.ui.set_up_button.setEnabled
 
199
        backend = self.mocker.mock()
 
200
        self.view.terms_and_conditions_button.clicked.connect(MATCH(callable))
 
201
        self.view.set_up_button.clicked.connect(MATCH(callable))
 
202
        self.view.password_edit.textChanged.connect(MATCH(callable))
 
203
        self.view.set_up_button.setEnabled
211
204
        self.mocker.result(lambda: None)
212
 
        self.view.ui.terms_checkbox.stateChanged.connect(MATCH(callable))
213
 
        self.view.ui.refresh_label.linkActivated.connect(MATCH(callable))
 
205
        self.view.terms_and_conditions_check_box.stateChanged.connect(
 
206
                                                             MATCH(callable))
 
207
        self.view.captcha_refresh_label.linkActivated.connect(MATCH(callable))
214
208
        # set the callbacks for the captcha generatio
215
 
        self.backend.on_captcha_generated_cb = MATCH(callable)
216
 
        self.backend.on_captcha_generation_error_cb = MATCH(callable)
217
 
        self.backend.on_user_registration_error_cb = MATCH(callable)
218
 
        self.backend.on_user_registered_cb = MATCH(callable)
 
209
        backend.on_captcha_generated_cb = MATCH(callable)
 
210
        backend.on_captcha_generation_error_cb = MATCH(callable)
 
211
        backend.on_user_registration_error_cb = MATCH(callable)
 
212
        backend.on_user_registered_cb = MATCH(callable)
219
213
        self.mocker.replay()
220
 
        self.controller._connect_ui_elements()
 
214
        self.controller._connect_ui_elements(self.view, backend)
221
215
 
222
216
    def test_is_correct_password_confirmation_false(self):
223
217
        """Test when the password is not correct."""
224
218
        password = 'test'
225
 
        self.view.ui.password_edit.text()
 
219
        self.view.password_edit.text()
226
220
        self.mocker.result('other')
227
221
        self.mocker.replay()
228
222
        self.assertFalse(
229
 
                    self.controller.is_correct_password_confirmation(password))
 
223
                    self.controller.is_correct_password_confirmation(password,
 
224
                                                                   self.view))
230
225
 
231
226
    def test_is_correct_password_confirmation_true(self):
232
227
        """Test when the password is correct."""
233
228
        password = 'test'
234
 
        self.view.ui.password_edit.text()
 
229
        self.view.password_edit.text()
235
230
        self.mocker.result(password)
236
231
        self.mocker.replay()
237
232
        self.assertTrue(
238
 
                    self.controller.is_correct_password_confirmation(password))
 
233
                    self.controller.is_correct_password_confirmation(password,
 
234
                                                                   self.view))
239
235
 
240
236
    def test_is_correct_email_confirmation_false(self):
241
237
        """Test when the emails are not the same."""
242
238
        email_address = 'address'
243
 
        self.view.ui.email_edit.text()
 
239
        self.view.email_edit.text()
244
240
        self.mocker.result('other')
245
241
        self.mocker.replay()
246
242
        self.assertFalse(
247
 
                self.controller.is_correct_email_confirmation(email_address))
 
243
                self.controller.is_correct_email_confirmation(email_address,
 
244
                                                              self.view))
248
245
 
249
246
    def test_is_correct_email_confirmation_true(self):
250
247
        """Test when the emails are the same."""
251
248
        email_address = 'address'
252
 
        self.view.ui.email_edit.text()
 
249
        self.view.email_edit.text()
253
250
        self.mocker.result(email_address)
254
251
        self.mocker.replay()
255
252
        self.assertTrue(
256
 
                self.controller.is_correct_email_confirmation(email_address))
 
253
                self.controller.is_correct_email_confirmation(email_address,
 
254
                                                              self.view))
257
255
 
258
256
    def test_set_next_tos(self):
259
257
        """Test the callback."""
263
261
        self.view.next = next_id
264
262
        self.view.wizard().next()
265
263
        self.mocker.replay()
266
 
        self.controller.set_next_tos()
 
264
        self.controller.set_next_tos(self.view)
267
265
 
268
266
    def test_set_next_validation(self):
269
267
        """Test the callback."""
270
 
        name = 'name'
 
268
        next_id = 4
271
269
        email = 'email@example.com'
272
270
        password = 'Qwerty9923'
273
271
        captcha_id = 'captcha_id'
274
272
        captcha_solution = 'captcha_solution'
275
273
        self.view.wizard().app_name
276
274
        self.mocker.result(self.app_name)
277
 
        self.view.ui.name_edit.text()
278
 
        self.mocker.result(name)
279
 
        self.view.ui.email_edit.text()
280
 
        self.mocker.result(email)
281
 
        self.view.ui.email_edit.text()
282
 
        self.mocker.result(email)
283
 
        self.view.ui.confirm_email_edit.text()
284
 
        self.mocker.result(email)
285
 
        self.view.ui.password_edit.text()
286
 
        self.mocker.result(password)
287
 
        self.view.ui.password_edit.text()
288
 
        self.mocker.result(password)
289
 
        self.view.ui.confirm_password_edit.text()
 
275
        self.view.email
 
276
        self.mocker.result(email)
 
277
        self.view.email_edit.text()
 
278
        self.mocker.result(email)
 
279
        self.view.confirm_email_edit.text()
 
280
        self.mocker.result(email)
 
281
        self.view.password_edit.text()
 
282
        self.mocker.result(password)
 
283
        self.view.password_edit.text()
 
284
        self.mocker.result(password)
 
285
        self.view.confirm_password_edit.text()
 
286
        self.mocker.result(password)
 
287
        self.view.email
 
288
        self.mocker.result(email)
 
289
        self.view.password
290
290
        self.mocker.result(password)
291
291
        self.view.captcha_id
292
292
        self.mocker.result(captcha_id)
293
 
        self.view.ui.captcha_solution_edit.text()
 
293
        self.view.captcha_solution
294
294
        self.mocker.result(captcha_solution)
295
 
        self.backend.register_user(self.app_name, email, password, name,
296
 
                                   captcha_id, captcha_solution)
 
295
        backend = self.mocker.mock()
 
296
        backend.register_user(self.app_name, email, password, captcha_id,
 
297
                              captcha_solution)
 
298
        self.view.wizard().email_verification_page_id
 
299
        self.mocker.result(next_id)
 
300
        self.view.next = next_id
 
301
        self.view.wizard().next()
297
302
        self.mocker.replay()
298
 
        self.controller.set_next_validation()
 
303
        self.controller.set_next_validation(self.view, backend)
299
304
 
300
305
    def test_set_next_validation_wrong_email(self):
301
306
        """Test the callback when there is a wrong email."""
302
307
        email = 'email@example.com'
303
 
        password = 'Qwerty9923'
304
308
        self.view.wizard().app_name
305
309
        self.mocker.result(self.app_name)
306
 
        self.view.ui.email_edit.text()
 
310
        self.view.email
307
311
        self.mocker.result(email)
308
 
        self.view.ui.confirm_email_edit.text()
 
312
        self.view.email_edit.text()
 
313
        self.mocker.result('email')
 
314
        self.view.confirm_email_edit.text()
309
315
        self.mocker.result('email2')
310
 
        self.view.ui.password_edit.text()
311
 
        self.mocker.result(password)
312
 
        self.view.ui.confirm_password_edit.text()
313
 
        self.mocker.result(password)
314
316
        self.message_box.critical(self.view, self.app_name, EMAIL_MISMATCH)
315
317
        self.mocker.replay()
316
 
        self.assertFalse(self.controller.validate_form())
 
318
        self.assertFalse(self.controller.validate_form(self.view))
317
319
 
318
320
    def test_set_next_validation_not_min_password(self):
319
321
        """Test the callback with a weak password."""
321
323
        email = 'email@example.com'
322
324
        self.view.wizard().app_name
323
325
        self.mocker.result(self.app_name)
324
 
        self.view.ui.email_edit.text()
325
 
        self.mocker.result(email)
326
 
        self.view.ui.confirm_email_edit.text()
327
 
        self.mocker.result(email)
328
 
        self.view.ui.password_edit.text()
329
 
        self.mocker.result(weak_password)
330
 
        self.view.ui.confirm_password_edit.text()
 
326
        self.view.email
 
327
        self.mocker.result(email)
 
328
        self.view.email_edit.text()
 
329
        self.mocker.result(email)
 
330
        self.view.confirm_email_edit.text()
 
331
        self.mocker.result(email)
 
332
        self.view.password_edit.text()
331
333
        self.mocker.result(weak_password)
332
334
        self.message_box.critical(self.view, self.app_name, PASSWORD_TOO_WEAK)
333
335
        self.mocker.replay()
334
 
        self.assertFalse(self.controller.validate_form())
 
336
        self.assertFalse(self.controller.validate_form(self.view))
335
337
 
336
338
    def test_set_next_validation_wrong_password(self):
337
339
        """Test the callback where the password is wrong."""
339
341
        email = 'email@example.com'
340
342
        self.view.wizard().app_name
341
343
        self.mocker.result(self.app_name)
342
 
        self.view.ui.email_edit.text()
343
 
        self.mocker.result(email)
344
 
        self.view.ui.confirm_email_edit.text()
345
 
        self.mocker.result(email)
346
 
        self.view.ui.password_edit.text()
347
 
        self.mocker.result(password)
348
 
        self.view.ui.confirm_password_edit.text()
 
344
        self.view.email
 
345
        self.mocker.result(email)
 
346
        self.view.email_edit.text()
 
347
        self.mocker.result(email)
 
348
        self.view.confirm_email_edit.text()
 
349
        self.mocker.result(email)
 
350
        self.view.password_edit.text()
 
351
        self.mocker.result(password)
 
352
        self.view.password_edit.text()
 
353
        self.mocker.result(password)
 
354
        self.view.confirm_password_edit.text()
349
355
        self.mocker.result('other_password')
350
356
        self.message_box.critical(self.view, self.app_name, PASSWORD_MISMATCH)
351
357
        self.mocker.replay()
352
 
        self.assertFalse(self.controller.validate_form())
 
358
        self.assertFalse(self.controller.validate_form(self.view))
 
359
 
 
360
    def test_update_password_strength(self):
 
361
        """Test the callback."""
 
362
        password = 'test'
 
363
        strength = 4
 
364
        self.get_password_strength(password)
 
365
        self.mocker.result(strength)
 
366
        self.view.set_strength_level(strength, password)
 
367
        self.mocker.replay()
 
368
        self.controller.update_password_strength(password, self.view)
353
369
 
354
370
    def test_set_line_edits_validations(self):
355
371
        """Set the validations to be performed on the edits."""
356
 
        self.view.ui.email_edit
 
372
        self.view.email_edit
357
373
        self.mocker.result(self.view)
358
374
        self.view.set_line_edit_validation_rule(self.view, is_correct_email)
359
 
        self.view.ui.confirm_email_edit
 
375
        self.view.confirm_email_edit
360
376
        self.mocker.result(self.view)
361
377
        self.view.set_line_edit_validation_rule(self.view, MATCH(callable))
362
 
        self.view.ui.confirm_email_edit.textChanged.emit
 
378
        self.view.confirm_email_edit.textChanged.emit
363
379
        self.mocker.result(lambda: None)
364
 
        self.view.ui.email_edit.textChanged.connect(MATCH(callable))
365
 
        self.view.ui.password_edit
 
380
        self.view.email_edit.textChanged.connect(MATCH(callable))
 
381
        self.view.password_edit
366
382
        self.mocker.result(self.view)
367
383
        self.view.set_line_edit_validation_rule(self.view,
368
384
                                                is_min_required_password)
369
 
        self.view.ui.confirm_password_edit
 
385
        self.view.confirm_password_edit
370
386
        self.mocker.result(self.view)
371
387
        self.view.set_line_edit_validation_rule(self.view, MATCH(callable))
372
 
        self.view.ui.confirm_password_edit.textChanged.emit
 
388
        self.view.confirm_password_edit.textChanged.emit
373
389
        self.mocker.result(lambda: None)
374
 
        self.view.ui.password_edit.textChanged.connect(MATCH(callable))
 
390
        self.view.password_edit.textChanged.connect(MATCH(callable))
375
391
        self.mocker.replay()
376
 
        self.controller._set_line_edits_validations()
 
392
        self.controller._set_line_edits_validations(self.view)
377
393
 
378
394
 
379
395
class TosControllerTestCase(MockerTestCase):
383
399
        """Set the tests."""
384
400
        super(TosControllerTestCase, self).setUp()
385
401
        self.view = self.mocker.mock()
386
 
        self.backend = self.mocker.mock()
387
402
        self.title = 'title'
388
403
        self.subtitle = 'sub'
389
404
        self.url = 'url'
390
405
        self.controller = TosController(title=self.title,
391
406
                                        subtitle=self.subtitle,
392
407
                                        tos_url=self.url)
393
 
        self.controller.view = self.view
394
408
 
395
409
    def test_setup_ui(self):
396
410
        """Test the set up of the ui."""
397
411
        self.view.setTitle(self.title)
398
412
        self.view.setSubTitle(self.subtitle)
399
 
        self.view.ui.terms_webkit.load(ANY)
 
413
        self.view.webkit.load(ANY)
400
414
        self.mocker.replay()
401
415
        self.controller.setupUi(self.view)
402
416
 
408
422
        """Set tests."""
409
423
        super(EmailVerificationControllerTestCase, self).setUp()
410
424
        self.view = self.mocker.mock()
411
 
        self.backend = self.mocker.mock()
412
425
        self.controller = EmailVerificationController()
413
 
        self.controller.view = self.view
414
 
        self.controller.backend = self.backend
415
426
 
416
427
    def test_set_translated_strings(self):
417
428
        """Test that strings are translated."""
418
 
        self.view.ui.verification_code_edit.setPlaceholderText(
419
 
                                                        VERIFY_EMAIL_TITLE)
 
429
        self.view.verification_code_edit.setPlaceholderText(VERIFY_EMAIL_TITLE)
420
430
        self.mocker.replay()
421
 
        self.controller._set_translated_strings()
 
431
        self.controller._set_translated_strings(self.view)
422
432
 
423
433
    def test_connect_ui_elements(self):
424
434
        """Set the ui connections."""
425
 
        self.view.next_button.clicked.connect(self.controller.validate_email)
426
 
        self.backend.on_email_validated_cb = MATCH(callable)
427
 
        self.backend.on_email_validation_error_cb = \
428
 
                                    self.controller.on_email_validation_error
 
435
        self.view.next_button.clicked.connect(MATCH(callable))
429
436
        self.mocker.replay()
430
 
        self.controller._connect_ui_elements()
 
437
        self.controller._connect_ui_elements(self.view)
431
438
 
432
439
    def test_set_titles(self):
433
440
        """Test that the titles are set."""
434
441
        self.view.setTitle(VERIFY_EMAIL_TITLE)
435
442
        self.view.setSubTitle(VERIFY_EMAIL_CONTENT)
436
443
        self.mocker.replay()
437
 
        self.controller._set_titles()
 
444
        self.controller._set_titles(self.view)
438
445
 
439
 
    def test_validate_email(self):
 
446
    def test_next_page(self):
440
447
        """Test the callback."""
441
 
        email_address = 'email@test.com'
442
 
        password = 'password'
443
 
        app_name = 'app_name'
444
 
        code = 'code'
445
 
        self.view.wizard().field('email_address').toString()
446
 
        self.mocker.result(email_address)
447
 
        self.view.wizard().field('password').toString()
448
 
        self.mocker.result(password)
449
 
        self.view.wizard().app_name
450
 
        self.mocker.result(app_name)
451
 
        self.view.ui.verification_code_edit.text()
452
 
        self.mocker.result(code)
453
 
        self.backend.validate_email(app_name, email_address, password, code)
 
448
        self.view.wizard().next()
454
449
        self.mocker.replay()
455
 
        self.controller.validate_email()
 
450
        self.controller.next_page(self.view)
456
451
 
457
452
 
458
453
class ErrorControllerTestCase(MockerTestCase):
461
456
    def setUp(self):
462
457
        """Set the tests."""
463
458
        super(ErrorControllerTestCase, self).setUp()
464
 
        self.view = self.mocker.mock()
465
 
        self.backend = self.mocker.mock()
466
459
        self.controller = ErrorController()
467
 
        self.controller.view = self.view
468
 
        self.controller.backend = self.backend
 
460
        self.view = self.mocker.mock()
469
461
 
470
462
    def test_set_ui(self):
471
463
        """Test the process that sets the ui."""
472
464
        self.view.next = -1
473
 
        self.view.ui.error_message_label
 
465
        self.view.error_message_label
474
466
        self.mocker.result(self.view)
475
467
        self.view.setText(ERROR)
476
468
        self.mocker.replay()
483
475
    def setUp(self):
484
476
        """Set the tests."""
485
477
        super(SuccessControllerTestCase, self).setUp()
486
 
        self.view = self.mocker.mock()
487
 
        self.backend = self.mocker.mock()
488
478
        self.controller = SuccessController()
489
 
        self.controller.view = self.view
490
 
        self.controller.backend = self.backend
 
479
        self.view = self.mocker.mock()
491
480
 
492
481
    def test_set_ui(self):
493
482
        """Test the process that sets the ui."""
494
483
        self.view.next = -1
495
 
        self.view.ui.success_message_label
 
484
        self.view.success_message_label
496
485
        self.mocker.result(self.view)
497
486
        self.view.setText(SUCCESS)
498
487
        self.mocker.replay()
506
495
        """Set tests."""
507
496
        super(UbuntuSSOWizardControllerTestCase, self).setUp()
508
497
        self.app_name = 'test'
509
 
        self.view = self.mocker.mock()
510
 
        self.backend = self.mocker.mock()
 
498
        self.controller = UbuntuSSOWizardController()
511
499
        self.callback = self.mocker.mock()
512
 
        self.controller = UbuntuSSOWizardController()
513
 
        self.controller.view = self.view
514
 
        self.controller.backend = self.backend
 
500
        self.view = self.mocker.mock()
515
501
 
516
502
    def test_on_user_cancelation(self):
517
503
        """Test that the callback is indeed called."""
521
507
        self.callback(self.app_name)
522
508
        self.view.close()
523
509
        self.mocker.replay()
524
 
        self.controller.on_user_cancelation()
 
510
        self.controller.on_user_cancelation(self.view)
525
511
 
526
512
    def test_on_login_success(self):
527
513
        """Test that the callback is indeed called."""
556
542
        self.view.next()
557
543
        self.view.setButtonLayout(buttons_layout)
558
544
        self.mocker.replay()
559
 
        self.controller.show_success_message()
 
545
        self.controller.show_success_message(self.view)
560
546
 
561
547
    def test_show_error_message(self):
562
548
        """Test that the correct page will be shown."""
573
559
        self.view.next()
574
560
        self.view.setButtonLayout(buttons_layout)
575
561
        self.mocker.replay()
576
 
        self.controller.show_error_message()
 
562
        self.controller.show_error_message(self.view)
577
563
 
578
564
    def test_setup_ui(self):
579
565
        """Test that the ui is connect."""
580
566
        self.view.setWizardStyle(QWizard.ModernStyle)
581
567
        self.view.button(QWizard.CancelButton)
582
568
        self.mocker.result(self.view)
583
 
        self.view.clicked.connect(self.controller.on_user_cancelation)
584
 
        self.view.loginSuccess.connect(self.controller.on_login_success)
585
 
        self.view.registrationSuccess.connect(
586
 
                                    self.controller.on_registration_success)
 
569
        self.view.clicked.connect(MATCH(callable))
 
570
        self.view.loginSuccess.connect(MATCH(callable))
 
571
        self.view.registrationSuccess.connect(MATCH(callable))
587
572
        self.mocker.replay()
588
573
        self.controller.setupUi(self.view)
589
574
 
595
580
        """Setup the tests."""
596
581
        super(ForgottenPasswordControllerTestCase, self).setUp()
597
582
        self.view = self.mocker.mock()
598
 
        self.backend = self.mocker.mock()
599
583
        self.controller = ForgottenPasswordController()
600
 
        self.controller.view = self.view
601
 
        self.controller.backend = self.backend
602
584
        self.app_name = 'app_name'
603
585
 
604
586
    def test_register_fields(self):
608
590
        self.mocker.result(line_edit)
609
591
        self.view.registerField('email_address', line_edit)
610
592
        self.mocker.replay()
611
 
        self.controller._register_fields()
 
593
        self.controller._register_fields(self.view)
612
594
 
613
595
    def test_set_translated_strings(self):
614
596
        """Ensure that the correct strings are translated."""
621
603
        self.view.send_button.setText(RESET_PASSWORD)
622
604
        self.view.try_again_button.setText(TRY_AGAIN_BUTTON)
623
605
        self.mocker.replay()
624
 
        self.controller._set_translated_strings()
 
606
        self.controller._set_translated_strings(self.view)
625
607
 
626
608
    def test_set_enhanced_line_edit(self):
627
609
        """Test that the correct line enhancements have been added."""
630
612
        self.mocker.result(line_edit)
631
613
        self.view.set_line_edit_validation_rule(line_edit, is_correct_email)
632
614
        self.mocker.replay()
633
 
        self.controller._set_enhanced_line_edit()
 
615
        self.controller._set_enhanced_line_edit(self.view)
634
616
 
635
617
    def test_connect_ui(self):
636
618
        """Test that the correct ui signals are connected."""
 
619
        backend = self.mocker.mock()
637
620
        self.view.send_button.clicked.connect(MATCH(callable))
638
 
        self.view.try_again_button.clicked.connect(
639
 
                                                  self.controller.on_try_again)
640
 
        self.backend.on_password_reset_token_sent_cb = MATCH(callable)
641
 
        self.backend.on_password_reset_error_cb = \
642
 
                                        self.controller.on_password_reset_error
 
621
        self.view.try_again_button.clicked.connect(MATCH(callable))
 
622
        backend.on_password_reset_token_sent_cb = MATCH(callable)
 
623
        backend.on_password_reset_error_cb = MATCH(callable)
643
624
        self.mocker.replay()
644
 
        self.controller._connect_ui()
 
625
        self.controller._connect_ui(self.view, backend)
645
626
 
646
627
    def test_on_try_again(self):
647
628
        """Test that the on_try_again callback does work as expected."""
649
630
        self.view.try_again_widget.setVisible(False)
650
631
        self.view.email_widget.setVisible(True)
651
632
        self.mocker.replay()
652
 
        self.controller.on_try_again()
 
633
        self.controller.on_try_again(self.view)
653
634
 
654
635
    def test_on_password_reset_token_sent(self):
655
636
        """Test that the on_password_token_sent callback works as expected."""
659
640
        self.view.next = page_id
660
641
        self.view.wizard().next()
661
642
        self.mocker.replay()
662
 
        self.controller.on_password_reset_token_sent()
 
643
        self.controller.on_password_reset_token_sent(self.view)
663
644
 
664
645
    def test_on_password_reset_error_token_error(self):
665
646
        """Test that the on_password_reset_error callback works as expected."""
667
648
        self.view.error_label.setText(REQUEST_PASSWORD_TOKEN_WRONG_EMAIL)
668
649
        self.view.error_label.setVisible(True)
669
650
        self.mocker.replay()
670
 
        self.controller.on_password_reset_error(self.app_name, error)
 
651
        self.controller.on_password_reset_error(self.app_name, error,
 
652
                                                self.view)
671
653
 
672
654
    def test_on_password_reset_error_general_error(self):
673
655
        """Test that the on_password_reset_error callback works as expected."""
677
659
        self.view.try_again_wisget.setVisible(True)
678
660
        self.view.error_label.setText(REQUEST_PASSWORD_TOKEN_TECH_ERROR)
679
661
        self.mocker.replay()
680
 
        self.controller.on_password_reset_error(self.app_name, error)
 
662
        self.controller.on_password_reset_error(self.app_name, error,
 
663
                                                self.view)
681
664
 
682
665
 
683
666
class ResetPasswordControllerTestCase(MockerTestCase):
687
670
        """Setup the tests."""
688
671
        super(ResetPasswordControllerTestCase, self).setUp()
689
672
        self.view = self.mocker.mock()
690
 
        self.backend = self.mocker.mock()
691
673
        self.controller = ResetPasswordController()
692
 
        self.controller.view = self.view
693
 
        self.controller.backend = self.backend
694
674
 
695
675
    def test_set_translated_strings(self):
696
676
        """Ensure that the correct strings are set."""
697
 
        self.view.ui.reset_code_line_edit.setPlaceholderText(RESET_CODE_ENTRY)
698
 
        self.view.ui.password_line_edit.setPlaceholderText(PASSWORD1_ENTRY)
699
 
        self.view.ui.confirm_password_line_edit.setPlaceholderText(
 
677
        self.view.reset_code_line_edit.setPlaceholderText(RESET_CODE_ENTRY)
 
678
        self.view.password_line_edit.setPlaceholderText(PASSWORD1_ENTRY)
 
679
        self.view.confirm_password_line_edit.setPlaceholderText(
700
680
                                                            PASSWORD2_ENTRY)
701
 
        self.view.ui.reset_password_button.setText(RESET_PASSWORD)
 
681
        self.view.reset_password_button.setText(RESET_PASSWORD)
702
682
        self.view.setSubTitle(PASSWORD_HELP)
703
683
        self.mocker.replay()
704
 
        self.controller._set_translated_strings()
 
684
        self.controller._set_translated_strings(self.view)
705
685
 
706
686
    def test_connect_ui(self):
707
687
        """Ensure that the diffent signals from the ui are connected."""
708
 
        self.view.ui.reset_password_button.clicked.connect(
709
 
                                            self.controller.set_new_password)
710
 
        self.backend.on_password_changed_cb = \
711
 
                                        self.controller.on_password_changed
712
 
        self.backend.on_password_change_error_cb = \
713
 
                                    self.controller.on_password_change_error
 
688
        backend = self.mocker.mock()
 
689
        self.view.reset_password_button.clicked.connect(MATCH(callable))
 
690
        backend.on_password_changed_cb = MATCH(callable)
 
691
        backend.on_password_change_error_cb = MATCH(callable)
714
692
        self.mocker.replay()
715
 
        self.controller._connect_ui()
 
693
        self.controller._connect_ui(self.view, backend)
716
694
 
717
695
    def test_add_line_edits_validations(self):
718
696
        """Ensure that the line validation have been added."""
719
697
        line_edit = 'line_edit'
720
698
        emit = 'emit'
721
 
        self.view.ui.password_line_edit
 
699
        self.view.password_line_edit
722
700
        self.mocker.result('line_edit')
723
701
        self.view.set_line_edit_validation_rule(line_edit,
724
702
                                                is_min_required_password)
725
 
        self.view.ui.confirm_password_line_edit
 
703
        self.view.confirm_password_line_edit
726
704
        self.mocker.result('line_edit')
727
705
        self.view.set_line_edit_validation_rule(line_edit, MATCH(callable))
728
 
        self.view.ui.confirm_password_line_edit.textChanged.emit
 
706
        self.view.confirm_password_line_edit.textChanged.emit
729
707
        self.mocker.result(emit)
730
 
        self.view.ui.password_line_edit.textChanged.connect(emit)
 
708
        self.view.password_line_edit.textChanged.connect(emit)
731
709
        self.mocker.replay()
732
 
        self.controller._add_line_edits_validations()
 
710
        self.controller._add_line_edits_validations(self.view)
733
711
 
734
712
    def test_set_new_password(self):
735
713
        """Test that the correct action is performed."""
737
715
        email = 'email'
738
716
        code = 'code'
739
717
        password = 'password'
 
718
        backend = self.mocker.mock()
740
719
        self.view.wizard().app_name
741
720
        self.mocker.result(app_name)
742
721
        self.view.wizard().field('email_address').toString()
743
722
        self.mocker.result(email)
744
 
        self.view.ui.reset_code_line_edit.text()
 
723
        self.view.reset_code
745
724
        self.mocker.result(code)
746
 
        self.view.ui.password_line_edit.text()
 
725
        self.view.password
747
726
        self.mocker.result(password)
748
 
        self.backend.set_new_password(app_name, email, code, password)
 
727
        backend.set_new_password(app_name, email, code, password)
749
728
        self.mocker.replay()
750
 
        self.controller.set_new_password()
 
729
        self.controller.set_new_password(self.view, backend)
751
730
 
752
731
    def test_is_correct_password_confirmation_true(self):
753
732
        """Test that the correct password confirmation is used."""
754
733
        password = 'password'
755
 
        self.view.ui.password_line_edit.text()
 
734
        self.view.password_line_edit.text()
756
735
        self.mocker.result(password)
757
736
        self.mocker.replay()
758
737
        self.assertTrue(self.controller.is_correct_password_confirmation(
759
 
                                                                    password))
 
738
                                                                    password,
 
739
                                                                    self.view))
760
740
 
761
741
    def test_is_correct_password_confirmation_false(self):
762
742
        """Test that the correct password confirmation is used."""
763
743
        password = 'password'
764
 
        self.view.ui.password_line_edit.text()
 
744
        self.view.password_line_edit.text()
765
745
        self.mocker.result(password + password)
766
746
        self.mocker.replay()
767
747
        self.assertFalse(self.controller.is_correct_password_confirmation(
768
 
                                                                    password))
 
748
                                                                    password,
 
749
                                                                    self.view))