Merge lp:~mandel/ubuntu-sso-client/implement_windows_main_1 into lp:ubuntu-sso-client

Proposed by Manuel de la Peña
Status: Merged
Approved by: Manuel de la Peña
Approved revision: 696
Merged at revision: 680
Proposed branch: lp:~mandel/ubuntu-sso-client/implement_windows_main_1
Merge into: lp:ubuntu-sso-client
Prerequisite: lp:~mandel/ubuntu-sso-client/implement_windows_networkstatus
Diff against target: 1267 lines (+741/-187)
9 files modified
run-tests (+1/-1)
run-tests.bat (+1/-1)
ubuntu_sso/main/__init__.py (+375/-0)
ubuntu_sso/main/linux.py (+48/-166)
ubuntu_sso/main/windows.py (+17/-0)
ubuntu_sso/tests/main/__init__.py (+17/-0)
ubuntu_sso/tests/main/test_common.py (+244/-0)
ubuntu_sso/tests/main/test_linux.py (+21/-19)
ubuntu_sso/tests/main/test_windows.py (+17/-0)
To merge this branch: bzr merge lp:~mandel/ubuntu-sso-client/implement_windows_main_1
Reviewer Review Type Date Requested Status
Alejandro J. Cura (community) Approve
Roberto Alsina (community) Approve
Review via email: mp+52707@code.launchpad.net

Commit message

First step of implementing the code in main on windows.

Description of the change

First step of implementing the code in main on windows.

To post a comment you must log in.
689. By Manuel de la Peña

Merged implement_windows_networkstatus into implement_windows_main_1.

690. By Manuel de la Peña

Merged implement_windows_networkstatus into implement_windows_main_1.

691. By Manuel de la Peña

Merged implement_windows_networkstatus into implement_windows_main_1.

692. By Manuel de la Peña

Renamed test files so they are correctly ignored.

693. By Manuel de la Peña

Renamed test files so they are correctly ignored.

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

+1 on windows

review: Approve
Revision history for this message
Alejandro J. Cura (alecu) wrote :

When running the tests on natty:

alecu@breetai:~/canonical/ubuntu-sso-client/review_implement_windows_main_1$ ./run-tests
Running test suite for ubuntu_sso
Xlib: extension "RANDR" missing on display ":99".
Traceback (most recent call last):
  File "/usr/bin/u1trial", line 246, in <module>
    main()
  File "/usr/bin/u1trial", line 243, in main
    TestRunner(force_gc=options.force_gc).run(testpath, options)
  File "/usr/bin/u1trial", line 181, in run
    options.ignored_modules, options.ignored_paths)
  File "/usr/bin/u1trial", line 160, in _collect_tests
    module_suite = self._load_unittest(filepath)
  File "/usr/bin/u1trial", line 88, in _load_unittest
    module = __import__(modpath, None, None, [""])
  File "/home/alecu/canonical/ubuntu-sso-client/review_implement_windows_main_1/ubuntu_sso/tests/networkstate/test_windows.py", line 20, in <module>
    from ubuntu_sso.networkstate.windows import (
  File "/home/alecu/canonical/ubuntu-sso-client/review_implement_windows_main_1/ubuntu_sso/networkstate/windows.py", line 23, in <module>
    import pythoncom
ImportError: No module named pythoncom

review: Needs Fixing
694. By Manuel de la Peña

Added the correct ignore to the runt-test script.

695. By Manuel de la Peña

Fixed style issues.

Revision history for this message
Alejandro J. Cura (alecu) wrote :

Great branch!

A couple of minor nitpicks:

 * a small typo: "Object object"
 * and a weird name for a test method: CredentialsManagementMockedTestCase.login (looks like it should be named test_login)

review: Approve
Revision history for this message
Manuel de la Peña (mandel) wrote :

Alecu,

Thanks for the comments, I'll fix those two thing you mentioned, better now than never :)

696. By Manuel de la Peña

Fixed test name and small typo.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'run-tests'
--- run-tests 2011-02-24 02:46:19 +0000
+++ run-tests 2011-03-17 08:43:34 +0000
@@ -33,5 +33,5 @@
33}33}
3434
35echo "Running test suite for ""$MODULE"35echo "Running test suite for ""$MODULE"
36`which xvfb-run` u1trial "$MODULE" -i "test_windows_networkstate.py" && style_check36`which xvfb-run` u1trial "$MODULE" -i "test_windows.py" && style_check
37rm -rf _trial_temp37rm -rf _trial_temp
3838
=== modified file 'run-tests.bat'
--- run-tests.bat 2011-03-15 08:27:10 +0000
+++ run-tests.bat 2011-03-17 08:43:34 +0000
@@ -51,7 +51,7 @@
51:PYTHONPRESENT51:PYTHONPRESENT
52ECHO Python found, executing the tests...52ECHO Python found, executing the tests...
53:: execute the tests with a number of ignored linux only modules53:: execute the tests with a number of ignored linux only modules
54"%PYTHONPATH%\python.exe" "%PYTHONPATH%\Scripts\u1trial" -c ubuntu_sso -i "test_gui.py, test_linux_keyring.py, test_linux_network_state.py"54"%PYTHONPATH%\python.exe" "%PYTHONPATH%\Scripts\u1trial" -c ubuntu_sso -i "test_gui.py, test_linux.py, test_txsecrets.py"
55"%PYTHONPATH%\python.exe" "%PYTHONPATH%\Scripts\u1lint" ubuntu_sso55"%PYTHONPATH%\python.exe" "%PYTHONPATH%\Scripts\u1lint" ubuntu_sso
56:: test for style if we can, if pep8 is not present, move to the end56:: test for style if we can, if pep8 is not present, move to the end
57IF EXIST "%PYTHONPATH%Scripts\pep8.exe"57IF EXIST "%PYTHONPATH%Scripts\pep8.exe"
5858
=== added directory 'ubuntu_sso/main'
=== added file 'ubuntu_sso/main/__init__.py'
--- ubuntu_sso/main/__init__.py 1970-01-01 00:00:00 +0000
+++ ubuntu_sso/main/__init__.py 2011-03-17 08:43:34 +0000
@@ -0,0 +1,375 @@
1# -*- coding: utf-8 -*-
2#
3# Author: Natalia Bidart <natalia.bidart@canonical.com>
4# Author: Alejandro J. Cura <alecu@canonical.com>
5# Author: Manuel de la Pena <manuel@canonical.com>
6#
7# Copyright 2011 Canonical Ltd.
8#
9# This program is free software: you can redistribute it and/or modify it
10# under the terms of the GNU General Public License version 3, as published
11# by the Free Software Foundation.
12#
13# This program is distributed in the hope that it will be useful, but
14# WITHOUT ANY WARRANTY; without even the implied warranties of
15# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
16# PURPOSE. See the GNU General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License along
19# with this program. If not, see <http://www.gnu.org/licenses/>.
20"""Main object implementations."""
21
22import os
23import sys
24import warnings
25
26from ubuntu_sso import NO_OP
27from ubuntu_sso.account import Account
28from ubuntu_sso.credentials import (Credentials, HELP_TEXT_KEY, PING_URL_KEY,
29 TC_URL_KEY, UI_CLASS_KEY, UI_MODULE_KEY, WINDOW_ID_KEY,
30 SUCCESS_CB_KEY, ERROR_CB_KEY, DENIAL_CB_KEY)
31from ubuntu_sso.keyring import get_token_name, U1_APP_NAME, Keyring
32from ubuntu_sso.logger import setup_logging
33
34logger = setup_logging("ubuntu_sso.main")
35U1_PING_URL = "https://one.ubuntu.com/oauth/sso-finished-so-get-tokens/"
36
37
38class SSOLoginProcessor(Account):
39 """Login and register users using the Ubuntu Single Sign On service.
40
41 Alias classname to maintain backwards compatibility. DO NOT USE, use
42 ubuntu_sso.account.Account instead.
43 """
44
45 def __init__(self, sso_service_class=None):
46 """Create a new SSO Account manager."""
47 msg = 'Use ubuntu_sso.account.Account instead.'
48 warnings.warn(msg, DeprecationWarning)
49 super(SSOLoginProcessor, self).__init__(sso_service_class)
50
51
52def except_to_errdict(e):
53 """Turn an exception into a dictionary to return thru DBus."""
54 result = {
55 "errtype": e.__class__.__name__,
56 }
57 if len(e.args) == 0:
58 result["message"] = e.__class__.__doc__
59 elif isinstance(e.args[0], dict):
60 result.update(e.args[0])
61 elif isinstance(e.args[0], basestring):
62 result["message"] = e.args[0]
63
64 return result
65
66
67class SSOLoginRoot(object):
68 """Login thru the Single Sign On service."""
69
70 def __init__(self, sso_login_processor_class=Account,
71 sso_service_class=None):
72 """Initiate the Login object."""
73 self.sso_login_processor_class = sso_login_processor_class
74 self.processor = self.sso_login_processor_class(
75 sso_service_class=sso_service_class)
76
77 def generate_captcha(self, app_name, filename, thread_execute, result_cb,
78 error_cb):
79 """Call the matching method in the processor."""
80 def f():
81 """Inner function that will be run in a thread."""
82 return self.processor.generate_captcha(filename)
83 thread_execute(f, app_name, result_cb, error_cb)
84
85 def register_user(self, app_name, email, password, captcha_id,
86 captcha_solution, thread_execute, result_cb, error_cb):
87 """Call the matching method in the processor."""
88 def f():
89 """Inner function that will be run in a thread."""
90 return self.processor.register_user(email, password,
91 captcha_id, captcha_solution)
92 thread_execute(f, app_name, result_cb, error_cb)
93
94 def login(self, app_name, email, password, thread_execute, result_cb,
95 error_cb, not_validated_cb):
96 """Call the matching method in the processor."""
97 def f():
98 """Inner function that will be run in a thread."""
99 token_name = get_token_name(app_name)
100 logger.debug('login: token_name %r, email %r, password <hidden>.',
101 token_name, email)
102 credentials = self.processor.login(email, password, token_name)
103 logger.debug('login returned not None credentials? %r.',
104 credentials is not None)
105 return credentials
106
107 def success_cb(app_name, credentials):
108 """Login finished successfull."""
109 is_validated = self.processor.is_validated(credentials)
110 logger.debug('user is validated? %r.', is_validated)
111 if is_validated:
112 # pylint: disable=E1101
113 d = Keyring().set_credentials(app_name, credentials)
114 d.addCallback(lambda _: result_cb(app_name, email))
115 d.addErrback(lambda failure: \
116 error_cb(app_name,
117 except_to_errdict(failure.value)))
118 else:
119 not_validated_cb(app_name, email)
120 thread_execute(f, app_name, success_cb, error_cb)
121
122 def validate_email(self, app_name, email, password, email_token,
123 thread_execute, result_cb, error_cb):
124 """Call the matching method in the processor."""
125
126 def f():
127 """Inner function that will be run in a thread."""
128 token_name = get_token_name(app_name)
129 credentials = self.processor.validate_email(email, password,
130 email_token, token_name)
131 return credentials
132
133 def success_cb(app_name, credentials):
134 """Validation finished successfully."""
135 # pylint: disable=E1101
136 d = Keyring().set_credentials(app_name, credentials)
137 d.addCallback(lambda _: result_cb(app_name, email))
138 failure_cb = lambda f: error_cb(app_name, f.value)
139 d.addErrback(failure_cb)
140
141 thread_execute(f, app_name, success_cb, error_cb)
142
143 def request_password_reset_token(self, app_name, email, thread_execute,
144 result_cb, error_cb):
145 """Call the matching method in the processor."""
146 def f():
147 """Inner function that will be run in a thread."""
148 return self.processor.request_password_reset_token(email)
149 thread_execute(f, app_name, result_cb, error_cb)
150
151 def set_new_password(self, app_name, email, token, new_password,
152 thread_execute, result_cb, error_cb):
153 """Call the matching method in the processor."""
154 def f():
155 """Inner function that will be run in a thread."""
156 return self.processor.set_new_password(email, token,
157 new_password)
158 thread_execute(f, app_name, result_cb, error_cb)
159
160
161class SSOCredentialsRoot(object):
162 """Object that gets credentials, and login/registers if needed."""
163
164 def __init__(self):
165 self.ping_url = os.environ.get('USSOC_PING_URL', U1_PING_URL)
166
167 def find_credentials(self, app_name, callback=NO_OP, errback=NO_OP):
168 """Get the credentials from the keyring or {} if not there."""
169
170 def log_result(result):
171 """Log the result and continue."""
172 logger.info('find_credentials: app_name "%s", result is {}? %s',
173 app_name, result == {})
174 return result
175
176 d = Credentials(app_name=app_name).find_credentials()
177 # pylint: disable=E1101
178 d.addCallback(log_result)
179 d.addCallbacks(callback, errback)
180
181 def login_or_register_to_get_credentials(self, app_name,
182 terms_and_conditions_url,
183 help_text, window_id,
184 success_cb, error_cb, denial_cb):
185 """Get credentials if found else prompt GUI to login or register.
186
187 'app_name' will be displayed in the GUI.
188 'terms_and_conditions_url' will be the URL pointing to T&C.
189 'help_text' is an explanatory text for the end-users, will be shown
190 below the headers.
191 'window_id' is the id of the window which will be set as a parent of
192 the GUI. If 0, no parent will be set.
193
194 """
195 ping_url = self.ping_url if app_name == U1_APP_NAME else None
196 obj = Credentials(app_name=app_name, ping_url=ping_url,
197 tc_url=terms_and_conditions_url,
198 help_text=help_text, window_id=window_id,
199 success_cb=success_cb, error_cb=error_cb,
200 denial_cb=denial_cb)
201 obj.register()
202
203 def login_to_get_credentials(self, app_name, help_text, window_id,
204 success_cb, error_cb, denial_cb):
205 """Get credentials if found else prompt GUI just to login
206
207 'app_name' will be displayed in the GUI.
208 'help_text' is an explanatory text for the end-users, will be shown
209 before the login fields.
210 'window_id' is the id of the window which will be set as a parent of
211 the GUI. If 0, no parent will be set.
212
213 """
214 ping_url = self.ping_url if app_name == U1_APP_NAME else None
215 obj = Credentials(app_name=app_name, ping_url=ping_url, tc_url=None,
216 help_text=help_text, window_id=window_id,
217 success_cb=success_cb, error_cb=error_cb,
218 denial_cb=denial_cb)
219 obj.login()
220
221 def clear_token(self, app_name, callback=NO_OP, errback=NO_OP):
222 """Clear the token for an application from the keyring.
223
224 'app_name' is the name of the application.
225 """
226 d = Credentials(app_name=app_name).clear_credentials()
227 # pylint: disable=E1101
228 d.addCallbacks(lambda _: callback(), errback)
229
230
231class CredentialsManagementRoot(object):
232 """Object that manages credentials.
233
234 Every exposed method in this class requires one mandatory argument:
235
236 - 'app_name': the name of the application. Will be displayed in the
237 GUI header, plus it will be used to find/build/clear tokens.
238
239 And accepts another parameter named 'args', which is a dictionary that
240 can contain the following:
241
242 - 'help_text': an explanatory text for the end-users, will be
243 shown below the header. This is an optional free text field.
244
245 - 'ping_url': the url to open after successful token retrieval. If
246 defined, the email will be attached to the url and will be pinged
247 with a OAuth-signed request.
248
249 - 'tc_url': the link to the Terms and Conditions page. If defined,
250 the checkbox to agree to the terms will link to it.
251
252 - 'window_id': the id of the window which will be set as a parent
253 of the GUI. If not defined, no parent will be set.
254
255 """
256
257 def __init__(self, found_cb, error_cb, denied_cb, *args, **kwargs):
258 """Create a new instance.
259
260 - 'found_cb' is a callback that will be executed when the credentials
261 were found.
262
263 - 'error_cb' is a callback that will be executed when there was an
264 error getting the credentials.
265
266 - 'denied_cb' is a callback that will be executed when the user denied
267 the use of the crendetials.
268
269 """
270 super(CredentialsManagementRoot, self).__init__(*args, **kwargs)
271 self.found_cb = found_cb
272 self.error_cb = error_cb
273 self.denied_cb = denied_cb
274
275 valid_keys = (HELP_TEXT_KEY, PING_URL_KEY, TC_URL_KEY,
276 UI_CLASS_KEY, UI_MODULE_KEY, WINDOW_ID_KEY)
277
278 def _parse_args(self, args):
279 """Retrieve values from the generic param 'args'."""
280 result = dict(i for i in args.iteritems() if i[0] in self.valid_keys)
281 result[WINDOW_ID_KEY] = int(args.get(WINDOW_ID_KEY, 0))
282 result[SUCCESS_CB_KEY] = self.found_cb
283 result[ERROR_CB_KEY] = self.error_cb
284 result[DENIAL_CB_KEY] = self.denied_cb
285 return result
286
287 def find_credentials(self, app_name, args, success_cb, error_cb):
288 """Look for the credentials for an application.
289
290 - 'app_name': the name of the application which credentials are
291 going to be removed.
292
293 - 'args' is a dictionary, currently not used.
294
295 - 'success_cb' is a callback that will be execute if the operation was
296 a success.
297
298 - 'error_cb' is a callback that will be executed if the operation had
299 an error.
300
301 """
302
303 obj = Credentials(app_name)
304 d = obj.find_credentials()
305 # pylint: disable=E1101
306 d.addCallback(success_cb)
307 d.addErrback(error_cb, app_name)
308
309 def clear_credentials(self, app_name, args, success_cb, error_cb):
310 """Clear the credentials for an application.
311
312 - 'app_name': the name of the application which credentials are
313 going to be removed.
314
315 - 'args' is a dictionary, currently not used.
316
317 - 'success_cb' is a callback that will be execute if the operation was
318 a success.
319
320 - 'error_cb' is a callback that will be executed if the operation had
321 an error.
322
323 """
324
325 obj = Credentials(app_name)
326 d = obj.clear_credentials()
327 # pylint: disable=E1101
328 d.addCallback(success_cb)
329 d.addErrback(error_cb, app_name)
330
331 def store_credentials(self, app_name, args, success_cb, error_cb):
332 """Store the token for an application.
333
334 - 'app_name': the name of the application which credentials are
335 going to be stored.
336
337 - 'args' is the dictionary holding the credentials. Needs to provide
338 the following mandatory keys: 'token', 'token_key', 'consumer_key',
339 'consumer_secret'.
340
341 - 'success_cb' is a callback that will be execute if the operation was
342 a success.
343
344 - 'error_cb' is a callback that will be executed if the operation had
345 an error.
346 """
347
348 obj = Credentials(app_name)
349 d = obj.store_credentials(args)
350 # pylint: disable=E1101
351 d.addCallback(success_cb)
352 d.addErrback(error_cb, app_name)
353
354 def register(self, app_name, args):
355 """Get credentials if found else prompt GUI to register."""
356 obj = Credentials(app_name, **self._parse_args(args))
357 obj.register()
358
359 def login(self, app_name, args):
360 """Get credentials if found else prompt GUI to login."""
361 obj = Credentials(app_name, **self._parse_args(args))
362 obj.login()
363
364# pylint: disable=C0103
365SSOLogin = None
366SSOCredentials = None
367CredentialsManagement = None
368
369if sys.platform == 'win32':
370 pass
371else:
372 from ubuntu_sso.main import linux
373 SSOLogin = linux.SSOLogin
374 SSOCredentials = linux.SSOCredentials
375 CredentialsManagement = linux.CredentialsManagement
0376
=== renamed file 'ubuntu_sso/main.py' => 'ubuntu_sso/main/linux.py'
--- ubuntu_sso/main.py 2011-01-28 13:45:09 +0000
+++ ubuntu_sso/main/linux.py 2011-03-17 08:43:34 +0000
@@ -27,21 +27,17 @@
2727
28"""28"""
2929
30import os
31import threading30import threading
32import warnings
3331
34import dbus.service32import dbus.service
3533
36from ubuntu_sso import (DBUS_ACCOUNT_PATH, DBUS_IFACE_USER_NAME,34from ubuntu_sso import (DBUS_ACCOUNT_PATH, DBUS_IFACE_USER_NAME,
37 DBUS_IFACE_CRED_NAME, DBUS_CREDENTIALS_IFACE, NO_OP)35 DBUS_IFACE_CRED_NAME, DBUS_CREDENTIALS_IFACE, NO_OP)
38from ubuntu_sso.account import Account36from ubuntu_sso.account import Account
39from ubuntu_sso.credentials import (Credentials, HELP_TEXT_KEY, PING_URL_KEY,37from ubuntu_sso.credentials import ERROR_KEY, ERROR_DETAIL_KEY
40 TC_URL_KEY, UI_CLASS_KEY, UI_MODULE_KEY, WINDOW_ID_KEY,
41 SUCCESS_CB_KEY, ERROR_CB_KEY, DENIAL_CB_KEY,
42 ERROR_KEY, ERROR_DETAIL_KEY)
43from ubuntu_sso.keyring import get_token_name, U1_APP_NAME, Keyring
44from ubuntu_sso.logger import setup_logging38from ubuntu_sso.logger import setup_logging
39from ubuntu_sso.main import (CredentialsManagementRoot, SSOLoginRoot,
40 SSOCredentialsRoot, except_to_errdict)
4541
4642
47# Disable the invalid name warning, as we have a lot of DBus style names43# Disable the invalid name warning, as we have a lot of DBus style names
@@ -49,39 +45,9 @@
4945
5046
51logger = setup_logging("ubuntu_sso.main")47logger = setup_logging("ubuntu_sso.main")
52U1_PING_URL = "https://one.ubuntu.com/oauth/sso-finished-so-get-tokens/"
53TIMEOUT_INTERVAL = 10000 # 10 seconds48TIMEOUT_INTERVAL = 10000 # 10 seconds
5449
5550
56class SSOLoginProcessor(Account):
57 """Login and register users using the Ubuntu Single Sign On service.
58
59 Alias classname to maintain backwards compatibility. DO NOT USE, use
60 ubuntu_sso.account.Account instead.
61 """
62
63 def __init__(self, sso_service_class=None):
64 """Create a new SSO Account manager."""
65 msg = 'Use ubuntu_sso.account.Account instead.'
66 warnings.warn(msg, DeprecationWarning)
67 super(SSOLoginProcessor, self).__init__(sso_service_class)
68
69
70def except_to_errdict(e):
71 """Turn an exception into a dictionary to return thru DBus."""
72 result = {
73 "errtype": e.__class__.__name__,
74 }
75 if len(e.args) == 0:
76 result["message"] = e.__class__.__doc__
77 elif isinstance(e.args[0], dict):
78 result.update(e.args[0])
79 elif isinstance(e.args[0], basestring):
80 result["message"] = e.args[0]
81
82 return result
83
84
85def blocking(f, app_name, result_cb, error_cb):51def blocking(f, app_name, result_cb, error_cb):
86 """Run f in a thread; return or throw an exception thru the callbacks."""52 """Run f in a thread; return or throw an exception thru the callbacks."""
87 def _in_thread():53 def _in_thread():
@@ -107,9 +73,7 @@
107 """Initiate the Login object."""73 """Initiate the Login object."""
108 dbus.service.Object.__init__(self, object_path=object_path,74 dbus.service.Object.__init__(self, object_path=object_path,
109 bus_name=bus_name)75 bus_name=bus_name)
110 self.sso_login_processor_class = sso_login_processor_class76 self.root = SSOLoginRoot(sso_login_processor_class, sso_service_class)
111 self.processor = self.sso_login_processor_class(
112 sso_service_class=sso_service_class)
11377
114 # generate_capcha signals78 # generate_capcha signals
115 @dbus.service.signal(DBUS_IFACE_USER_NAME, signature="ss")79 @dbus.service.signal(DBUS_IFACE_USER_NAME, signature="ss")
@@ -128,11 +92,9 @@
128 in_signature='ss')92 in_signature='ss')
129 def generate_captcha(self, app_name, filename):93 def generate_captcha(self, app_name, filename):
130 """Call the matching method in the processor."""94 """Call the matching method in the processor."""
131 def f():95 self.root.generate_captcha(app_name, filename, blocking,
132 """Inner function that will be run in a thread."""96 self.CaptchaGenerated,
133 return self.processor.generate_captcha(filename)97 self.CaptchaGenerationError)
134 blocking(f, app_name, self.CaptchaGenerated,
135 self.CaptchaGenerationError)
13698
137 # register_user signals99 # register_user signals
138 @dbus.service.signal(DBUS_IFACE_USER_NAME, signature="ss")100 @dbus.service.signal(DBUS_IFACE_USER_NAME, signature="ss")
@@ -152,11 +114,10 @@
152 def register_user(self, app_name, email, password,114 def register_user(self, app_name, email, password,
153 captcha_id, captcha_solution):115 captcha_id, captcha_solution):
154 """Call the matching method in the processor."""116 """Call the matching method in the processor."""
155 def f():117 self.root.register_user(app_name, email, password, captcha_id,
156 """Inner function that will be run in a thread."""118 captcha_solution, blocking,
157 return self.processor.register_user(email, password,119 self.UserRegistered,
158 captcha_id, captcha_solution)120 self.UserRegistrationError)
159 blocking(f, app_name, self.UserRegistered, self.UserRegistrationError)
160121
161 # login signals122 # login signals
162 @dbus.service.signal(DBUS_IFACE_USER_NAME, signature="ss")123 @dbus.service.signal(DBUS_IFACE_USER_NAME, signature="ss")
@@ -181,30 +142,8 @@
181 in_signature='sss')142 in_signature='sss')
182 def login(self, app_name, email, password):143 def login(self, app_name, email, password):
183 """Call the matching method in the processor."""144 """Call the matching method in the processor."""
184 def f():145 self.root.login(app_name, email, password, blocking, self.LoggedIn,
185 """Inner function that will be run in a thread."""146 self.LoginError, self.UserNotValidated)
186 token_name = get_token_name(app_name)
187 logger.debug('login: token_name %r, email %r, password <hidden>.',
188 token_name, email)
189 credentials = self.processor.login(email, password, token_name)
190 logger.debug('login returned not None credentials? %r.',
191 credentials is not None)
192 return credentials
193
194 def success_cb(app_name, credentials):
195 """Login finished successfull."""
196 is_validated = self.processor.is_validated(credentials)
197 logger.debug('user is validated? %r.', is_validated)
198 if is_validated:
199 # pylint: disable=E1101
200 d = Keyring().set_credentials(app_name, credentials)
201 d.addCallback(lambda _: self.LoggedIn(app_name, email))
202 d.addErrback(lambda failure: \
203 self.LoginError(app_name,
204 except_to_errdict(failure.value)))
205 else:
206 self.UserNotValidated(app_name, email)
207 blocking(f, app_name, success_cb, self.LoginError)
208147
209 # validate_email signals148 # validate_email signals
210 @dbus.service.signal(DBUS_IFACE_USER_NAME, signature="ss")149 @dbus.service.signal(DBUS_IFACE_USER_NAME, signature="ss")
@@ -223,23 +162,9 @@
223 in_signature='ssss')162 in_signature='ssss')
224 def validate_email(self, app_name, email, password, email_token):163 def validate_email(self, app_name, email, password, email_token):
225 """Call the matching method in the processor."""164 """Call the matching method in the processor."""
226165 self.root.validate_email(app_name, email, password, email_token,
227 def f():166 blocking, self.EmailValidated,
228 """Inner function that will be run in a thread."""167 self.EmailValidationError)
229 token_name = get_token_name(app_name)
230 credentials = self.processor.validate_email(email, password,
231 email_token, token_name)
232 return credentials
233
234 def success_cb(app_name, credentials):
235 """Validation finished successfully."""
236 # pylint: disable=E1101
237 d = Keyring().set_credentials(app_name, credentials)
238 d.addCallback(lambda _: self.EmailValidated(app_name, email))
239 failure_cb = lambda f: self.EmailValidationError(app_name, f.value)
240 d.addErrback(failure_cb)
241
242 blocking(f, app_name, success_cb, self.EmailValidationError)
243168
244 # request_password_reset_token signals169 # request_password_reset_token signals
245 @dbus.service.signal(DBUS_IFACE_USER_NAME, signature="ss")170 @dbus.service.signal(DBUS_IFACE_USER_NAME, signature="ss")
@@ -258,11 +183,9 @@
258 in_signature='ss')183 in_signature='ss')
259 def request_password_reset_token(self, app_name, email):184 def request_password_reset_token(self, app_name, email):
260 """Call the matching method in the processor."""185 """Call the matching method in the processor."""
261 def f():186 self.root.request_password_reset_token(app_name, email, blocking,
262 """Inner function that will be run in a thread."""187 self.PasswordResetTokenSent,
263 return self.processor.request_password_reset_token(email)188 self.PasswordResetError)
264 blocking(f, app_name, self.PasswordResetTokenSent,
265 self.PasswordResetError)
266189
267 # set_new_password signals190 # set_new_password signals
268 @dbus.service.signal(DBUS_IFACE_USER_NAME, signature="ss")191 @dbus.service.signal(DBUS_IFACE_USER_NAME, signature="ss")
@@ -281,11 +204,9 @@
281 in_signature='ssss')204 in_signature='ssss')
282 def set_new_password(self, app_name, email, token, new_password):205 def set_new_password(self, app_name, email, token, new_password):
283 """Call the matching method in the processor."""206 """Call the matching method in the processor."""
284 def f():207 self.root.set_new_password(app_name, email, token, new_password,
285 """Inner function that will be run in a thread."""208 blocking, self.PasswordChanged,
286 return self.processor.set_new_password(email, token,209 self.PasswordChangeError)
287 new_password)
288 blocking(f, app_name, self.PasswordChanged, self.PasswordChangeError)
289210
290211
291class SSOCredentials(dbus.service.Object):212class SSOCredentials(dbus.service.Object):
@@ -296,7 +217,7 @@
296217
297 def __init__(self, *args, **kwargs):218 def __init__(self, *args, **kwargs):
298 dbus.service.Object.__init__(self, *args, **kwargs)219 dbus.service.Object.__init__(self, *args, **kwargs)
299 self.ping_url = os.environ.get('USSOC_PING_URL', U1_PING_URL)220 self.root = SSOCredentialsRoot()
300221
301 def _process_error(self, app_name, error_dict):222 def _process_error(self, app_name, error_dict):
302 """Process the 'error_dict' and emit CredentialsError."""223 """Process the 'error_dict' and emit CredentialsError."""
@@ -327,17 +248,7 @@
327 async_callbacks=("callback", "errback"))248 async_callbacks=("callback", "errback"))
328 def find_credentials(self, app_name, callback=NO_OP, errback=NO_OP):249 def find_credentials(self, app_name, callback=NO_OP, errback=NO_OP):
329 """Get the credentials from the keyring or {} if not there."""250 """Get the credentials from the keyring or {} if not there."""
330251 self.root.find_credentials(app_name, callback, errback)
331 def log_result(result):
332 """Log the result and continue."""
333 logger.info('find_credentials: app_name "%s", result is {}? %s',
334 app_name, result == {})
335 return result
336
337 d = Credentials(app_name=app_name).find_credentials()
338 # pylint: disable=E1101
339 d.addCallback(log_result)
340 d.addCallbacks(callback, errback)
341252
342 @dbus.service.method(dbus_interface=DBUS_IFACE_CRED_NAME,253 @dbus.service.method(dbus_interface=DBUS_IFACE_CRED_NAME,
343 in_signature="sssx", out_signature="")254 in_signature="sssx", out_signature="")
@@ -354,14 +265,12 @@
354 the GUI. If 0, no parent will be set.265 the GUI. If 0, no parent will be set.
355266
356 """267 """
357 ping_url = self.ping_url if app_name == U1_APP_NAME else None268 self.root.login_or_register_to_get_credentials(app_name,
358 obj = Credentials(app_name=app_name, ping_url=ping_url,269 terms_and_conditions_url,
359 tc_url=terms_and_conditions_url,270 help_text, window_id,
360 help_text=help_text, window_id=window_id,271 self.CredentialsFound,
361 success_cb=self.CredentialsFound,272 self._process_error,
362 error_cb=self._process_error,273 self.AuthorizationDenied)
363 denial_cb=self.AuthorizationDenied)
364 obj.register()
365274
366 @dbus.service.method(dbus_interface=DBUS_IFACE_CRED_NAME,275 @dbus.service.method(dbus_interface=DBUS_IFACE_CRED_NAME,
367 in_signature="ssx", out_signature="")276 in_signature="ssx", out_signature="")
@@ -375,13 +284,10 @@
375 the GUI. If 0, no parent will be set.284 the GUI. If 0, no parent will be set.
376285
377 """286 """
378 ping_url = self.ping_url if app_name == U1_APP_NAME else None287 self.root.login_to_get_credentials(app_name, help_text, window_id,
379 obj = Credentials(app_name=app_name, ping_url=ping_url, tc_url=None,288 self.CredentialsFound,
380 help_text=help_text, window_id=window_id,289 self._process_error,
381 success_cb=self.CredentialsFound,290 self.AuthorizationDenied)
382 error_cb=self._process_error,
383 denial_cb=self.AuthorizationDenied)
384 obj.login()
385291
386 @dbus.service.method(dbus_interface=DBUS_IFACE_CRED_NAME,292 @dbus.service.method(dbus_interface=DBUS_IFACE_CRED_NAME,
387 in_signature='s', out_signature='',293 in_signature='s', out_signature='',
@@ -391,9 +297,7 @@
391297
392 'app_name' is the name of the application.298 'app_name' is the name of the application.
393 """299 """
394 d = Credentials(app_name=app_name).clear_credentials()300 self.root.clear_token(app_name, callback, errback)
395 # pylint: disable=E1101
396 d.addCallbacks(lambda _: callback(), errback)
397301
398302
399class CredentialsManagement(dbus.service.Object):303class CredentialsManagement(dbus.service.Object):
@@ -427,22 +331,13 @@
427 self._ref_count = 0331 self._ref_count = 0
428 self.timeout_func = timeout_func332 self.timeout_func = timeout_func
429 self.shutdown_func = shutdown_func333 self.shutdown_func = shutdown_func
334 self.root = CredentialsManagementRoot(self.CredentialsFound,
335 self.CredentialsError,
336 self.AuthorizationDenied)
430337
431 # Operator not preceded by a space (fails with dbus decorators)338 # Operator not preceded by a space (fails with dbus decorators)
432 # pylint: disable=C0322339 # pylint: disable=C0322
433340
434 valid_keys = (HELP_TEXT_KEY, PING_URL_KEY, TC_URL_KEY,
435 UI_CLASS_KEY, UI_MODULE_KEY, WINDOW_ID_KEY)
436
437 def _parse_args(self, args):
438 """Retrieve values from the generic param 'args'."""
439 result = dict(i for i in args.iteritems() if i[0] in self.valid_keys)
440 result[WINDOW_ID_KEY] = int(args.get(WINDOW_ID_KEY, 0))
441 result[SUCCESS_CB_KEY] = self.CredentialsFound
442 result[ERROR_CB_KEY] = self.CredentialsError
443 result[DENIAL_CB_KEY] = self.AuthorizationDenied
444 return result
445
446 def _process_failure(self, failure, app_name):341 def _process_failure(self, failure, app_name):
447 """Process the 'failure' and emit CredentialsError."""342 """Process the 'failure' and emit CredentialsError."""
448 self.CredentialsError(app_name, except_to_errdict(failure.value))343 self.CredentialsError(app_name, except_to_errdict(failure.value))
@@ -539,11 +434,8 @@
539 else:434 else:
540 self.CredentialsNotFound(app_name)435 self.CredentialsNotFound(app_name)
541436
542 obj = Credentials(app_name)437 self.root.find_credentials(app_name, args, success_cb,
543 d = obj.find_credentials()438 self._process_failure)
544 # pylint: disable=E1101
545 d.addCallback(success_cb)
546 d.addErrback(self._process_failure, app_name)
547439
548 @dbus.service.method(dbus_interface=DBUS_CREDENTIALS_IFACE,440 @dbus.service.method(dbus_interface=DBUS_CREDENTIALS_IFACE,
549 in_signature='sa{ss}', out_signature='')441 in_signature='sa{ss}', out_signature='')
@@ -557,12 +449,9 @@
557449
558 """450 """
559 self.ref_count += 1451 self.ref_count += 1
560452 self.root.clear_credentials(app_name, args,
561 obj = Credentials(app_name)453 lambda _: self.CredentialsCleared(app_name),
562 d = obj.clear_credentials()454 self._process_failure)
563 # pylint: disable=E1101
564 d.addCallback(lambda _: self.CredentialsCleared(app_name))
565 d.addErrback(self._process_failure, app_name)
566455
567 @dbus.service.method(dbus_interface=DBUS_CREDENTIALS_IFACE,456 @dbus.service.method(dbus_interface=DBUS_CREDENTIALS_IFACE,
568 in_signature='sa{ss}', out_signature='')457 in_signature='sa{ss}', out_signature='')
@@ -578,27 +467,20 @@
578467
579 """468 """
580 self.ref_count += 1469 self.ref_count += 1
581470 self.root.store_credentials(app_name, args,
582 obj = Credentials(app_name)471 lambda _: self.CredentialsStored(app_name),
583 d = obj.store_credentials(args)472 self._process_failure)
584 # pylint: disable=E1101
585 d.addCallback(lambda _: self.CredentialsStored(app_name))
586 d.addErrback(self._process_failure, app_name)
587473
588 @dbus.service.method(dbus_interface=DBUS_CREDENTIALS_IFACE,474 @dbus.service.method(dbus_interface=DBUS_CREDENTIALS_IFACE,
589 in_signature='sa{ss}', out_signature='')475 in_signature='sa{ss}', out_signature='')
590 def register(self, app_name, args):476 def register(self, app_name, args):
591 """Get credentials if found else prompt GUI to register."""477 """Get credentials if found else prompt GUI to register."""
592 self.ref_count += 1478 self.ref_count += 1
593479 self.root.register(app_name, args)
594 obj = Credentials(app_name, **self._parse_args(args))
595 obj.register()
596480
597 @dbus.service.method(dbus_interface=DBUS_CREDENTIALS_IFACE,481 @dbus.service.method(dbus_interface=DBUS_CREDENTIALS_IFACE,
598 in_signature='sa{ss}', out_signature='')482 in_signature='sa{ss}', out_signature='')
599 def login(self, app_name, args):483 def login(self, app_name, args):
600 """Get credentials if found else prompt GUI to login."""484 """Get credentials if found else prompt GUI to login."""
601 self.ref_count += 1485 self.ref_count += 1
602486 self.root.login(app_name, args)
603 obj = Credentials(app_name, **self._parse_args(args))
604 obj.login()
605487
=== added file 'ubuntu_sso/main/windows.py'
--- ubuntu_sso/main/windows.py 1970-01-01 00:00:00 +0000
+++ ubuntu_sso/main/windows.py 2011-03-17 08:43:34 +0000
@@ -0,0 +1,17 @@
1# -*- coding: utf-8 -*-
2# Author: Manuel de la Pena <manuel@canonical.com>
3#
4# Copyright 2011 Canonical Ltd.
5#
6# This program is free software: you can redistribute it and/or modify it
7# under the terms of the GNU General Public License version 3, as published
8# by the Free Software Foundation.
9#
10# This program is distributed in the hope that it will be useful, but
11# WITHOUT ANY WARRANTY; without even the implied warranties of
12# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
13# PURPOSE. See the GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License along
16# with this program. If not, see <http://www.gnu.org/licenses/>.
17"""Main implementation on windows."""
018
=== renamed file 'ubuntu_sso/tests/keyring/test_linux_keyring.py' => 'ubuntu_sso/tests/keyring/test_linux.py'
=== renamed file 'ubuntu_sso/tests/keyring/test_windows_keyring.py' => 'ubuntu_sso/tests/keyring/test_windows.py'
=== added directory 'ubuntu_sso/tests/main'
=== added file 'ubuntu_sso/tests/main/__init__.py'
--- ubuntu_sso/tests/main/__init__.py 1970-01-01 00:00:00 +0000
+++ ubuntu_sso/tests/main/__init__.py 2011-03-17 08:43:34 +0000
@@ -0,0 +1,17 @@
1# -*- coding: utf-8 -*-
2# Author: Manuel de la Pena <manuel@canonical.com>
3#
4# Copyright 2011 Canonical Ltd.
5#
6# This program is free software: you can redistribute it and/or modify it
7# under the terms of the GNU General Public License version 3, as published
8# by the Free Software Foundation.
9#
10# This program is distributed in the hope that it will be useful, but
11# WITHOUT ANY WARRANTY; without even the implied warranties of
12# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
13# PURPOSE. See the GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License along
16# with this program. If not, see <http://www.gnu.org/licenses/>.
17"""Test the different main implementations."""
018
=== added file 'ubuntu_sso/tests/main/test_common.py'
--- ubuntu_sso/tests/main/test_common.py 1970-01-01 00:00:00 +0000
+++ ubuntu_sso/tests/main/test_common.py 2011-03-17 08:43:34 +0000
@@ -0,0 +1,244 @@
1# -*- coding: utf-8 -*-
2#
3# test_main - tests for ubuntu_sso.main
4#
5# Author: Natalia Bidart <natalia.bidart@canonical.com>
6# Author: Alejandro J. Cura <alecu@canonical.com>
7# Author: Manuel de la Pena <manuel@canonical.com>
8#
9# Copyright 2009-2010 Canonical Ltd.
10#
11# This program is free software: you can redistribute it and/or modify it
12# under the terms of the GNU General Public License version 3, as published
13# by the Free Software Foundation.
14#
15# This program is distributed in the hope that it will be useful, but
16# WITHOUT ANY WARRANTY; without even the implied warranties of
17# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
18# PURPOSE. See the GNU General Public License for more details.
19#
20# You should have received a copy of the GNU General Public License along
21# with this program. If not, see <http://www.gnu.org/licenses/>.
22"""Tests share by diff platforms."""
23
24import os
25
26from unittest import TestCase
27from mocker import MockerTestCase, MATCH
28from ubuntu_sso.main import (
29 CredentialsManagement,
30 SSOCredentialsRoot,
31 SSOCredentials,
32 SSOLogin,
33 U1_PING_URL)
34
35
36class EnvironOverridesTestCase(TestCase):
37 """Some URLs can be set from the environment for testing/QA purposes."""
38
39 def test_override_ping_url(self):
40 """The ping url can be set from the environ via USSOC_PING_URL."""
41 fake_url = 'this is not really a URL'
42 old_url = os.environ.get('USSOC_PING_URL')
43 os.environ['USSOC_PING_URL'] = fake_url
44 try:
45 creds = SSOCredentialsRoot()
46 self.assertEqual(creds.ping_url, fake_url)
47 finally:
48 if old_url:
49 os.environ['USSOC_PING_URL'] = old_url
50 else:
51 del os.environ['USSOC_PING_URL']
52
53 def test_no_override_ping_url(self):
54 """If the environ is unset, the default ping url is used."""
55 creds = SSOCredentialsRoot()
56 self.assertEqual(creds.ping_url, U1_PING_URL)
57
58
59class SSOLoginMockedTestCase(MockerTestCase):
60 """Test that the call are relied correctly."""
61
62 def setUp(self):
63 """Setup tests."""
64 super(SSOLoginMockedTestCase, self).setUp()
65 self.root = self.mocker.mock()
66 mockbusname = self.mocker.mock()
67 mockbus = self.mocker.mock()
68 mockbusname.get_bus()
69 self.mocker.result(mockbus)
70 self.login = SSOLogin(mockbus)
71 self.login.root = self.root
72 self.mocker.reset()
73
74 def test_generate_captcha(self):
75 """Test that the call is relayed."""
76 app_name = 'app'
77 filename = 'file'
78 self.root.generate_captcha(app_name, filename, MATCH(callable),
79 MATCH(callable), MATCH(callable))
80 self.mocker.replay()
81 self.login.generate_captcha(app_name, filename)
82
83 def test_register_user(self):
84 """Test that the call is relayed."""
85 app_name = 'app'
86 email = 'email'
87 password = 'pwd'
88 captcha_id = 'id'
89 captcha_solution = 'hello'
90 self.root.register_user(app_name, email, password, captcha_id,
91 captcha_solution, MATCH(callable),
92 MATCH(callable), MATCH(callable))
93 self.mocker.replay()
94 self.login.register_user(app_name, email, password, captcha_id,
95 captcha_solution)
96
97 def test_login(self):
98 """Test that the call is relayed."""
99 app_name = 'app'
100 email = 'email'
101 password = 'password'
102 self.root.login(app_name, email, password, MATCH(callable),
103 MATCH(callable), MATCH(callable),
104 MATCH(callable))
105 self.mocker.mock()
106 self.mocker.replay()
107 self.login.login(app_name, email, password)
108
109 def test_validate_email(self):
110 """Test that the call is relayed."""
111 app_name = 'app'
112 email = 'email'
113 password = 'passwrd'
114 email_token = 'token'
115 self.root.validate_email(app_name, email, password, email_token,
116 MATCH(callable), MATCH(callable),
117 MATCH(callable))
118 self.mocker.replay()
119 self.login.validate_email(app_name, email, password, email_token)
120
121 def test_request_password_reset_tolen(self):
122 """Test that the call is relayed."""
123 app_name = 'app'
124 email = 'email'
125 self.root.request_password_reset_token(app_name, email,
126 MATCH(callable),
127 MATCH(callable),
128 MATCH(callable))
129 self.mocker.replay()
130 self.login.request_password_reset_token(app_name, email)
131
132 def test_set_new_password(self):
133 """Test that the call is relayed."""
134 app_name = 'app'
135 email = 'email'
136 token = 'token'
137 new_password = 'new'
138 self.root.set_new_password(app_name, email, token, new_password,
139 MATCH(callable), MATCH(callable),
140 MATCH(callable))
141 self.mocker.replay()
142 self.login.set_new_password(app_name, email, token, new_password)
143
144
145class SSOCredentialsMockedTestCase(MockerTestCase):
146 """Test that the call are relied correctly."""
147
148 def setUp(self):
149 """Setup tests."""
150 super(SSOCredentialsMockedTestCase, self).setUp()
151 self.root = self.mocker.mock()
152 mockbusname = self.mocker.mock()
153 mockbus = self.mocker.mock()
154 mockbusname.get_bus()
155 self.mocker.result(mockbus)
156 self.cred = SSOCredentials(mockbus)
157 self.cred.root = self.root
158 self.mocker.reset()
159
160 def test_find_credentials(self):
161 """Test that the call is relayed."""
162 app_name = 'app'
163 result_cb = error_cb = lambda: None
164 self.root.find_credentials(app_name, result_cb, error_cb)
165 self.mocker.mock()
166 self.mocker.replay()
167 self.cred.find_credentials(app_name, result_cb, error_cb)
168
169 def test_login_or_register_to_get_credentials(self):
170 """Test that the call is relayed."""
171 app_name = 'app'
172 terms = 'terms'
173 help_text = 'help'
174 window_id = 'id'
175 self.root.login_or_register_to_get_credentials(app_name, terms,
176 help_text, window_id,
177 MATCH(callable),
178 MATCH(callable),
179 MATCH(callable))
180 self.mocker.replay()
181 self.cred.login_or_register_to_get_credentials(app_name, terms,
182 help_text, window_id)
183
184 def test_clear_token(self):
185 """Test that the call is relayed."""
186 app_name = 'app'
187 result_cb = error_cb = lambda: None
188 self.root.clear_token(app_name, result_cb, error_cb)
189 self.mocker.replay()
190 self.cred.clear_token(app_name, result_cb, error_cb)
191
192
193class CredentialsManagementMockedTestCase(MockerTestCase):
194 """Test that the call are relied correctly."""
195
196 def setUp(self):
197 """Setup tests."""
198 super(CredentialsManagementMockedTestCase, self).setUp()
199 self.root = self.mocker.mock()
200 self.cred = CredentialsManagement(None, None)
201 self.cred.root = self.root
202
203 def test_find_credentials(self):
204 """Test that the call is relayed."""
205 app_name = 'app'
206 args = 'args'
207 self.root.find_credentials(app_name, args, MATCH(callable),
208 MATCH(callable))
209 self.mocker.replay()
210 self.cred.find_credentials(app_name, args)
211
212 def test_clear_credentials(self):
213 """Test that the call is relayed."""
214 app_name = 'app'
215 args = 'args'
216 self.root.clear_credentials(app_name, args, MATCH(callable),
217 MATCH(callable))
218 self.mocker.replay()
219 self.cred.clear_credentials(app_name, args)
220
221 def test_store_credentials(self):
222 """Test that the call is relayed."""
223 app_name = 'app'
224 args = 'args'
225 self.root.store_credentials(app_name, args, MATCH(callable),
226 MATCH(callable))
227 self.mocker.replay()
228 self.cred.store_credentials(app_name, args)
229
230 def test_register(self):
231 """Test that the call is relayed."""
232 app_name = 'app'
233 args = 'args'
234 self.root.register(app_name, args)
235 self.mocker.replay()
236 self.cred.register(app_name, args)
237
238 def test_login(self):
239 """Test that the call is relayed."""
240 app_name = 'app'
241 args = 'args'
242 self.root.login(app_name, args)
243 self.mocker.replay()
244 self.cred.login(app_name, args)
0245
=== renamed file 'ubuntu_sso/tests/test_main.py' => 'ubuntu_sso/tests/main/test_linux.py'
--- ubuntu_sso/tests/test_main.py 2011-01-28 13:45:09 +0000
+++ ubuntu_sso/tests/main/test_linux.py 2011-03-17 08:43:34 +0000
@@ -31,12 +31,13 @@
3131
32import ubuntu_sso.keyring32import ubuntu_sso.keyring
33import ubuntu_sso.main33import ubuntu_sso.main
34import ubuntu_sso.main.linux
3435
35from ubuntu_sso import DBUS_CREDENTIALS_IFACE36from ubuntu_sso import DBUS_CREDENTIALS_IFACE
36from ubuntu_sso.keyring import U1_APP_NAME37from ubuntu_sso.keyring import U1_APP_NAME
37from ubuntu_sso.main import (U1_PING_URL, TIMEOUT_INTERVAL,38from ubuntu_sso.main import (U1_PING_URL, except_to_errdict,
38 blocking, except_to_errdict,
39 CredentialsManagement, SSOCredentials, SSOLogin)39 CredentialsManagement, SSOCredentials, SSOLogin)
40from ubuntu_sso.main.linux import TIMEOUT_INTERVAL, blocking
40from ubuntu_sso.main import (HELP_TEXT_KEY, PING_URL_KEY,41from ubuntu_sso.main import (HELP_TEXT_KEY, PING_URL_KEY,
41 TC_URL_KEY, UI_CLASS_KEY, UI_MODULE_KEY, WINDOW_ID_KEY,42 TC_URL_KEY, UI_CLASS_KEY, UI_MODULE_KEY, WINDOW_ID_KEY,
42 SUCCESS_CB_KEY, ERROR_CB_KEY, DENIAL_CB_KEY)43 SUCCESS_CB_KEY, ERROR_CB_KEY, DENIAL_CB_KEY)
@@ -120,7 +121,7 @@
120 expected_result = "expected result"121 expected_result = "expected result"
121 self.create_mock_processor().generate_captcha(filename)122 self.create_mock_processor().generate_captcha(filename)
122 self.mocker.result(expected_result)123 self.mocker.result(expected_result)
123 self.patch(ubuntu_sso.main, "blocking", fake_ok_blocking)124 self.patch(ubuntu_sso.main.linux, "blocking", fake_ok_blocking)
124 self.mocker.replay()125 self.mocker.replay()
125126
126 def verify(app_name, result):127 def verify(app_name, result):
@@ -143,7 +144,7 @@
143 expected_result = "expected result"144 expected_result = "expected result"
144 self.create_mock_processor().generate_captcha(filename)145 self.create_mock_processor().generate_captcha(filename)
145 self.mocker.result(expected_result)146 self.mocker.result(expected_result)
146 self.patch(ubuntu_sso.main, "blocking", fake_err_blocking)147 self.patch(ubuntu_sso.main.linux, "blocking", fake_err_blocking)
147 self.mocker.replay()148 self.mocker.replay()
148149
149 def verify(app_name, errdict):150 def verify(app_name, errdict):
@@ -166,7 +167,7 @@
166 self.create_mock_processor().register_user(EMAIL, PASSWORD, CAPTCHA_ID,167 self.create_mock_processor().register_user(EMAIL, PASSWORD, CAPTCHA_ID,
167 CAPTCHA_SOLUTION)168 CAPTCHA_SOLUTION)
168 self.mocker.result(expected_result)169 self.mocker.result(expected_result)
169 self.patch(ubuntu_sso.main, "blocking", fake_ok_blocking)170 self.patch(ubuntu_sso.main.linux, "blocking", fake_ok_blocking)
170 self.mocker.replay()171 self.mocker.replay()
171172
172 def verify(app_name, result):173 def verify(app_name, result):
@@ -190,7 +191,7 @@
190 self.create_mock_processor().register_user(EMAIL, PASSWORD, CAPTCHA_ID,191 self.create_mock_processor().register_user(EMAIL, PASSWORD, CAPTCHA_ID,
191 CAPTCHA_SOLUTION)192 CAPTCHA_SOLUTION)
192 self.mocker.result(expected_result)193 self.mocker.result(expected_result)
193 self.patch(ubuntu_sso.main, "blocking", fake_err_blocking)194 self.patch(ubuntu_sso.main.linux, "blocking", fake_err_blocking)
194 self.mocker.replay()195 self.mocker.replay()
195196
196 def verify(app_name, errdict):197 def verify(app_name, errdict):
@@ -215,7 +216,7 @@
215 self.mocker.result(TOKEN)216 self.mocker.result(TOKEN)
216 processor.is_validated(TOKEN)217 processor.is_validated(TOKEN)
217 self.mocker.result(True)218 self.mocker.result(True)
218 self.patch(ubuntu_sso.main, "blocking", fake_ok_blocking)219 self.patch(ubuntu_sso.main.linux, "blocking", fake_ok_blocking)
219 self.mocker.replay()220 self.mocker.replay()
220221
221 def verify(app_name, result):222 def verify(app_name, result):
@@ -241,7 +242,7 @@
241 self.mocker.result(TOKEN)242 self.mocker.result(TOKEN)
242 processor.is_validated(TOKEN)243 processor.is_validated(TOKEN)
243 self.mocker.result(False)244 self.mocker.result(False)
244 self.patch(ubuntu_sso.main, "blocking", fake_ok_blocking)245 self.patch(ubuntu_sso.main.linux, "blocking", fake_ok_blocking)
245 self.mocker.replay()246 self.mocker.replay()
246247
247 def verify(app_name, email):248 def verify(app_name, email):
@@ -263,7 +264,7 @@
263 """The login method fails as expected when get_token_name fails."""264 """The login method fails as expected when get_token_name fails."""
264 d = Deferred()265 d = Deferred()
265 self.create_mock_processor()266 self.create_mock_processor()
266 self.patch(ubuntu_sso.main, "blocking", fake_err_blocking)267 self.patch(ubuntu_sso.main.linux, "blocking", fake_err_blocking)
267268
268 def fake_gtn(*args):269 def fake_gtn(*args):
269 """A fake get_token_name that fails."""270 """A fake get_token_name that fails."""
@@ -296,7 +297,7 @@
296 processor.is_validated(TOKEN)297 processor.is_validated(TOKEN)
297 self.mocker.result(True)298 self.mocker.result(True)
298299
299 self.patch(ubuntu_sso.main, "blocking", fake_ok_blocking)300 self.patch(ubuntu_sso.main.linux, "blocking", fake_ok_blocking)
300301
301 def fake_set_creds(*args):302 def fake_set_creds(*args):
302 """A fake Keyring.set_credentials that fails."""303 """A fake Keyring.set_credentials that fails."""
@@ -327,7 +328,7 @@
327 self.create_mock_processor().validate_email(EMAIL, PASSWORD,328 self.create_mock_processor().validate_email(EMAIL, PASSWORD,
328 EMAIL_TOKEN, TOKEN_NAME)329 EMAIL_TOKEN, TOKEN_NAME)
329 self.mocker.result(TOKEN)330 self.mocker.result(TOKEN)
330 self.patch(ubuntu_sso.main, "blocking", fake_ok_blocking)331 self.patch(ubuntu_sso.main.linux, "blocking", fake_ok_blocking)
331 self.mocker.replay()332 self.mocker.replay()
332333
333 def verify(app_name, result):334 def verify(app_name, result):
@@ -348,7 +349,7 @@
348 """Test that the validate_email method fails as expected."""349 """Test that the validate_email method fails as expected."""
349 d = Deferred()350 d = Deferred()
350 self.create_mock_processor()351 self.create_mock_processor()
351 self.patch(ubuntu_sso.main, "blocking", fake_err_blocking)352 self.patch(ubuntu_sso.main.linux, "blocking", fake_err_blocking)
352353
353 def fake_gtn(*args):354 def fake_gtn(*args):
354 """A fake get_token_name that fails."""355 """A fake get_token_name that fails."""
@@ -376,7 +377,7 @@
376 d = Deferred()377 d = Deferred()
377 processor = self.create_mock_processor()378 processor = self.create_mock_processor()
378 processor.request_password_reset_token(EMAIL)379 processor.request_password_reset_token(EMAIL)
379 self.patch(ubuntu_sso.main, "blocking", fake_ok_blocking)380 self.patch(ubuntu_sso.main.linux, "blocking", fake_ok_blocking)
380 self.mocker.result(EMAIL)381 self.mocker.result(EMAIL)
381 self.mocker.replay()382 self.mocker.replay()
382383
@@ -399,7 +400,7 @@
399400
400 self.create_mock_processor().request_password_reset_token(EMAIL)401 self.create_mock_processor().request_password_reset_token(EMAIL)
401 self.mocker.result(EMAIL)402 self.mocker.result(EMAIL)
402 self.patch(ubuntu_sso.main, "blocking", fake_err_blocking)403 self.patch(ubuntu_sso.main.linux, "blocking", fake_err_blocking)
403 self.mocker.replay()404 self.mocker.replay()
404405
405 def verify(app_name, errdict):406 def verify(app_name, errdict):
@@ -421,7 +422,7 @@
421 self.create_mock_processor().set_new_password(EMAIL, EMAIL_TOKEN,422 self.create_mock_processor().set_new_password(EMAIL, EMAIL_TOKEN,
422 PASSWORD)423 PASSWORD)
423 self.mocker.result(EMAIL)424 self.mocker.result(EMAIL)
424 self.patch(ubuntu_sso.main, "blocking", fake_ok_blocking)425 self.patch(ubuntu_sso.main.linux, "blocking", fake_ok_blocking)
425 self.mocker.replay()426 self.mocker.replay()
426427
427 def verify(app_name, result):428 def verify(app_name, result):
@@ -445,7 +446,7 @@
445 self.create_mock_processor().set_new_password(EMAIL, EMAIL_TOKEN,446 self.create_mock_processor().set_new_password(EMAIL, EMAIL_TOKEN,
446 PASSWORD)447 PASSWORD)
447 self.mocker.result(expected_result)448 self.mocker.result(expected_result)
448 self.patch(ubuntu_sso.main, "blocking", fake_err_blocking)449 self.patch(ubuntu_sso.main.linux, "blocking", fake_err_blocking)
449 self.mocker.replay()450 self.mocker.replay()
450451
451 def verify(app_name, errdict):452 def verify(app_name, errdict):
@@ -687,7 +688,7 @@
687 os.environ['USSOC_PING_URL'] = fake_url688 os.environ['USSOC_PING_URL'] = fake_url
688 try:689 try:
689 creds = SSOCredentials(None)690 creds = SSOCredentials(None)
690 self.assertEqual(creds.ping_url, fake_url)691 self.assertEqual(creds.root.ping_url, fake_url)
691 finally:692 finally:
692 if old_url:693 if old_url:
693 os.environ['USSOC_PING_URL'] = old_url694 os.environ['USSOC_PING_URL'] = old_url
@@ -697,7 +698,7 @@
697 def test_no_override_ping_url(self):698 def test_no_override_ping_url(self):
698 """If the environ is unset, the default ping url is used."""699 """If the environ is unset, the default ping url is used."""
699 creds = SSOCredentials(None)700 creds = SSOCredentials(None)
700 self.assertEqual(creds.ping_url, U1_PING_URL)701 self.assertEqual(creds.root.ping_url, U1_PING_URL)
701702
702703
703class CredentialsManagementTestCase(TestCase):704class CredentialsManagementTestCase(TestCase):
@@ -746,7 +747,8 @@
746747
747 def test_is_dbus_object(self):748 def test_is_dbus_object(self):
748 """CredentialsManagement is a Dbus object."""749 """CredentialsManagement is a Dbus object."""
749 self.assertIsInstance(self.client, ubuntu_sso.main.dbus.service.Object)750 self.assertIsInstance(self.client,
751 ubuntu_sso.main.linux.dbus.service.Object)
750752
751753
752class FakeCredentials(object):754class FakeCredentials(object):
753755
=== added file 'ubuntu_sso/tests/main/test_windows.py'
--- ubuntu_sso/tests/main/test_windows.py 1970-01-01 00:00:00 +0000
+++ ubuntu_sso/tests/main/test_windows.py 2011-03-17 08:43:34 +0000
@@ -0,0 +1,17 @@
1# -*- coding: utf-8 -*-
2# Author: Manuel de la Pena <manuel@canonical.com>
3#
4# Copyright 2011 Canonical Ltd.
5#
6# This program is free software: you can redistribute it and/or modify it
7# under the terms of the GNU General Public License version 3, as published
8# by the Free Software Foundation.
9#
10# This program is distributed in the hope that it will be useful, but
11# WITHOUT ANY WARRANTY; without even the implied warranties of
12# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
13# PURPOSE. See the GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License along
16# with this program. If not, see <http://www.gnu.org/licenses/>.
17"""Windows tests."""
018
=== renamed file 'ubuntu_sso/tests/networkstate/test_linux_networkstate.py' => 'ubuntu_sso/tests/networkstate/test_linux.py'
=== renamed file 'ubuntu_sso/tests/networkstate/test_windows_networkstate.py' => 'ubuntu_sso/tests/networkstate/test_windows.py'

Subscribers

People subscribed via source and target branches