Merge lp:~nataliabidart/ubuntuone-control-panel/services-more-robust into lp:ubuntuone-control-panel

Proposed by Natalia Bidart
Status: Merged
Approved by: Natalia Bidart
Approved revision: 122
Merged at revision: 122
Proposed branch: lp:~nataliabidart/ubuntuone-control-panel/services-more-robust
Merge into: lp:ubuntuone-control-panel
Diff against target: 133 lines (+54/-7)
2 files modified
ubuntuone/controlpanel/gtk/gui.py (+18/-7)
ubuntuone/controlpanel/gtk/tests/test_gui_basic.py (+36/-0)
To merge this branch: bzr merge lp:~nataliabidart/ubuntuone-control-panel/services-more-robust
Reviewer Review Type Date Requested Status
Roberto Alsina (community) Approve
Eric Casteleijn (community) Approve
Review via email: mp+55963@code.launchpad.net

Commit message

- Small improvement to show something else besides the generic "Value can not be retrieved." error (LP: #722485).

To post a comment you must log in.
Revision history for this message
Eric Casteleijn (thisfred) wrote :

awesome

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

+1, I hated that error.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ubuntuone/controlpanel/gtk/gui.py'
2--- ubuntuone/controlpanel/gtk/gui.py 2011-03-30 19:47:22 +0000
3+++ ubuntuone/controlpanel/gtk/gui.py 2011-04-01 16:22:14 +0000
4@@ -55,7 +55,8 @@
5 from ubuntuone.controlpanel.backend import (DEVICE_TYPE_PHONE,
6 DEVICE_TYPE_COMPUTER, bool_str)
7 from ubuntuone.controlpanel.logger import setup_logging, log_call
8-from ubuntuone.controlpanel.utils import get_data_file
9+from ubuntuone.controlpanel.utils import (get_data_file,
10+ ERROR_TYPE, ERROR_MESSAGE)
11
12 from ubuntuone.controlpanel.gtk import package_manager, TRANSLATION_DOMAIN
13
14@@ -68,6 +69,7 @@
15 ERROR_COLOR = 'red'
16 LOADING = _('Loading...')
17 VALUE_ERROR = _('Value could not be retrieved.')
18+UNKNOWN_ERROR = _('Unknown error')
19 WARNING_MARKUP = '<span foreground="%s"><b>%%s</b></span>' % ERROR_COLOR
20 KILOBYTES = 1024
21 NO_OP = lambda *a, **kw: None
22@@ -240,10 +242,19 @@
23 self.message.set_markup(message)
24
25 @log_call(logger.error)
26- def on_error(self, message=None):
27+ def on_error(self, message=None, error_dict=None):
28 """Use this callback to stop the Loading and set a warning message."""
29- if message == None:
30+ if message is None and error_dict is None:
31 message = VALUE_ERROR
32+ elif message is None and error_dict is not None:
33+ error_type = error_dict.get(ERROR_TYPE, UNKNOWN_ERROR)
34+ error_msg = error_dict.get(ERROR_MESSAGE)
35+ if error_msg:
36+ message = "%s (%s: %s)" % (VALUE_ERROR, error_type, error_msg)
37+ else:
38+ message = "%s (%s)" % (VALUE_ERROR, error_type)
39+
40+ assert message is not None
41
42 self.message.stop()
43 self.message.set_markup(WARNING_MARKUP % message)
44@@ -557,7 +568,7 @@
45 @log_call(logger.error)
46 def on_volumes_info_error(self, error_dict=None):
47 """Backend notifies of an error when fetching volumes info."""
48- self.on_error()
49+ self.on_error(error_dict=error_dict)
50
51 @log_call(logger.info)
52 def on_volume_settings_changed(self, volume_id):
53@@ -875,7 +886,7 @@
54 @log_call(logger.error)
55 def on_devices_info_error(self, error_dict=None):
56 """Backend notifies of an error when fetching volumes info."""
57- self.on_error()
58+ self.on_error(error_dict=error_dict)
59 self.is_processing = False
60
61 @log_call(logger.warning)
62@@ -1200,6 +1211,7 @@
63 @log_call(logger.debug)
64 def load(self):
65 """Load info."""
66+ self.replications.hide()
67 if self.install_box is not None:
68 self.itself.remove(self.install_box)
69 self.install_box = None
70@@ -1207,7 +1219,6 @@
71 logger.info('load: has_desktopcouch? %r', self.has_desktopcouch)
72 if not self.has_desktopcouch:
73 self.message.set_text('')
74- self.replications.hide()
75
76 self.install_box = InstallPackage(self.DESKTOPCOUCH_PKG)
77 self.install_box.connect('finished', self.load_replications)
78@@ -1259,7 +1270,7 @@
79 error_dict.get('error_type', None) == 'NoPairingRecord':
80 self.on_error(self.NO_PAIRING_RECORD)
81 else:
82- self.on_error()
83+ self.on_error(error_dict=error_dict)
84
85
86 class FileSyncStatus(gtk.HBox, ControlPanelMixin):
87
88=== modified file 'ubuntuone/controlpanel/gtk/tests/test_gui_basic.py'
89--- ubuntuone/controlpanel/gtk/tests/test_gui_basic.py 2011-03-29 19:14:21 +0000
90+++ ubuntuone/controlpanel/gtk/tests/test_gui_basic.py 2011-04-01 16:22:14 +0000
91@@ -324,6 +324,42 @@
92 self.assert_warning_correct(self.ui.message, msg)
93 self.assertFalse(self.ui.message.active)
94
95+ def test_on_error_with_error_dict(self):
96+ """Callback to stop the Loading and show the error from error_dict."""
97+ msg = u'Qué mala suerte! <i>this does not rock</i>'
98+ error_dict = {gui.ERROR_TYPE: 'YaddaError', gui.ERROR_MESSAGE: msg}
99+ self.ui.on_error(error_dict=error_dict)
100+
101+ expected_msg = "%s (%s: %s)" % (gui.VALUE_ERROR, 'YaddaError', msg)
102+ self.assert_warning_correct(self.ui.message, expected_msg)
103+ self.assertFalse(self.ui.message.active)
104+
105+ def test_on_error_with_error_dict_without_error_type(self):
106+ """Callback to stop the Loading and show the error from error_dict."""
107+ error_dict = {}
108+ self.ui.on_error(error_dict=error_dict)
109+
110+ expected_msg = "%s (%s)" % (gui.VALUE_ERROR, gui.UNKNOWN_ERROR)
111+ self.assert_warning_correct(self.ui.message, expected_msg)
112+ self.assertFalse(self.ui.message.active)
113+
114+ def test_on_error_with_error_dict_without_error_message(self):
115+ """Callback to stop the Loading and show the error from error_dict."""
116+ error_dict = {gui.ERROR_TYPE: 'YaddaError'}
117+ self.ui.on_error(error_dict=error_dict)
118+
119+ expected_msg = "%s (%s)" % (gui.VALUE_ERROR, 'YaddaError')
120+ self.assert_warning_correct(self.ui.message, expected_msg)
121+ self.assertFalse(self.ui.message.active)
122+
123+ def test_on_error_with_message_and_error_dict(self):
124+ """Callback to stop the Loading and show a info message."""
125+ error_dict = {gui.ERROR_TYPE: 'YaddaError', gui.ERROR_MESSAGE: 'test'}
126+ msg = 'WOW! <i>this does not rock</i> :-/'
127+ self.ui.on_error(message=msg, error_dict=error_dict)
128+ self.assert_warning_correct(self.ui.message, msg)
129+ self.assertFalse(self.ui.message.active)
130+
131 def test_is_processing(self):
132 """The flag 'is_processing' is False on start."""
133 self.assertFalse(self.ui.is_processing)

Subscribers

People subscribed via source and target branches