Merge lp:~nataliabidart/ubuntu-sso-client/restore-register-api into lp:ubuntu-sso-client/stable-1-0
- restore-register-api
- Merge into stable-1-0
Proposed by
Natalia Bidart
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Natalia Bidart | ||||
Approved revision: | 646 | ||||
Merged at revision: | 645 | ||||
Proposed branch: | lp:~nataliabidart/ubuntu-sso-client/restore-register-api | ||||
Merge into: | lp:ubuntu-sso-client/stable-1-0 | ||||
Diff against target: |
354 lines (+124/-45) 5 files modified
run-tests (+1/-1) ubuntu_sso/gui.py (+4/-4) ubuntu_sso/main.py (+30/-8) ubuntu_sso/tests/test_gui.py (+12/-12) ubuntu_sso/tests/test_main.py (+77/-20) |
||||
To merge this branch: | bzr merge lp:~nataliabidart/ubuntu-sso-client/restore-register-api | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Roberto Alsina (community) | Approve | ||
Joshua Hoover (community) | tested | Approve | |
Review via email: mp+55396@code.launchpad.net |
Commit message
- Restoring former API for register_user. Added a new method call register_with_name to ensure no API is broke (LP: #709494).
Description of the change
To properly test please use the SRU instructions in the attached bug report. Thanks!
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'run-tests' | |||
2 | --- run-tests 2010-09-03 19:32:51 +0000 | |||
3 | +++ run-tests 2011-03-29 17:46:34 +0000 | |||
4 | @@ -16,7 +16,7 @@ | |||
5 | 16 | # with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | # with this program. If not, see <http://www.gnu.org/licenses/>. |
6 | 17 | 17 | ||
7 | 18 | `which xvfb-run` ./contrib/test "$@" | 18 | `which xvfb-run` ./contrib/test "$@" |
9 | 19 | pylint contrib ubuntu_sso | 19 | pylint ubuntu_sso |
10 | 20 | if [ -x `which pep8` ]; then | 20 | if [ -x `which pep8` ]; then |
11 | 21 | pep8 --repeat bin/ contrib/ ubuntu_sso/ | 21 | pep8 --repeat bin/ contrib/ ubuntu_sso/ |
12 | 22 | else | 22 | else |
13 | 23 | 23 | ||
14 | === modified file 'ubuntu_sso/gui.py' | |||
15 | --- ubuntu_sso/gui.py 2011-03-24 13:01:02 +0000 | |||
16 | +++ ubuntu_sso/gui.py 2011-03-29 17:46:34 +0000 | |||
17 | @@ -808,10 +808,10 @@ | |||
18 | 808 | self.user_email = email1 | 808 | self.user_email = email1 |
19 | 809 | self.user_password = password1 | 809 | self.user_password = password1 |
20 | 810 | 810 | ||
25 | 811 | logger.info('Calling register_user with email %r, password <hidden>,' \ | 811 | logger.info('Calling register_with_name with email %r, password, ' |
26 | 812 | ' name %r, captcha_id %r and captcha_solution %r.', email1, | 812 | '<hidden> name %r, captcha_id %r and captcha_solution %r.', |
27 | 813 | name, self._captcha_id, captcha_solution) | 813 | email1, name, self._captcha_id, captcha_solution) |
28 | 814 | f = self.backend.register_user | 814 | f = self.backend.register_with_name |
29 | 815 | f(self.app_name, email1, password1, name, | 815 | f(self.app_name, email1, password1, name, |
30 | 816 | self._captcha_id, captcha_solution, | 816 | self._captcha_id, captcha_solution, |
31 | 817 | reply_handler=NO_OP, error_handler=NO_OP) | 817 | reply_handler=NO_OP, error_handler=NO_OP) |
32 | 818 | 818 | ||
33 | === modified file 'ubuntu_sso/main.py' | |||
34 | --- ubuntu_sso/main.py 2011-03-24 13:01:02 +0000 | |||
35 | +++ ubuntu_sso/main.py 2011-03-29 17:46:34 +0000 | |||
36 | @@ -171,19 +171,19 @@ | |||
37 | 171 | 171 | ||
38 | 172 | return captcha['captcha_id'] | 172 | return captcha['captcha_id'] |
39 | 173 | 173 | ||
41 | 174 | def register_user(self, email, password, displayname, | 174 | def register_with_name(self, email, password, displayname, |
42 | 175 | captcha_id, captcha_solution): | 175 | captcha_id, captcha_solution): |
43 | 176 | """Register a new user with 'email' and 'password'.""" | 176 | """Register a new user with 'email' and 'password'.""" |
45 | 177 | logger.debug('register_user: email: %r password: <hidden>, ' | 177 | logger.debug('register_with_name: email: %r password: <hidden>, ' |
46 | 178 | 'displayname: %r, captcha_id: %r, captcha_solution: %r', | 178 | 'displayname: %r, captcha_id: %r, captcha_solution: %r', |
47 | 179 | email, displayname, captcha_id, captcha_solution) | 179 | email, displayname, captcha_id, captcha_solution) |
48 | 180 | sso_service = self.sso_service_class(None, self.service_url) | 180 | sso_service = self.sso_service_class(None, self.service_url) |
49 | 181 | if not self._valid_email(email): | 181 | if not self._valid_email(email): |
51 | 182 | logger.error('register_user: InvalidEmailError for email: %r', | 182 | logger.error('register_with_name: InvalidEmailError for email: %r', |
52 | 183 | email) | 183 | email) |
53 | 184 | raise InvalidEmailError() | 184 | raise InvalidEmailError() |
54 | 185 | if not self._valid_password(password): | 185 | if not self._valid_password(password): |
56 | 186 | logger.error('register_user: InvalidPasswordError') | 186 | logger.error('register_with_name: InvalidPasswordError') |
57 | 187 | raise InvalidPasswordError() | 187 | raise InvalidPasswordError() |
58 | 188 | 188 | ||
59 | 189 | result = sso_service.registrations.register( | 189 | result = sso_service.registrations.register( |
60 | @@ -191,7 +191,7 @@ | |||
61 | 191 | displayname=displayname, | 191 | displayname=displayname, |
62 | 192 | captcha_id=captcha_id, | 192 | captcha_id=captcha_id, |
63 | 193 | captcha_solution=captcha_solution) | 193 | captcha_solution=captcha_solution) |
65 | 194 | logger.info('register_user: email: %r result: %r', email, result) | 194 | logger.info('register_with_name: email: %r result: %r', email, result) |
66 | 195 | 195 | ||
67 | 196 | if result['status'] == 'error': | 196 | if result['status'] == 'error': |
68 | 197 | errorsdict = self._format_webservice_errors(result['errors']) | 197 | errorsdict = self._format_webservice_errors(result['errors']) |
69 | @@ -201,6 +201,17 @@ | |||
70 | 201 | else: | 201 | else: |
71 | 202 | return email | 202 | return email |
72 | 203 | 203 | ||
73 | 204 | def register_user(self, email, password, | ||
74 | 205 | captcha_id, captcha_solution): | ||
75 | 206 | """Register a new user with 'email' and 'password'.""" | ||
76 | 207 | logger.debug('register_user: email: %r password: <hidden>, ' | ||
77 | 208 | 'captcha_id: %r, captcha_solution: %r', | ||
78 | 209 | email, captcha_id, captcha_solution) | ||
79 | 210 | res = self.register_with_name(email, password, displayname='', | ||
80 | 211 | captcha_id=captcha_id, | ||
81 | 212 | captcha_solution=captcha_solution) | ||
82 | 213 | return res | ||
83 | 214 | |||
84 | 204 | def login(self, email, password, token_name): | 215 | def login(self, email, password, token_name): |
85 | 205 | """Login a user with 'email' and 'password'.""" | 216 | """Login a user with 'email' and 'password'.""" |
86 | 206 | logger.debug('login: email: %r password: <hidden>, token_name: %r', | 217 | logger.debug('login: email: %r password: <hidden>, token_name: %r', |
87 | @@ -380,13 +391,24 @@ | |||
88 | 380 | 'app_name "%s" and error %r', app_name, error) | 391 | 'app_name "%s" and error %r', app_name, error) |
89 | 381 | 392 | ||
90 | 382 | @dbus.service.method(dbus_interface=DBUS_IFACE_USER_NAME, | 393 | @dbus.service.method(dbus_interface=DBUS_IFACE_USER_NAME, |
91 | 394 | in_signature='sssss') | ||
92 | 395 | def register_user(self, app_name, email, password, | ||
93 | 396 | captcha_id, captcha_solution): | ||
94 | 397 | """Call the matching method in the processor.""" | ||
95 | 398 | def f(): | ||
96 | 399 | """Inner function that will be run in a thread.""" | ||
97 | 400 | return self.processor.register_user(email, password, | ||
98 | 401 | captcha_id, captcha_solution) | ||
99 | 402 | blocking(f, app_name, self.UserRegistered, self.UserRegistrationError) | ||
100 | 403 | |||
101 | 404 | @dbus.service.method(dbus_interface=DBUS_IFACE_USER_NAME, | ||
102 | 383 | in_signature='ssssss') | 405 | in_signature='ssssss') |
105 | 384 | def register_user(self, app_name, email, password, name, | 406 | def register_with_name(self, app_name, email, password, name, |
106 | 385 | captcha_id, captcha_solution): | 407 | captcha_id, captcha_solution): |
107 | 386 | """Call the matching method in the processor.""" | 408 | """Call the matching method in the processor.""" |
108 | 387 | def f(): | 409 | def f(): |
109 | 388 | """Inner function that will be run in a thread.""" | 410 | """Inner function that will be run in a thread.""" |
111 | 389 | return self.processor.register_user(email, password, name, | 411 | return self.processor.register_with_name(email, password, name, |
112 | 390 | captcha_id, captcha_solution) | 412 | captcha_id, captcha_solution) |
113 | 391 | blocking(f, app_name, self.UserRegistered, self.UserRegistrationError) | 413 | blocking(f, app_name, self.UserRegistered, self.UserRegistrationError) |
114 | 392 | 414 | ||
115 | 393 | 415 | ||
116 | === modified file 'ubuntu_sso/tests/test_gui.py' | |||
117 | --- ubuntu_sso/tests/test_gui.py 2011-03-24 13:01:02 +0000 | |||
118 | +++ ubuntu_sso/tests/test_gui.py 2011-03-29 17:46:34 +0000 | |||
119 | @@ -63,7 +63,7 @@ | |||
120 | 63 | self._args = args | 63 | self._args = args |
121 | 64 | self._kwargs = kwargs | 64 | self._kwargs = kwargs |
122 | 65 | self._called = {} | 65 | self._called = {} |
124 | 66 | for i in ('generate_captcha', 'login', 'register_user', | 66 | for i in ('generate_captcha', 'login', 'register_with_name', |
125 | 67 | 'validate_email', 'request_password_reset_token', | 67 | 'validate_email', 'request_password_reset_token', |
126 | 68 | 'set_new_password'): | 68 | 'set_new_password'): |
127 | 69 | setattr(self, i, self._record_call(i)) | 69 | setattr(self, i, self._record_call(i)) |
128 | @@ -674,8 +674,8 @@ | |||
129 | 674 | """Clicking 'join_ok_button' sends info to backend using 'register'.""" | 674 | """Clicking 'join_ok_button' sends info to backend using 'register'.""" |
130 | 675 | self.click_join_with_valid_data() | 675 | self.click_join_with_valid_data() |
131 | 676 | 676 | ||
134 | 677 | # assert register_user was called | 677 | # assert register_with_name was called |
135 | 678 | expected = 'register_user' | 678 | expected = 'register_with_name' |
136 | 679 | self.assertIn(expected, self.ui.backend._called) | 679 | self.assertIn(expected, self.ui.backend._called) |
137 | 680 | self.assertEqual(self.ui.backend._called[expected], | 680 | self.assertEqual(self.ui.backend._called[expected], |
138 | 681 | ((APP_NAME, EMAIL, PASSWORD, NAME, CAPTCHA_ID, | 681 | ((APP_NAME, EMAIL, PASSWORD, NAME, CAPTCHA_ID, |
139 | @@ -1161,7 +1161,7 @@ | |||
140 | 1161 | 1161 | ||
141 | 1162 | self.assert_correct_entry_warning(self.ui.name_entry, | 1162 | self.assert_correct_entry_warning(self.ui.name_entry, |
142 | 1163 | self.ui.FIELD_REQUIRED) | 1163 | self.ui.FIELD_REQUIRED) |
144 | 1164 | self.assertNotIn('register_user', self.ui.backend._called) | 1164 | self.assertNotIn('register_with_name', self.ui.backend._called) |
145 | 1165 | 1165 | ||
146 | 1166 | def test_warning_is_shown_if_empty_email(self): | 1166 | def test_warning_is_shown_if_empty_email(self): |
147 | 1167 | """A warning message is shown if emails are empty.""" | 1167 | """A warning message is shown if emails are empty.""" |
148 | @@ -1174,7 +1174,7 @@ | |||
149 | 1174 | self.ui.FIELD_REQUIRED) | 1174 | self.ui.FIELD_REQUIRED) |
150 | 1175 | self.assert_correct_entry_warning(self.ui.email2_entry, | 1175 | self.assert_correct_entry_warning(self.ui.email2_entry, |
151 | 1176 | self.ui.FIELD_REQUIRED) | 1176 | self.ui.FIELD_REQUIRED) |
153 | 1177 | self.assertNotIn('register_user', self.ui.backend._called) | 1177 | self.assertNotIn('register_with_name', self.ui.backend._called) |
154 | 1178 | 1178 | ||
155 | 1179 | def test_warning_is_shown_if_email_mismatch(self): | 1179 | def test_warning_is_shown_if_email_mismatch(self): |
156 | 1180 | """A warning message is shown if emails doesn't match.""" | 1180 | """A warning message is shown if emails doesn't match.""" |
157 | @@ -1187,7 +1187,7 @@ | |||
158 | 1187 | self.ui.EMAIL_MISMATCH) | 1187 | self.ui.EMAIL_MISMATCH) |
159 | 1188 | self.assert_correct_entry_warning(self.ui.email2_entry, | 1188 | self.assert_correct_entry_warning(self.ui.email2_entry, |
160 | 1189 | self.ui.EMAIL_MISMATCH) | 1189 | self.ui.EMAIL_MISMATCH) |
162 | 1190 | self.assertNotIn('register_user', self.ui.backend._called) | 1190 | self.assertNotIn('register_with_name', self.ui.backend._called) |
163 | 1191 | 1191 | ||
164 | 1192 | def test_warning_is_shown_if_invalid_email(self): | 1192 | def test_warning_is_shown_if_invalid_email(self): |
165 | 1193 | """A warning message is shown if email is invalid.""" | 1193 | """A warning message is shown if email is invalid.""" |
166 | @@ -1200,7 +1200,7 @@ | |||
167 | 1200 | self.ui.EMAIL_INVALID) | 1200 | self.ui.EMAIL_INVALID) |
168 | 1201 | self.assert_correct_entry_warning(self.ui.email2_entry, | 1201 | self.assert_correct_entry_warning(self.ui.email2_entry, |
169 | 1202 | self.ui.EMAIL_INVALID) | 1202 | self.ui.EMAIL_INVALID) |
171 | 1203 | self.assertNotIn('register_user', self.ui.backend._called) | 1203 | self.assertNotIn('register_with_name', self.ui.backend._called) |
172 | 1204 | 1204 | ||
173 | 1205 | def test_password_help_is_always_shown(self): | 1205 | def test_password_help_is_always_shown(self): |
174 | 1206 | """Password help text is correctly displayed.""" | 1206 | """Password help text is correctly displayed.""" |
175 | @@ -1208,7 +1208,7 @@ | |||
176 | 1208 | 'password help text is visible.') | 1208 | 'password help text is visible.') |
177 | 1209 | self.assertEqual(self.ui.password_help_label.get_text(), | 1209 | self.assertEqual(self.ui.password_help_label.get_text(), |
178 | 1210 | self.ui.PASSWORD_HELP) | 1210 | self.ui.PASSWORD_HELP) |
180 | 1211 | self.assertNotIn('register_user', self.ui.backend._called) | 1211 | self.assertNotIn('register_with_name', self.ui.backend._called) |
181 | 1212 | 1212 | ||
182 | 1213 | def test_warning_is_shown_if_password_mismatch(self): | 1213 | def test_warning_is_shown_if_password_mismatch(self): |
183 | 1214 | """A warning message is shown if password doesn't match.""" | 1214 | """A warning message is shown if password doesn't match.""" |
184 | @@ -1221,7 +1221,7 @@ | |||
185 | 1221 | self.ui.PASSWORD_MISMATCH) | 1221 | self.ui.PASSWORD_MISMATCH) |
186 | 1222 | self.assert_correct_entry_warning(self.ui.password2_entry, | 1222 | self.assert_correct_entry_warning(self.ui.password2_entry, |
187 | 1223 | self.ui.PASSWORD_MISMATCH) | 1223 | self.ui.PASSWORD_MISMATCH) |
189 | 1224 | self.assertNotIn('register_user', self.ui.backend._called) | 1224 | self.assertNotIn('register_with_name', self.ui.backend._called) |
190 | 1225 | 1225 | ||
191 | 1226 | def test_warning_is_shown_if_password_too_weak(self): | 1226 | def test_warning_is_shown_if_password_too_weak(self): |
192 | 1227 | """A warning message is shown if password is too weak.""" | 1227 | """A warning message is shown if password is too weak.""" |
193 | @@ -1236,7 +1236,7 @@ | |||
194 | 1236 | self.ui.PASSWORD_TOO_WEAK) | 1236 | self.ui.PASSWORD_TOO_WEAK) |
195 | 1237 | self.assert_correct_entry_warning(self.ui.password2_entry, | 1237 | self.assert_correct_entry_warning(self.ui.password2_entry, |
196 | 1238 | self.ui.PASSWORD_TOO_WEAK) | 1238 | self.ui.PASSWORD_TOO_WEAK) |
198 | 1239 | self.assertNotIn('register_user', self.ui.backend._called) | 1239 | self.assertNotIn('register_with_name', self.ui.backend._called) |
199 | 1240 | 1240 | ||
200 | 1241 | def test_warning_is_shown_if_tc_not_accepted(self): | 1241 | def test_warning_is_shown_if_tc_not_accepted(self): |
201 | 1242 | """A warning message is shown if TC are not accepted.""" | 1242 | """A warning message is shown if TC are not accepted.""" |
202 | @@ -1247,7 +1247,7 @@ | |||
203 | 1247 | 1247 | ||
204 | 1248 | self.assert_correct_label_warning(self.ui.tc_warning_label, | 1248 | self.assert_correct_label_warning(self.ui.tc_warning_label, |
205 | 1249 | self.ui.TC_NOT_ACCEPTED) | 1249 | self.ui.TC_NOT_ACCEPTED) |
207 | 1250 | self.assertNotIn('register_user', self.ui.backend._called) | 1250 | self.assertNotIn('register_with_name', self.ui.backend._called) |
208 | 1251 | 1251 | ||
209 | 1252 | def test_warning_is_shown_if_not_captcha_solution(self): | 1252 | def test_warning_is_shown_if_not_captcha_solution(self): |
210 | 1253 | """A warning message is shown if TC are not accepted.""" | 1253 | """A warning message is shown if TC are not accepted.""" |
211 | @@ -1258,7 +1258,7 @@ | |||
212 | 1258 | 1258 | ||
213 | 1259 | self.assert_correct_entry_warning(self.ui.captcha_solution_entry, | 1259 | self.assert_correct_entry_warning(self.ui.captcha_solution_entry, |
214 | 1260 | self.ui.FIELD_REQUIRED) | 1260 | self.ui.FIELD_REQUIRED) |
216 | 1261 | self.assertNotIn('register_user', self.ui.backend._called) | 1261 | self.assertNotIn('register_with_name', self.ui.backend._called) |
217 | 1262 | 1262 | ||
218 | 1263 | def test_no_warning_messages_if_valid_data(self): | 1263 | def test_no_warning_messages_if_valid_data(self): |
219 | 1264 | """No warning messages are shown if the data is valid.""" | 1264 | """No warning messages are shown if the data is valid.""" |
220 | 1265 | 1265 | ||
221 | === modified file 'ubuntu_sso/tests/test_main.py' | |||
222 | --- ubuntu_sso/tests/test_main.py 2011-03-24 13:01:02 +0000 | |||
223 | +++ ubuntu_sso/tests/test_main.py 2011-03-29 17:46:34 +0000 | |||
224 | @@ -200,7 +200,6 @@ | |||
225 | 200 | """Init.""" | 200 | """Init.""" |
226 | 201 | self.processor = SSOLoginProcessor(sso_service_class=FakedSSOServer) | 201 | self.processor = SSOLoginProcessor(sso_service_class=FakedSSOServer) |
227 | 202 | self.register_kwargs = dict(email=EMAIL, password=PASSWORD, | 202 | self.register_kwargs = dict(email=EMAIL, password=PASSWORD, |
228 | 203 | displayname=NAME, | ||
229 | 204 | captcha_id=CAPTCHA_ID, | 203 | captcha_id=CAPTCHA_ID, |
230 | 205 | captcha_solution=CAPTCHA_SOLUTION) | 204 | captcha_solution=CAPTCHA_SOLUTION) |
231 | 206 | self.login_kwargs = dict(email=EMAIL, password=PASSWORD, | 205 | self.login_kwargs = dict(email=EMAIL, password=PASSWORD, |
232 | @@ -404,6 +403,16 @@ | |||
233 | 404 | self.assertIn('Received invalid reply: %s' % STATUS_UNKNOWN, exc) | 403 | self.assertIn('Received invalid reply: %s' % STATUS_UNKNOWN, exc) |
234 | 405 | 404 | ||
235 | 406 | 405 | ||
236 | 406 | class SSORegistrationWithNameTestCase(SSOLoginProcessorTestCase): | ||
237 | 407 | """Test suite for the SSO login processor for register_with_name.""" | ||
238 | 408 | |||
239 | 409 | def setUp(self): | ||
240 | 410 | """Init.""" | ||
241 | 411 | super(SSORegistrationWithNameTestCase, self).setUp() | ||
242 | 412 | self.register_kwargs['displayname'] = NAME | ||
243 | 413 | self.processor.register_user = self.processor.register_with_name | ||
244 | 414 | |||
245 | 415 | |||
246 | 407 | class BlockingSampleException(Exception): | 416 | class BlockingSampleException(Exception): |
247 | 408 | """The exception that will be thrown by the fake blocking.""" | 417 | """The exception that will be thrown by the fake blocking.""" |
248 | 409 | 418 | ||
249 | @@ -515,7 +524,7 @@ | |||
250 | 515 | """Test that the register_user method works ok.""" | 524 | """Test that the register_user method works ok.""" |
251 | 516 | d = Deferred() | 525 | d = Deferred() |
252 | 517 | expected_result = "expected result" | 526 | expected_result = "expected result" |
254 | 518 | self.create_mock_processor().register_user(EMAIL, PASSWORD, NAME, | 527 | self.create_mock_processor().register_user(EMAIL, PASSWORD, |
255 | 519 | CAPTCHA_ID, CAPTCHA_SOLUTION) | 528 | CAPTCHA_ID, CAPTCHA_SOLUTION) |
256 | 520 | self.mocker.result(expected_result) | 529 | self.mocker.result(expected_result) |
257 | 521 | self.patch(ubuntu_sso.main, "blocking", self.fake_ok_blocking) | 530 | self.patch(ubuntu_sso.main, "blocking", self.fake_ok_blocking) |
258 | @@ -531,7 +540,7 @@ | |||
259 | 531 | sso_login_processor_class=self.mockprocessorclass) | 540 | sso_login_processor_class=self.mockprocessorclass) |
260 | 532 | self.patch(client, "UserRegistered", verify) | 541 | self.patch(client, "UserRegistered", verify) |
261 | 533 | self.patch(client, "UserRegistrationError", d.errback) | 542 | self.patch(client, "UserRegistrationError", d.errback) |
263 | 534 | client.register_user(APP_NAME, EMAIL, PASSWORD, NAME, CAPTCHA_ID, | 543 | client.register_user(APP_NAME, EMAIL, PASSWORD, CAPTCHA_ID, |
264 | 535 | CAPTCHA_SOLUTION) | 544 | CAPTCHA_SOLUTION) |
265 | 536 | return d | 545 | return d |
266 | 537 | 546 | ||
267 | @@ -539,23 +548,71 @@ | |||
268 | 539 | """Test that the register_user method fails as expected.""" | 548 | """Test that the register_user method fails as expected.""" |
269 | 540 | d = Deferred() | 549 | d = Deferred() |
270 | 541 | expected_result = "expected result" | 550 | expected_result = "expected result" |
288 | 542 | self.create_mock_processor().register_user(EMAIL, PASSWORD, NAME, | 551 | self.create_mock_processor().register_user(EMAIL, PASSWORD, |
289 | 543 | CAPTCHA_ID, CAPTCHA_SOLUTION) | 552 | CAPTCHA_ID, CAPTCHA_SOLUTION) |
290 | 544 | self.mocker.result(expected_result) | 553 | self.mocker.result(expected_result) |
291 | 545 | self.patch(ubuntu_sso.main, "blocking", self.fake_err_blocking) | 554 | self.patch(ubuntu_sso.main, "blocking", self.fake_err_blocking) |
292 | 546 | self.mocker.replay() | 555 | self.mocker.replay() |
293 | 547 | 556 | ||
294 | 548 | def verify(app_name, errdict): | 557 | def verify(app_name, errdict): |
295 | 549 | """The actual test.""" | 558 | """The actual test.""" |
296 | 550 | self.assertEqual(errdict["errtype"], "BlockingSampleException") | 559 | self.assertEqual(errdict["errtype"], "BlockingSampleException") |
297 | 551 | self.assertEqual(app_name, APP_NAME) | 560 | self.assertEqual(app_name, APP_NAME) |
298 | 552 | d.callback("Ok") | 561 | d.callback("Ok") |
299 | 553 | 562 | ||
300 | 554 | client = SSOLogin(self.mockbusname, | 563 | client = SSOLogin(self.mockbusname, |
301 | 555 | sso_login_processor_class=self.mockprocessorclass) | 564 | sso_login_processor_class=self.mockprocessorclass) |
302 | 556 | self.patch(client, "UserRegistered", d.errback) | 565 | self.patch(client, "UserRegistered", d.errback) |
303 | 557 | self.patch(client, "UserRegistrationError", verify) | 566 | self.patch(client, "UserRegistrationError", verify) |
304 | 558 | client.register_user(APP_NAME, EMAIL, PASSWORD, NAME, CAPTCHA_ID, | 567 | client.register_user(APP_NAME, EMAIL, PASSWORD, CAPTCHA_ID, |
305 | 568 | CAPTCHA_SOLUTION) | ||
306 | 569 | return d | ||
307 | 570 | |||
308 | 571 | def test_register_with_name(self): | ||
309 | 572 | """Test that the register_with_name method works ok.""" | ||
310 | 573 | d = Deferred() | ||
311 | 574 | expected_result = "expected result" | ||
312 | 575 | self.create_mock_processor().register_with_name(EMAIL, PASSWORD, NAME, | ||
313 | 576 | CAPTCHA_ID, CAPTCHA_SOLUTION) | ||
314 | 577 | self.mocker.result(expected_result) | ||
315 | 578 | self.patch(ubuntu_sso.main, "blocking", self.fake_ok_blocking) | ||
316 | 579 | self.mocker.replay() | ||
317 | 580 | |||
318 | 581 | def verify(app_name, result): | ||
319 | 582 | """The actual test.""" | ||
320 | 583 | self.assertEqual(result, expected_result) | ||
321 | 584 | self.assertEqual(app_name, APP_NAME) | ||
322 | 585 | d.callback(result) | ||
323 | 586 | |||
324 | 587 | client = SSOLogin(self.mockbusname, | ||
325 | 588 | sso_login_processor_class=self.mockprocessorclass) | ||
326 | 589 | self.patch(client, "UserRegistered", verify) | ||
327 | 590 | self.patch(client, "UserRegistrationError", d.errback) | ||
328 | 591 | client.register_with_name(APP_NAME, EMAIL, PASSWORD, NAME, CAPTCHA_ID, | ||
329 | 592 | CAPTCHA_SOLUTION) | ||
330 | 593 | return d | ||
331 | 594 | |||
332 | 595 | def test_register_with_name_error(self): | ||
333 | 596 | """Test that the register_with_name method fails as expected.""" | ||
334 | 597 | d = Deferred() | ||
335 | 598 | expected_result = "expected result" | ||
336 | 599 | self.create_mock_processor().register_with_name(EMAIL, PASSWORD, NAME, | ||
337 | 600 | CAPTCHA_ID, CAPTCHA_SOLUTION) | ||
338 | 601 | self.mocker.result(expected_result) | ||
339 | 602 | self.patch(ubuntu_sso.main, "blocking", self.fake_err_blocking) | ||
340 | 603 | self.mocker.replay() | ||
341 | 604 | |||
342 | 605 | def verify(app_name, errdict): | ||
343 | 606 | """The actual test.""" | ||
344 | 607 | self.assertEqual(errdict["errtype"], "BlockingSampleException") | ||
345 | 608 | self.assertEqual(app_name, APP_NAME) | ||
346 | 609 | d.callback("Ok") | ||
347 | 610 | |||
348 | 611 | client = SSOLogin(self.mockbusname, | ||
349 | 612 | sso_login_processor_class=self.mockprocessorclass) | ||
350 | 613 | self.patch(client, "UserRegistered", d.errback) | ||
351 | 614 | self.patch(client, "UserRegistrationError", verify) | ||
352 | 615 | client.register_with_name(APP_NAME, EMAIL, PASSWORD, NAME, CAPTCHA_ID, | ||
353 | 559 | CAPTCHA_SOLUTION) | 616 | CAPTCHA_SOLUTION) |
354 | 560 | return d | 617 | return d |
355 | 561 | 618 |
Works as expected.