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

« back to all changes in this revision

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

Fix pylint warnings

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
    CAPTCHA_SOLUTION_ENTRY,
29
29
    EMAIL1_ENTRY,
30
30
    EMAIL2_ENTRY,
 
31
    EMAIL_MISMATCH,
31
32
    EXISTING_ACCOUNT_CHOICE_BUTTON,
32
33
    FORGOTTEN_PASSWORD_BUTTON,
33
34
    JOIN_HEADER_LABEL,
35
36
    PASSWORD1_ENTRY,
36
37
    PASSWORD2_ENTRY,
37
38
    PASSWORD_HELP,
 
39
    PASSWORD_TOO_WEAK,
 
40
    PASSWORD_MISMATCH,
38
41
    SET_UP_ACCOUNT_CHOICE_BUTTON,
39
42
    SET_UP_ACCOUNT_BUTTON,
40
43
    SIGN_IN_BUTTON,
95
98
        """Setup tests."""
96
99
        super(CurrentUserControllerTestCase, self).setUp()
97
100
        self.view = self.mocker.mock()
98
 
        self.controller = CurrentUserController(title='the title')
 
101
        self.backend = self.mocker.mock()
 
102
        self.connect = self.mocker.mock()
 
103
        self.signal = self.mocker.replace('PyQt4.QtCore.SIGNAL')
 
104
        self.controller = CurrentUserController(title='the title',
 
105
                                                backend=self.backend)
99
106
 
100
 
    def test_setup_ui(self):
 
107
    def test_translated_strings(self):
101
108
        """test that the ui is correctly set up."""
102
 
        self.view.setTitle(self.controller._title)
103
109
        self.view.email_edit.setPlaceholderText(EMAIL1_ENTRY)
104
110
        self.view.password_edit.setPlaceholderText(PASSWORD1_ENTRY)
105
111
        self.view.forgot_password_label.setText(FORGOTTEN_PASSWORD_BUTTON)
106
112
        self.view.sign_in_button.setText(SIGN_IN_BUTTON)
107
113
        self.mocker.replay()
108
 
        self.controller.setupUi(self.view)
 
114
        self.controller._set_translated_strings(self.view)
 
115
 
 
116
    def test_connect_ui(self):
 
117
        """test that the ui is correctly set up."""
 
118
        self.view.sign_in_button.clicked.connect(MATCH(callable))
 
119
        self.backend.on_login_error_cb = MATCH(callable)
 
120
        self.backend.on_logged_in_cb = MATCH(callable)
 
121
        self.mocker.replay()
 
122
        self.controller._connect_buttons(self.view, self.backend)
109
123
 
110
124
 
111
125
class SetUpAccountControllerTestCase(MockerTestCase):
119
133
                                 'ubuntu_sso.utils.ui.get_password_strength')
120
134
        self.app_name = 'test'
121
135
        self.help = 'help'
 
136
        self.message_box = self.mocker.mock()
122
137
        self.controller = SetUpAccountController(app_name=self.app_name,
123
 
                                                 help_message=self.help)
 
138
                                                 help_message=self.help,
 
139
                                                 message_box=self.message_box)
124
140
 
125
141
    def test_set_translated_strings(self):
126
142
        """Ensure all the strings are set."""
148
164
 
149
165
    def test_connect_ui_elements(self):
150
166
        """Test that the ui elements are correctly connect."""
 
167
        backend = self.mocker.mock()
151
168
        self.view.terms_and_conditions_button.clicked.connect(MATCH(callable))
152
169
        self.view.set_up_button.clicked.connect(MATCH(callable))
153
170
        self.view.password_edit.textChanged.connect(MATCH(callable))
154
171
        self.view.set_up_button.setEnabled
155
 
        self.mocker.result(lambda:None)
 
172
        self.mocker.result(lambda: None)
156
173
        self.view.terms_and_conditions_check_box.stateChanged.connect(
157
174
                                                             MATCH(callable))
 
175
        self.view.captcha_refresh_label.linkActivated.connect(MATCH(callable))
 
176
        # set the callbacks for the captcha generatio
 
177
        backend.on_captcha_generated_cb = MATCH(callable)
 
178
        backend.on_captcha_generation_error_cb = MATCH(callable)
 
179
        backend.on_user_registration_error_cb = MATCH(callable)
158
180
        self.mocker.replay()
159
 
        self.controller._connect_ui_elements(self.view)
 
181
        self.controller._connect_ui_elements(self.view, backend)
160
182
 
161
183
    def test_is_correct_password_confirmation_false(self):
162
184
        """Test when the password is not correct."""
219
241
 
220
242
    def test_set_next_validation(self):
221
243
        """Test the callback."""
 
244
        email = 'email@example.com'
 
245
        password = 'Qwerty9923'
 
246
        captcha_id = 'captcha_id'
 
247
        captcha_solution = 'captcha_solution'
 
248
        self.view.email
 
249
        self.mocker.result(email)
 
250
        self.view.email_edit.text()
 
251
        self.mocker.result(email)
 
252
        self.view.confirm_email_edit.text()
 
253
        self.mocker.result(email)
 
254
        self.view.password_edit.text()
 
255
        self.mocker.result(password)
 
256
        self.view.password_edit.text()
 
257
        self.mocker.result(password)
 
258
        self.view.confirm_password_edit.text()
 
259
        self.mocker.result(password)
 
260
        self.view.email
 
261
        self.mocker.result(email)
 
262
        self.view.password
 
263
        self.mocker.result(password)
 
264
        self.view.captcha_id
 
265
        self.mocker.result(captcha_id)
 
266
        self.view.captcha_solution
 
267
        self.mocker.result(captcha_solution)
 
268
        backend = self.mocker.mock()
 
269
        backend.register_user(self.app_name, email, password, captcha_id,
 
270
                              captcha_solution)
222
271
        self.view.next = self.controller._validation_id
223
272
        self.view.wizard().next()
224
273
        self.mocker.replay()
225
 
        self.controller.set_next_validation(self.view)
 
274
        self.controller.set_next_validation(self.view, backend)
 
275
 
 
276
    def test_set_next_validation_wrong_email(self):
 
277
        """Test the callback when there is a wrong email."""
 
278
        email = 'email@example.com'
 
279
        self.view.email
 
280
        self.mocker.result(email)
 
281
        self.view.email_edit.text()
 
282
        self.mocker.result('email')
 
283
        self.view.confirm_email_edit.text()
 
284
        self.mocker.result('email2')
 
285
        self.message_box.critical(self.view, self.app_name, EMAIL_MISMATCH)
 
286
        self.mocker.replay()
 
287
        self.assertFalse(self.controller.validate_form(self.view))
 
288
 
 
289
    def test_set_next_validation_not_min_password(self):
 
290
        """Test the callback with a weak password."""
 
291
        weak_password = 'weak'
 
292
        email = 'email@example.com'
 
293
        self.view.email
 
294
        self.mocker.result(email)
 
295
        self.view.email_edit.text()
 
296
        self.mocker.result(email)
 
297
        self.view.confirm_email_edit.text()
 
298
        self.mocker.result(email)
 
299
        self.view.password_edit.text()
 
300
        self.mocker.result(weak_password)
 
301
        self.message_box.critical(self.view, self.app_name, PASSWORD_TOO_WEAK)
 
302
        self.mocker.replay()
 
303
        self.assertFalse(self.controller.validate_form(self.view))
 
304
 
 
305
    def test_set_next_validation_wrong_password(self):
 
306
        """Test the callback where the password is wrong."""
 
307
        password = 'Qwerty9923'
 
308
        email = 'email@example.com'
 
309
        self.view.email
 
310
        self.mocker.result(email)
 
311
        self.view.email_edit.text()
 
312
        self.mocker.result(email)
 
313
        self.view.confirm_email_edit.text()
 
314
        self.mocker.result(email)
 
315
        self.view.password_edit.text()
 
316
        self.mocker.result(password)
 
317
        self.view.password_edit.text()
 
318
        self.mocker.result(password)
 
319
        self.view.confirm_password_edit.text()
 
320
        self.mocker.result('other_password')
 
321
        self.message_box.critical(self.view, self.app_name, PASSWORD_MISMATCH)
 
322
        self.mocker.replay()
 
323
        self.assertFalse(self.controller.validate_form(self.view))
226
324
 
227
325
    def test_update_password_strength(self):
228
326
        """Test the callback."""