Merge lp:~nataliabidart/ubuntu-sso-client/no-more-deprecated-service into lp:ubuntu-sso-client
- no-more-deprecated-service
- Merge into trunk
Proposed by
Natalia Bidart
Status: | Merged |
---|---|
Approved by: | Natalia Bidart |
Approved revision: | 796 |
Merged at revision: | 796 |
Proposed branch: | lp:~nataliabidart/ubuntu-sso-client/no-more-deprecated-service |
Merge into: | lp:ubuntu-sso-client |
Diff against target: |
1346 lines (+45/-836) 9 files modified
bin/ubuntu-sso-login (+2/-3) bin/windows-ubuntu-sso-login (+1/-3) ubuntu_sso/main/__init__.py (+1/-98) ubuntu_sso/main/linux.py (+0/-107) ubuntu_sso/main/tests/test_common.py (+3/-75) ubuntu_sso/main/tests/test_linux.py (+33/-176) ubuntu_sso/main/tests/test_windows.py (+2/-189) ubuntu_sso/main/windows.py (+3/-181) ubuntu_sso/qt/controllers.py (+0/-4) |
To merge this branch: | bzr merge lp:~nataliabidart/ubuntu-sso-client/no-more-deprecated-service |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Manuel de la Peña (community) | Approve | ||
Roberto Alsina (community) | Approve | ||
Review via email: mp+77241@code.launchpad.net |
Commit message
- Removing the deprecated SSOCredentials interface (LP: #859635).
Description of the change
To post a comment you must log in.
Revision history for this message
Manuel de la Peña (mandel) wrote : | # |
About time we get these classes out :)
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'bin/ubuntu-sso-login' |
2 | --- bin/ubuntu-sso-login 2011-01-11 19:13:19 +0000 |
3 | +++ bin/ubuntu-sso-login 2011-09-27 21:50:39 +0000 |
4 | @@ -29,7 +29,7 @@ |
5 | # the locale and imports decimal, and that generates the following trace: |
6 | # Traceback (most recent call last): |
7 | # File "/usr/lib/ubuntu-sso-client/ubuntu-sso-login", line 33 |
8 | -# from ubuntu_sso.main import SSOLogin, SSOCredentials |
9 | +# from ubuntu_sso.main import SSOLogin |
10 | # File "/usr/lib/pymodules/python2.6/ubuntu_sso/main.py", line 42 |
11 | # from lazr.restfulclient.resource import ServiceRoot |
12 | # File "/usr/lib/python2.6/dist-packages/lazr/restfulclient/resource.py", |
13 | @@ -52,7 +52,7 @@ |
14 | |
15 | from ubuntu_sso import (DBUS_BUS_NAME, DBUS_ACCOUNT_PATH, DBUS_CRED_PATH, |
16 | DBUS_CREDENTIALS_PATH) |
17 | -from ubuntu_sso.main import SSOLogin, SSOCredentials, CredentialsManagement |
18 | +from ubuntu_sso.main import SSOLogin, CredentialsManagement |
19 | |
20 | from ubuntu_sso.logger import setup_logging |
21 | |
22 | @@ -93,7 +93,6 @@ |
23 | logger.info("Starting Ubuntu SSO login manager for bus %r.", DBUS_BUS_NAME) |
24 | bus_name = dbus.service.BusName(DBUS_BUS_NAME, bus=dbus.SessionBus()) |
25 | SSOLogin(bus_name, object_path=DBUS_ACCOUNT_PATH) |
26 | - SSOCredentials(bus_name, object_path=DBUS_CRED_PATH) |
27 | CredentialsManagement(timeout_func=gtk.timeout_add, |
28 | shutdown_func=gtk.main_quit, |
29 | bus_name=bus_name, object_path=DBUS_CREDENTIALS_PATH) |
30 | |
31 | === modified file 'bin/windows-ubuntu-sso-login' |
32 | --- bin/windows-ubuntu-sso-login 2011-07-22 22:00:45 +0000 |
33 | +++ bin/windows-ubuntu-sso-login 2011-09-27 21:50:39 +0000 |
34 | @@ -37,7 +37,6 @@ |
35 | from ubuntu_sso.main.windows import ( |
36 | CredentialsManagement, |
37 | LOCALHOST, |
38 | - SSOCredentials, |
39 | SSOLogin, |
40 | UbuntuSSORoot, |
41 | get_activation_config, |
42 | @@ -61,9 +60,8 @@ |
43 | port = yield ai.get_port() |
44 | |
45 | login = SSOLogin('ignored') |
46 | - creds = SSOCredentials() |
47 | creds_management = CredentialsManagement(add_timeout, reactor.stop) |
48 | - root = UbuntuSSORoot(login, creds, creds_management) |
49 | + root = UbuntuSSORoot(soo_login=login, cred_manager=creds_management) |
50 | |
51 | reactor.listenTCP(port, PBServerFactory(root), interface=LOCALHOST) |
52 | |
53 | |
54 | === modified file 'ubuntu_sso/main/__init__.py' |
55 | --- ubuntu_sso/main/__init__.py 2011-09-14 18:15:33 +0000 |
56 | +++ ubuntu_sso/main/__init__.py 2011-09-27 21:50:39 +0000 |
57 | @@ -19,11 +19,8 @@ |
58 | # with this program. If not, see <http://www.gnu.org/licenses/>. |
59 | """Main object implementations.""" |
60 | |
61 | -import os |
62 | import sys |
63 | -import warnings |
64 | |
65 | -from ubuntu_sso import NO_OP |
66 | from ubuntu_sso.account import Account |
67 | from ubuntu_sso.credentials import ( |
68 | Credentials, |
69 | @@ -37,7 +34,7 @@ |
70 | UI_MODULE_KEY, |
71 | WINDOW_ID_KEY, |
72 | ) |
73 | -from ubuntu_sso.keyring import get_token_name, U1_APP_NAME, Keyring |
74 | +from ubuntu_sso.keyring import get_token_name, Keyring |
75 | from ubuntu_sso.logger import setup_logging |
76 | |
77 | |
78 | @@ -46,20 +43,6 @@ |
79 | TIMEOUT_INTERVAL = 10000 # 10 seconds |
80 | |
81 | |
82 | -class SSOLoginProcessor(Account): |
83 | - """Login and register users using the Ubuntu Single Sign On service. |
84 | - |
85 | - Alias classname to maintain backwards compatibility. DO NOT USE, use |
86 | - ubuntu_sso.account.Account instead. |
87 | - """ |
88 | - |
89 | - def __init__(self, sso_service_class=None): |
90 | - """Create a new SSO Account manager.""" |
91 | - msg = 'Use ubuntu_sso.account.Account instead.' |
92 | - warnings.warn(msg, DeprecationWarning) |
93 | - super(SSOLoginProcessor, self).__init__(sso_service_class) |
94 | - |
95 | - |
96 | def except_to_errdict(e): |
97 | """Turn an exception into a dictionary to return thru DBus.""" |
98 | result = { |
99 | @@ -169,84 +152,6 @@ |
100 | thread_execute(f, app_name, result_cb, error_cb) |
101 | |
102 | |
103 | -class SSOCredentialsRoot(object): |
104 | - """Object that gets credentials, and login/registers if needed. |
105 | - |
106 | - This class is DEPRECATED, use CredentialsManagementRoot instead. |
107 | - |
108 | - """ |
109 | - |
110 | - def __init__(self): |
111 | - self.ping_url = os.environ.get('USSOC_PING_URL', U1_PING_URL) |
112 | - msg = 'Use ubuntu_sso.main.CredentialsManagementRoot instead.' |
113 | - warnings.warn(msg, DeprecationWarning) |
114 | - |
115 | - def find_credentials(self, app_name, callback=NO_OP, errback=NO_OP): |
116 | - """Get the credentials from the keyring or {} if not there.""" |
117 | - |
118 | - def log_result(result): |
119 | - """Log the result and continue.""" |
120 | - logger.info('find_credentials: app_name "%s", result is {}? %s', |
121 | - app_name, result == {}) |
122 | - return result |
123 | - |
124 | - d = Credentials(app_name=app_name).find_credentials() |
125 | - # pylint: disable=E1101 |
126 | - d.addCallback(log_result) |
127 | - d.addCallbacks(callback, errback) |
128 | - |
129 | - def login_or_register_to_get_credentials(self, app_name, |
130 | - terms_and_conditions_url, |
131 | - help_text, window_id, |
132 | - success_cb, error_cb, denial_cb, |
133 | - ui_module='ubuntu_sso.gtk.gui'): |
134 | - """Get credentials if found else prompt GUI to login or register. |
135 | - |
136 | - 'app_name' will be displayed in the GUI. |
137 | - 'terms_and_conditions_url' will be the URL pointing to T&C. |
138 | - 'help_text' is an explanatory text for the end-users, will be shown |
139 | - below the headers. |
140 | - 'window_id' is the id of the window which will be set as a parent of |
141 | - the GUI. If 0, no parent will be set. |
142 | - |
143 | - """ |
144 | - ping_url = self.ping_url if app_name == U1_APP_NAME else None |
145 | - obj = Credentials(app_name=app_name, ping_url=ping_url, |
146 | - tc_url=terms_and_conditions_url, |
147 | - help_text=help_text, window_id=window_id, |
148 | - success_cb=success_cb, error_cb=error_cb, |
149 | - denial_cb=denial_cb, ui_module=ui_module) |
150 | - obj.register() |
151 | - |
152 | - def login_to_get_credentials(self, app_name, help_text, window_id, |
153 | - success_cb, error_cb, denial_cb, |
154 | - ui_module='ubuntu_sso.gtk.gui'): |
155 | - """Get credentials if found else prompt GUI just to login |
156 | - |
157 | - 'app_name' will be displayed in the GUI. |
158 | - 'help_text' is an explanatory text for the end-users, will be shown |
159 | - before the login fields. |
160 | - 'window_id' is the id of the window which will be set as a parent of |
161 | - the GUI. If 0, no parent will be set. |
162 | - |
163 | - """ |
164 | - ping_url = self.ping_url if app_name == U1_APP_NAME else None |
165 | - obj = Credentials(app_name=app_name, ping_url=ping_url, tc_url=None, |
166 | - help_text=help_text, window_id=window_id, |
167 | - success_cb=success_cb, error_cb=error_cb, |
168 | - denial_cb=denial_cb, ui_module=ui_module) |
169 | - obj.login() |
170 | - |
171 | - def clear_token(self, app_name, callback=NO_OP, errback=NO_OP): |
172 | - """Clear the token for an application from the keyring. |
173 | - |
174 | - 'app_name' is the name of the application. |
175 | - """ |
176 | - d = Credentials(app_name=app_name).clear_credentials() |
177 | - # pylint: disable=E1101 |
178 | - d.addCallbacks(lambda _: callback(), errback) |
179 | - |
180 | - |
181 | class CredentialsManagementRoot(object): |
182 | """Object that manages credentials. |
183 | |
184 | @@ -434,7 +339,6 @@ |
185 | if sys.platform == 'win32': |
186 | from ubuntu_sso.main import windows |
187 | SSOLogin = windows.SSOLogin |
188 | - SSOCredentials = windows.SSOCredentials |
189 | CredentialsManagement = windows.CredentialsManagement |
190 | TIMEOUT_INTERVAL = 10000000000 # forever |
191 | thread_execute = windows.blocking |
192 | @@ -442,7 +346,6 @@ |
193 | else: |
194 | from ubuntu_sso.main import linux |
195 | SSOLogin = linux.SSOLogin |
196 | - SSOCredentials = linux.SSOCredentials |
197 | CredentialsManagement = linux.CredentialsManagement |
198 | thread_execute = linux.blocking |
199 | get_sso_login_backend = linux.get_sso_login_backend |
200 | |
201 | === modified file 'ubuntu_sso/main/linux.py' |
202 | --- ubuntu_sso/main/linux.py 2011-09-14 18:15:33 +0000 |
203 | +++ ubuntu_sso/main/linux.py 2011-09-27 21:50:39 +0000 |
204 | @@ -28,24 +28,19 @@ |
205 | """ |
206 | |
207 | import threading |
208 | -import warnings |
209 | |
210 | import dbus.service |
211 | |
212 | from ubuntu_sso import ( |
213 | DBUS_ACCOUNT_PATH, |
214 | DBUS_CREDENTIALS_IFACE, |
215 | - DBUS_IFACE_CRED_NAME, |
216 | DBUS_IFACE_USER_NAME, |
217 | - NO_OP, |
218 | ) |
219 | from ubuntu_sso.account import Account |
220 | -from ubuntu_sso.credentials import ERROR_KEY, ERROR_DETAIL_KEY |
221 | from ubuntu_sso.logger import setup_logging |
222 | from ubuntu_sso.main import ( |
223 | CredentialsManagementRoot, |
224 | SSOLoginRoot, |
225 | - SSOCredentialsRoot, |
226 | except_to_errdict, |
227 | ) |
228 | |
229 | @@ -83,8 +78,6 @@ |
230 | dbus.service.Object.__init__(self, object_path=object_path, |
231 | bus_name=bus_name) |
232 | self.root = SSOLoginRoot(sso_login_processor_class, sso_service_class) |
233 | - msg = 'Use ubuntu_sso.main.CredentialsManagement instead.' |
234 | - warnings.warn(msg, DeprecationWarning) |
235 | |
236 | # generate_capcha signals |
237 | @dbus.service.signal(DBUS_IFACE_USER_NAME, signature="ss") |
238 | @@ -220,106 +213,6 @@ |
239 | self.PasswordChangeError) |
240 | |
241 | |
242 | -class SSOCredentials(dbus.service.Object): |
243 | - """DBus object that gets credentials, and login/registers if needed. |
244 | - |
245 | - This class is Deprecated. DO NOT USE, use CredentialsManagement instead. |
246 | - |
247 | - """ |
248 | - |
249 | - # Operator not preceded by a space (fails with dbus decorators) |
250 | - # pylint: disable=C0322 |
251 | - |
252 | - def __init__(self, *args, **kwargs): |
253 | - dbus.service.Object.__init__(self, *args, **kwargs) |
254 | - self.root = SSOCredentialsRoot() |
255 | - warnings.warn('%r DBus object is deprecated, please use %r instead.' % |
256 | - (DBUS_IFACE_CRED_NAME, DBUS_CREDENTIALS_IFACE), |
257 | - DeprecationWarning) |
258 | - |
259 | - def _process_error(self, app_name, error_dict): |
260 | - """Process the 'error_dict' and emit CredentialsError.""" |
261 | - msg = error_dict.get(ERROR_KEY, 'No error message given.') |
262 | - detail = error_dict.get(ERROR_DETAIL_KEY, 'No detailed error given.') |
263 | - self.CredentialsError(app_name, msg, detail) |
264 | - |
265 | - @dbus.service.signal(DBUS_IFACE_CRED_NAME, signature="s") |
266 | - def AuthorizationDenied(self, app_name): |
267 | - """Signal thrown when the user denies the authorization.""" |
268 | - logger.info('SSOCredentials: emitting AuthorizationDenied with ' |
269 | - 'app_name "%s"', app_name) |
270 | - |
271 | - @dbus.service.signal(DBUS_IFACE_CRED_NAME, signature="sa{ss}") |
272 | - def CredentialsFound(self, app_name, credentials): |
273 | - """Signal thrown when the credentials are found.""" |
274 | - logger.info('SSOCredentials: emitting CredentialsFound with ' |
275 | - 'app_name "%s"', app_name) |
276 | - |
277 | - @dbus.service.signal(DBUS_IFACE_CRED_NAME, signature="sss") |
278 | - def CredentialsError(self, app_name, error_message, detailed_error): |
279 | - """Signal thrown when there is a problem finding the credentials.""" |
280 | - logger.error('SSOCredentials: emitting CredentialsError with app_name ' |
281 | - '"%s" and error_message %r', app_name, error_message) |
282 | - |
283 | - @dbus.service.method(dbus_interface=DBUS_IFACE_CRED_NAME, |
284 | - in_signature="s", out_signature="a{ss}", |
285 | - async_callbacks=("callback", "errback")) |
286 | - def find_credentials(self, app_name, callback=NO_OP, errback=NO_OP): |
287 | - """Get the credentials from the keyring or {} if not there.""" |
288 | - self.root.find_credentials(app_name, callback, errback) |
289 | - |
290 | - @dbus.service.method(dbus_interface=DBUS_IFACE_CRED_NAME, |
291 | - in_signature="sssx", out_signature="") |
292 | - def login_or_register_to_get_credentials(self, app_name, |
293 | - terms_and_conditions_url, |
294 | - help_text, window_id): |
295 | - """Get credentials if found else prompt GUI to login or register. |
296 | - |
297 | - 'app_name' will be displayed in the GUI. |
298 | - 'terms_and_conditions_url' will be the URL pointing to T&C. |
299 | - 'help_text' is an explanatory text for the end-users, will be shown |
300 | - below the headers. |
301 | - 'window_id' is the id of the window which will be set as a parent of |
302 | - the GUI. If 0, no parent will be set. |
303 | - |
304 | - """ |
305 | - self.root.login_or_register_to_get_credentials(app_name, |
306 | - terms_and_conditions_url, |
307 | - help_text, window_id, |
308 | - self.CredentialsFound, |
309 | - self._process_error, |
310 | - self.AuthorizationDenied, |
311 | - ui_module='ubuntu_sso.gtk.gui') |
312 | - |
313 | - @dbus.service.method(dbus_interface=DBUS_IFACE_CRED_NAME, |
314 | - in_signature="ssx", out_signature="") |
315 | - def login_to_get_credentials(self, app_name, help_text, window_id): |
316 | - """Get credentials if found else prompt GUI just to login |
317 | - |
318 | - 'app_name' will be displayed in the GUI. |
319 | - 'help_text' is an explanatory text for the end-users, will be shown |
320 | - before the login fields. |
321 | - 'window_id' is the id of the window which will be set as a parent of |
322 | - the GUI. If 0, no parent will be set. |
323 | - |
324 | - """ |
325 | - self.root.login_to_get_credentials(app_name, help_text, window_id, |
326 | - self.CredentialsFound, |
327 | - self._process_error, |
328 | - self.AuthorizationDenied, |
329 | - ui_module='ubuntu_sso.gtk.gui') |
330 | - |
331 | - @dbus.service.method(dbus_interface=DBUS_IFACE_CRED_NAME, |
332 | - in_signature='s', out_signature='', |
333 | - async_callbacks=("callback", "errback")) |
334 | - def clear_token(self, app_name, callback=NO_OP, errback=NO_OP): |
335 | - """Clear the token for an application from the keyring. |
336 | - |
337 | - 'app_name' is the name of the application. |
338 | - """ |
339 | - self.root.clear_token(app_name, callback, errback) |
340 | - |
341 | - |
342 | class CredentialsManagement(dbus.service.Object): |
343 | """DBus object that manages credentials. |
344 | |
345 | |
346 | === modified file 'ubuntu_sso/main/tests/test_common.py' |
347 | --- ubuntu_sso/main/tests/test_common.py 2011-08-22 16:21:36 +0000 |
348 | +++ ubuntu_sso/main/tests/test_common.py 2011-09-27 21:50:39 +0000 |
349 | @@ -21,39 +21,14 @@ |
350 | # with this program. If not, see <http://www.gnu.org/licenses/>. |
351 | """Tests share by diff platforms.""" |
352 | |
353 | -import os |
354 | - |
355 | from unittest import TestCase |
356 | + |
357 | from mocker import MockerTestCase, MATCH |
358 | + |
359 | from ubuntu_sso.main import ( |
360 | CredentialsManagement, |
361 | - SSOCredentialsRoot, |
362 | - SSOCredentials, |
363 | SSOLogin, |
364 | - U1_PING_URL) |
365 | - |
366 | - |
367 | -class EnvironOverridesTestCase(TestCase): |
368 | - """Some URLs can be set from the environment for testing/QA purposes.""" |
369 | - |
370 | - def test_override_ping_url(self): |
371 | - """The ping url can be set from the environ via USSOC_PING_URL.""" |
372 | - fake_url = 'this is not really a URL' |
373 | - old_url = os.environ.get('USSOC_PING_URL') |
374 | - os.environ['USSOC_PING_URL'] = fake_url |
375 | - try: |
376 | - creds = SSOCredentialsRoot() |
377 | - self.assertEqual(creds.ping_url, fake_url) |
378 | - finally: |
379 | - if old_url: |
380 | - os.environ['USSOC_PING_URL'] = old_url |
381 | - else: |
382 | - del os.environ['USSOC_PING_URL'] |
383 | - |
384 | - def test_no_override_ping_url(self): |
385 | - """If the environ is unset, the default ping url is used.""" |
386 | - creds = SSOCredentialsRoot() |
387 | - self.assertEqual(creds.ping_url, U1_PING_URL) |
388 | +) |
389 | |
390 | |
391 | class SSOLoginMockedTestCase(MockerTestCase): |
392 | @@ -142,53 +117,6 @@ |
393 | self.login.set_new_password(app_name, email, token, new_password) |
394 | |
395 | |
396 | -class SSOCredentialsMockedTestCase(MockerTestCase): |
397 | - """Test that the call are relied correctly.""" |
398 | - |
399 | - def setUp(self): |
400 | - """Setup tests.""" |
401 | - super(SSOCredentialsMockedTestCase, self).setUp() |
402 | - self.root = self.mocker.mock() |
403 | - mockbusname = self.mocker.mock() |
404 | - mockbus = self.mocker.mock() |
405 | - mockbusname.get_bus() |
406 | - self.mocker.result(mockbus) |
407 | - self.cred = SSOCredentials(mockbus) |
408 | - self.cred.root = self.root |
409 | - self.mocker.reset() |
410 | - |
411 | - def test_find_credentials(self): |
412 | - """Test that the call is relayed.""" |
413 | - app_name = 'app' |
414 | - result_cb = error_cb = lambda: None |
415 | - self.root.find_credentials(app_name, MATCH(callable), MATCH(callable)) |
416 | - self.mocker.mock() |
417 | - self.mocker.replay() |
418 | - self.cred.find_credentials(app_name, result_cb, error_cb) |
419 | - |
420 | - def test_login_or_register_to_get_credentials(self): |
421 | - """Test that the call is relayed.""" |
422 | - app_name = 'app' |
423 | - terms = 'terms' |
424 | - help_text = 'help' |
425 | - window_id = 'id' |
426 | - self.root.login_or_register_to_get_credentials(app_name, terms, |
427 | - help_text, window_id, MATCH(callable), |
428 | - MATCH(callable), MATCH(callable), |
429 | - ui_module=MATCH(lambda x: isinstance(x, str))) |
430 | - self.mocker.replay() |
431 | - self.cred.login_or_register_to_get_credentials(app_name, terms, |
432 | - help_text, window_id) |
433 | - |
434 | - def test_clear_token(self): |
435 | - """Test that the call is relayed.""" |
436 | - app_name = 'app' |
437 | - result_cb = error_cb = lambda: None |
438 | - self.root.clear_token(app_name, MATCH(callable), MATCH(callable)) |
439 | - self.mocker.replay() |
440 | - self.cred.clear_token(app_name, result_cb, error_cb) |
441 | - |
442 | - |
443 | class CredentialsManagementMockedTestCase(MockerTestCase, TestCase): |
444 | """Test that the call are relied correctly.""" |
445 | |
446 | |
447 | === modified file 'ubuntu_sso/main/tests/test_linux.py' |
448 | --- ubuntu_sso/main/tests/test_linux.py 2011-08-22 16:21:36 +0000 |
449 | +++ ubuntu_sso/main/tests/test_linux.py 2011-09-27 21:50:39 +0000 |
450 | @@ -21,11 +21,9 @@ |
451 | """Tests for the main SSO client code.""" |
452 | |
453 | import logging |
454 | -import os |
455 | |
456 | -from mocker import Mocker, MockerTestCase, ARGS, KWARGS, MATCH |
457 | +from mocker import Mocker, ARGS, KWARGS |
458 | from twisted.internet import defer |
459 | -from twisted.internet.defer import Deferred, inlineCallbacks |
460 | from twisted.trial.unittest import TestCase |
461 | from ubuntuone.devtools.handlers import MementoHandler |
462 | |
463 | @@ -34,9 +32,12 @@ |
464 | import ubuntu_sso.main.linux |
465 | |
466 | from ubuntu_sso import DBUS_CREDENTIALS_IFACE |
467 | -from ubuntu_sso.keyring import U1_APP_NAME |
468 | -from ubuntu_sso.main import (U1_PING_URL, except_to_errdict, |
469 | - CredentialsManagement, SSOCredentials, SSOLogin, TIMEOUT_INTERVAL) |
470 | +from ubuntu_sso.main import ( |
471 | + except_to_errdict, |
472 | + CredentialsManagement, |
473 | + SSOLogin, |
474 | + TIMEOUT_INTERVAL, |
475 | +) |
476 | from ubuntu_sso.main.linux import blocking |
477 | from ubuntu_sso.main import (HELP_TEXT_KEY, PING_URL_KEY, |
478 | TC_URL_KEY, UI_CLASS_KEY, UI_MODULE_KEY, WINDOW_ID_KEY, |
479 | @@ -116,7 +117,7 @@ |
480 | |
481 | def test_generate_captcha(self): |
482 | """Test that the captcha method works ok.""" |
483 | - d = Deferred() |
484 | + d = defer.Deferred() |
485 | filename = "sample filename" |
486 | expected_result = "expected result" |
487 | self.create_mock_processor().generate_captcha(filename) |
488 | @@ -139,7 +140,7 @@ |
489 | |
490 | def test_generate_captcha_error(self): |
491 | """Test that the captcha method fails as expected.""" |
492 | - d = Deferred() |
493 | + d = defer.Deferred() |
494 | filename = "sample filename" |
495 | expected_result = "expected result" |
496 | self.create_mock_processor().generate_captcha(filename) |
497 | @@ -162,7 +163,7 @@ |
498 | |
499 | def test_register_user(self): |
500 | """Test that the register_user method works ok.""" |
501 | - d = Deferred() |
502 | + d = defer.Deferred() |
503 | expected_result = "expected result" |
504 | self.create_mock_processor().register_user(EMAIL, PASSWORD, NAME, |
505 | CAPTCHA_ID, CAPTCHA_SOLUTION) |
506 | @@ -186,7 +187,7 @@ |
507 | |
508 | def test_register_user_error(self): |
509 | """Test that the register_user method fails as expected.""" |
510 | - d = Deferred() |
511 | + d = defer.Deferred() |
512 | expected_result = "expected result" |
513 | self.create_mock_processor().register_user(EMAIL, PASSWORD, NAME, |
514 | CAPTCHA_ID, CAPTCHA_SOLUTION) |
515 | @@ -210,7 +211,7 @@ |
516 | |
517 | def test_login(self): |
518 | """Test that the login method works ok.""" |
519 | - d = Deferred() |
520 | + d = defer.Deferred() |
521 | processor = self.create_mock_processor() |
522 | processor.login(EMAIL, PASSWORD, TOKEN_NAME) |
523 | self.mocker.result(TOKEN) |
524 | @@ -236,7 +237,7 @@ |
525 | |
526 | def test_login_user_not_validated(self): |
527 | """Test that the login sends EmailNotValidated signal.""" |
528 | - d = Deferred() |
529 | + d = defer.Deferred() |
530 | processor = self.create_mock_processor() |
531 | processor.login(EMAIL, PASSWORD, TOKEN_NAME) |
532 | self.mocker.result(TOKEN) |
533 | @@ -262,7 +263,7 @@ |
534 | |
535 | def test_login_error_get_token_name(self): |
536 | """The login method fails as expected when get_token_name fails.""" |
537 | - d = Deferred() |
538 | + d = defer.Deferred() |
539 | self.create_mock_processor() |
540 | self.patch(ubuntu_sso.main.linux, "blocking", fake_err_blocking) |
541 | |
542 | @@ -290,7 +291,7 @@ |
543 | |
544 | def test_login_error_set_credentials(self): |
545 | """The login method fails as expected when set_credentials fails.""" |
546 | - d = Deferred() |
547 | + d = defer.Deferred() |
548 | processor = self.create_mock_processor() |
549 | processor.login(EMAIL, PASSWORD, TOKEN_NAME) |
550 | self.mocker.result(TOKEN) |
551 | @@ -324,7 +325,7 @@ |
552 | |
553 | def test_validate_email(self): |
554 | """Test that the validate_email method works ok.""" |
555 | - d = Deferred() |
556 | + d = defer.Deferred() |
557 | self.create_mock_processor().validate_email(EMAIL, PASSWORD, |
558 | EMAIL_TOKEN, TOKEN_NAME) |
559 | self.mocker.result(TOKEN) |
560 | @@ -347,7 +348,7 @@ |
561 | |
562 | def test_validate_email_error(self): |
563 | """Test that the validate_email method fails as expected.""" |
564 | - d = Deferred() |
565 | + d = defer.Deferred() |
566 | self.create_mock_processor() |
567 | self.patch(ubuntu_sso.main.linux, "blocking", fake_err_blocking) |
568 | |
569 | @@ -374,7 +375,7 @@ |
570 | |
571 | def test_request_password_reset_token(self): |
572 | """Test that the request_password_reset_token method works ok.""" |
573 | - d = Deferred() |
574 | + d = defer.Deferred() |
575 | processor = self.create_mock_processor() |
576 | processor.request_password_reset_token(EMAIL) |
577 | self.patch(ubuntu_sso.main, "thread_execute", fake_ok_blocking) |
578 | @@ -396,7 +397,7 @@ |
579 | |
580 | def test_request_password_reset_token_error(self): |
581 | """Test the request_password_reset_token method fails as expected.""" |
582 | - d = Deferred() |
583 | + d = defer.Deferred() |
584 | |
585 | self.create_mock_processor().request_password_reset_token(EMAIL) |
586 | self.mocker.result(EMAIL) |
587 | @@ -418,7 +419,7 @@ |
588 | |
589 | def test_set_new_password(self): |
590 | """Test that the set_new_password method works ok.""" |
591 | - d = Deferred() |
592 | + d = defer.Deferred() |
593 | self.create_mock_processor().set_new_password(EMAIL, EMAIL_TOKEN, |
594 | PASSWORD) |
595 | self.mocker.result(EMAIL) |
596 | @@ -440,7 +441,7 @@ |
597 | |
598 | def test_set_new_password_error(self): |
599 | """Test that the set_new_password method fails as expected.""" |
600 | - d = Deferred() |
601 | + d = defer.Deferred() |
602 | expected_result = "expected result" |
603 | |
604 | self.create_mock_processor().set_new_password(EMAIL, EMAIL_TOKEN, |
605 | @@ -470,7 +471,7 @@ |
606 | |
607 | def test_blocking(self): |
608 | """Test the normal behaviour.""" |
609 | - d = Deferred() |
610 | + d = defer.Deferred() |
611 | expected_result = "expected result" |
612 | |
613 | def f(): |
614 | @@ -488,7 +489,7 @@ |
615 | |
616 | def test_blocking_error(self): |
617 | """Test the behaviour when an Exception is raised.""" |
618 | - d = Deferred() |
619 | + d = defer.Deferred() |
620 | expected_error_message = "expected error message" |
621 | |
622 | def f(): |
623 | @@ -559,150 +560,6 @@ |
624 | self.assertEqual(result["errtype"], e.__class__.__name__) |
625 | |
626 | |
627 | -class RegisterSampleException(Exception): |
628 | - """A mock exception thrown just when testing.""" |
629 | - |
630 | - |
631 | -class ApplicationCredentialsTestCase(TestCase, MockerTestCase): |
632 | - """Tests for the ApplicationCredentials related DBus methods.""" |
633 | - |
634 | - timeout = 5 |
635 | - |
636 | - def setUp(self): |
637 | - MockerTestCase.setUp(self) |
638 | - |
639 | - self.client = SSOCredentials(self.mocker.mock()) |
640 | - |
641 | - mock_class = self.mocker.replace("ubuntu_sso.credentials.Credentials") |
642 | - mock_class(app_name=APP_NAME) |
643 | - self.creds_obj = self.mocker.mock() |
644 | - self.mocker.result(self.creds_obj) |
645 | - |
646 | - @inlineCallbacks |
647 | - def test_find_credentials(self): |
648 | - """find_credentials immediately returns the token when found.""" |
649 | - expected_creds = "expected creds" |
650 | - self.creds_obj.find_credentials() |
651 | - self.mocker.result(defer.succeed(expected_creds)) |
652 | - self.mocker.replay() |
653 | - |
654 | - d = Deferred() |
655 | - self.client.find_credentials(APP_NAME, d.callback, d.errback) |
656 | - creds = yield d |
657 | - self.assertEqual(creds, expected_creds) |
658 | - |
659 | - @inlineCallbacks |
660 | - def test_credentials_not_found(self): |
661 | - """find_credentials immediately returns {} when no creds found.""" |
662 | - expected_creds = {} |
663 | - self.creds_obj.find_credentials() |
664 | - self.mocker.result(defer.succeed(expected_creds)) |
665 | - self.mocker.replay() |
666 | - |
667 | - d = Deferred() |
668 | - self.client.find_credentials(APP_NAME, d.callback, d.errback) |
669 | - creds = yield d |
670 | - self.assertEqual(creds, expected_creds) |
671 | - |
672 | - |
673 | -class ApplicationCredentialsGUITestCase(TestCase, MockerTestCase): |
674 | - """Tests for the ApplicationCredentials register/login DBus method.""" |
675 | - |
676 | - app_name = APP_NAME |
677 | - ping_url = None |
678 | - |
679 | - def setUp(self): |
680 | - MockerTestCase.setUp(self) |
681 | - self.client = SSOCredentials(self.mocker.mock()) |
682 | - self.args = {PING_URL_KEY: self.ping_url, |
683 | - TC_URL_KEY: TC_URL, HELP_TEXT_KEY: HELP_TEXT, |
684 | - WINDOW_ID_KEY: WINDOW_ID, |
685 | - SUCCESS_CB_KEY: self.client.CredentialsFound, |
686 | - ERROR_CB_KEY: self.client._process_error, |
687 | - DENIAL_CB_KEY: self.client.AuthorizationDenied} |
688 | - |
689 | - def test_login_or_register(self): |
690 | - """login_or_register is correct.""" |
691 | - self.args[UI_MODULE_KEY] = MATCH(lambda x: isinstance(x, str)) |
692 | - mock_class = self.mocker.replace("ubuntu_sso.credentials.Credentials") |
693 | - mock_class(app_name=self.app_name, **self.args) |
694 | - creds_obj = self.mocker.mock() |
695 | - self.mocker.result(creds_obj) |
696 | - |
697 | - creds_obj.register() |
698 | - self.mocker.replay() |
699 | - |
700 | - args = (self.app_name, TC_URL, HELP_TEXT, WINDOW_ID) |
701 | - self.client.login_or_register_to_get_credentials(*args) |
702 | - |
703 | - def test_login_only(self): |
704 | - """login_or_register is correct.""" |
705 | - self.args[TC_URL_KEY] = None |
706 | - self.args[UI_MODULE_KEY] = MATCH(lambda x: isinstance(x, str)) |
707 | - mock_class = self.mocker.replace("ubuntu_sso.credentials.Credentials") |
708 | - mock_class(app_name=self.app_name, **self.args) |
709 | - creds_obj = self.mocker.mock() |
710 | - self.mocker.result(creds_obj) |
711 | - |
712 | - creds_obj.login() |
713 | - self.mocker.replay() |
714 | - |
715 | - args = (self.app_name, HELP_TEXT, WINDOW_ID) |
716 | - self.client.login_to_get_credentials(*args) |
717 | - |
718 | - |
719 | -class ApplicationCredentialsU1TestCase(ApplicationCredentialsGUITestCase): |
720 | - """Tests for the ApplicationCredentials register/login DBus method. |
721 | - |
722 | - Specifically for APP_NAME == U1_APP_NAME. |
723 | - |
724 | - """ |
725 | - |
726 | - app_name = U1_APP_NAME |
727 | - ping_url = U1_PING_URL |
728 | - |
729 | - |
730 | -class ApplicationCredentialsClearTokenTestCase(TestCase, MockerTestCase): |
731 | - """Tests for the ApplicationCredentials related DBus methods.""" |
732 | - |
733 | - def test_clear_token(self): |
734 | - """Check that clear_token tries removing the correct token.""" |
735 | - mock_class = self.mocker.replace("ubuntu_sso.credentials.Credentials") |
736 | - mock_class(app_name=APP_NAME) |
737 | - creds_obj = self.mocker.mock() |
738 | - self.mocker.result(creds_obj) |
739 | - |
740 | - creds_obj.clear_credentials() |
741 | - self.mocker.result(defer.succeed(None)) |
742 | - self.mocker.replay() |
743 | - |
744 | - client = SSOCredentials(self.mocker.mock()) |
745 | - client.clear_token(APP_NAME) |
746 | - |
747 | - |
748 | -class EnvironOverridesTestCase(TestCase): |
749 | - """Some URLs can be set from the environment for testing/QA purposes.""" |
750 | - |
751 | - def test_override_ping_url(self): |
752 | - """The ping url can be set from the environ via USSOC_PING_URL.""" |
753 | - fake_url = 'this is not really a URL' |
754 | - old_url = os.environ.get('USSOC_PING_URL') |
755 | - os.environ['USSOC_PING_URL'] = fake_url |
756 | - try: |
757 | - creds = SSOCredentials(None) |
758 | - self.assertEqual(creds.root.ping_url, fake_url) |
759 | - finally: |
760 | - if old_url: |
761 | - os.environ['USSOC_PING_URL'] = old_url |
762 | - else: |
763 | - del os.environ['USSOC_PING_URL'] |
764 | - |
765 | - def test_no_override_ping_url(self): |
766 | - """If the environ is unset, the default ping url is used.""" |
767 | - creds = SSOCredentials(None) |
768 | - self.assertEqual(creds.root.ping_url, U1_PING_URL) |
769 | - |
770 | - |
771 | class CredentialsManagementTestCase(TestCase): |
772 | """Tests for the CredentialsManagement DBus interface.""" |
773 | |
774 | @@ -776,7 +633,7 @@ |
775 | |
776 | def test_find_credentials(self): |
777 | """Keep proper track of on going requests.""" |
778 | - d = Deferred() |
779 | + d = defer.Deferred() |
780 | |
781 | def verify(*args): |
782 | """Make the check.""" |
783 | @@ -790,7 +647,7 @@ |
784 | |
785 | def test_clear_credentials(self): |
786 | """Keep proper track of on going requests.""" |
787 | - d = Deferred() |
788 | + d = defer.Deferred() |
789 | |
790 | def verify(*args): |
791 | """Make the check.""" |
792 | @@ -804,7 +661,7 @@ |
793 | |
794 | def test_store_credentials(self): |
795 | """Keep proper track of on going requests.""" |
796 | - d = Deferred() |
797 | + d = defer.Deferred() |
798 | |
799 | def verify(*args): |
800 | """Make the check.""" |
801 | @@ -1004,7 +861,7 @@ |
802 | If the creds are found, CredentialsFound is emitted. |
803 | |
804 | """ |
805 | - d = Deferred() |
806 | + d = defer.Deferred() |
807 | |
808 | def verify(app_name, creds): |
809 | """The actual test.""" |
810 | @@ -1032,7 +889,7 @@ |
811 | If the creds are not found, CredentialsNotFound is emitted. |
812 | |
813 | """ |
814 | - d = Deferred() |
815 | + d = defer.Deferred() |
816 | |
817 | def verify(app_name): |
818 | """The actual test.""" |
819 | @@ -1056,7 +913,7 @@ |
820 | |
821 | def test_find_credentials_error(self): |
822 | """If find_credentials fails, CredentialsError is sent.""" |
823 | - d = Deferred() |
824 | + d = defer.Deferred() |
825 | |
826 | def verify(app_name, errdict): |
827 | """The actual test.""" |
828 | @@ -1091,7 +948,7 @@ |
829 | |
830 | def test_clear_credentials_does_not_block(self): |
831 | """Calling clear_credentials does not block but return thru signals.""" |
832 | - d = Deferred() |
833 | + d = defer.Deferred() |
834 | |
835 | def verify(app_name): |
836 | """The actual test.""" |
837 | @@ -1115,7 +972,7 @@ |
838 | |
839 | def test_clear_credentials_error(self): |
840 | """If clear_credentials fails, CredentialsError is sent.""" |
841 | - d = Deferred() |
842 | + d = defer.Deferred() |
843 | |
844 | def verify(app_name, errdict): |
845 | """The actual test.""" |
846 | @@ -1152,7 +1009,7 @@ |
847 | If the creds are stored, CredentialsStored is emitted. |
848 | |
849 | """ |
850 | - d = Deferred() |
851 | + d = defer.Deferred() |
852 | |
853 | def verify(app_name): |
854 | """The actual test.""" |
855 | @@ -1176,7 +1033,7 @@ |
856 | |
857 | def test_store_credentials_error(self): |
858 | """If store_credentials fails, CredentialsError is sent.""" |
859 | - d = Deferred() |
860 | + d = defer.Deferred() |
861 | |
862 | def verify(app_name, errdict): |
863 | """The actual test.""" |
864 | |
865 | === modified file 'ubuntu_sso/main/tests/test_windows.py' |
866 | --- ubuntu_sso/main/tests/test_windows.py 2011-09-14 18:21:11 +0000 |
867 | +++ ubuntu_sso/main/tests/test_windows.py 2011-09-27 21:50:39 +0000 |
868 | @@ -37,8 +37,6 @@ |
869 | CredentialsManagementClient, |
870 | LOCALHOST, |
871 | SignalBroadcaster, |
872 | - SSOCredentials, |
873 | - SSOCredentialsClient, |
874 | SSOLogin, |
875 | SSOLoginClient, |
876 | UbuntuSSORoot, |
877 | @@ -269,7 +267,7 @@ |
878 | self.root = self.mocker.mock() |
879 | self.login = SSOLogin(None) |
880 | # start pb |
881 | - self.sso_root = UbuntuSSORoot(self.login, None, None) |
882 | + self.sso_root = UbuntuSSORoot(sso_login=self.login) |
883 | self.server_factory = SaveProtocolServerFactory(self.sso_root) |
884 | # pylint: disable=E1101 |
885 | port = get_sso_pb_port() |
886 | @@ -542,191 +540,6 @@ |
887 | self.mocker.verify() |
888 | |
889 | |
890 | -class SSOCredentialsTestCase(TestCase): |
891 | - """Test the credentials class.""" |
892 | - |
893 | - @defer.inlineCallbacks |
894 | - def setUp(self): |
895 | - """Set up tests.""" |
896 | - yield super(SSOCredentialsTestCase, self).setUp() |
897 | - self.mocker = Mocker() |
898 | - self.root = self.mocker.mock() |
899 | - self.except_to_errdict = self.mocker.replace( |
900 | - 'ubuntu_sso.main.except_to_errdict') |
901 | - self.creds = SSOCredentials(None) |
902 | - self.creds.root = self.root |
903 | - # start pb |
904 | - self.sso_root = UbuntuSSORoot(None, self.creds, None) |
905 | - self.server_factory = SaveProtocolServerFactory(self.sso_root) |
906 | - # pylint: disable=E1101 |
907 | - port = get_sso_pb_port() |
908 | - self.listener = reactor.listenTCP(port, self.server_factory) |
909 | - self.client_factory = PBClientFactory() |
910 | - self.connector = reactor.connectTCP(LOCALHOST, port, |
911 | - self.client_factory) |
912 | - self.client = yield self._get_client() |
913 | - # pylint: enable=E1101 |
914 | - |
915 | - def tearDown(self): |
916 | - """Clean reactor.""" |
917 | - if self.server_factory.protocolInstance is not None: |
918 | - self.server_factory.protocolInstance.transport.loseConnection() |
919 | - return defer.gatherResults([self._tearDownServer(), |
920 | - self._tearDownClient()]) |
921 | - |
922 | - def _tearDownServer(self): |
923 | - """Teardown the server.""" |
924 | - return defer.maybeDeferred(self.listener.stopListening) |
925 | - |
926 | - def _tearDownClient(self): |
927 | - """Tear down the client.""" |
928 | - self.connector.disconnect() |
929 | - return defer.succeed(None) |
930 | - |
931 | - @defer.inlineCallbacks |
932 | - def _get_client(self): |
933 | - """Get the client.""" |
934 | - # request the remote object and create a client |
935 | - root = yield self.client_factory.getRootObject() |
936 | - remote = yield root.callRemote('get_sso_credentials') |
937 | - client = SSOCredentialsClient(remote) |
938 | - yield client.register_to_signals() |
939 | - # set the cb |
940 | - for signal_name in ['on_authorization_denied_cb', |
941 | - 'on_credentials_found_cb', |
942 | - 'on_credentials_error_cb']: |
943 | - setattr(client, signal_name, self.mocker.mock()) |
944 | - defer.returnValue(client) |
945 | - |
946 | - @defer.inlineCallbacks |
947 | - def test_emit_authorization_denied(self): |
948 | - """Test that the cb is executed.""" |
949 | - app_name = 'app' |
950 | - |
951 | - self.client.on_authorization_denied_cb(app_name) |
952 | - self.mocker.replay() |
953 | - self.creds.emit_authorization_denied(app_name) |
954 | - yield self.client.unregister_to_signals() |
955 | - self.mocker.verify() |
956 | - |
957 | - @defer.inlineCallbacks |
958 | - def test_emit_credentials_found(self): |
959 | - """Test that the cb was executed.""" |
960 | - app_name = 'app' |
961 | - credentials = 'cred' |
962 | - |
963 | - self.client.on_credentials_found_cb(app_name, credentials) |
964 | - self.mocker.replay() |
965 | - self.creds.emit_credentials_found(app_name, credentials) |
966 | - yield self.client.unregister_to_signals() |
967 | - self.mocker.verify() |
968 | - |
969 | - @defer.inlineCallbacks |
970 | - def test_emit_credentials_error(self): |
971 | - """Test that the cb was executed.""" |
972 | - app_name = 'app' |
973 | - raised_error = 'error' |
974 | - detail = 'detail' |
975 | - |
976 | - self.client.on_credentials_error_cb(app_name, raised_error, detail) |
977 | - self.mocker.replay() |
978 | - self.creds.emit_credentials_error(app_name, raised_error, detail) |
979 | - yield self.client.unregister_to_signals() |
980 | - self.mocker.verify() |
981 | - |
982 | - @defer.inlineCallbacks |
983 | - def test_find_credentials_no_kword(self): |
984 | - """Ensure that the root is called.""" |
985 | - app_name = 'app' |
986 | - callback = lambda: None |
987 | - errback = lambda: None |
988 | - |
989 | - self.root.find_credentials(app_name, MATCH(callable), |
990 | - MATCH(callable)) |
991 | - self.mocker.replay() |
992 | - yield self.client.find_credentials(app_name, callback, errback) |
993 | - yield self.client.unregister_to_signals() |
994 | - |
995 | - @defer.inlineCallbacks |
996 | - def test_find_credentials_(self): |
997 | - """Ensure that the root is called.""" |
998 | - app_name = 'app' |
999 | - callback = lambda: None |
1000 | - errback = lambda: None |
1001 | - |
1002 | - self.root.find_credentials(app_name, MATCH(callable), |
1003 | - MATCH(callable)) |
1004 | - self.mocker.replay() |
1005 | - yield self.client.find_credentials(app_name, callback=callback, |
1006 | - errback=errback) |
1007 | - yield self.client.unregister_to_signals() |
1008 | - |
1009 | - @defer.inlineCallbacks |
1010 | - def test_login_or_register_to_get_credentials(self): |
1011 | - """Ensure that the root is called.""" |
1012 | - app_name = 'app' |
1013 | - terms = 'terms' |
1014 | - help_txt = 'help' |
1015 | - window_id = 'window_id' |
1016 | - |
1017 | - # pylint: disable=W0212 |
1018 | - self.root.login_or_register_to_get_credentials(app_name, terms, |
1019 | - help_txt, window_id, |
1020 | - self.creds.emit_credentials_found, |
1021 | - self.creds._process_error, |
1022 | - self.creds.emit_authorization_denied, |
1023 | - ui_module='ubuntu_sso.qt.gui') |
1024 | - # pylint: enable=W0212 |
1025 | - self.mocker.replay() |
1026 | - yield self.client.login_or_register_to_get_credentials(app_name, terms, |
1027 | - help_txt, window_id) |
1028 | - yield self.client.unregister_to_signals() |
1029 | - |
1030 | - @defer.inlineCallbacks |
1031 | - def test_login_to_get_credentials(self): |
1032 | - """Ensure that the root is called.""" |
1033 | - app_name = 'app' |
1034 | - help_txt = 'help' |
1035 | - window_id = 'window_id' |
1036 | - |
1037 | - # pylint: disable=W0212 |
1038 | - self.root.login_to_get_credentials(app_name, help_txt, window_id, |
1039 | - self.creds.emit_credentials_found, |
1040 | - self.creds._process_error, |
1041 | - self.creds.emit_authorization_denied, |
1042 | - ui_module='ubuntu_sso.qt.gui') |
1043 | - # pylint: enable=W0212 |
1044 | - self.mocker.replay() |
1045 | - yield self.client.login_to_get_credentials(app_name, help_txt, |
1046 | - window_id) |
1047 | - yield self.client.unregister_to_signals() |
1048 | - |
1049 | - @defer.inlineCallbacks |
1050 | - def test_clear_token_no_kword(self): |
1051 | - """Ensure that the root is called.""" |
1052 | - app_name = 'app' |
1053 | - callback = lambda: None |
1054 | - errback = lambda: None |
1055 | - |
1056 | - self.root.clear_token(app_name, MATCH(callable), MATCH(callable)) |
1057 | - self.mocker.replay() |
1058 | - yield self.client.clear_token(app_name, callback, errback) |
1059 | - yield self.client.unregister_to_signals() |
1060 | - |
1061 | - @defer.inlineCallbacks |
1062 | - def test_clear_token(self): |
1063 | - """Ensure that the root is called.""" |
1064 | - app_name = 'app' |
1065 | - callback = lambda: None |
1066 | - errback = lambda: None |
1067 | - |
1068 | - self.root.clear_token(app_name, MATCH(callable), MATCH(callable)) |
1069 | - self.mocker.replay() |
1070 | - yield self.client.clear_token(app_name, callback=callback, |
1071 | - errback=errback) |
1072 | - yield self.client.unregister_to_signals() |
1073 | - |
1074 | - |
1075 | class CredentialsManagementTestCase(TestCase): |
1076 | """Test the management class.""" |
1077 | |
1078 | @@ -741,7 +554,7 @@ |
1079 | self.creds = CredentialsManagement(None, None) |
1080 | self.creds.root = self.root |
1081 | # start pb |
1082 | - self.sso_root = UbuntuSSORoot(None, None, self.creds) |
1083 | + self.sso_root = UbuntuSSORoot(cred_manager=self.creds) |
1084 | self.server_factory = SaveProtocolServerFactory(self.sso_root) |
1085 | # pylint: disable=E1101 |
1086 | port = get_sso_pb_port() |
1087 | |
1088 | === modified file 'ubuntu_sso/main/windows.py' |
1089 | --- ubuntu_sso/main/windows.py 2011-09-14 20:59:39 +0000 |
1090 | +++ ubuntu_sso/main/windows.py 2011-09-27 21:50:39 +0000 |
1091 | @@ -17,8 +17,6 @@ |
1092 | # with this program. If not, see <http://www.gnu.org/licenses/>. |
1093 | """Main implementation on windows.""" |
1094 | |
1095 | -import warnings |
1096 | - |
1097 | from functools import wraps |
1098 | |
1099 | # pylint: disable=F0401 |
1100 | @@ -36,14 +34,11 @@ |
1101 | Root, |
1102 | ) |
1103 | |
1104 | -from ubuntu_sso import NO_OP |
1105 | from ubuntu_sso.account import Account |
1106 | -from ubuntu_sso.credentials import ERROR_KEY, ERROR_DETAIL_KEY |
1107 | from ubuntu_sso.logger import setup_logging |
1108 | from ubuntu_sso.main import ( |
1109 | CredentialsManagementRoot, |
1110 | SSOLoginRoot, |
1111 | - SSOCredentialsRoot, |
1112 | except_to_errdict, |
1113 | ) |
1114 | from ubuntu_sso.utils.tcpactivation import ActivationConfig, ActivationClient |
1115 | @@ -334,100 +329,6 @@ |
1116 | self.emit_password_change_error) |
1117 | |
1118 | |
1119 | -class SSOCredentials(Referenceable, SignalBroadcaster): |
1120 | - """DBus object that gets credentials, and login/registers if needed.""" |
1121 | - |
1122 | - __metaclass__ = RemoteMeta |
1123 | - |
1124 | - # calls that will be accessible remotely |
1125 | - remote_calls = [ |
1126 | - 'find_credentials', |
1127 | - 'login_or_register_to_get_credentials', |
1128 | - 'login_to_get_credentials', |
1129 | - 'clear_token', |
1130 | - ] |
1131 | - |
1132 | - def __init__(self, *args, **kwargs): |
1133 | - super(SSOCredentials, self).__init__() |
1134 | - self.root = SSOCredentialsRoot() |
1135 | - |
1136 | - def _process_error(self, app_name, error_dict): |
1137 | - """Process the 'error_dict' and emit CredentialsError.""" |
1138 | - msg = error_dict.get(ERROR_KEY, 'No error message given.') |
1139 | - detail = error_dict.get(ERROR_DETAIL_KEY, 'No detailed error given.') |
1140 | - self.emit_credentials_error(app_name, msg, detail) |
1141 | - |
1142 | - def emit_authorization_denied(self, app_name): |
1143 | - """Signal thrown when the user denies the authorization.""" |
1144 | - logger.info('SSOCredentials: emitting AuthorizationDenied with ' |
1145 | - 'app_name "%s"', app_name) |
1146 | - self.emit_signal('on_authorization_denied', app_name) |
1147 | - |
1148 | - def emit_credentials_found(self, app_name, credentials): |
1149 | - """Signal thrown when the credentials are found.""" |
1150 | - logger.info('SSOCredentials: emitting CredentialsFound with ' |
1151 | - 'app_name "%s"', app_name) |
1152 | - self.emit_signal('on_credentials_found', app_name, credentials) |
1153 | - |
1154 | - def emit_credentials_error(self, app_name, error_message, detailed_error): |
1155 | - """Signal thrown when there is a problem finding the credentials.""" |
1156 | - logger.error('SSOCredentials: emitting CredentialsError with app_name ' |
1157 | - '"%s" and error_message %r', app_name, error_message) |
1158 | - self.emit_signal('on_credentials_error', app_name, error_message, |
1159 | - detailed_error) |
1160 | - |
1161 | - def find_credentials(self, app_name, callback=NO_OP, errback=NO_OP): |
1162 | - """Get the credentials from the keyring or {} if not there.""" |
1163 | - self.root.find_credentials(app_name, remote_handler(callback), |
1164 | - remote_handler(errback)) |
1165 | - |
1166 | - def login_or_register_to_get_credentials(self, app_name, |
1167 | - terms_and_conditions_url, |
1168 | - help_text, window_id, |
1169 | - ui_module='ubuntu_sso.qt.gui'): |
1170 | - """Get credentials if found else prompt GUI to login or register. |
1171 | - |
1172 | - 'app_name' will be displayed in the GUI. |
1173 | - 'terms_and_conditions_url' will be the URL pointing to T&C. |
1174 | - 'help_text' is an explanatory text for the end-users, will be shown |
1175 | - below the headers. |
1176 | - 'window_id' is the id of the window which will be set as a parent of |
1177 | - the GUI. If 0, no parent will be set. |
1178 | - |
1179 | - """ |
1180 | - self.root.login_or_register_to_get_credentials(app_name, |
1181 | - terms_and_conditions_url, |
1182 | - help_text, window_id, |
1183 | - self.emit_credentials_found, |
1184 | - self._process_error, |
1185 | - self.emit_authorization_denied, |
1186 | - ui_module=ui_module) |
1187 | - |
1188 | - def login_to_get_credentials(self, app_name, help_text, window_id): |
1189 | - """Get credentials if found else prompt GUI just to login |
1190 | - |
1191 | - 'app_name' will be displayed in the GUI. |
1192 | - 'help_text' is an explanatory text for the end-users, will be shown |
1193 | - before the login fields. |
1194 | - 'window_id' is the id of the window which will be set as a parent of |
1195 | - the GUI. If 0, no parent will be set. |
1196 | - |
1197 | - """ |
1198 | - self.root.login_to_get_credentials(app_name, help_text, window_id, |
1199 | - self.emit_credentials_found, |
1200 | - self._process_error, |
1201 | - self.emit_authorization_denied, |
1202 | - ui_module='ubuntu_sso.qt.gui') |
1203 | - |
1204 | - def clear_token(self, app_name, callback=NO_OP, errback=NO_OP): |
1205 | - """Clear the token for an application from the keyring. |
1206 | - |
1207 | - 'app_name' is the name of the application. |
1208 | - """ |
1209 | - self.root.clear_token(app_name, remote_handler(callback), |
1210 | - remote_handler(errback)) |
1211 | - |
1212 | - |
1213 | class CredentialsManagement(Referenceable, SignalBroadcaster): |
1214 | """Object that manages credentials. |
1215 | |
1216 | @@ -595,24 +496,19 @@ |
1217 | # calls that will be accessible remotely |
1218 | remote_calls = [ |
1219 | 'get_sso_login', |
1220 | - 'get_sso_credentials', |
1221 | - 'get_cred_manager'] |
1222 | + 'get_cred_manager', |
1223 | + ] |
1224 | |
1225 | - def __init__(self, sso_login, sso_credentials, cred_manager): |
1226 | + def __init__(self, sso_login=None, cred_manager=None): |
1227 | """Create a new instance that will expose the objects.""" |
1228 | super(UbuntuSSORoot, self).__init__() |
1229 | self._sso_login = sso_login |
1230 | - self._sso_credentials = sso_credentials |
1231 | self._cred_manager = cred_manager |
1232 | |
1233 | def get_sso_login(self): |
1234 | """Return the sso_login.""" |
1235 | return self._sso_login |
1236 | |
1237 | - def get_sso_credentials(self): |
1238 | - """Return the sso credentials.""" |
1239 | - return self._sso_credentials |
1240 | - |
1241 | def get_cred_manager(self): |
1242 | """Return the credentials manager.""" |
1243 | return self._cred_manager |
1244 | @@ -807,80 +703,6 @@ |
1245 | """Call the matching method in the processor.""" |
1246 | |
1247 | |
1248 | -class SSOCredentialsClient(RemoteClient, Referenceable): |
1249 | - """Deprecated client for the remote SSOCredentials object. |
1250 | - |
1251 | - This class is deprecated! |
1252 | - """ |
1253 | - |
1254 | - __metaclass__ = RemoteMeta |
1255 | - |
1256 | - # calls that will be accessible remotely |
1257 | - remote_calls = [ |
1258 | - 'on_authorization_denied', |
1259 | - 'on_credentials_found', |
1260 | - 'on_credentials_error', |
1261 | - ] |
1262 | - |
1263 | - def __init__(self, remote_login): |
1264 | - """Create a client for the cred API.""" |
1265 | - warnings.warn("SSOCredentialsClient is deprecated.", |
1266 | - DeprecationWarning) |
1267 | - super(SSOCredentialsClient, self).__init__(remote_login) |
1268 | - |
1269 | - @signal |
1270 | - def on_authorization_denied(self, app_name): |
1271 | - """Signal thrown when the user denies the authorization.""" |
1272 | - |
1273 | - @signal |
1274 | - def on_credentials_found(self, app_name, credentials): |
1275 | - """Signal thrown when the credentials are found.""" |
1276 | - |
1277 | - @signal |
1278 | - def on_credentials_error(self, app_name, error_message, detailed_error): |
1279 | - """Signal thrown when there is a problem finding the credentials.""" |
1280 | - |
1281 | - @callbacks(callbacks_names=[('callback', 2), ('errback', 3)]) |
1282 | - @remote |
1283 | - def find_credentials(self, app_name, callback=NO_OP, errback=NO_OP): |
1284 | - """Get the credentials from the keyring or {} if not there.""" |
1285 | - |
1286 | - @remote |
1287 | - def login_or_register_to_get_credentials(self, app_name, |
1288 | - terms_and_conditions_url, |
1289 | - help_text, window_id): |
1290 | - """Get credentials if found else prompt GUI to login or register. |
1291 | - |
1292 | - 'app_name' will be displayed in the GUI. |
1293 | - 'terms_and_conditions_url' will be the URL pointing to T&C. |
1294 | - 'help_text' is an explanatory text for the end-users, will be shown |
1295 | - below the headers. |
1296 | - 'window_id' is the id of the window which will be set as a parent of |
1297 | - the GUI. If 0, no parent will be set. |
1298 | - |
1299 | - """ |
1300 | - |
1301 | - @remote |
1302 | - def login_to_get_credentials(self, app_name, help_text, window_id): |
1303 | - """Get credentials if found else prompt GUI just to login |
1304 | - |
1305 | - 'app_name' will be displayed in the GUI. |
1306 | - 'help_text' is an explanatory text for the end-users, will be shown |
1307 | - before the login fields. |
1308 | - 'window_id' is the id of the window which will be set as a parent of |
1309 | - the GUI. If 0, no parent will be set. |
1310 | - |
1311 | - """ |
1312 | - |
1313 | - @callbacks(callbacks_names=[('callback', 2), ('errback', 3)]) |
1314 | - @remote |
1315 | - def clear_token(self, app_name, callback=NO_OP, errback=NO_OP): |
1316 | - """Clear the token for an application from the keyring. |
1317 | - |
1318 | - 'app_name' is the name of the application. |
1319 | - """ |
1320 | - |
1321 | - |
1322 | class CredentialsManagementClient(RemoteClient, Referenceable): |
1323 | """Client that can perform calls to the remote CredManagement object.""" |
1324 | |
1325 | |
1326 | === modified file 'ubuntu_sso/qt/controllers.py' |
1327 | --- ubuntu_sso/qt/controllers.py 2011-09-21 21:41:04 +0000 |
1328 | +++ ubuntu_sso/qt/controllers.py 2011-09-27 21:50:39 +0000 |
1329 | @@ -77,9 +77,6 @@ |
1330 | logger = setup_logging('ubuntu_sso.controllers') |
1331 | FAKE_URL = '<a href="http://one.ubuntu.com">%s</a>' |
1332 | |
1333 | -# pylint: disable=W0511 |
1334 | -# disabled warnings about TODO comments |
1335 | - |
1336 | |
1337 | # Based on the gtk implementation |
1338 | def _build_general_error_message(errordict): |
1339 | @@ -916,7 +913,6 @@ |
1340 | logger.debug('UbuntuSSOWizardController.on_registration_success') |
1341 | result = yield self.registration_success_callback(unicode(app_name), |
1342 | unicode(email)) |
1343 | - # TODO: what to do? |
1344 | logger.debug('Result from callback is %s', result) |
1345 | if result == 0: |
1346 | logger.info('Success in calling the given registration_callback') |
+1