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)
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)
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)
122
self.controller._connect_buttons(self.view, self.backend)
111
125
class SetUpAccountControllerTestCase(MockerTestCase):
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(
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)
161
183
def test_is_correct_password_confirmation_false(self):
162
184
"""Test when the password is not correct."""
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'
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)
261
self.mocker.result(email)
263
self.mocker.result(password)
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,
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)
276
def test_set_next_validation_wrong_email(self):
277
"""Test the callback when there is a wrong email."""
278
email = 'email@example.com'
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)
287
self.assertFalse(self.controller.validate_form(self.view))
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'
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)
303
self.assertFalse(self.controller.validate_form(self.view))
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'
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)
323
self.assertFalse(self.controller.validate_form(self.view))
227
325
def test_update_password_strength(self):
228
326
"""Test the callback."""