Merge lp:~nataliabidart/ubuntu-sso-client/restore-register-api into lp:ubuntu-sso-client/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
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.
Revision history for this message
Joshua Hoover (joshuahoover) wrote :

Works as expected.

review: Approve (tested)
Revision history for this message
Roberto Alsina (ralsina) wrote :

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'run-tests'
--- run-tests 2010-09-03 19:32:51 +0000
+++ run-tests 2011-03-29 17:46:34 +0000
@@ -16,7 +16,7 @@
16# with this program. If not, see <http://www.gnu.org/licenses/>.16# with this program. If not, see <http://www.gnu.org/licenses/>.
1717
18`which xvfb-run` ./contrib/test "$@"18`which xvfb-run` ./contrib/test "$@"
19pylint contrib ubuntu_sso19pylint ubuntu_sso
20if [ -x `which pep8` ]; then20if [ -x `which pep8` ]; then
21 pep8 --repeat bin/ contrib/ ubuntu_sso/21 pep8 --repeat bin/ contrib/ ubuntu_sso/
22else22else
2323
=== modified file 'ubuntu_sso/gui.py'
--- ubuntu_sso/gui.py 2011-03-24 13:01:02 +0000
+++ ubuntu_sso/gui.py 2011-03-29 17:46:34 +0000
@@ -808,10 +808,10 @@
808 self.user_email = email1808 self.user_email = email1
809 self.user_password = password1809 self.user_password = password1
810810
811 logger.info('Calling register_user with email %r, password <hidden>,' \811 logger.info('Calling register_with_name with email %r, password, '
812 ' name %r, captcha_id %r and captcha_solution %r.', email1,812 '<hidden> name %r, captcha_id %r and captcha_solution %r.',
813 name, self._captcha_id, captcha_solution)813 email1, name, self._captcha_id, captcha_solution)
814 f = self.backend.register_user814 f = self.backend.register_with_name
815 f(self.app_name, email1, password1, name,815 f(self.app_name, email1, password1, name,
816 self._captcha_id, captcha_solution,816 self._captcha_id, captcha_solution,
817 reply_handler=NO_OP, error_handler=NO_OP)817 reply_handler=NO_OP, error_handler=NO_OP)
818818
=== modified file 'ubuntu_sso/main.py'
--- ubuntu_sso/main.py 2011-03-24 13:01:02 +0000
+++ ubuntu_sso/main.py 2011-03-29 17:46:34 +0000
@@ -171,19 +171,19 @@
171171
172 return captcha['captcha_id']172 return captcha['captcha_id']
173173
174 def register_user(self, email, password, displayname,174 def register_with_name(self, email, password, displayname,
175 captcha_id, captcha_solution):175 captcha_id, captcha_solution):
176 """Register a new user with 'email' and 'password'."""176 """Register a new user with 'email' and 'password'."""
177 logger.debug('register_user: email: %r password: <hidden>, '177 logger.debug('register_with_name: email: %r password: <hidden>, '
178 'displayname: %r, captcha_id: %r, captcha_solution: %r',178 'displayname: %r, captcha_id: %r, captcha_solution: %r',
179 email, displayname, captcha_id, captcha_solution)179 email, displayname, captcha_id, captcha_solution)
180 sso_service = self.sso_service_class(None, self.service_url)180 sso_service = self.sso_service_class(None, self.service_url)
181 if not self._valid_email(email):181 if not self._valid_email(email):
182 logger.error('register_user: InvalidEmailError for email: %r',182 logger.error('register_with_name: InvalidEmailError for email: %r',
183 email)183 email)
184 raise InvalidEmailError()184 raise InvalidEmailError()
185 if not self._valid_password(password):185 if not self._valid_password(password):
186 logger.error('register_user: InvalidPasswordError')186 logger.error('register_with_name: InvalidPasswordError')
187 raise InvalidPasswordError()187 raise InvalidPasswordError()
188188
189 result = sso_service.registrations.register(189 result = sso_service.registrations.register(
@@ -191,7 +191,7 @@
191 displayname=displayname,191 displayname=displayname,
192 captcha_id=captcha_id,192 captcha_id=captcha_id,
193 captcha_solution=captcha_solution)193 captcha_solution=captcha_solution)
194 logger.info('register_user: email: %r result: %r', email, result)194 logger.info('register_with_name: email: %r result: %r', email, result)
195195
196 if result['status'] == 'error':196 if result['status'] == 'error':
197 errorsdict = self._format_webservice_errors(result['errors'])197 errorsdict = self._format_webservice_errors(result['errors'])
@@ -201,6 +201,17 @@
201 else:201 else:
202 return email202 return email
203203
204 def register_user(self, email, password,
205 captcha_id, captcha_solution):
206 """Register a new user with 'email' and 'password'."""
207 logger.debug('register_user: email: %r password: <hidden>, '
208 'captcha_id: %r, captcha_solution: %r',
209 email, captcha_id, captcha_solution)
210 res = self.register_with_name(email, password, displayname='',
211 captcha_id=captcha_id,
212 captcha_solution=captcha_solution)
213 return res
214
204 def login(self, email, password, token_name):215 def login(self, email, password, token_name):
205 """Login a user with 'email' and 'password'."""216 """Login a user with 'email' and 'password'."""
206 logger.debug('login: email: %r password: <hidden>, token_name: %r',217 logger.debug('login: email: %r password: <hidden>, token_name: %r',
@@ -380,13 +391,24 @@
380 'app_name "%s" and error %r', app_name, error)391 'app_name "%s" and error %r', app_name, error)
381392
382 @dbus.service.method(dbus_interface=DBUS_IFACE_USER_NAME,393 @dbus.service.method(dbus_interface=DBUS_IFACE_USER_NAME,
394 in_signature='sssss')
395 def register_user(self, app_name, email, password,
396 captcha_id, captcha_solution):
397 """Call the matching method in the processor."""
398 def f():
399 """Inner function that will be run in a thread."""
400 return self.processor.register_user(email, password,
401 captcha_id, captcha_solution)
402 blocking(f, app_name, self.UserRegistered, self.UserRegistrationError)
403
404 @dbus.service.method(dbus_interface=DBUS_IFACE_USER_NAME,
383 in_signature='ssssss')405 in_signature='ssssss')
384 def register_user(self, app_name, email, password, name,406 def register_with_name(self, app_name, email, password, name,
385 captcha_id, captcha_solution):407 captcha_id, captcha_solution):
386 """Call the matching method in the processor."""408 """Call the matching method in the processor."""
387 def f():409 def f():
388 """Inner function that will be run in a thread."""410 """Inner function that will be run in a thread."""
389 return self.processor.register_user(email, password, name,411 return self.processor.register_with_name(email, password, name,
390 captcha_id, captcha_solution)412 captcha_id, captcha_solution)
391 blocking(f, app_name, self.UserRegistered, self.UserRegistrationError)413 blocking(f, app_name, self.UserRegistered, self.UserRegistrationError)
392414
393415
=== modified file 'ubuntu_sso/tests/test_gui.py'
--- ubuntu_sso/tests/test_gui.py 2011-03-24 13:01:02 +0000
+++ ubuntu_sso/tests/test_gui.py 2011-03-29 17:46:34 +0000
@@ -63,7 +63,7 @@
63 self._args = args63 self._args = args
64 self._kwargs = kwargs64 self._kwargs = kwargs
65 self._called = {}65 self._called = {}
66 for i in ('generate_captcha', 'login', 'register_user',66 for i in ('generate_captcha', 'login', 'register_with_name',
67 'validate_email', 'request_password_reset_token',67 'validate_email', 'request_password_reset_token',
68 'set_new_password'):68 'set_new_password'):
69 setattr(self, i, self._record_call(i))69 setattr(self, i, self._record_call(i))
@@ -674,8 +674,8 @@
674 """Clicking 'join_ok_button' sends info to backend using 'register'."""674 """Clicking 'join_ok_button' sends info to backend using 'register'."""
675 self.click_join_with_valid_data()675 self.click_join_with_valid_data()
676676
677 # assert register_user was called677 # assert register_with_name was called
678 expected = 'register_user'678 expected = 'register_with_name'
679 self.assertIn(expected, self.ui.backend._called)679 self.assertIn(expected, self.ui.backend._called)
680 self.assertEqual(self.ui.backend._called[expected],680 self.assertEqual(self.ui.backend._called[expected],
681 ((APP_NAME, EMAIL, PASSWORD, NAME, CAPTCHA_ID,681 ((APP_NAME, EMAIL, PASSWORD, NAME, CAPTCHA_ID,
@@ -1161,7 +1161,7 @@
11611161
1162 self.assert_correct_entry_warning(self.ui.name_entry,1162 self.assert_correct_entry_warning(self.ui.name_entry,
1163 self.ui.FIELD_REQUIRED)1163 self.ui.FIELD_REQUIRED)
1164 self.assertNotIn('register_user', self.ui.backend._called)1164 self.assertNotIn('register_with_name', self.ui.backend._called)
11651165
1166 def test_warning_is_shown_if_empty_email(self):1166 def test_warning_is_shown_if_empty_email(self):
1167 """A warning message is shown if emails are empty."""1167 """A warning message is shown if emails are empty."""
@@ -1174,7 +1174,7 @@
1174 self.ui.FIELD_REQUIRED)1174 self.ui.FIELD_REQUIRED)
1175 self.assert_correct_entry_warning(self.ui.email2_entry,1175 self.assert_correct_entry_warning(self.ui.email2_entry,
1176 self.ui.FIELD_REQUIRED)1176 self.ui.FIELD_REQUIRED)
1177 self.assertNotIn('register_user', self.ui.backend._called)1177 self.assertNotIn('register_with_name', self.ui.backend._called)
11781178
1179 def test_warning_is_shown_if_email_mismatch(self):1179 def test_warning_is_shown_if_email_mismatch(self):
1180 """A warning message is shown if emails doesn't match."""1180 """A warning message is shown if emails doesn't match."""
@@ -1187,7 +1187,7 @@
1187 self.ui.EMAIL_MISMATCH)1187 self.ui.EMAIL_MISMATCH)
1188 self.assert_correct_entry_warning(self.ui.email2_entry,1188 self.assert_correct_entry_warning(self.ui.email2_entry,
1189 self.ui.EMAIL_MISMATCH)1189 self.ui.EMAIL_MISMATCH)
1190 self.assertNotIn('register_user', self.ui.backend._called)1190 self.assertNotIn('register_with_name', self.ui.backend._called)
11911191
1192 def test_warning_is_shown_if_invalid_email(self):1192 def test_warning_is_shown_if_invalid_email(self):
1193 """A warning message is shown if email is invalid."""1193 """A warning message is shown if email is invalid."""
@@ -1200,7 +1200,7 @@
1200 self.ui.EMAIL_INVALID)1200 self.ui.EMAIL_INVALID)
1201 self.assert_correct_entry_warning(self.ui.email2_entry,1201 self.assert_correct_entry_warning(self.ui.email2_entry,
1202 self.ui.EMAIL_INVALID)1202 self.ui.EMAIL_INVALID)
1203 self.assertNotIn('register_user', self.ui.backend._called)1203 self.assertNotIn('register_with_name', self.ui.backend._called)
12041204
1205 def test_password_help_is_always_shown(self):1205 def test_password_help_is_always_shown(self):
1206 """Password help text is correctly displayed."""1206 """Password help text is correctly displayed."""
@@ -1208,7 +1208,7 @@
1208 'password help text is visible.')1208 'password help text is visible.')
1209 self.assertEqual(self.ui.password_help_label.get_text(),1209 self.assertEqual(self.ui.password_help_label.get_text(),
1210 self.ui.PASSWORD_HELP)1210 self.ui.PASSWORD_HELP)
1211 self.assertNotIn('register_user', self.ui.backend._called)1211 self.assertNotIn('register_with_name', self.ui.backend._called)
12121212
1213 def test_warning_is_shown_if_password_mismatch(self):1213 def test_warning_is_shown_if_password_mismatch(self):
1214 """A warning message is shown if password doesn't match."""1214 """A warning message is shown if password doesn't match."""
@@ -1221,7 +1221,7 @@
1221 self.ui.PASSWORD_MISMATCH)1221 self.ui.PASSWORD_MISMATCH)
1222 self.assert_correct_entry_warning(self.ui.password2_entry,1222 self.assert_correct_entry_warning(self.ui.password2_entry,
1223 self.ui.PASSWORD_MISMATCH)1223 self.ui.PASSWORD_MISMATCH)
1224 self.assertNotIn('register_user', self.ui.backend._called)1224 self.assertNotIn('register_with_name', self.ui.backend._called)
12251225
1226 def test_warning_is_shown_if_password_too_weak(self):1226 def test_warning_is_shown_if_password_too_weak(self):
1227 """A warning message is shown if password is too weak."""1227 """A warning message is shown if password is too weak."""
@@ -1236,7 +1236,7 @@
1236 self.ui.PASSWORD_TOO_WEAK)1236 self.ui.PASSWORD_TOO_WEAK)
1237 self.assert_correct_entry_warning(self.ui.password2_entry,1237 self.assert_correct_entry_warning(self.ui.password2_entry,
1238 self.ui.PASSWORD_TOO_WEAK)1238 self.ui.PASSWORD_TOO_WEAK)
1239 self.assertNotIn('register_user', self.ui.backend._called)1239 self.assertNotIn('register_with_name', self.ui.backend._called)
12401240
1241 def test_warning_is_shown_if_tc_not_accepted(self):1241 def test_warning_is_shown_if_tc_not_accepted(self):
1242 """A warning message is shown if TC are not accepted."""1242 """A warning message is shown if TC are not accepted."""
@@ -1247,7 +1247,7 @@
12471247
1248 self.assert_correct_label_warning(self.ui.tc_warning_label,1248 self.assert_correct_label_warning(self.ui.tc_warning_label,
1249 self.ui.TC_NOT_ACCEPTED)1249 self.ui.TC_NOT_ACCEPTED)
1250 self.assertNotIn('register_user', self.ui.backend._called)1250 self.assertNotIn('register_with_name', self.ui.backend._called)
12511251
1252 def test_warning_is_shown_if_not_captcha_solution(self):1252 def test_warning_is_shown_if_not_captcha_solution(self):
1253 """A warning message is shown if TC are not accepted."""1253 """A warning message is shown if TC are not accepted."""
@@ -1258,7 +1258,7 @@
12581258
1259 self.assert_correct_entry_warning(self.ui.captcha_solution_entry,1259 self.assert_correct_entry_warning(self.ui.captcha_solution_entry,
1260 self.ui.FIELD_REQUIRED)1260 self.ui.FIELD_REQUIRED)
1261 self.assertNotIn('register_user', self.ui.backend._called)1261 self.assertNotIn('register_with_name', self.ui.backend._called)
12621262
1263 def test_no_warning_messages_if_valid_data(self):1263 def test_no_warning_messages_if_valid_data(self):
1264 """No warning messages are shown if the data is valid."""1264 """No warning messages are shown if the data is valid."""
12651265
=== modified file 'ubuntu_sso/tests/test_main.py'
--- ubuntu_sso/tests/test_main.py 2011-03-24 13:01:02 +0000
+++ ubuntu_sso/tests/test_main.py 2011-03-29 17:46:34 +0000
@@ -200,7 +200,6 @@
200 """Init."""200 """Init."""
201 self.processor = SSOLoginProcessor(sso_service_class=FakedSSOServer)201 self.processor = SSOLoginProcessor(sso_service_class=FakedSSOServer)
202 self.register_kwargs = dict(email=EMAIL, password=PASSWORD,202 self.register_kwargs = dict(email=EMAIL, password=PASSWORD,
203 displayname=NAME,
204 captcha_id=CAPTCHA_ID,203 captcha_id=CAPTCHA_ID,
205 captcha_solution=CAPTCHA_SOLUTION)204 captcha_solution=CAPTCHA_SOLUTION)
206 self.login_kwargs = dict(email=EMAIL, password=PASSWORD,205 self.login_kwargs = dict(email=EMAIL, password=PASSWORD,
@@ -404,6 +403,16 @@
404 self.assertIn('Received invalid reply: %s' % STATUS_UNKNOWN, exc)403 self.assertIn('Received invalid reply: %s' % STATUS_UNKNOWN, exc)
405404
406405
406class SSORegistrationWithNameTestCase(SSOLoginProcessorTestCase):
407 """Test suite for the SSO login processor for register_with_name."""
408
409 def setUp(self):
410 """Init."""
411 super(SSORegistrationWithNameTestCase, self).setUp()
412 self.register_kwargs['displayname'] = NAME
413 self.processor.register_user = self.processor.register_with_name
414
415
407class BlockingSampleException(Exception):416class BlockingSampleException(Exception):
408 """The exception that will be thrown by the fake blocking."""417 """The exception that will be thrown by the fake blocking."""
409418
@@ -515,7 +524,7 @@
515 """Test that the register_user method works ok."""524 """Test that the register_user method works ok."""
516 d = Deferred()525 d = Deferred()
517 expected_result = "expected result"526 expected_result = "expected result"
518 self.create_mock_processor().register_user(EMAIL, PASSWORD, NAME,527 self.create_mock_processor().register_user(EMAIL, PASSWORD,
519 CAPTCHA_ID, CAPTCHA_SOLUTION)528 CAPTCHA_ID, CAPTCHA_SOLUTION)
520 self.mocker.result(expected_result)529 self.mocker.result(expected_result)
521 self.patch(ubuntu_sso.main, "blocking", self.fake_ok_blocking)530 self.patch(ubuntu_sso.main, "blocking", self.fake_ok_blocking)
@@ -531,7 +540,7 @@
531 sso_login_processor_class=self.mockprocessorclass)540 sso_login_processor_class=self.mockprocessorclass)
532 self.patch(client, "UserRegistered", verify)541 self.patch(client, "UserRegistered", verify)
533 self.patch(client, "UserRegistrationError", d.errback)542 self.patch(client, "UserRegistrationError", d.errback)
534 client.register_user(APP_NAME, EMAIL, PASSWORD, NAME, CAPTCHA_ID,543 client.register_user(APP_NAME, EMAIL, PASSWORD, CAPTCHA_ID,
535 CAPTCHA_SOLUTION)544 CAPTCHA_SOLUTION)
536 return d545 return d
537546
@@ -539,23 +548,71 @@
539 """Test that the register_user method fails as expected."""548 """Test that the register_user method fails as expected."""
540 d = Deferred()549 d = Deferred()
541 expected_result = "expected result"550 expected_result = "expected result"
542 self.create_mock_processor().register_user(EMAIL, PASSWORD, NAME,551 self.create_mock_processor().register_user(EMAIL, PASSWORD,
543 CAPTCHA_ID, CAPTCHA_SOLUTION)552 CAPTCHA_ID, CAPTCHA_SOLUTION)
544 self.mocker.result(expected_result)553 self.mocker.result(expected_result)
545 self.patch(ubuntu_sso.main, "blocking", self.fake_err_blocking)554 self.patch(ubuntu_sso.main, "blocking", self.fake_err_blocking)
546 self.mocker.replay()555 self.mocker.replay()
547556
548 def verify(app_name, errdict):557 def verify(app_name, errdict):
549 """The actual test."""558 """The actual test."""
550 self.assertEqual(errdict["errtype"], "BlockingSampleException")559 self.assertEqual(errdict["errtype"], "BlockingSampleException")
551 self.assertEqual(app_name, APP_NAME)560 self.assertEqual(app_name, APP_NAME)
552 d.callback("Ok")561 d.callback("Ok")
553562
554 client = SSOLogin(self.mockbusname,563 client = SSOLogin(self.mockbusname,
555 sso_login_processor_class=self.mockprocessorclass)564 sso_login_processor_class=self.mockprocessorclass)
556 self.patch(client, "UserRegistered", d.errback)565 self.patch(client, "UserRegistered", d.errback)
557 self.patch(client, "UserRegistrationError", verify)566 self.patch(client, "UserRegistrationError", verify)
558 client.register_user(APP_NAME, EMAIL, PASSWORD, NAME, CAPTCHA_ID,567 client.register_user(APP_NAME, EMAIL, PASSWORD, CAPTCHA_ID,
568 CAPTCHA_SOLUTION)
569 return d
570
571 def test_register_with_name(self):
572 """Test that the register_with_name method works ok."""
573 d = Deferred()
574 expected_result = "expected result"
575 self.create_mock_processor().register_with_name(EMAIL, PASSWORD, NAME,
576 CAPTCHA_ID, CAPTCHA_SOLUTION)
577 self.mocker.result(expected_result)
578 self.patch(ubuntu_sso.main, "blocking", self.fake_ok_blocking)
579 self.mocker.replay()
580
581 def verify(app_name, result):
582 """The actual test."""
583 self.assertEqual(result, expected_result)
584 self.assertEqual(app_name, APP_NAME)
585 d.callback(result)
586
587 client = SSOLogin(self.mockbusname,
588 sso_login_processor_class=self.mockprocessorclass)
589 self.patch(client, "UserRegistered", verify)
590 self.patch(client, "UserRegistrationError", d.errback)
591 client.register_with_name(APP_NAME, EMAIL, PASSWORD, NAME, CAPTCHA_ID,
592 CAPTCHA_SOLUTION)
593 return d
594
595 def test_register_with_name_error(self):
596 """Test that the register_with_name method fails as expected."""
597 d = Deferred()
598 expected_result = "expected result"
599 self.create_mock_processor().register_with_name(EMAIL, PASSWORD, NAME,
600 CAPTCHA_ID, CAPTCHA_SOLUTION)
601 self.mocker.result(expected_result)
602 self.patch(ubuntu_sso.main, "blocking", self.fake_err_blocking)
603 self.mocker.replay()
604
605 def verify(app_name, errdict):
606 """The actual test."""
607 self.assertEqual(errdict["errtype"], "BlockingSampleException")
608 self.assertEqual(app_name, APP_NAME)
609 d.callback("Ok")
610
611 client = SSOLogin(self.mockbusname,
612 sso_login_processor_class=self.mockprocessorclass)
613 self.patch(client, "UserRegistered", d.errback)
614 self.patch(client, "UserRegistrationError", verify)
615 client.register_with_name(APP_NAME, EMAIL, PASSWORD, NAME, CAPTCHA_ID,
559 CAPTCHA_SOLUTION)616 CAPTCHA_SOLUTION)
560 return d617 return d
561618

Subscribers

People subscribed via source and target branches