Ubuntu Single Sign On Client

Merge lp:~nataliabidart/ubuntu-sso-client/restore-register-api into lp:ubuntu-sso-client/stable-1-0

Proposed by Natalia Bidart on 2011-03-29
Status: Merged
Approved by: Natalia Bidart on 2011-03-29
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
To merge this branch: bzr merge lp:~nataliabidart/ubuntu-sso-client/restore-register-api
Reviewer Review Type Date Requested Status
Roberto Alsina Approve on 2011-03-29
Joshua Hoover (community) tested 2011-03-29 Approve on 2011-03-29
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.
Joshua Hoover (joshuahoover) wrote :

Works as expected.

review: Approve (tested)
Roberto Alsina (ralsina) wrote :

+1

review: Approve

Preview Diff

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 # with this program. If not, see <http://www.gnu.org/licenses/>.
6
7 `which xvfb-run` ./contrib/test "$@"
8-pylint contrib ubuntu_sso
9+pylint ubuntu_sso
10 if [ -x `which pep8` ]; then
11 pep8 --repeat bin/ contrib/ ubuntu_sso/
12 else
13
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 self.user_email = email1
19 self.user_password = password1
20
21- logger.info('Calling register_user with email %r, password <hidden>,' \
22- ' name %r, captcha_id %r and captcha_solution %r.', email1,
23- name, self._captcha_id, captcha_solution)
24- f = self.backend.register_user
25+ logger.info('Calling register_with_name with email %r, password, '
26+ '<hidden> name %r, captcha_id %r and captcha_solution %r.',
27+ email1, name, self._captcha_id, captcha_solution)
28+ f = self.backend.register_with_name
29 f(self.app_name, email1, password1, name,
30 self._captcha_id, captcha_solution,
31 reply_handler=NO_OP, error_handler=NO_OP)
32
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
38 return captcha['captcha_id']
39
40- def register_user(self, email, password, displayname,
41+ def register_with_name(self, email, password, displayname,
42 captcha_id, captcha_solution):
43 """Register a new user with 'email' and 'password'."""
44- logger.debug('register_user: email: %r password: <hidden>, '
45+ logger.debug('register_with_name: email: %r password: <hidden>, '
46 'displayname: %r, captcha_id: %r, captcha_solution: %r',
47 email, displayname, captcha_id, captcha_solution)
48 sso_service = self.sso_service_class(None, self.service_url)
49 if not self._valid_email(email):
50- logger.error('register_user: InvalidEmailError for email: %r',
51+ logger.error('register_with_name: InvalidEmailError for email: %r',
52 email)
53 raise InvalidEmailError()
54 if not self._valid_password(password):
55- logger.error('register_user: InvalidPasswordError')
56+ logger.error('register_with_name: InvalidPasswordError')
57 raise InvalidPasswordError()
58
59 result = sso_service.registrations.register(
60@@ -191,7 +191,7 @@
61 displayname=displayname,
62 captcha_id=captcha_id,
63 captcha_solution=captcha_solution)
64- logger.info('register_user: email: %r result: %r', email, result)
65+ logger.info('register_with_name: email: %r result: %r', email, result)
66
67 if result['status'] == 'error':
68 errorsdict = self._format_webservice_errors(result['errors'])
69@@ -201,6 +201,17 @@
70 else:
71 return email
72
73+ def register_user(self, email, password,
74+ captcha_id, captcha_solution):
75+ """Register a new user with 'email' and 'password'."""
76+ logger.debug('register_user: email: %r password: <hidden>, '
77+ 'captcha_id: %r, captcha_solution: %r',
78+ email, captcha_id, captcha_solution)
79+ res = self.register_with_name(email, password, displayname='',
80+ captcha_id=captcha_id,
81+ captcha_solution=captcha_solution)
82+ return res
83+
84 def login(self, email, password, token_name):
85 """Login a user with 'email' and 'password'."""
86 logger.debug('login: email: %r password: <hidden>, token_name: %r',
87@@ -380,13 +391,24 @@
88 'app_name "%s" and error %r', app_name, error)
89
90 @dbus.service.method(dbus_interface=DBUS_IFACE_USER_NAME,
91+ in_signature='sssss')
92+ def register_user(self, app_name, email, password,
93+ captcha_id, captcha_solution):
94+ """Call the matching method in the processor."""
95+ def f():
96+ """Inner function that will be run in a thread."""
97+ return self.processor.register_user(email, password,
98+ captcha_id, captcha_solution)
99+ blocking(f, app_name, self.UserRegistered, self.UserRegistrationError)
100+
101+ @dbus.service.method(dbus_interface=DBUS_IFACE_USER_NAME,
102 in_signature='ssssss')
103- def register_user(self, app_name, email, password, name,
104- captcha_id, captcha_solution):
105+ def register_with_name(self, app_name, email, password, name,
106+ captcha_id, captcha_solution):
107 """Call the matching method in the processor."""
108 def f():
109 """Inner function that will be run in a thread."""
110- return self.processor.register_user(email, password, name,
111+ return self.processor.register_with_name(email, password, name,
112 captcha_id, captcha_solution)
113 blocking(f, app_name, self.UserRegistered, self.UserRegistrationError)
114
115
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 self._args = args
121 self._kwargs = kwargs
122 self._called = {}
123- for i in ('generate_captcha', 'login', 'register_user',
124+ for i in ('generate_captcha', 'login', 'register_with_name',
125 'validate_email', 'request_password_reset_token',
126 'set_new_password'):
127 setattr(self, i, self._record_call(i))
128@@ -674,8 +674,8 @@
129 """Clicking 'join_ok_button' sends info to backend using 'register'."""
130 self.click_join_with_valid_data()
131
132- # assert register_user was called
133- expected = 'register_user'
134+ # assert register_with_name was called
135+ expected = 'register_with_name'
136 self.assertIn(expected, self.ui.backend._called)
137 self.assertEqual(self.ui.backend._called[expected],
138 ((APP_NAME, EMAIL, PASSWORD, NAME, CAPTCHA_ID,
139@@ -1161,7 +1161,7 @@
140
141 self.assert_correct_entry_warning(self.ui.name_entry,
142 self.ui.FIELD_REQUIRED)
143- self.assertNotIn('register_user', self.ui.backend._called)
144+ self.assertNotIn('register_with_name', self.ui.backend._called)
145
146 def test_warning_is_shown_if_empty_email(self):
147 """A warning message is shown if emails are empty."""
148@@ -1174,7 +1174,7 @@
149 self.ui.FIELD_REQUIRED)
150 self.assert_correct_entry_warning(self.ui.email2_entry,
151 self.ui.FIELD_REQUIRED)
152- self.assertNotIn('register_user', self.ui.backend._called)
153+ self.assertNotIn('register_with_name', self.ui.backend._called)
154
155 def test_warning_is_shown_if_email_mismatch(self):
156 """A warning message is shown if emails doesn't match."""
157@@ -1187,7 +1187,7 @@
158 self.ui.EMAIL_MISMATCH)
159 self.assert_correct_entry_warning(self.ui.email2_entry,
160 self.ui.EMAIL_MISMATCH)
161- self.assertNotIn('register_user', self.ui.backend._called)
162+ self.assertNotIn('register_with_name', self.ui.backend._called)
163
164 def test_warning_is_shown_if_invalid_email(self):
165 """A warning message is shown if email is invalid."""
166@@ -1200,7 +1200,7 @@
167 self.ui.EMAIL_INVALID)
168 self.assert_correct_entry_warning(self.ui.email2_entry,
169 self.ui.EMAIL_INVALID)
170- self.assertNotIn('register_user', self.ui.backend._called)
171+ self.assertNotIn('register_with_name', self.ui.backend._called)
172
173 def test_password_help_is_always_shown(self):
174 """Password help text is correctly displayed."""
175@@ -1208,7 +1208,7 @@
176 'password help text is visible.')
177 self.assertEqual(self.ui.password_help_label.get_text(),
178 self.ui.PASSWORD_HELP)
179- self.assertNotIn('register_user', self.ui.backend._called)
180+ self.assertNotIn('register_with_name', self.ui.backend._called)
181
182 def test_warning_is_shown_if_password_mismatch(self):
183 """A warning message is shown if password doesn't match."""
184@@ -1221,7 +1221,7 @@
185 self.ui.PASSWORD_MISMATCH)
186 self.assert_correct_entry_warning(self.ui.password2_entry,
187 self.ui.PASSWORD_MISMATCH)
188- self.assertNotIn('register_user', self.ui.backend._called)
189+ self.assertNotIn('register_with_name', self.ui.backend._called)
190
191 def test_warning_is_shown_if_password_too_weak(self):
192 """A warning message is shown if password is too weak."""
193@@ -1236,7 +1236,7 @@
194 self.ui.PASSWORD_TOO_WEAK)
195 self.assert_correct_entry_warning(self.ui.password2_entry,
196 self.ui.PASSWORD_TOO_WEAK)
197- self.assertNotIn('register_user', self.ui.backend._called)
198+ self.assertNotIn('register_with_name', self.ui.backend._called)
199
200 def test_warning_is_shown_if_tc_not_accepted(self):
201 """A warning message is shown if TC are not accepted."""
202@@ -1247,7 +1247,7 @@
203
204 self.assert_correct_label_warning(self.ui.tc_warning_label,
205 self.ui.TC_NOT_ACCEPTED)
206- self.assertNotIn('register_user', self.ui.backend._called)
207+ self.assertNotIn('register_with_name', self.ui.backend._called)
208
209 def test_warning_is_shown_if_not_captcha_solution(self):
210 """A warning message is shown if TC are not accepted."""
211@@ -1258,7 +1258,7 @@
212
213 self.assert_correct_entry_warning(self.ui.captcha_solution_entry,
214 self.ui.FIELD_REQUIRED)
215- self.assertNotIn('register_user', self.ui.backend._called)
216+ self.assertNotIn('register_with_name', self.ui.backend._called)
217
218 def test_no_warning_messages_if_valid_data(self):
219 """No warning messages are shown if the data is valid."""
220
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 """Init."""
226 self.processor = SSOLoginProcessor(sso_service_class=FakedSSOServer)
227 self.register_kwargs = dict(email=EMAIL, password=PASSWORD,
228- displayname=NAME,
229 captcha_id=CAPTCHA_ID,
230 captcha_solution=CAPTCHA_SOLUTION)
231 self.login_kwargs = dict(email=EMAIL, password=PASSWORD,
232@@ -404,6 +403,16 @@
233 self.assertIn('Received invalid reply: %s' % STATUS_UNKNOWN, exc)
234
235
236+class SSORegistrationWithNameTestCase(SSOLoginProcessorTestCase):
237+ """Test suite for the SSO login processor for register_with_name."""
238+
239+ def setUp(self):
240+ """Init."""
241+ super(SSORegistrationWithNameTestCase, self).setUp()
242+ self.register_kwargs['displayname'] = NAME
243+ self.processor.register_user = self.processor.register_with_name
244+
245+
246 class BlockingSampleException(Exception):
247 """The exception that will be thrown by the fake blocking."""
248
249@@ -515,7 +524,7 @@
250 """Test that the register_user method works ok."""
251 d = Deferred()
252 expected_result = "expected result"
253- self.create_mock_processor().register_user(EMAIL, PASSWORD, NAME,
254+ self.create_mock_processor().register_user(EMAIL, PASSWORD,
255 CAPTCHA_ID, CAPTCHA_SOLUTION)
256 self.mocker.result(expected_result)
257 self.patch(ubuntu_sso.main, "blocking", self.fake_ok_blocking)
258@@ -531,7 +540,7 @@
259 sso_login_processor_class=self.mockprocessorclass)
260 self.patch(client, "UserRegistered", verify)
261 self.patch(client, "UserRegistrationError", d.errback)
262- client.register_user(APP_NAME, EMAIL, PASSWORD, NAME, CAPTCHA_ID,
263+ client.register_user(APP_NAME, EMAIL, PASSWORD, CAPTCHA_ID,
264 CAPTCHA_SOLUTION)
265 return d
266
267@@ -539,23 +548,71 @@
268 """Test that the register_user method fails as expected."""
269 d = Deferred()
270 expected_result = "expected result"
271- self.create_mock_processor().register_user(EMAIL, PASSWORD, NAME,
272- CAPTCHA_ID, CAPTCHA_SOLUTION)
273- self.mocker.result(expected_result)
274- self.patch(ubuntu_sso.main, "blocking", self.fake_err_blocking)
275- self.mocker.replay()
276-
277- def verify(app_name, errdict):
278- """The actual test."""
279- self.assertEqual(errdict["errtype"], "BlockingSampleException")
280- self.assertEqual(app_name, APP_NAME)
281- d.callback("Ok")
282-
283- client = SSOLogin(self.mockbusname,
284- sso_login_processor_class=self.mockprocessorclass)
285- self.patch(client, "UserRegistered", d.errback)
286- self.patch(client, "UserRegistrationError", verify)
287- client.register_user(APP_NAME, EMAIL, PASSWORD, NAME, CAPTCHA_ID,
288+ self.create_mock_processor().register_user(EMAIL, PASSWORD,
289+ CAPTCHA_ID, CAPTCHA_SOLUTION)
290+ self.mocker.result(expected_result)
291+ self.patch(ubuntu_sso.main, "blocking", self.fake_err_blocking)
292+ self.mocker.replay()
293+
294+ def verify(app_name, errdict):
295+ """The actual test."""
296+ self.assertEqual(errdict["errtype"], "BlockingSampleException")
297+ self.assertEqual(app_name, APP_NAME)
298+ d.callback("Ok")
299+
300+ client = SSOLogin(self.mockbusname,
301+ sso_login_processor_class=self.mockprocessorclass)
302+ self.patch(client, "UserRegistered", d.errback)
303+ self.patch(client, "UserRegistrationError", verify)
304+ client.register_user(APP_NAME, EMAIL, PASSWORD, CAPTCHA_ID,
305+ CAPTCHA_SOLUTION)
306+ return d
307+
308+ def test_register_with_name(self):
309+ """Test that the register_with_name method works ok."""
310+ d = Deferred()
311+ expected_result = "expected result"
312+ self.create_mock_processor().register_with_name(EMAIL, PASSWORD, NAME,
313+ CAPTCHA_ID, CAPTCHA_SOLUTION)
314+ self.mocker.result(expected_result)
315+ self.patch(ubuntu_sso.main, "blocking", self.fake_ok_blocking)
316+ self.mocker.replay()
317+
318+ def verify(app_name, result):
319+ """The actual test."""
320+ self.assertEqual(result, expected_result)
321+ self.assertEqual(app_name, APP_NAME)
322+ d.callback(result)
323+
324+ client = SSOLogin(self.mockbusname,
325+ sso_login_processor_class=self.mockprocessorclass)
326+ self.patch(client, "UserRegistered", verify)
327+ self.patch(client, "UserRegistrationError", d.errback)
328+ client.register_with_name(APP_NAME, EMAIL, PASSWORD, NAME, CAPTCHA_ID,
329+ CAPTCHA_SOLUTION)
330+ return d
331+
332+ def test_register_with_name_error(self):
333+ """Test that the register_with_name method fails as expected."""
334+ d = Deferred()
335+ expected_result = "expected result"
336+ self.create_mock_processor().register_with_name(EMAIL, PASSWORD, NAME,
337+ CAPTCHA_ID, CAPTCHA_SOLUTION)
338+ self.mocker.result(expected_result)
339+ self.patch(ubuntu_sso.main, "blocking", self.fake_err_blocking)
340+ self.mocker.replay()
341+
342+ def verify(app_name, errdict):
343+ """The actual test."""
344+ self.assertEqual(errdict["errtype"], "BlockingSampleException")
345+ self.assertEqual(app_name, APP_NAME)
346+ d.callback("Ok")
347+
348+ client = SSOLogin(self.mockbusname,
349+ sso_login_processor_class=self.mockprocessorclass)
350+ self.patch(client, "UserRegistered", d.errback)
351+ self.patch(client, "UserRegistrationError", verify)
352+ client.register_with_name(APP_NAME, EMAIL, PASSWORD, NAME, CAPTCHA_ID,
353 CAPTCHA_SOLUTION)
354 return d
355

Subscribers

People subscribed via source and target branches