Merge lp:~nataliabidart/ubuntuone-control-panel/new-creds into lp:ubuntuone-control-panel

Proposed by Natalia Bidart
Status: Merged
Approved by: Natalia Bidart
Approved revision: 203
Merged at revision: 201
Proposed branch: lp:~nataliabidart/ubuntuone-control-panel/new-creds
Merge into: lp:ubuntuone-control-panel
Diff against target: 996 lines (+285/-203)
8 files modified
run-tests (+4/-2)
setup.py (+12/-6)
ubuntuone/controlpanel/gui/gtk/gui.py (+46/-70)
ubuntuone/controlpanel/gui/gtk/tests/__init__.py (+12/-14)
ubuntuone/controlpanel/gui/gtk/tests/test_gui.py (+19/-19)
ubuntuone/controlpanel/gui/gtk/tests/test_gui_basic.py (+126/-81)
ubuntuone/controlpanel/login_client.py (+18/-5)
ubuntuone/controlpanel/tests/test_login_client.py (+48/-6)
To merge this branch: bzr merge lp:~nataliabidart/ubuntuone-control-panel/new-creds
Reviewer Review Type Date Requested Status
John Lenton (community) Approve
Roberto Alsina (community) Approve
Review via email: mp+72077@code.launchpad.net

Commit message

- Using CredentialsManagementTool instead of SSO dbus backend (LP: #828805).

To post a comment you must log in.
Revision history for this message
Roberto Alsina (ralsina) wrote :

+1

review: Approve
Revision history for this message
John Lenton (chipaca) wrote :

Good.

What does GTK_MODULES break?

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'run-tests'
--- run-tests 2011-07-15 17:50:50 +0000
+++ run-tests 2011-08-18 17:23:16 +0000
@@ -37,14 +37,16 @@
37fi37fi
3838
39style_check() {39style_check() {
40 u1lint --ignore ubuntuone/controlpanel/gui/qt/ui ubuntuone/40 u1lint --ignore ubuntuone/controlpanel/gui/qt/ui
41 if [ -x `which pep8` ]; then41 if [ -x `which pep8` ]; then
42 pep8 --exclude '.svn,CVS,.bzr,.hg,.git,*_ui.py,*_rc.py' --repeat bin/ $MODULE42 pep8 --exclude '.svn,CVS,.bzr,.hg,.git,*_ui.py,*_rc.py' --repeat .
43 else43 else
44 echo "Please install the 'pep8' package."44 echo "Please install the 'pep8' package."
45 fi45 fi
46}46}
4747
48unset GTK_MODULES
49
48./setup.py build50./setup.py build
49echo "Running test suite for ""$MODULE"51echo "Running test suite for ""$MODULE"
50if [ "$USE_QT" -eq 0 ]; then52if [ "$USE_QT" -eq 0 ]; then
5153
=== modified file 'setup.py'
--- setup.py 2011-08-12 19:09:02 +0000
+++ setup.py 2011-08-18 17:23:16 +0000
@@ -46,6 +46,7 @@
46CLEANFILES = [46CLEANFILES = [
47 SERVICE_FILE, GUI_SERVICE_FILE, MESSAGE_ENTRY, CONSTANTS, POT_FILE,47 SERVICE_FILE, GUI_SERVICE_FILE, MESSAGE_ENTRY, CONSTANTS, POT_FILE,
48 'MANIFEST']48 'MANIFEST']
49QT_UI_DIR = os.path.join('ubuntuone', 'controlpanel', 'gui', 'qt', 'ui')
4950
5051
51def replace_prefix(prefix):52def replace_prefix(prefix):
@@ -64,7 +65,7 @@
64 def run(self):65 def run(self):
65 """Do the install.66 """Do the install.
6667
67 Read from *.service.in and generate .service files with reeplacing68 Read from *.service.in and generate .service files by replacing
68 @prefix@ by self.prefix.69 @prefix@ by self.prefix.
6970
70 """71 """
@@ -75,7 +76,6 @@
75class ControlPanelBuild(build_extra.build_extra):76class ControlPanelBuild(build_extra.build_extra):
76 """Build PyQt (.ui) files and resources."""77 """Build PyQt (.ui) files and resources."""
7778
78 QT_UI_DIR = os.path.join('ubuntuone', 'controlpanel', 'gui', 'qt', 'ui')
79 description = "build PyQt GUIs (.ui) and resources (.qrc)"79 description = "build PyQt GUIs (.ui) and resources (.qrc)"
8080
81 def compile_ui(self, ui_file, py_file=None):81 def compile_ui(self, ui_file, py_file=None):
@@ -86,7 +86,7 @@
86 # python file in the qt moodule86 # python file in the qt moodule
87 py_file = os.path.split(ui_file)[1]87 py_file = os.path.split(ui_file)[1]
88 py_file = os.path.splitext(py_file)[0] + '_ui.py'88 py_file = os.path.splitext(py_file)[0] + '_ui.py'
89 py_file = os.path.join(self.QT_UI_DIR, py_file)89 py_file = os.path.join(QT_UI_DIR, py_file)
90 # we indeed want to catch Exception, is ugly but we need it90 # we indeed want to catch Exception, is ugly but we need it
91 # pylint: disable=W070391 # pylint: disable=W0703
92 try:92 try:
@@ -112,7 +112,7 @@
112 if py_file is None:112 if py_file is None:
113 py_file = os.path.split(qrc_file)[1]113 py_file = os.path.split(qrc_file)[1]
114 py_file = os.path.splitext(py_file)[0] + '_rc.py'114 py_file = os.path.splitext(py_file)[0] + '_rc.py'
115 py_file = os.path.join(self.QT_UI_DIR, py_file)115 py_file = os.path.join(QT_UI_DIR, py_file)
116 path = os.getenv('PATH')116 path = os.getenv('PATH')
117 os.putenv('PATH', path + os.path.pathsep + os.path.join(117 os.putenv('PATH', path + os.path.pathsep + os.path.join(
118 os.path.dirname(PyQt4.__file__), 'bin'))118 os.path.dirname(PyQt4.__file__), 'bin'))
@@ -218,6 +218,12 @@
218 if os.path.exists(built_file):218 if os.path.exists(built_file):
219 os.unlink(built_file)219 os.unlink(built_file)
220220
221 for dirpath, _, filenames in os.walk(os.path.join(QT_UI_DIR)):
222 for current_file in filenames:
223 if current_file.endswith('_ui.py') or\
224 current_file.endswith('_rc.py'):
225 os.unlink(os.path.join(dirpath, current_file))
226
221 DistUtilsExtra.auto.clean_build_tree.run(self)227 DistUtilsExtra.auto.clean_build_tree.run(self)
222228
223229
@@ -228,8 +234,8 @@
228 author='Natalia Bidart',234 author='Natalia Bidart',
229 author_email='natalia.bidart@canonical.com',235 author_email='natalia.bidart@canonical.com',
230 description='Ubuntu One Control Panel',236 description='Ubuntu One Control Panel',
231 long_description='Application to manage a Ubuntu One account. Provides a'\237 long_description='Application to manage a Ubuntu One account. Provides' \
232 'DBus service to query/modify all the Ubuntu One bits.',238 ' a DBus service to query/modify all the Ubuntu One bits.',
233 url='https://launchpad.net/ubuntuone-control-panel',239 url='https://launchpad.net/ubuntuone-control-panel',
234 packages=[240 packages=[
235 'ubuntuone', 'ubuntuone.controlpanel', 'ubuntuone.controlpanel.gui',241 'ubuntuone', 'ubuntuone.controlpanel', 'ubuntuone.controlpanel.gui',
236242
=== modified file 'ubuntuone/controlpanel/gui/gtk/gui.py'
--- ubuntuone/controlpanel/gui/gtk/gui.py 2011-06-01 18:10:22 +0000
+++ ubuntuone/controlpanel/gui/gtk/gui.py 2011-08-18 17:23:16 +0000
@@ -28,17 +28,15 @@
28import dbus28import dbus
29import gtk29import gtk
30import gobject30import gobject
31import ubuntu_sso
3231
33from dbus.mainloop.glib import DBusGMainLoop32from dbus.mainloop.glib import DBusGMainLoop
34from ubuntu_sso import networkstate33from ubuntu_sso import networkstate
35from ubuntu_sso.credentials import (TC_URL_KEY, HELP_TEXT_KEY, WINDOW_ID_KEY,
36 PING_URL_KEY)
37# No name 'clientdefs' in module 'ubuntuone'
38# pylint: disable=E0611,F040134# pylint: disable=E0611,F0401
39from gi.repository import GLib35from gi.repository import GLib
40from ubuntuone.clientdefs import (APP_NAME as U1_APP_NAME, TC_URL as U1_TC_URL,36from ubuntuone.platform.credentials import (
41 PING_URL as U1_PING_URL, DESCRIPTION as U1_DESCRIPTION)37 APP_NAME as U1_APP_NAME,
38 CredentialsManagementTool,
39)
42# pylint: enable=E0611,F040140# pylint: enable=E0611,F0401
4341
44# Wildcard import ubuntuone.controlpanel.gui42# Wildcard import ubuntuone.controlpanel.gui
@@ -123,21 +121,6 @@
123 gtk.main()121 gtk.main()
124122
125123
126def filter_by_app_name(f):
127 """Excecute 'f' filtering by app_name."""
128
129 @wraps(f)
130 def filter_by_app_name_inner(instance, app_name, *args, **kwargs):
131 """Execute 'f' only if 'app_name' matches 'U1_APP_NAME'."""
132 if app_name == U1_APP_NAME:
133 return f(instance, app_name, *args, **kwargs)
134 else:
135 logger.info('%s: ignoring call since received app_name '\
136 '"%s" (expected "%s")',
137 f.__name__, app_name, U1_APP_NAME)
138 return filter_by_app_name_inner
139
140
141def on_size_allocate(widget, allocation, label):124def on_size_allocate(widget, allocation, label):
142 """Resize labels according to who 'widget' is being resized."""125 """Resize labels according to who 'widget' is being resized."""
143 label.set_size_request(allocation.width - 2, -1)126 label.set_size_request(allocation.width - 2, -1)
@@ -272,23 +255,9 @@
272255
273 def __init__(self, main_window):256 def __init__(self, main_window):
274 GreyableBin.__init__(self)257 GreyableBin.__init__(self)
275258 creds_backend = CredentialsManagementTool()
276 sso_backend = None
277 bus = dbus.SessionBus()
278 try:
279 obj = bus.get_object(ubuntu_sso.DBUS_BUS_NAME,
280 ubuntu_sso.DBUS_CREDENTIALS_PATH,
281 follow_name_owner_changes=True)
282 iface = ubuntu_sso.DBUS_CREDENTIALS_IFACE
283 sso_backend = dbus.Interface(obj, dbus_interface=iface)
284 except dbus.exceptions.DBusException:
285 logger.exception('Can not connect to DBus at %r',
286 (ubuntu_sso.DBUS_BUS_NAME,
287 ubuntu_sso.DBUS_CREDENTIALS_PATH))
288 raise
289
290 ControlPanelMixin.__init__(self, filename='overview.ui',259 ControlPanelMixin.__init__(self, filename='overview.ui',
291 backend_instance=sso_backend)260 backend_instance=creds_backend)
292 self.add(self.itself)261 self.add(self.itself)
293 self.banner.set_from_file(get_data_file(OVERVIEW_BANNER))262 self.banner.set_from_file(get_data_file(OVERVIEW_BANNER))
294 self.files_icon.set_from_file(get_data_file(FILES_ICON))263 self.files_icon.set_from_file(get_data_file(FILES_ICON))
@@ -305,15 +274,6 @@
305 self._credentials_are_new = False274 self._credentials_are_new = False
306 self.show()275 self.show()
307276
308 self.backend.connect_to_signal('CredentialsFound',
309 self.on_credentials_found)
310 self.backend.connect_to_signal('CredentialsNotFound',
311 self.on_credentials_not_found)
312 self.backend.connect_to_signal('CredentialsError',
313 self.on_credentials_error)
314 self.backend.connect_to_signal('AuthorizationDenied',
315 self.on_authorization_denied)
316
317 kw = dict(result_cb=self.on_network_state_changed)277 kw = dict(result_cb=self.on_network_state_changed)
318 self.network_manager_state = networkstate.NetworkManagerState(**kw)278 self.network_manager_state = networkstate.NetworkManagerState(**kw)
319 self.network_manager_state.find_online_state()279 self.network_manager_state.find_online_state()
@@ -323,6 +283,14 @@
323 ControlPanelMixin._set_warning(self, message,283 ControlPanelMixin._set_warning(self, message,
324 label=self.warning_label)284 label=self.warning_label)
325285
286 def _window_xid(self):
287 """Return settings for credentials backend."""
288 if self.main_window.window is not None:
289 settings = {'window_id': str(self.main_window.window.xid)}
290 else:
291 settings = {}
292 return settings
293
326 def set_property(self, prop_name, new_value):294 def set_property(self, prop_name, new_value):
327 """Override 'set_property' to disable buttons if prop is 'greyed'."""295 """Override 'set_property' to disable buttons if prop is 'greyed'."""
328 if prop_name == 'greyed':296 if prop_name == 'greyed':
@@ -342,21 +310,17 @@
342310
343 def on_join_now_button_clicked(self, *a, **kw):311 def on_join_now_button_clicked(self, *a, **kw):
344 """User wants to join now."""312 """User wants to join now."""
345 settings = {TC_URL_KEY: U1_TC_URL, HELP_TEXT_KEY: U1_DESCRIPTION,313 d = self.backend.register(**self._window_xid())
346 WINDOW_ID_KEY: str(self.main_window.window.xid),314 d.addCallback(self.on_credentials_result)
347 PING_URL_KEY: U1_PING_URL}315 d.addErrback(self.on_credentials_error)
348 self.backend.register(U1_APP_NAME, settings,
349 reply_handler=NO_OP, error_handler=error_handler)
350 self.set_property('greyed', True)316 self.set_property('greyed', True)
351 self.warning_label.set_text('')317 self.warning_label.set_text('')
352318
353 def on_connect_button_clicked(self, *a, **kw):319 def on_connect_button_clicked(self, *a, **kw):
354 """User wants to connect now."""320 """User wants to connect now."""
355 settings = {TC_URL_KEY: U1_TC_URL, HELP_TEXT_KEY: U1_DESCRIPTION,321 d = self.backend.login(**self._window_xid())
356 WINDOW_ID_KEY: str(self.main_window.window.xid),322 d.addCallback(self.on_credentials_result)
357 PING_URL_KEY: U1_PING_URL}323 d.addErrback(self.on_credentials_error)
358 self.backend.login(U1_APP_NAME, settings,
359 reply_handler=NO_OP, error_handler=error_handler)
360 self.set_property('greyed', True)324 self.set_property('greyed', True)
361 self.warning_label.set_text('')325 self.warning_label.set_text('')
362326
@@ -364,31 +328,42 @@
364 """User wants to learn more."""328 """User wants to learn more."""
365 uri_hook(self.learn_more_button, LEARN_MORE_LINK)329 uri_hook(self.learn_more_button, LEARN_MORE_LINK)
366330
367 @filter_by_app_name331 def on_credentials_result(self, result):
332 """Process the credentials response.
333
334 If 'result' is a non empty dict, they were found.
335 If 'result' is an empty dict, they were not found.
336 If 'result' is None, the user cancelled the process.
337
338 """
339 if result is None:
340 self.on_authorization_denied()
341 elif result == {}:
342 self.on_credentials_not_found()
343 else:
344 self.on_credentials_found(result)
345
368 @log_call(logger.info, with_args=False)346 @log_call(logger.info, with_args=False)
369 def on_credentials_found(self, app_name, credentials):347 def on_credentials_found(self, credentials):
370 """SSO backend notifies of credentials found."""348 """Credentials backend notifies of credentials found."""
371 self.set_property('greyed', False)349 self.set_property('greyed', False)
372 self.emit('credentials-found', self._credentials_are_new, credentials)350 self.emit('credentials-found', self._credentials_are_new, credentials)
373351
374 @filter_by_app_name
375 @log_call(logger.info)352 @log_call(logger.info)
376 def on_credentials_not_found(self, app_name):353 def on_credentials_not_found(self):
377 """SSO backend notifies of credentials not found."""354 """Creds backend notifies of credentials not found."""
378 self._credentials_are_new = True355 self._credentials_are_new = True
379 self.set_property('greyed', False)356 self.set_property('greyed', False)
380357
381 @filter_by_app_name
382 @log_call(logger.error)358 @log_call(logger.error)
383 def on_credentials_error(self, app_name, error_dict):359 def on_credentials_error(self, error_dict):
384 """SSO backend notifies of an error when fetching credentials."""360 """Creds backend notifies of an error when fetching credentials."""
385 self.set_property('greyed', False)361 self.set_property('greyed', False)
386 self._set_warning(CREDENTIALS_ERROR)362 self._set_warning(CREDENTIALS_ERROR)
387363
388 @filter_by_app_name
389 @log_call(logger.info)364 @log_call(logger.info)
390 def on_authorization_denied(self, app_name):365 def on_authorization_denied(self):
391 """SSO backend notifies that user refused auth for 'app_name'."""366 """Creds backend notifies that user refused auth for 'app_name'."""
392 self.set_property('greyed', False)367 self.set_property('greyed', False)
393368
394 @log_call(logger.info)369 @log_call(logger.info)
@@ -402,8 +377,9 @@
402 else:377 else:
403 self.set_sensitive(True)378 self.set_sensitive(True)
404 self.warning_label.set_text(msg)379 self.warning_label.set_text(msg)
405 self.backend.find_credentials(U1_APP_NAME, {},380 d = self.backend.find_credentials()
406 reply_handler=NO_OP, error_handler=error_handler)381 d.addCallback(self.on_credentials_result)
382 d.addErrback(self.on_credentials_error)
407383
408384
409class DashboardPanel(UbuntuOneBin, ControlPanelMixin):385class DashboardPanel(UbuntuOneBin, ControlPanelMixin):
410386
=== modified file 'ubuntuone/controlpanel/gui/gtk/tests/__init__.py'
--- ubuntuone/controlpanel/gui/gtk/tests/__init__.py 2011-05-26 22:18:04 +0000
+++ ubuntuone/controlpanel/gui/gtk/tests/__init__.py 2011-08-18 17:23:16 +0000
@@ -22,6 +22,7 @@
2222
23from collections import defaultdict23from collections import defaultdict
2424
25from twisted.internet import defer
25from ubuntuone.devtools.handlers import MementoHandler26from ubuntuone.devtools.handlers import MementoHandler
2627
27from ubuntuone.controlpanel.gui.gtk import gui28from ubuntuone.controlpanel.gui.gtk import gui
@@ -83,14 +84,12 @@
83 self._signals[signal].append(handler)84 self._signals[signal].append(handler)
8485
8586
86class FakedSSOBackend(FakedDBusBackend):87class FakedCredentialsBackend(FakedObject):
87 """Fake a SSO Backend, act as a dbus.Interface."""88 """Fake a credentials backend."""
8889
89 bus_name = gui.ubuntu_sso.DBUS_BUS_NAME
90 object_path = gui.ubuntu_sso.DBUS_CREDENTIALS_PATH
91 iface = gui.ubuntu_sso.DBUS_CREDENTIALS_IFACE
92 exposed_methods = ['find_credentials', 'clear_credentials',90 exposed_methods = ['find_credentials', 'clear_credentials',
93 'login', 'register']91 'login', 'register']
92 next_result = defer.succeed(None)
9493
9594
96class FakedControlPanelBackend(FakedDBusBackend):95class FakedControlPanelBackend(FakedDBusBackend):
@@ -135,8 +134,6 @@
135 if dbus_interface == gui.DBUS_PREFERENCES_IFACE:134 if dbus_interface == gui.DBUS_PREFERENCES_IFACE:
136 return FakedControlPanelBackend(obj, dbus_interface,135 return FakedControlPanelBackend(obj, dbus_interface,
137 *args, **kwargs)136 *args, **kwargs)
138 if dbus_interface == gui.ubuntu_sso.DBUS_CREDENTIALS_IFACE:
139 return FakedSSOBackend(obj, dbus_interface, *args, **kwargs)
140 if dbus_interface == gui.DBUS_IFACE_GUI:137 if dbus_interface == gui.DBUS_IFACE_GUI:
141 return FakeControlPanelBackend(138 return FakeControlPanelBackend(
142 obj, dbus_interface, *args, **kwargs)139 obj, dbus_interface, *args, **kwargs)
@@ -188,9 +185,11 @@
188 # pylint: disable=E1102185 # pylint: disable=E1102
189 klass = None186 klass = None
190 kwargs = {}187 kwargs = {}
188 backend_is_dbus = True
191189
192 def setUp(self):190 def setUp(self):
193 super(BaseTestCase, self).setUp()191 super(BaseTestCase, self).setUp()
192 self.patch(gui, 'CredentialsManagementTool', FakedCredentialsBackend)
194 self.patch(gui.os.path, 'expanduser',193 self.patch(gui.os.path, 'expanduser',
195 lambda path: path.replace('~', USER_HOME))194 lambda path: path.replace('~', USER_HOME))
196 self.patch(gui.gtk, 'main', lambda: None)195 self.patch(gui.gtk, 'main', lambda: None)
@@ -221,14 +220,13 @@
221 pb = gui.gtk.gdk.pixbuf_new_from_file(gui.get_data_file(filename))220 pb = gui.gtk.gdk.pixbuf_new_from_file(gui.get_data_file(filename))
222 self.assertEqual(image.get_pixbuf().get_pixels(), pb.get_pixels())221 self.assertEqual(image.get_pixbuf().get_pixels(), pb.get_pixels())
223222
224 def assert_backend_called(self, method_name, args, backend=None):223 def assert_backend_called(self, method_name, *args, **kwargs):
225 """Check that the control panel backend 'method_name' was called."""224 """Check that the control panel backend 'method_name' was called."""
226 if backend is None:225 if self.backend_is_dbus:
227 backend = self.ui.backend226 kwargs = {'reply_handler': gui.NO_OP,
228 self.assertIn(method_name, backend._called)227 'error_handler': gui.error_handler}
229 kwargs = {'reply_handler': gui.NO_OP,228 self.assertIn(method_name, self.ui.backend._called)
230 'error_handler': gui.error_handler}229 self.assertEqual(self.ui.backend._called[method_name], (args, kwargs))
231 self.assertEqual(backend._called[method_name], (args, kwargs))
232230
233 def assert_warning_correct(self, warning, text):231 def assert_warning_correct(self, warning, text):
234 """Check that 'warning' is visible, showing 'text'."""232 """Check that 'warning' is visible, showing 'text'."""
235233
=== modified file 'ubuntuone/controlpanel/gui/gtk/tests/test_gui.py'
--- ubuntuone/controlpanel/gui/gtk/tests/test_gui.py 2011-06-01 21:18:46 +0000
+++ ubuntuone/controlpanel/gui/gtk/tests/test_gui.py 2011-08-18 17:23:16 +0000
@@ -159,7 +159,7 @@
159 self.ui.backend._called.pop('volumes_info', None)159 self.ui.backend._called.pop('volumes_info', None)
160 self.ui.load()160 self.ui.load()
161161
162 self.assert_backend_called('volumes_info', ())162 self.assert_backend_called('volumes_info')
163163
164 def test_is_processing_after_load(self):164 def test_is_processing_after_load(self):
165 """The ui is processing when contents are load."""165 """The ui is processing when contents are load."""
@@ -440,7 +440,7 @@
440 subscribed = gui.bool_str(not bool(volume['subscribed']))440 subscribed = gui.bool_str(not bool(volume['subscribed']))
441 # backend was called441 # backend was called
442 self.assert_backend_called('change_volume_settings',442 self.assert_backend_called('change_volume_settings',
443 (fid, {'subscribed': subscribed}))443 fid, {'subscribed': subscribed})
444 # store was updated444 # store was updated
445 it = self.ui.volumes_store.get_iter(path)445 it = self.ui.volumes_store.get_iter(path)
446 value = self.ui.volumes_store.get_value(it, 1)446 value = self.ui.volumes_store.get_value(it, 1)
@@ -572,7 +572,7 @@
572 """Changing throttling settings updates the backend properly."""572 """Changing throttling settings updates the backend properly."""
573 expected = self.ui.__dict__573 expected = self.ui.__dict__
574 self.assert_backend_called('change_device_settings',574 self.assert_backend_called('change_device_settings',
575 (self.ui.id, expected))575 self.ui.id, expected)
576 self.assertEqual(self.ui.warning_label.get_text(), '')576 self.assertEqual(self.ui.warning_label.get_text(), '')
577577
578 limit_enabled = self.ui.throttling_limits.get_sensitive()578 limit_enabled = self.ui.throttling_limits.get_sensitive()
@@ -806,7 +806,7 @@
806 self.ui.is_local = False806 self.ui.is_local = False
807 self.ui.remove.clicked()807 self.ui.remove.clicked()
808808
809 self.assert_backend_called('remove_device', (self.ui.id,))809 self.assert_backend_called('remove_device', self.ui.id)
810 self.assertFalse(self.ui.get_sensitive(),810 self.assertFalse(self.ui.get_sensitive(),
811 'Must be disabled while removing.')811 'Must be disabled while removing.')
812812
@@ -936,7 +936,7 @@
936 self.ui.backend._called.pop('devices_info', None)936 self.ui.backend._called.pop('devices_info', None)
937 self.ui.load()937 self.ui.load()
938938
939 self.assert_backend_called('devices_info', ())939 self.assert_backend_called('devices_info')
940940
941 def test_is_processing_after_load(self):941 def test_is_processing_after_load(self):
942 """The ui is processing when contents are load."""942 """The ui is processing when contents are load."""
@@ -1246,7 +1246,7 @@
12461246
1247 def test_file_sync_status_is_requested(self):1247 def test_file_sync_status_is_requested(self):
1248 """The file sync status is requested to the backend."""1248 """The file sync status is requested to the backend."""
1249 self.assert_backend_called('file_sync_status', ())1249 self.assert_backend_called('file_sync_status')
12501250
1251 def test_is_disabled(self):1251 def test_is_disabled(self):
1252 """Until file sync status is given, the widget is disabled."""1252 """Until file sync status is given, the widget is disabled."""
@@ -1273,10 +1273,10 @@
1273 assert self.ui.button.get_active()1273 assert self.ui.button.get_active()
12741274
1275 self.ui.button.set_active(not self.ui.button.get_active())1275 self.ui.button.set_active(not self.ui.button.get_active())
1276 self.assert_backend_called('disable_files', ())1276 self.assert_backend_called('disable_files')
12771277
1278 self.ui.button.set_active(not self.ui.button.get_active())1278 self.ui.button.set_active(not self.ui.button.get_active())
1279 self.assert_backend_called('enable_files', ())1279 self.assert_backend_called('enable_files')
12801280
1281 def test_on_file_sync_enabled(self):1281 def test_on_file_sync_enabled(self):
1282 """When file sync is enabled, the button is active."""1282 """When file sync is enabled, the button is active."""
@@ -1330,7 +1330,7 @@
13301330
1331 args = (self.service_id,1331 args = (self.service_id,
1332 {'enabled': gui.bool_str(self.ui.button.get_active())})1332 {'enabled': gui.bool_str(self.ui.button.get_active())})
1333 self.assert_backend_called('change_replication_settings', args)1333 self.assert_backend_called('change_replication_settings', *args)
13341334
1335 def test_dependency(self):1335 def test_dependency(self):
1336 """The dependency box is None."""1336 """The dependency box is None."""
@@ -1543,7 +1543,7 @@
1543 self.ui.load_replications()1543 self.ui.load_replications()
15441544
1545 self.assertTrue(self.ui.message.active)1545 self.assertTrue(self.ui.message.active)
1546 self.assert_backend_called('replications_info', ())1546 self.assert_backend_called('replications_info')
15471547
15481548
1549class ServicesWithDesktopcouchTestCase(ServicesTestCase):1549class ServicesWithDesktopcouchTestCase(ServicesTestCase):
@@ -1750,7 +1750,7 @@
1750 def test_file_sync_status_is_requested_on_load(self):1750 def test_file_sync_status_is_requested_on_load(self):
1751 """The file sync status is requested to the backend."""1751 """The file sync status is requested to the backend."""
1752 self.ui.load()1752 self.ui.load()
1753 self.assert_backend_called('file_sync_status', ())1753 self.assert_backend_called('file_sync_status')
17541754
1755 def test_on_file_sync_status_disabled(self):1755 def test_on_file_sync_status_disabled(self):
1756 """The file sync is disabled.1756 """The file sync is disabled.
@@ -1862,43 +1862,43 @@
1862 self.ui.backend._called.clear()1862 self.ui.backend._called.clear()
1863 self.ui.on_files_start_error({'error_msg': 'error msg'})1863 self.ui.on_files_start_error({'error_msg': 'error msg'})
18641864
1865 self.assert_backend_called('file_sync_status', ())1865 self.assert_backend_called('file_sync_status')
18661866
1867 def test_on_connect_clicked(self):1867 def test_on_connect_clicked(self):
1868 """User requested connection."""1868 """User requested connection."""
1869 self.ui.on_connect_clicked(self.ui.button)1869 self.ui.on_connect_clicked(self.ui.button)
18701870
1871 self.assert_backend_called('connect_files', ())1871 self.assert_backend_called('connect_files')
18721872
1873 def test_on_disconnect_clicked(self):1873 def test_on_disconnect_clicked(self):
1874 """User requested disconnection."""1874 """User requested disconnection."""
1875 self.ui.on_disconnect_clicked(self.ui.button)1875 self.ui.on_disconnect_clicked(self.ui.button)
18761876
1877 self.assert_backend_called('disconnect_files', ())1877 self.assert_backend_called('disconnect_files')
18781878
1879 def test_on_enable_clicked(self):1879 def test_on_enable_clicked(self):
1880 """User requested enable the service."""1880 """User requested enable the service."""
1881 self.ui.on_enable_clicked(self.ui.button)1881 self.ui.on_enable_clicked(self.ui.button)
18821882
1883 self.assert_backend_called('enable_files', ())1883 self.assert_backend_called('enable_files')
18841884
1885 def test_on_restart_clicked(self):1885 def test_on_restart_clicked(self):
1886 """User requested restart the service."""1886 """User requested restart the service."""
1887 self.ui.on_restart_clicked(self.ui.button)1887 self.ui.on_restart_clicked(self.ui.button)
18881888
1889 self.assert_backend_called('restart_files', ())1889 self.assert_backend_called('restart_files')
18901890
1891 def test_on_start_clicked(self):1891 def test_on_start_clicked(self):
1892 """User requested start the service."""1892 """User requested start the service."""
1893 self.ui.on_start_clicked(self.ui.button)1893 self.ui.on_start_clicked(self.ui.button)
18941894
1895 self.assert_backend_called('start_files', ())1895 self.assert_backend_called('start_files')
18961896
1897 def test_on_stop_clicked(self):1897 def test_on_stop_clicked(self):
1898 """User requested stop the service."""1898 """User requested stop the service."""
1899 self.ui.on_stop_clicked(self.ui.button)1899 self.ui.on_stop_clicked(self.ui.button)
19001900
1901 self.assert_backend_called('stop_files', ())1901 self.assert_backend_called('stop_files')
19021902
19031903
1904class ManagementPanelTestCase(ControlPanelMixinTestCase):1904class ManagementPanelTestCase(ControlPanelMixinTestCase):
@@ -1992,7 +1992,7 @@
1992 def test_account_info_is_requested_on_load(self):1992 def test_account_info_is_requested_on_load(self):
1993 """The account info is requested to the backend."""1993 """The account info is requested to the backend."""
1994 self.ui.load()1994 self.ui.load()
1995 self.assert_backend_called('account_info', ())1995 self.assert_backend_called('account_info')
19961996
1997 def test_file_sync_status_info_is_requested_on_load(self):1997 def test_file_sync_status_info_is_requested_on_load(self):
1998 """The file sync status info is requested to the backend."""1998 """The file sync status info is requested to the backend."""
19991999
=== modified file 'ubuntuone/controlpanel/gui/gtk/tests/test_gui_basic.py'
--- ubuntuone/controlpanel/gui/gtk/tests/test_gui_basic.py 2011-05-24 16:05:30 +0000
+++ ubuntuone/controlpanel/gui/gtk/tests/test_gui_basic.py 2011-08-18 17:23:16 +0000
@@ -20,9 +20,14 @@
2020
21from __future__ import division21from __future__ import division
2222
23from twisted.internet import defer
24from twisted.python.failure import Failure
2325
24from ubuntuone.controlpanel.gui.gtk import gui26from ubuntuone.controlpanel.gui.gtk import gui
25from ubuntuone.controlpanel.gui.gtk.tests import BaseTestCase, FakedSSOBackend27from ubuntuone.controlpanel.gui.gtk.tests import (
28 BaseTestCase,
29 FakedCredentialsBackend,
30)
26from ubuntuone.controlpanel.tests import TOKEN31from ubuntuone.controlpanel.tests import TOKEN
2732
28from ubuntuone.devtools.testcase import skipIf33from ubuntuone.devtools.testcase import skipIf
@@ -287,7 +292,7 @@
287 """On 'credentials-found' signal, ask syncdaemon to connect."""292 """On 'credentials-found' signal, ask syncdaemon to connect."""
288 # credentials are new293 # credentials are new
289 self.ui.overview.emit('credentials-found', True, object())294 self.ui.overview.emit('credentials-found', True, object())
290 self.assert_backend_called('connect_files', ())295 self.assert_backend_called('connect_files')
291296
292 def test_local_device_removed_shows_overview_panel(self):297 def test_local_device_removed_shows_overview_panel(self):
293 """On 'local-device-removed' signal, the overview panel is shown."""298 """On 'local-device-removed' signal, the overview panel is shown."""
@@ -306,7 +311,7 @@
306 def test_backend_is_shutdown_on_close(self):311 def test_backend_is_shutdown_on_close(self):
307 """When the control panel is closed, the backend is shutdown."""312 """When the control panel is closed, the backend is shutdown."""
308 self.ui.emit('destroy')313 self.ui.emit('destroy')
309 self.assert_backend_called('shutdown', ())314 self.assert_backend_called('shutdown')
310315
311316
312class UbuntuOneBinTestCase(BaseTestCase):317class UbuntuOneBinTestCase(BaseTestCase):
@@ -437,6 +442,11 @@
437 klass = gui.OverviewPanel442 klass = gui.OverviewPanel
438 kwargs = {'main_window': gui.gtk.Window()}443 kwargs = {'main_window': gui.gtk.Window()}
439 ui_filename = 'overview.ui'444 ui_filename = 'overview.ui'
445 backend_is_dbus = False
446
447 def setUp(self):
448 super(OverwiewPanelTestCase, self).setUp()
449 gui.gtk.link_button_set_uri_hook(lambda *a: None)
440450
441 def test_is_a_greyable_bin(self):451 def test_is_a_greyable_bin(self):
442 """Inherits from GreyableBin."""452 """Inherits from GreyableBin."""
@@ -450,20 +460,102 @@
450 """The 'join_now' button is the default widget."""460 """The 'join_now' button is the default widget."""
451 self.assertTrue(self.ui.join_now_button.get_property('can-default'))461 self.assertTrue(self.ui.join_now_button.get_property('can-default'))
452462
453 def test_sso_backend(self):463 def test_backend(self):
454 """Has a correct SSO backend."""464 """Has a correct backend."""
455 self.assertIsInstance(self.ui.backend, FakedSSOBackend)465 self.assertIsInstance(self.ui.backend, FakedCredentialsBackend)
456466
457 def test_sso_backend_signals(self):467
458 """The proper signals are connected to the backend."""468class OverwiewPanelBackendCallbacksTestCase(OverwiewPanelTestCase):
459 self.assertEqual(self.ui.backend._signals['CredentialsFound'],469 """Proper callbacks are chained to the credentials backend methods."""
460 [self.ui.on_credentials_found])470
461 self.assertEqual(self.ui.backend._signals['CredentialsNotFound'],471 failure = Exception()
462 [self.ui.on_credentials_not_found])472
463 self.assertEqual(self.ui.backend._signals['CredentialsError'],473 def test_find_credentials_fired_with_credentials(self):
464 [self.ui.on_credentials_error])474 """Test that on_credentials_found is called."""
465 self.assertEqual(self.ui.backend._signals['AuthorizationDenied'],475 self.ui.backend.next_result = defer.succeed(TOKEN)
466 [self.ui.on_authorization_denied])476 self.patch(self.ui, 'on_credentials_found', self._set_called)
477
478 self.ui.on_network_state_changed(gui.networkstate.ONLINE)
479
480 self.assertEqual(self._called, ((TOKEN,), {}))
481
482 def test_find_credentials_fired_without_credentials(self):
483 """Test that on_credentials_not_found is called."""
484 self.ui.backend.next_result = defer.succeed({})
485 self.patch(self.ui, 'on_credentials_not_found', self._set_called)
486
487 self.ui.on_network_state_changed(gui.networkstate.ONLINE)
488
489 self.assertEqual(self._called, ((), {}))
490
491 def test_find_credentials_errback(self):
492 """Test that on_credentials_error is called."""
493 self.ui.backend.next_result = defer.fail(self.failure)
494 self.patch(self.ui, 'on_credentials_error', self._set_called)
495
496 self.ui.on_network_state_changed(gui.networkstate.ONLINE)
497
498 failure = self._called[0][0]
499 self.assertIsInstance(failure, Failure)
500 self.assertEqual(failure.value, self.failure)
501
502 def test_register_fired_with_credentials(self):
503 """Test that on_credentials_found is called."""
504 self.ui.backend.next_result = defer.succeed(TOKEN)
505 self.patch(self.ui, 'on_credentials_found', self._set_called)
506
507 self.ui.join_now_button.clicked()
508
509 self.assertEqual(self._called, ((TOKEN,), {}))
510
511 def test_register_fired_with_credentials_none(self):
512 """Test that on_authorization_denied is called."""
513 self.ui.backend.next_result = defer.succeed(None)
514 self.patch(self.ui, 'on_authorization_denied', self._set_called)
515
516 self.ui.join_now_button.clicked()
517
518 self.assertEqual(self._called, ((), {}))
519
520 def test_register_errback(self):
521 """Test that on_credentials_error is called."""
522 self.ui.backend.next_result = defer.fail(self.failure)
523 self.patch(self.ui, 'on_credentials_error', self._set_called)
524
525 self.ui.join_now_button.clicked()
526
527 failure = self._called[0][0]
528 self.assertIsInstance(failure, Failure)
529 self.assertEqual(failure.value, self.failure)
530
531 def test_login_fired_with_credentials(self):
532 """Test that on_credentials_found is called."""
533 self.ui.backend.next_result = defer.succeed(TOKEN)
534 self.patch(self.ui, 'on_credentials_found', self._set_called)
535
536 self.ui.connect_button.clicked()
537
538 self.assertEqual(self._called, ((TOKEN,), {}))
539
540 def test_login_fired_with_credentials_none(self):
541 """Test that on_authorization_denied is called."""
542 self.ui.backend.next_result = defer.succeed(None)
543 self.patch(self.ui, 'on_authorization_denied', self._set_called)
544
545 self.ui.connect_button.clicked()
546
547 self.assertEqual(self._called, ((), {}))
548
549 def test_login_errback(self):
550 """Test that on_credentials_error is called."""
551 self.ui.backend.next_result = defer.fail(self.failure)
552 self.patch(self.ui, 'on_credentials_error', self._set_called)
553
554 self.ui.connect_button.clicked()
555
556 failure = self._called[0][0]
557 self.assertIsInstance(failure, Failure)
558 self.assertEqual(failure.value, self.failure)
467559
468560
469class OverwiewNetworkStatePanelTestCase(OverwiewPanelTestCase):561class OverwiewNetworkStatePanelTestCase(OverwiewPanelTestCase):
@@ -514,13 +606,13 @@
514 def test_find_credentials_is_called(self):606 def test_find_credentials_is_called(self):
515 """Credentials are asked to SSO backend."""607 """Credentials are asked to SSO backend."""
516 self.assertFalse(self.ui._credentials_are_new)608 self.assertFalse(self.ui._credentials_are_new)
517 self.assert_backend_called('find_credentials', (gui.U1_APP_NAME, {}))609 self.assert_backend_called('find_credentials')
518610
519 def test_on_credentials_found(self):611 def test_on_credentials_found(self):
520 """Callback 'on_credentials_found' is correct."""612 """Callback 'on_credentials_found' is correct."""
521 self.ui.connect('credentials-found', self._set_called)613 self.ui.connect('credentials-found', self._set_called)
522614
523 self.ui.on_credentials_found(gui.U1_APP_NAME, TOKEN)615 self.ui.on_credentials_found(TOKEN)
524616
525 self.assertFalse(self.ui.get_property('greyed'), 'Must not be greyed.')617 self.assertFalse(self.ui.get_property('greyed'), 'Must not be greyed.')
526 # assume credentials were in local keyring618 # assume credentials were in local keyring
@@ -531,9 +623,9 @@
531 self.ui.connect('credentials-found', self._set_called)623 self.ui.connect('credentials-found', self._set_called)
532624
533 # credentials weren't in the system625 # credentials weren't in the system
534 self.ui.on_credentials_not_found(gui.U1_APP_NAME)626 self.ui.on_credentials_not_found()
535 # now they are!627 # now they are!
536 self.ui.on_credentials_found(gui.U1_APP_NAME, TOKEN)628 self.ui.on_credentials_found(TOKEN)
537629
538 self.assertFalse(self.ui.get_property('greyed'), 'Must not be greyed.')630 self.assertFalse(self.ui.get_property('greyed'), 'Must not be greyed.')
539 # assume credentials were not in local keyring631 # assume credentials were not in local keyring
@@ -541,70 +633,31 @@
541633
542 def test_on_credentials_not_found(self):634 def test_on_credentials_not_found(self):
543 """Callback 'on_credentials_not_found' is correct."""635 """Callback 'on_credentials_not_found' is correct."""
544 self.ui.on_credentials_not_found(gui.U1_APP_NAME)636 self.ui.on_credentials_not_found()
545 self.assertTrue(self.ui.get_visible())637 self.assertTrue(self.ui.get_visible())
546 self.assertTrue(self.ui._credentials_are_new)638 self.assertTrue(self.ui._credentials_are_new)
547639
548 def test_on_credentials_error(self):640 def test_on_credentials_error(self):
549 """Callback 'on_credentials_error' is correct."""641 """Callback 'on_credentials_error' is correct."""
550 self.ui.on_credentials_error(gui.U1_APP_NAME, {})642 self.ui.on_credentials_error({})
551 self.assertTrue(self.ui.get_visible())643 self.assertTrue(self.ui.get_visible())
552 self.assert_warning_correct(self.ui.warning_label,644 self.assert_warning_correct(self.ui.warning_label,
553 gui.CREDENTIALS_ERROR)645 gui.CREDENTIALS_ERROR)
554646
555 def test_on_authorization_denied(self):647 def test_on_authorization_denied(self):
556 """Callback 'on_authorization_denied' is correct."""648 """Callback 'on_authorization_denied' is correct."""
557 self.ui.on_authorization_denied(gui.U1_APP_NAME)649 self.ui.on_authorization_denied()
558 self.assertTrue(self.ui.get_visible())650 self.assertTrue(self.ui.get_visible())
559 self.assertFalse(self.ui.get_property('greyed'), 'Must not be greyed.')651 self.assertFalse(self.ui.get_property('greyed'), 'Must not be greyed.')
560 self.assertEqual(self.ui.warning_label.get_text(), '')652 self.assertEqual(self.ui.warning_label.get_text(), '')
561653
562654
563class OverwiewPanelAppNameMismatchTestCase(OverwiewPanelTestCase):
564 """The test suite for the overview panel when the app_name won't match."""
565
566 NOT_U1_APP = 'Not ' + gui.U1_APP_NAME
567
568 def test_filter_by_app_name(self):
569 """The filter_by_app_name decorator is correct."""
570 f = gui.filter_by_app_name(self._set_called)
571 f(self.ui, self.NOT_U1_APP)
572 self.assertFalse(self._called)
573 self.assertTrue(self.memento.check_info('ignoring', self.NOT_U1_APP))
574
575 args = ('test', object())
576 kwargs = {'really': 'AWESOME'}
577 f(self.ui, gui.U1_APP_NAME, *args, **kwargs)
578 self.assertEqual(self._called,
579 ((self.ui, gui.U1_APP_NAME,) + args, kwargs))
580
581 def test_on_credentials_found(self):
582 """Callback 'on_credentials_found' is not executed."""
583 self.assert_function_decorated(gui.filter_by_app_name,
584 self.ui.on_credentials_found)
585
586 def test_on_credentials_not_found(self):
587 """Callback 'on_credentials_not_found' is not executed."""
588 self.assert_function_decorated(gui.filter_by_app_name,
589 self.ui.on_credentials_not_found)
590
591 def test_on_credentials_error(self):
592 """Callback 'on_credentials_error' is not executed."""
593 self.assert_function_decorated(gui.filter_by_app_name,
594 self.ui.on_credentials_error)
595
596 def test_on_authorization_denied(self):
597 """Callback 'on_authorization_denied' is not executed."""
598 self.assert_function_decorated(gui.filter_by_app_name,
599 self.ui.on_authorization_denied)
600
601
602class OverwiewPanelNoCredsTestCase(OverwiewPanelTestCase):655class OverwiewPanelNoCredsTestCase(OverwiewPanelTestCase):
603 """The test suite for the overview panel when no credentials are found."""656 """The test suite for the overview panel when no credentials are found."""
604657
605 def setUp(self):658 def setUp(self):
606 super(OverwiewPanelNoCredsTestCase, self).setUp()659 super(OverwiewPanelNoCredsTestCase, self).setUp()
607 self.ui.on_credentials_not_found(gui.U1_APP_NAME)660 self.ui.on_credentials_not_found()
608661
609 def test_startup_visibility(self):662 def test_startup_visibility(self):
610 """The widget is visible at startup."""663 """The widget is visible at startup."""
@@ -631,12 +684,8 @@
631 self.ui.join_now_button.clicked()684 self.ui.join_now_button.clicked()
632685
633 window_id = self.kwargs['main_window'].window.xid686 window_id = self.kwargs['main_window'].window.xid
634 args = (gui.U1_APP_NAME,687 kwargs = {'window_id': str(window_id)}
635 {gui.TC_URL_KEY: gui.U1_TC_URL,688 self.assert_backend_called('register', **kwargs)
636 gui.HELP_TEXT_KEY: gui.U1_DESCRIPTION,
637 gui.WINDOW_ID_KEY: str(window_id),
638 gui.PING_URL_KEY: gui.U1_PING_URL})
639 self.assert_backend_called('register', args)
640689
641 def test_connect_button_clicked(self):690 def test_connect_button_clicked(self):
642 """Test the 'join now' button callback."""691 """Test the 'join now' button callback."""
@@ -646,12 +695,8 @@
646 self.ui.connect_button.clicked()695 self.ui.connect_button.clicked()
647696
648 window_id = self.kwargs['main_window'].window.xid697 window_id = self.kwargs['main_window'].window.xid
649 args = (gui.U1_APP_NAME,698 kwargs = {'window_id': str(window_id)}
650 {gui.TC_URL_KEY: gui.U1_TC_URL,699 self.assert_backend_called('login', **kwargs)
651 gui.HELP_TEXT_KEY: gui.U1_DESCRIPTION,
652 gui.WINDOW_ID_KEY: str(window_id),
653 gui.PING_URL_KEY: gui.U1_PING_URL})
654 self.assert_backend_called('login', args)
655700
656 def test_join_now_button_clicked_set_greyed(self):701 def test_join_now_button_clicked_set_greyed(self):
657 """Clicking on 'join_now' self is greyed."""702 """Clicking on 'join_now' self is greyed."""
@@ -660,7 +705,7 @@
660705
661 def test_join_now_button_clicked_removes_warning(self):706 def test_join_now_button_clicked_removes_warning(self):
662 """Clicking on 'join_now' the warnings are removed."""707 """Clicking on 'join_now' the warnings are removed."""
663 self.ui.on_authorization_denied(gui.U1_APP_NAME) # show warning708 self.ui.on_authorization_denied() # show warning
664 self.ui.join_now_button.clicked()709 self.ui.join_now_button.clicked()
665710
666 self.assertEqual(self.ui.warning_label.get_text(), '')711 self.assertEqual(self.ui.warning_label.get_text(), '')
@@ -672,7 +717,7 @@
672717
673 def test_connect_button_clicked_removes_warning(self):718 def test_connect_button_clicked_removes_warning(self):
674 """Clicking on 'connect' the warnings are removed."""719 """Clicking on 'connect' the warnings are removed."""
675 self.ui.on_authorization_denied(gui.U1_APP_NAME) # show warning720 self.ui.on_authorization_denied() # show warning
676 self.ui.connect_button.clicked()721 self.ui.connect_button.clicked()
677722
678 self.assertEqual(self.ui.warning_label.get_text(), '')723 self.assertEqual(self.ui.warning_label.get_text(), '')
@@ -688,21 +733,21 @@
688 def test_on_credentials_not_found_unset_greyed(self):733 def test_on_credentials_not_found_unset_greyed(self):
689 """Callback 'on_credentials_not_found' unsets the 'greyed' prop."""734 """Callback 'on_credentials_not_found' unsets the 'greyed' prop."""
690 self.ui.connect_button.clicked()735 self.ui.connect_button.clicked()
691 self.ui.on_credentials_not_found(gui.U1_APP_NAME)736 self.ui.on_credentials_not_found()
692737
693 self.assertFalse(self.ui.get_property('greyed'), 'Must not be greyed.')738 self.assertFalse(self.ui.get_property('greyed'), 'Must not be greyed.')
694739
695 def test_on_credentials_error_unset_greyed(self):740 def test_on_credentials_error_unset_greyed(self):
696 """Callback 'on_credentials_error' unsets the 'greyed' prop."""741 """Callback 'on_credentials_error' unsets the 'greyed' prop."""
697 self.ui.connect_button.clicked()742 self.ui.connect_button.clicked()
698 self.ui.on_credentials_error(gui.U1_APP_NAME, {})743 self.ui.on_credentials_error({})
699744
700 self.assertFalse(self.ui.get_property('greyed'), 'Must not be greyed.')745 self.assertFalse(self.ui.get_property('greyed'), 'Must not be greyed.')
701746
702 def test_on_authorization_denied_unset_greyed(self):747 def test_on_authorization_denied_unset_greyed(self):
703 """Callback 'on_authorization_denied' unsets the 'greyed' prop."""748 """Callback 'on_authorization_denied' unsets the 'greyed' prop."""
704 self.ui.connect_button.clicked()749 self.ui.connect_button.clicked()
705 self.ui.on_authorization_denied(gui.U1_APP_NAME)750 self.ui.on_authorization_denied()
706751
707 self.assertFalse(self.ui.get_property('greyed'), 'Must not be greyed.')752 self.assertFalse(self.ui.get_property('greyed'), 'Must not be greyed.')
708753
709754
=== modified file 'ubuntuone/controlpanel/login_client.py'
--- ubuntuone/controlpanel/login_client.py 2011-06-17 15:56:54 +0000
+++ ubuntuone/controlpanel/login_client.py 2011-08-18 17:23:16 +0000
@@ -18,14 +18,15 @@
1818
19"""Client to access Ubuntu One credentials."""19"""Client to access Ubuntu One credentials."""
2020
21# pylint: disable=E0611, F0401
22from ubuntuone.platform.credentials import CredentialsManagementTool
23# pylint: enable=E0611, F0401
24
2125
22def get_sso_proxy():26def get_sso_proxy():
23 """Return a login client."""27 """Return a login client."""
24 # No name 'credentials' in module 'ubuntuone.platform'28 result = CredentialsManagementTool()
25 # Reimport 'credentials' (imported line 22)29 return result
26 # pylint: disable=E0611,W0404
27 from ubuntuone.platform import credentials
28 return credentials.CredentialsManagementTool()
2930
3031
31def get_credentials():32def get_credentials():
@@ -38,3 +39,15 @@
38 """Clear the credentials for Ubuntu One."""39 """Clear the credentials for Ubuntu One."""
39 proxy = get_sso_proxy()40 proxy = get_sso_proxy()
40 return proxy.clear_credentials()41 return proxy.clear_credentials()
42
43
44def login(*args, **kwargs):
45 """Get the credentials for Ubuntu One offering the user to login."""
46 proxy = get_sso_proxy()
47 return proxy.login(*args, **kwargs)
48
49
50def register(*args, **kwargs):
51 """Get the credentials for Ubuntu One offering the user to register."""
52 proxy = get_sso_proxy()
53 return proxy.register(*args, **kwargs)
4154
=== modified file 'ubuntuone/controlpanel/tests/test_login_client.py'
--- ubuntuone/controlpanel/tests/test_login_client.py 2011-06-17 15:56:54 +0000
+++ ubuntuone/controlpanel/tests/test_login_client.py 2011-08-18 17:23:16 +0000
@@ -19,10 +19,6 @@
19"""Tests for the service when accessing the login client."""19"""Tests for the service when accessing the login client."""
2020
21from twisted.internet import defer21from twisted.internet import defer
22# No name 'credentials' in module 'ubuntuone.platform'
23# pylint: disable=E0611
24from ubuntuone.platform import credentials
25# pylint: enable=E0611
2622
27from ubuntuone.controlpanel import login_client23from ubuntuone.controlpanel import login_client
28from ubuntuone.controlpanel.tests import TestCase, TOKEN24from ubuntuone.controlpanel.tests import TestCase, TOKEN
@@ -49,13 +45,23 @@
49 FakedCredentialsManagementTool.credentials = None45 FakedCredentialsManagementTool.credentials = None
50 yield46 yield
5147
48 @defer.inlineCallbacks
49 def login(self):
50 """Create credentials for Ubuntu One by logging in."""
51 yield defer.succeed(FakedCredentialsManagementTool.credentials)
52
53 @defer.inlineCallbacks
54 def register(self):
55 """Create credentials for Ubuntu One by registering."""
56 yield defer.succeed(FakedCredentialsManagementTool.credentials)
57
5258
53class BaseTestCase(TestCase):59class BaseTestCase(TestCase):
54 """Base TestCase for the login client methods."""60 """Base TestCase for the login client methods."""
5561
56 def setUp(self):62 def setUp(self):
57 super(BaseTestCase, self).setUp()63 super(BaseTestCase, self).setUp()
58 self.patch(credentials, 'CredentialsManagementTool',64 self.patch(login_client, 'CredentialsManagementTool',
59 FakedCredentialsManagementTool)65 FakedCredentialsManagementTool)
60 FakedCredentialsManagementTool.credentials = TOKEN66 FakedCredentialsManagementTool.credentials = TOKEN
6167
@@ -87,7 +93,7 @@
8793
88 @defer.inlineCallbacks94 @defer.inlineCallbacks
89 def test_clear_credentials(self):95 def test_clear_credentials(self):
90 """The credentials are properly retrieved."""96 """The credentials are properly cleared."""
91 yield login_client.clear_credentials()97 yield login_client.clear_credentials()
92 self.assertEqual(None, FakedCredentialsManagementTool.credentials)98 self.assertEqual(None, FakedCredentialsManagementTool.credentials)
9399
@@ -98,3 +104,39 @@
98 self.fake_fail)104 self.fake_fail)
99 yield self.assertFailure(login_client.clear_credentials(),105 yield self.assertFailure(login_client.clear_credentials(),
100 CustomError)106 CustomError)
107
108
109class LoginTestCase(BaseTestCase):
110 """Test for the login method."""
111
112 @defer.inlineCallbacks
113 def test_login(self):
114 """The credentials are properly retrieved."""
115 yield login_client.login()
116 self.assertEqual(TOKEN, FakedCredentialsManagementTool.credentials)
117
118 @defer.inlineCallbacks
119 def test_login_throws_an_error(self):
120 """If login fails, the error is propagated."""
121 self.patch(FakedCredentialsManagementTool, 'login',
122 self.fake_fail)
123 yield self.assertFailure(login_client.login(),
124 CustomError)
125
126
127class RegisterTestCase(BaseTestCase):
128 """Test for the register method."""
129
130 @defer.inlineCallbacks
131 def test_register(self):
132 """The credentials are properly retrieved."""
133 yield login_client.register()
134 self.assertEqual(TOKEN, FakedCredentialsManagementTool.credentials)
135
136 @defer.inlineCallbacks
137 def test_register_throws_an_error(self):
138 """If register fails, the error is propagated."""
139 self.patch(FakedCredentialsManagementTool, 'register',
140 self.fake_fail)
141 yield self.assertFailure(login_client.register(),
142 CustomError)

Subscribers

People subscribed via source and target branches