Merge lp:~nataliabidart/ubuntuone-control-panel/devices into lp:ubuntuone-control-panel
- devices
- Merge into trunk
Status: | Merged | ||||||||
---|---|---|---|---|---|---|---|---|---|
Approved by: | Natalia Bidart | ||||||||
Approved revision: | 46 | ||||||||
Merged at revision: | 36 | ||||||||
Proposed branch: | lp:~nataliabidart/ubuntuone-control-panel/devices | ||||||||
Merge into: | lp:ubuntuone-control-panel | ||||||||
Prerequisite: | lp:~nataliabidart/ubuntuone-control-panel/more-logging-and-ids | ||||||||
Diff against target: |
927 lines (+711/-22) 5 files modified
data/device.ui (+201/-0) data/devices.ui (+31/-1) data/folders.ui (+1/-1) ubuntuone/controlpanel/gtk/gui.py (+172/-9) ubuntuone/controlpanel/gtk/tests/test_gui.py (+306/-11) |
||||||||
To merge this branch: | bzr merge lp:~nataliabidart/ubuntuone-control-panel/devices | ||||||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Roberto Alsina (community) | Approve | ||
Roman Yepishev (community) | fieldtest | Approve | |
Review via email: mp+43975@code.launchpad.net |
Description of the change
To run the tests, do:
./run-tests
To test IRL, open 3 terminals pointing to this branch, and run:
terminal 1: DEBUG=True PYTHONPATH=. ./bin/ubuntuone
terminal 2: DEBUG=True PYTHONPATH=. ./bin/ubuntuone
and play with the 3rd tab. Note: the 'Remove' device button so far does nothing. Throttling settings are properly updated, you can check by looking the ~/.config/
Martin Albisetti (beuno) wrote : | # |
Roman Yepishev (rye) wrote : | # |
When an attempt is made to change max upload/download speed or enable/disable bandwidth usage limits some kind of flickering occurs which is not present in ubuntuone-
This can be seen here - http://
- 45. By Natalia Bidart
-
Merged trunk in.
- 46. By Natalia Bidart
-
UI is not disabled while changing setting for a device.
Roman Yepishev (rye) wrote : | # |
Yep, no flickering occurs.
Roberto Alsina (ralsina) wrote : | # |
Approved, fieldtested on narwhal.
Preview Diff
1 | === added file 'data/device.ui' | |||
2 | --- data/device.ui 1970-01-01 00:00:00 +0000 | |||
3 | +++ data/device.ui 2010-12-17 17:27:34 +0000 | |||
4 | @@ -0,0 +1,201 @@ | |||
5 | 1 | <?xml version="1.0" encoding="UTF-8"?> | ||
6 | 2 | <interface> | ||
7 | 3 | <requires lib="gtk+" version="2.16"/> | ||
8 | 4 | <!-- interface-naming-policy project-wide --> | ||
9 | 5 | <object class="GtkVBox" id="itself"> | ||
10 | 6 | <property name="visible">True</property> | ||
11 | 7 | <property name="spacing">5</property> | ||
12 | 8 | <child> | ||
13 | 9 | <object class="GtkHBox" id="hbox1"> | ||
14 | 10 | <property name="visible">True</property> | ||
15 | 11 | <property name="spacing">15</property> | ||
16 | 12 | <child> | ||
17 | 13 | <object class="GtkVBox" id="vbox1"> | ||
18 | 14 | <property name="visible">True</property> | ||
19 | 15 | <property name="spacing">5</property> | ||
20 | 16 | <child> | ||
21 | 17 | <object class="GtkHBox" id="hbox2"> | ||
22 | 18 | <property name="visible">True</property> | ||
23 | 19 | <child> | ||
24 | 20 | <object class="GtkImage" id="device_type"> | ||
25 | 21 | <property name="visible">True</property> | ||
26 | 22 | <property name="icon_name">computer</property> | ||
27 | 23 | </object> | ||
28 | 24 | <packing> | ||
29 | 25 | <property name="expand">False</property> | ||
30 | 26 | <property name="position">0</property> | ||
31 | 27 | </packing> | ||
32 | 28 | </child> | ||
33 | 29 | <child> | ||
34 | 30 | <object class="GtkLabel" id="device_name"> | ||
35 | 31 | <property name="visible">True</property> | ||
36 | 32 | <property name="xalign">0</property> | ||
37 | 33 | <property name="xpad">5</property> | ||
38 | 34 | <property name="label">My Laptop</property> | ||
39 | 35 | </object> | ||
40 | 36 | <packing> | ||
41 | 37 | <property name="position">1</property> | ||
42 | 38 | </packing> | ||
43 | 39 | </child> | ||
44 | 40 | <child> | ||
45 | 41 | <object class="GtkLabel" id="device_id"> | ||
46 | 42 | <property name="label" translatable="yes">device id (hidden)</property> | ||
47 | 43 | </object> | ||
48 | 44 | <packing> | ||
49 | 45 | <property name="expand">False</property> | ||
50 | 46 | <property name="position">2</property> | ||
51 | 47 | </packing> | ||
52 | 48 | </child> | ||
53 | 49 | <child> | ||
54 | 50 | <object class="GtkLabel" id="date_added"> | ||
55 | 51 | <property name="label">30.02.09</property> | ||
56 | 52 | </object> | ||
57 | 53 | <packing> | ||
58 | 54 | <property name="expand">False</property> | ||
59 | 55 | <property name="position">3</property> | ||
60 | 56 | </packing> | ||
61 | 57 | </child> | ||
62 | 58 | </object> | ||
63 | 59 | <packing> | ||
64 | 60 | <property name="position">0</property> | ||
65 | 61 | </packing> | ||
66 | 62 | </child> | ||
67 | 63 | <child> | ||
68 | 64 | <object class="GtkTable" id="throttling"> | ||
69 | 65 | <property name="visible">True</property> | ||
70 | 66 | <property name="n_rows">3</property> | ||
71 | 67 | <property name="n_columns">2</property> | ||
72 | 68 | <property name="column_spacing">3</property> | ||
73 | 69 | <property name="row_spacing">3</property> | ||
74 | 70 | <child> | ||
75 | 71 | <object class="GtkCheckButton" id="limit_bandwidth"> | ||
76 | 72 | <property name="label" translatable="yes">Limit bandwidth usage</property> | ||
77 | 73 | <property name="visible">True</property> | ||
78 | 74 | <property name="can_focus">True</property> | ||
79 | 75 | <property name="receives_default">False</property> | ||
80 | 76 | <property name="draw_indicator">True</property> | ||
81 | 77 | <signal name="toggled" handler="on_limit_bandwidth_toggled"/> | ||
82 | 78 | </object> | ||
83 | 79 | </child> | ||
84 | 80 | <child> | ||
85 | 81 | <object class="GtkLabel" id="max_upload_speed_label"> | ||
86 | 82 | <property name="visible">True</property> | ||
87 | 83 | <property name="xalign">1</property> | ||
88 | 84 | <property name="xpad">5</property> | ||
89 | 85 | <property name="label" translatable="yes">Max upload speed (KiB/s)</property> | ||
90 | 86 | </object> | ||
91 | 87 | <packing> | ||
92 | 88 | <property name="top_attach">1</property> | ||
93 | 89 | <property name="bottom_attach">2</property> | ||
94 | 90 | </packing> | ||
95 | 91 | </child> | ||
96 | 92 | <child> | ||
97 | 93 | <object class="GtkLabel" id="max_download_speed_label"> | ||
98 | 94 | <property name="visible">True</property> | ||
99 | 95 | <property name="xalign">1</property> | ||
100 | 96 | <property name="xpad">5</property> | ||
101 | 97 | <property name="label" translatable="yes">Max download speed (KiB/s)</property> | ||
102 | 98 | </object> | ||
103 | 99 | <packing> | ||
104 | 100 | <property name="top_attach">2</property> | ||
105 | 101 | <property name="bottom_attach">3</property> | ||
106 | 102 | </packing> | ||
107 | 103 | </child> | ||
108 | 104 | <child> | ||
109 | 105 | <object class="GtkSpinButton" id="max_upload_speed"> | ||
110 | 106 | <property name="visible">True</property> | ||
111 | 107 | <property name="can_focus">True</property> | ||
112 | 108 | <property name="invisible_char">•</property> | ||
113 | 109 | <property name="activates_default">True</property> | ||
114 | 110 | <property name="adjustment">adjustment1</property> | ||
115 | 111 | <signal name="value_changed" handler="on_max_upload_speed_value_changed"/> | ||
116 | 112 | </object> | ||
117 | 113 | <packing> | ||
118 | 114 | <property name="left_attach">1</property> | ||
119 | 115 | <property name="right_attach">2</property> | ||
120 | 116 | <property name="top_attach">1</property> | ||
121 | 117 | <property name="bottom_attach">2</property> | ||
122 | 118 | <property name="x_options">GTK_FILL</property> | ||
123 | 119 | <property name="y_options">GTK_FILL</property> | ||
124 | 120 | </packing> | ||
125 | 121 | </child> | ||
126 | 122 | <child> | ||
127 | 123 | <object class="GtkSpinButton" id="max_download_speed"> | ||
128 | 124 | <property name="visible">True</property> | ||
129 | 125 | <property name="can_focus">True</property> | ||
130 | 126 | <property name="invisible_char">•</property> | ||
131 | 127 | <property name="activates_default">True</property> | ||
132 | 128 | <property name="adjustment">adjustment2</property> | ||
133 | 129 | <signal name="value_changed" handler="on_max_download_speed_value_changed"/> | ||
134 | 130 | </object> | ||
135 | 131 | <packing> | ||
136 | 132 | <property name="left_attach">1</property> | ||
137 | 133 | <property name="right_attach">2</property> | ||
138 | 134 | <property name="top_attach">2</property> | ||
139 | 135 | <property name="bottom_attach">3</property> | ||
140 | 136 | </packing> | ||
141 | 137 | </child> | ||
142 | 138 | <child> | ||
143 | 139 | <placeholder/> | ||
144 | 140 | </child> | ||
145 | 141 | </object> | ||
146 | 142 | <packing> | ||
147 | 143 | <property name="expand">False</property> | ||
148 | 144 | <property name="position">1</property> | ||
149 | 145 | </packing> | ||
150 | 146 | </child> | ||
151 | 147 | </object> | ||
152 | 148 | <packing> | ||
153 | 149 | <property name="expand">False</property> | ||
154 | 150 | <property name="position">0</property> | ||
155 | 151 | </packing> | ||
156 | 152 | </child> | ||
157 | 153 | <child> | ||
158 | 154 | <object class="GtkVButtonBox" id="vbuttonbox1"> | ||
159 | 155 | <property name="visible">True</property> | ||
160 | 156 | <property name="layout_style">start</property> | ||
161 | 157 | <child> | ||
162 | 158 | <object class="GtkButton" id="remove"> | ||
163 | 159 | <property name="label">gtk-remove</property> | ||
164 | 160 | <property name="visible">True</property> | ||
165 | 161 | <property name="can_focus">True</property> | ||
166 | 162 | <property name="receives_default">True</property> | ||
167 | 163 | <property name="use_stock">True</property> | ||
168 | 164 | </object> | ||
169 | 165 | <packing> | ||
170 | 166 | <property name="expand">False</property> | ||
171 | 167 | <property name="fill">False</property> | ||
172 | 168 | <property name="position">0</property> | ||
173 | 169 | </packing> | ||
174 | 170 | </child> | ||
175 | 171 | </object> | ||
176 | 172 | <packing> | ||
177 | 173 | <property name="expand">False</property> | ||
178 | 174 | <property name="pack_type">end</property> | ||
179 | 175 | <property name="position">1</property> | ||
180 | 176 | </packing> | ||
181 | 177 | </child> | ||
182 | 178 | </object> | ||
183 | 179 | <packing> | ||
184 | 180 | <property name="expand">False</property> | ||
185 | 181 | <property name="position">0</property> | ||
186 | 182 | </packing> | ||
187 | 183 | </child> | ||
188 | 184 | <child> | ||
189 | 185 | <object class="GtkLabel" id="warning_label"> | ||
190 | 186 | <property name="visible">True</property> | ||
191 | 187 | </object> | ||
192 | 188 | <packing> | ||
193 | 189 | <property name="position">1</property> | ||
194 | 190 | </packing> | ||
195 | 191 | </child> | ||
196 | 192 | </object> | ||
197 | 193 | <object class="GtkAdjustment" id="adjustment1"> | ||
198 | 194 | <property name="upper">10000</property> | ||
199 | 195 | <property name="step_increment">1</property> | ||
200 | 196 | </object> | ||
201 | 197 | <object class="GtkAdjustment" id="adjustment2"> | ||
202 | 198 | <property name="upper">10000</property> | ||
203 | 199 | <property name="step_increment">1</property> | ||
204 | 200 | </object> | ||
205 | 201 | </interface> | ||
206 | 0 | 202 | ||
207 | === modified file 'data/devices.ui' | |||
208 | --- data/devices.ui 2010-10-21 21:14:24 +0000 | |||
209 | +++ data/devices.ui 2010-12-17 17:27:34 +0000 | |||
210 | @@ -7,7 +7,37 @@ | |||
211 | 7 | <property name="border_width">10</property> | 7 | <property name="border_width">10</property> |
212 | 8 | <property name="spacing">10</property> | 8 | <property name="spacing">10</property> |
213 | 9 | <child> | 9 | <child> |
215 | 10 | <placeholder/> | 10 | <object class="GtkScrolledWindow" id="scrolledwindow1"> |
216 | 11 | <property name="visible">True</property> | ||
217 | 12 | <property name="can_focus">True</property> | ||
218 | 13 | <property name="hscrollbar_policy">automatic</property> | ||
219 | 14 | <property name="vscrollbar_policy">automatic</property> | ||
220 | 15 | <child> | ||
221 | 16 | <object class="GtkViewport" id="viewport1"> | ||
222 | 17 | <property name="visible">True</property> | ||
223 | 18 | <property name="resize_mode">queue</property> | ||
224 | 19 | <property name="shadow_type">none</property> | ||
225 | 20 | <child> | ||
226 | 21 | <object class="GtkAlignment" id="alignment1"> | ||
227 | 22 | <property name="visible">True</property> | ||
228 | 23 | <property name="xscale">0</property> | ||
229 | 24 | <property name="yscale">0</property> | ||
230 | 25 | <child> | ||
231 | 26 | <object class="GtkVBox" id="devices"> | ||
232 | 27 | <property name="visible">True</property> | ||
233 | 28 | <child> | ||
234 | 29 | <placeholder/> | ||
235 | 30 | </child> | ||
236 | 31 | </object> | ||
237 | 32 | </child> | ||
238 | 33 | </object> | ||
239 | 34 | </child> | ||
240 | 35 | </object> | ||
241 | 36 | </child> | ||
242 | 37 | </object> | ||
243 | 38 | <packing> | ||
244 | 39 | <property name="position">0</property> | ||
245 | 40 | </packing> | ||
246 | 11 | </child> | 41 | </child> |
247 | 12 | </object> | 42 | </object> |
248 | 13 | </interface> | 43 | </interface> |
249 | 14 | 44 | ||
250 | === modified file 'data/folders.ui' | |||
251 | --- data/folders.ui 2010-12-14 15:54:29 +0000 | |||
252 | +++ data/folders.ui 2010-12-17 17:27:34 +0000 | |||
253 | @@ -31,7 +31,7 @@ | |||
254 | 31 | <property name="resize_mode">queue</property> | 31 | <property name="resize_mode">queue</property> |
255 | 32 | <property name="shadow_type">none</property> | 32 | <property name="shadow_type">none</property> |
256 | 33 | <child> | 33 | <child> |
258 | 34 | <object class="GtkAlignment" id="folders_alignment"> | 34 | <object class="GtkAlignment" id="folders"> |
259 | 35 | <property name="visible">True</property> | 35 | <property name="visible">True</property> |
260 | 36 | <property name="xscale">0</property> | 36 | <property name="xscale">0</property> |
261 | 37 | <property name="yscale">0</property> | 37 | <property name="yscale">0</property> |
262 | 38 | 38 | ||
263 | === modified file 'ubuntuone/controlpanel/gtk/gui.py' | |||
264 | --- ubuntuone/controlpanel/gtk/gui.py 2010-12-14 19:16:25 +0000 | |||
265 | +++ ubuntuone/controlpanel/gtk/gui.py 2010-12-17 17:27:34 +0000 | |||
266 | @@ -47,6 +47,8 @@ | |||
267 | 47 | 47 | ||
268 | 48 | from ubuntuone.controlpanel import (DBUS_BUS_NAME, DBUS_PREFERENCES_PATH, | 48 | from ubuntuone.controlpanel import (DBUS_BUS_NAME, DBUS_PREFERENCES_PATH, |
269 | 49 | DBUS_PREFERENCES_IFACE) | 49 | DBUS_PREFERENCES_IFACE) |
270 | 50 | from ubuntuone.controlpanel.backend import (DEVICE_TYPE_PHONE, | ||
271 | 51 | DEVICE_TYPE_COMPUTER) | ||
272 | 50 | from ubuntuone.controlpanel.logger import setup_logging, log_call | 52 | from ubuntuone.controlpanel.logger import setup_logging, log_call |
273 | 51 | from ubuntuone.controlpanel.utils import get_data_file | 53 | from ubuntuone.controlpanel.utils import get_data_file |
274 | 52 | 54 | ||
275 | @@ -69,6 +71,12 @@ | |||
276 | 69 | _('Sync data between computers.\n' | 71 | _('Sync data between computers.\n' |
277 | 70 | '<small>«this is custom text #<i>N</i>»</small>')] | 72 | '<small>«this is custom text #<i>N</i>»</small>')] |
278 | 71 | WARNING_MARKUP = '<span foreground="%s"><b>%%s</b></span>' % ORANGE | 73 | WARNING_MARKUP = '<span foreground="%s"><b>%%s</b></span>' % ORANGE |
279 | 74 | KILOBYTES = 1024 | ||
280 | 75 | |||
281 | 76 | |||
282 | 77 | def bool_str(value): | ||
283 | 78 | """Return the string representation of a bool (dbus-compatible).""" | ||
284 | 79 | return 'True' if value else '' | ||
285 | 72 | 80 | ||
286 | 73 | 81 | ||
287 | 74 | def filter_by_app_name(f): | 82 | def filter_by_app_name(f): |
288 | @@ -151,6 +159,8 @@ | |||
289 | 151 | self.set_title(self.TITLE % {'app_name': U1_APP_NAME}) | 159 | self.set_title(self.TITLE % {'app_name': U1_APP_NAME}) |
290 | 152 | self.set_position(gtk.WIN_POS_CENTER_ALWAYS) | 160 | self.set_position(gtk.WIN_POS_CENTER_ALWAYS) |
291 | 153 | self.set_icon_name('ubuntuone') | 161 | self.set_icon_name('ubuntuone') |
292 | 162 | self.set_geometry_hints(max_width=736, max_height=525) # bug #683164 | ||
293 | 163 | |||
294 | 154 | self.connect('delete-event', lambda w, e: gtk.main_quit()) | 164 | self.connect('delete-event', lambda w, e: gtk.main_quit()) |
295 | 155 | self.show() | 165 | self.show() |
296 | 156 | 166 | ||
297 | @@ -377,7 +387,7 @@ | |||
298 | 377 | def __init__(self): | 387 | def __init__(self): |
299 | 378 | UbuntuOneBin.__init__(self) | 388 | UbuntuOneBin.__init__(self) |
300 | 379 | ControlPanelMixin.__init__(self, filename='account.ui') | 389 | ControlPanelMixin.__init__(self, filename='account.ui') |
302 | 380 | self.pack_start(self.itself) | 390 | self.add(self.itself) |
303 | 381 | self.show() | 391 | self.show() |
304 | 382 | 392 | ||
305 | 383 | self.backend.connect_to_signal('AccountInfoReady', | 393 | self.backend.connect_to_signal('AccountInfoReady', |
306 | @@ -421,7 +431,7 @@ | |||
307 | 421 | def __init__(self): | 431 | def __init__(self): |
308 | 422 | UbuntuOneBin.__init__(self) | 432 | UbuntuOneBin.__init__(self) |
309 | 423 | ControlPanelMixin.__init__(self, filename='folders.ui') | 433 | ControlPanelMixin.__init__(self, filename='folders.ui') |
311 | 424 | self.pack_start(self.itself) | 434 | self.add(self.itself) |
312 | 425 | self.show_all() | 435 | self.show_all() |
313 | 426 | 436 | ||
314 | 427 | self.backend.connect_to_signal('VolumesInfoReady', | 437 | self.backend.connect_to_signal('VolumesInfoReady', |
315 | @@ -433,13 +443,12 @@ | |||
316 | 433 | self.label_alignment.add(self.volumes_label) | 443 | self.label_alignment.add(self.volumes_label) |
317 | 434 | self._subscribed = [] | 444 | self._subscribed = [] |
318 | 435 | 445 | ||
319 | 436 | @log_call(logger.debug) | ||
320 | 437 | def on_volumes_info_ready(self, info): | 446 | def on_volumes_info_ready(self, info): |
321 | 438 | """Backend notifies of volumes info.""" | 447 | """Backend notifies of volumes info.""" |
322 | 439 | self.volumes_label.stop() | 448 | self.volumes_label.stop() |
323 | 440 | 449 | ||
324 | 441 | if self.volumes is not None: | 450 | if self.volumes is not None: |
326 | 442 | self.folders_alignment.remove(self.volumes) | 451 | self.folders.remove(self.volumes) |
327 | 443 | self.volumes = None | 452 | self.volumes = None |
328 | 444 | 453 | ||
329 | 445 | if not info: | 454 | if not info: |
330 | @@ -473,7 +482,7 @@ | |||
331 | 473 | self._subscribed.append(subscribed) | 482 | self._subscribed.append(subscribed) |
332 | 474 | self.volumes.attach(subscribed, 1, 2, i + 1, i + 2, xoptions=0) | 483 | self.volumes.attach(subscribed, 1, 2, i + 1, i + 2, xoptions=0) |
333 | 475 | 484 | ||
335 | 476 | self.folders_alignment.add(self.volumes) | 485 | self.folders.add(self.volumes) |
336 | 477 | 486 | ||
337 | 478 | @log_call(logger.error) | 487 | @log_call(logger.error) |
338 | 479 | def on_volumes_info_error(self, error_dict=None): | 488 | def on_volumes_info_error(self, error_dict=None): |
339 | @@ -485,7 +494,7 @@ | |||
340 | 485 | def on_subscribed_clicked(self, checkbutton): | 494 | def on_subscribed_clicked(self, checkbutton): |
341 | 486 | """The user toggled 'checkbutton'.""" | 495 | """The user toggled 'checkbutton'.""" |
342 | 487 | volume_id = checkbutton.get_label() | 496 | volume_id = checkbutton.get_label() |
344 | 488 | subscribed = 'True' if checkbutton.get_active() else '' | 497 | subscribed = bool_str(checkbutton.get_active()) |
345 | 489 | self.backend.change_volume_settings(volume_id, | 498 | self.backend.change_volume_settings(volume_id, |
346 | 490 | {'subscribed': subscribed}) | 499 | {'subscribed': subscribed}) |
347 | 491 | 500 | ||
348 | @@ -495,6 +504,140 @@ | |||
349 | 495 | self.volumes_label.start() | 504 | self.volumes_label.start() |
350 | 496 | 505 | ||
351 | 497 | 506 | ||
352 | 507 | class Device(gtk.VBox, ControlPanelMixin): | ||
353 | 508 | """The devices panel.""" | ||
354 | 509 | |||
355 | 510 | DEVICE_CHANGE_ERROR = _('The settings could not be changed,\n' | ||
356 | 511 | 'previous values were restored.') | ||
357 | 512 | |||
358 | 513 | def __init__(self): | ||
359 | 514 | gtk.VBox.__init__(self) | ||
360 | 515 | ControlPanelMixin.__init__(self, filename='device.ui') | ||
361 | 516 | |||
362 | 517 | self._updating = False | ||
363 | 518 | self._last_settings = {} | ||
364 | 519 | self.configurable = False | ||
365 | 520 | |||
366 | 521 | self.update(device_id='', device_name='', limit_bandwidth=False, | ||
367 | 522 | max_upload_speed=0, max_download_speed=0) | ||
368 | 523 | |||
369 | 524 | self.add(self.itself) | ||
370 | 525 | self.device_id.hide() | ||
371 | 526 | self.show() | ||
372 | 527 | |||
373 | 528 | self.backend.connect_to_signal('DeviceSettingsChanged', | ||
374 | 529 | self.on_device_settings_changed) | ||
375 | 530 | self.backend.connect_to_signal('DeviceSettingsChangeError', | ||
376 | 531 | self.on_device_settings_change_error) | ||
377 | 532 | |||
378 | 533 | def _change_device_settings(self, *args): | ||
379 | 534 | """Update backend settings for this device.""" | ||
380 | 535 | if self._updating: | ||
381 | 536 | return | ||
382 | 537 | |||
383 | 538 | # Not disabling the GUI to avoid annyong twitchings | ||
384 | 539 | #self.set_sensitive(False) | ||
385 | 540 | self.warning_label.set_text('') | ||
386 | 541 | self.backend.change_device_settings(self.device_id.get_text(), | ||
387 | 542 | self.__dict__) | ||
388 | 543 | |||
389 | 544 | def _block_signals(f): | ||
390 | 545 | """Execute 'f' while having the _updating flag set.""" | ||
391 | 546 | |||
392 | 547 | # pylint: disable=E0213,W0212,E1102 | ||
393 | 548 | |||
394 | 549 | @wraps(f) | ||
395 | 550 | def inner(self, *args, **kwargs): | ||
396 | 551 | """Execute 'f' while having the _updating flag set.""" | ||
397 | 552 | old = self._updating | ||
398 | 553 | self._updating = True | ||
399 | 554 | |||
400 | 555 | result = f(self, *args, **kwargs) | ||
401 | 556 | |||
402 | 557 | self._updating = old | ||
403 | 558 | return result | ||
404 | 559 | |||
405 | 560 | return inner | ||
406 | 561 | |||
407 | 562 | on_limit_bandwidth_toggled = _change_device_settings | ||
408 | 563 | on_max_upload_speed_value_changed = _change_device_settings | ||
409 | 564 | on_max_download_speed_value_changed = _change_device_settings | ||
410 | 565 | |||
411 | 566 | @_block_signals | ||
412 | 567 | def update(self, **kwargs): | ||
413 | 568 | """Update according to named parameters. | ||
414 | 569 | |||
415 | 570 | Possible settings are: | ||
416 | 571 | * device_id (string, not shown to the user) | ||
417 | 572 | * device_name (string) | ||
418 | 573 | * type (either DEVICE_TYPE_PHONE or DEVICE_TYPE_COMPUTER) | ||
419 | 574 | * configurable (True/False) | ||
420 | 575 | * if configurable, the following can be set: | ||
421 | 576 | * limit_bandwidth (True/False) | ||
422 | 577 | * max_upload_speed (bytes) | ||
423 | 578 | * max_download_speed (bytes) | ||
424 | 579 | |||
425 | 580 | """ | ||
426 | 581 | if 'device_id' in kwargs: | ||
427 | 582 | self.device_id.set_text(kwargs['device_id']) | ||
428 | 583 | |||
429 | 584 | if 'device_name' in kwargs: | ||
430 | 585 | self.device_name.set_markup('<b>%s</b>' % kwargs['device_name']) | ||
431 | 586 | |||
432 | 587 | if 'device_type' in kwargs: | ||
433 | 588 | dtype = kwargs['device_type'] | ||
434 | 589 | if dtype in (DEVICE_TYPE_COMPUTER, DEVICE_TYPE_PHONE): | ||
435 | 590 | self.device_type.set_from_icon_name(dtype.lower(), | ||
436 | 591 | gtk.ICON_SIZE_BUTTON) | ||
437 | 592 | |||
438 | 593 | if 'configurable' in kwargs: | ||
439 | 594 | self.configurable = bool(kwargs['configurable']) | ||
440 | 595 | self.throttling.set_visible(self.configurable) | ||
441 | 596 | |||
442 | 597 | if 'limit_bandwidth' in kwargs: | ||
443 | 598 | self.limit_bandwidth.set_active(bool(kwargs['limit_bandwidth'])) | ||
444 | 599 | |||
445 | 600 | for speed in ('max_upload_speed', 'max_download_speed'): | ||
446 | 601 | if speed in kwargs: | ||
447 | 602 | value = int(kwargs[speed]) // KILOBYTES | ||
448 | 603 | getattr(self, speed).set_value(value) | ||
449 | 604 | |||
450 | 605 | self._last_settings = self.__dict__ | ||
451 | 606 | |||
452 | 607 | @property | ||
453 | 608 | def __dict__(self): | ||
454 | 609 | result = { | ||
455 | 610 | 'device_id': self.device_id.get_text(), | ||
456 | 611 | 'device_name': self.device_name.get_text(), | ||
457 | 612 | 'device_type': self.device_type.get_icon_name()[0].capitalize(), | ||
458 | 613 | 'configurable': bool_str(self.configurable), | ||
459 | 614 | 'limit_bandwidth': bool_str(self.limit_bandwidth.get_active()), | ||
460 | 615 | 'max_upload_speed': \ | ||
461 | 616 | str(self.max_upload_speed.get_value_as_int() * KILOBYTES), | ||
462 | 617 | 'max_download_speed': \ | ||
463 | 618 | str(self.max_download_speed.get_value_as_int() * KILOBYTES), | ||
464 | 619 | } | ||
465 | 620 | return result | ||
466 | 621 | |||
467 | 622 | @log_call(logger.info) | ||
468 | 623 | def on_device_settings_changed(self, device_id): | ||
469 | 624 | """The change of this device settings succeded.""" | ||
470 | 625 | if device_id != self.device_id.get_text(): | ||
471 | 626 | return | ||
472 | 627 | self.set_sensitive(True) | ||
473 | 628 | self.warning_label.set_text('') | ||
474 | 629 | self._last_settings = self.__dict__ | ||
475 | 630 | |||
476 | 631 | @log_call(logger.error) | ||
477 | 632 | def on_device_settings_change_error(self, device_id, error_dict=None): | ||
478 | 633 | """The change of this device settings failed.""" | ||
479 | 634 | if device_id != self.device_id.get_text(): | ||
480 | 635 | return | ||
481 | 636 | self.update(**self._last_settings) | ||
482 | 637 | self._set_warning(self.DEVICE_CHANGE_ERROR, self.warning_label) | ||
483 | 638 | self.set_sensitive(True) | ||
484 | 639 | |||
485 | 640 | |||
486 | 498 | class DevicesPanel(UbuntuOneBin, ControlPanelMixin): | 641 | class DevicesPanel(UbuntuOneBin, ControlPanelMixin): |
487 | 499 | """The devices panel.""" | 642 | """The devices panel.""" |
488 | 500 | 643 | ||
489 | @@ -504,9 +647,29 @@ | |||
490 | 504 | def __init__(self): | 647 | def __init__(self): |
491 | 505 | UbuntuOneBin.__init__(self) | 648 | UbuntuOneBin.__init__(self) |
492 | 506 | ControlPanelMixin.__init__(self, filename='devices.ui') | 649 | ControlPanelMixin.__init__(self, filename='devices.ui') |
494 | 507 | self.pack_start(self.itself) | 650 | self.add(self.itself) |
495 | 508 | self.show() | 651 | self.show() |
496 | 509 | 652 | ||
497 | 653 | self.backend.connect_to_signal('DevicesInfoReady', | ||
498 | 654 | self.on_devices_info_ready) | ||
499 | 655 | self.backend.connect_to_signal('DevicesInfoError', | ||
500 | 656 | self.on_devices_info_error) | ||
501 | 657 | self.backend.devices_info() | ||
502 | 658 | |||
503 | 659 | def on_devices_info_ready(self, info): | ||
504 | 660 | """Backend notifies of devices info.""" | ||
505 | 661 | for device_info in info: | ||
506 | 662 | device = Device() | ||
507 | 663 | device_info['device_name'] = device_info.pop('name', '') | ||
508 | 664 | device_info['device_type'] = device_info.pop('type', | ||
509 | 665 | DEVICE_TYPE_COMPUTER) | ||
510 | 666 | device.update(**device_info) | ||
511 | 667 | self.devices.pack_start(device) | ||
512 | 668 | |||
513 | 669 | @log_call(logger.error) | ||
514 | 670 | def on_devices_info_error(self, error_dict=None): | ||
515 | 671 | """Backend notifies of an error when fetching volumes info.""" | ||
516 | 672 | |||
517 | 510 | 673 | ||
518 | 511 | class ApplicationsPanel(UbuntuOneBin, ControlPanelMixin): | 674 | class ApplicationsPanel(UbuntuOneBin, ControlPanelMixin): |
519 | 512 | """The applications panel.""" | 675 | """The applications panel.""" |
520 | @@ -517,7 +680,7 @@ | |||
521 | 517 | def __init__(self): | 680 | def __init__(self): |
522 | 518 | UbuntuOneBin.__init__(self) | 681 | UbuntuOneBin.__init__(self) |
523 | 519 | ControlPanelMixin.__init__(self, filename='applications.ui') | 682 | ControlPanelMixin.__init__(self, filename='applications.ui') |
525 | 520 | self.pack_start(self.itself) | 683 | self.add(self.itself) |
526 | 521 | self.show() | 684 | self.show() |
527 | 522 | 685 | ||
528 | 523 | 686 | ||
529 | @@ -543,7 +706,7 @@ | |||
530 | 543 | def __init__(self): | 706 | def __init__(self): |
531 | 544 | gtk.VBox.__init__(self) | 707 | gtk.VBox.__init__(self) |
532 | 545 | ControlPanelMixin.__init__(self, filename='management.ui') | 708 | ControlPanelMixin.__init__(self, filename='management.ui') |
534 | 546 | self.pack_start(self.itself) | 709 | self.add(self.itself) |
535 | 547 | self.show() | 710 | self.show() |
536 | 548 | 711 | ||
537 | 549 | self.backend.connect_to_signal('AccountInfoReady', | 712 | self.backend.connect_to_signal('AccountInfoReady', |
538 | 550 | 713 | ||
539 | === modified file 'ubuntuone/controlpanel/gtk/tests/test_gui.py' | |||
540 | --- ubuntuone/controlpanel/gtk/tests/test_gui.py 2010-12-14 19:16:25 +0000 | |||
541 | +++ ubuntuone/controlpanel/gtk/tests/test_gui.py 2010-12-17 17:27:34 +0000 | |||
542 | @@ -45,6 +45,23 @@ | |||
543 | 45 | {'volume_id': '2', 'suggested_path': '~/baz', 'subscribed': 'True'}, | 45 | {'volume_id': '2', 'suggested_path': '~/baz', 'subscribed': 'True'}, |
544 | 46 | ] | 46 | ] |
545 | 47 | 47 | ||
546 | 48 | FAKE_DEVICE_INFO = { | ||
547 | 49 | 'device_id': '1258-6854', 'device_name': 'Baz', 'device_type': 'Computer', | ||
548 | 50 | 'configurable': 'True', 'limit_bandwidth': 'True', | ||
549 | 51 | 'max_upload_speed': '1000', 'max_download_speed': '72548', | ||
550 | 52 | } | ||
551 | 53 | |||
552 | 54 | FAKE_DEVICES_INFO = [ | ||
553 | 55 | {'device_id': '0', 'name': 'Foo', 'type': 'Computer', 'configurable': ''}, | ||
554 | 56 | {'device_id': '1', 'name': 'Bar', 'type': 'Phone', 'configurable': ''}, | ||
555 | 57 | {'device_id': '2', 'name': 'Z', 'type': 'Computer', | ||
556 | 58 | 'configurable': 'True', 'limit_bandwidth': '', | ||
557 | 59 | 'max_upload_speed': '0', 'max_download_speed': '0'}, | ||
558 | 60 | {'device_id': '1258-6854', 'name': 'Baz', 'type': 'Computer', | ||
559 | 61 | 'configurable': 'True', 'limit_bandwidth': 'True', | ||
560 | 62 | 'max_upload_speed': '1000', 'max_download_speed': '72548'}, | ||
561 | 63 | ] | ||
562 | 64 | |||
563 | 48 | 65 | ||
564 | 49 | class FakedObject(object): | 66 | class FakedObject(object): |
565 | 50 | """Fake an object, record every call.""" | 67 | """Fake an object, record every call.""" |
566 | @@ -108,8 +125,10 @@ | |||
567 | 108 | bus_name = gui.DBUS_BUS_NAME | 125 | bus_name = gui.DBUS_BUS_NAME |
568 | 109 | object_path = gui.DBUS_PREFERENCES_PATH | 126 | object_path = gui.DBUS_PREFERENCES_PATH |
569 | 110 | iface = gui.DBUS_PREFERENCES_IFACE | 127 | iface = gui.DBUS_PREFERENCES_IFACE |
572 | 111 | exposed_methods = ['account_info', 'devices_info', 'volumes_info', | 128 | exposed_methods = [ |
573 | 112 | 'file_sync_status', 'change_volume_settings'] | 129 | 'account_info', 'devices_info', 'change_device_settings', |
574 | 130 | 'volumes_info', 'change_volume_settings', 'file_sync_status', | ||
575 | 131 | ] | ||
576 | 113 | 132 | ||
577 | 114 | 133 | ||
578 | 115 | class FakedSessionBus(object): | 134 | class FakedSessionBus(object): |
579 | @@ -268,8 +287,8 @@ | |||
580 | 268 | self.assertEqual(self.ui.get_icon_name(), 'ubuntuone') | 287 | self.assertEqual(self.ui.get_icon_name(), 'ubuntuone') |
581 | 269 | 288 | ||
582 | 270 | def test_max_size(self): | 289 | def test_max_size(self): |
585 | 271 | """Max size is not bigger than 966x576 (LP: #645526).""" | 290 | """Max size is not bigger than 736x525 (LP: #645526, LP: #683164).""" |
586 | 272 | self.assertTrue(self.ui.get_size_request() <= (966, 576)) | 291 | self.assertTrue(self.ui.get_size_request() <= (736, 525)) |
587 | 273 | 292 | ||
588 | 274 | 293 | ||
589 | 275 | class ControlPanelTestCase(ControlPanelMixinTestCase): | 294 | class ControlPanelTestCase(ControlPanelMixinTestCase): |
590 | @@ -801,8 +820,7 @@ | |||
591 | 801 | self.ui.on_volumes_info_ready(FAKE_VOLUMES_INFO) | 820 | self.ui.on_volumes_info_ready(FAKE_VOLUMES_INFO) |
592 | 802 | 821 | ||
593 | 803 | self.assertFalse(self.ui.label_alignment.get_visible()) | 822 | self.assertFalse(self.ui.label_alignment.get_visible()) |
596 | 804 | self.assertEqual(self.ui.folders_alignment.get_children(), | 823 | self.assertEqual(self.ui.folders.get_children(), [self.ui.volumes]) |
595 | 805 | [self.ui.volumes]) | ||
597 | 806 | 824 | ||
598 | 807 | volumes = self.ui.volumes.get_children() | 825 | volumes = self.ui.volumes.get_children() |
599 | 808 | volumes.reverse() | 826 | volumes.reverse() |
600 | @@ -828,8 +846,8 @@ | |||
601 | 828 | self.ui.on_volumes_info_ready(FAKE_VOLUMES_INFO) | 846 | self.ui.on_volumes_info_ready(FAKE_VOLUMES_INFO) |
602 | 829 | self.ui.on_volumes_info_ready(FAKE_VOLUMES_INFO) | 847 | self.ui.on_volumes_info_ready(FAKE_VOLUMES_INFO) |
603 | 830 | 848 | ||
606 | 831 | self.assertEqual(len(self.ui.folders_alignment.get_children()), 1) | 849 | self.assertEqual(len(self.ui.folders.get_children()), 1) |
607 | 832 | child = self.ui.folders_alignment.get_children()[0] | 850 | child = self.ui.folders.get_children()[0] |
608 | 833 | self.assertEqual(child, self.ui.volumes) | 851 | self.assertEqual(child, self.ui.volumes) |
609 | 834 | 852 | ||
610 | 835 | volumes = filter(lambda w: isinstance(w, gui.gtk.CheckButton), | 853 | volumes = filter(lambda w: isinstance(w, gui.gtk.CheckButton), |
611 | @@ -840,7 +858,7 @@ | |||
612 | 840 | """When there are no volumes, a notification is shown.""" | 858 | """When there are no volumes, a notification is shown.""" |
613 | 841 | self.ui.on_volumes_info_ready([]) | 859 | self.ui.on_volumes_info_ready([]) |
614 | 842 | # no volumes table | 860 | # no volumes table |
616 | 843 | self.assertEqual(len(self.ui.folders_alignment.get_children()), 0) | 861 | self.assertEqual(len(self.ui.folders.get_children()), 0) |
617 | 844 | self.assertTrue(self.ui.volumes is None) | 862 | self.assertTrue(self.ui.volumes is None) |
618 | 845 | 863 | ||
619 | 846 | def test_on_subscribed_clicked(self): | 864 | def test_on_subscribed_clicked(self): |
620 | @@ -852,14 +870,14 @@ | |||
621 | 852 | checkbutton.clicked() | 870 | checkbutton.clicked() |
622 | 853 | fid = checkbutton.get_label() | 871 | fid = checkbutton.get_label() |
623 | 854 | 872 | ||
625 | 855 | subscribed = 'True' if checkbutton.get_active() else '' | 873 | subscribed = gui.bool_str(checkbutton.get_active()) |
626 | 856 | self.assert_backend_called(method, | 874 | self.assert_backend_called(method, |
627 | 857 | (fid, {'subscribed': subscribed})) | 875 | (fid, {'subscribed': subscribed})) |
628 | 858 | # clean backend calls | 876 | # clean backend calls |
629 | 859 | self.ui.backend._called.pop(method) | 877 | self.ui.backend._called.pop(method) |
630 | 860 | 878 | ||
631 | 861 | checkbutton.clicked() | 879 | checkbutton.clicked() |
633 | 862 | subscribed = 'True' if checkbutton.get_active() else '' | 880 | subscribed = gui.bool_str(checkbutton.get_active()) |
634 | 863 | self.assert_backend_called('change_volume_settings', | 881 | self.assert_backend_called('change_volume_settings', |
635 | 864 | (fid, {'subscribed': subscribed})) | 882 | (fid, {'subscribed': subscribed})) |
636 | 865 | 883 | ||
637 | @@ -881,6 +899,239 @@ | |||
638 | 881 | self.test_on_volumes_info_ready_with_no_volumes() | 899 | self.test_on_volumes_info_ready_with_no_volumes() |
639 | 882 | 900 | ||
640 | 883 | 901 | ||
641 | 902 | class DeviceTestCase(ControlPanelMixinTestCase): | ||
642 | 903 | """The test suite for the device widget.""" | ||
643 | 904 | |||
644 | 905 | klass = gui.Device | ||
645 | 906 | ui_filename = 'device.ui' | ||
646 | 907 | |||
647 | 908 | def assert_device_equal(self, device, expected): | ||
648 | 909 | """Assert that the device has the values from expected.""" | ||
649 | 910 | self.assertEqual(device.device_id.get_text(), | ||
650 | 911 | expected['device_id']) | ||
651 | 912 | self.assertEqual(device.device_name.get_text(), | ||
652 | 913 | expected['device_name']) | ||
653 | 914 | self.assertEqual(device.device_type.get_icon_name()[0], | ||
654 | 915 | expected['device_type'].lower()) | ||
655 | 916 | self.assertEqual(device.configurable, | ||
656 | 917 | bool(expected['configurable'])) | ||
657 | 918 | self.assertEqual(device.limit_bandwidth.get_active(), | ||
658 | 919 | bool(expected['limit_bandwidth'])) | ||
659 | 920 | |||
660 | 921 | value = int(expected['max_upload_speed']) // gui.KILOBYTES | ||
661 | 922 | self.assertEqual(device.max_upload_speed.get_value_as_int(), value) | ||
662 | 923 | value = int(expected['max_download_speed']) // gui.KILOBYTES | ||
663 | 924 | self.assertEqual(device.max_download_speed.get_value_as_int(), value) | ||
664 | 925 | |||
665 | 926 | def assert_device_settings_changed(self): | ||
666 | 927 | """Changing throttling settings updates the backend properly.""" | ||
667 | 928 | expected = self.ui.__dict__ | ||
668 | 929 | self.assert_backend_called('change_device_settings', | ||
669 | 930 | (self.ui.device_id.get_text(), expected)) | ||
670 | 931 | self.assertEqual(self.ui.warning_label.get_text(), '') | ||
671 | 932 | |||
672 | 933 | def modify_settings(self): | ||
673 | 934 | """Modify settings so values actually change.""" | ||
674 | 935 | new_val = not self.ui.limit_bandwidth.get_active() | ||
675 | 936 | self.ui.limit_bandwidth.set_active(new_val) | ||
676 | 937 | |||
677 | 938 | new_val = self.ui.max_upload_speed.get_value_as_int() + 1 | ||
678 | 939 | self.ui.max_upload_speed.set_value(new_val) | ||
679 | 940 | |||
680 | 941 | new_val = self.ui.max_download_speed.get_value_as_int() + 1 | ||
681 | 942 | self.ui.max_download_speed.set_value(new_val) | ||
682 | 943 | |||
683 | 944 | def test_is_a_vbox(self): | ||
684 | 945 | """Inherits from VBox.""" | ||
685 | 946 | self.assertIsInstance(self.ui, gui.gtk.VBox) | ||
686 | 947 | |||
687 | 948 | def test_inner_widget_is_packed(self): | ||
688 | 949 | """The 'itself' vbox is packed into the widget.""" | ||
689 | 950 | self.assertIn(self.ui.itself, self.ui.get_children()) | ||
690 | 951 | |||
691 | 952 | def test_is_visible(self): | ||
692 | 953 | """Is visible.""" | ||
693 | 954 | self.assertTrue(self.ui.get_visible()) | ||
694 | 955 | |||
695 | 956 | def test_is_sensitive(self): | ||
696 | 957 | """Is sensitive.""" | ||
697 | 958 | self.assertTrue(self.ui.get_sensitive()) | ||
698 | 959 | |||
699 | 960 | def test_warning_label_is_cleared(self): | ||
700 | 961 | """The warning label is cleared.""" | ||
701 | 962 | self.assertEqual(self.ui.warning_label.get_text(), '') | ||
702 | 963 | |||
703 | 964 | def test_device_id_is_hidden(self): | ||
704 | 965 | """The device id label is hidden.""" | ||
705 | 966 | self.assertFalse(self.ui.device_id.get_visible()) | ||
706 | 967 | |||
707 | 968 | def test_default_values(self): | ||
708 | 969 | """Default values are correct.""" | ||
709 | 970 | self.assertEqual(self.ui.device_id.get_text(), '') | ||
710 | 971 | self.assertEqual(self.ui.device_name.get_text(), '') | ||
711 | 972 | self.assertEqual(self.ui.device_type.get_icon_name()[0], | ||
712 | 973 | gui.DEVICE_TYPE_COMPUTER.lower()) | ||
713 | 974 | self.assertEqual(self.ui.configurable, False) | ||
714 | 975 | self.assertEqual(self.ui.limit_bandwidth.get_active(), False) | ||
715 | 976 | self.assertEqual(self.ui.max_upload_speed.get_value_as_int(), 0) | ||
716 | 977 | self.assertEqual(self.ui.max_download_speed.get_value_as_int(), 0) | ||
717 | 978 | |||
718 | 979 | def test_init_does_not_call_backend(self): | ||
719 | 980 | """When updating, the backend is not called.""" | ||
720 | 981 | self.assertEqual(self.ui.backend._called, {}) | ||
721 | 982 | |||
722 | 983 | def test_update_device_id(self): | ||
723 | 984 | """A device can be updated from a dict.""" | ||
724 | 985 | value = '741-822-963' | ||
725 | 986 | self.ui.update(device_id=value) | ||
726 | 987 | self.assertEqual(value, self.ui.device_id.get_text()) | ||
727 | 988 | |||
728 | 989 | def test_update_device_name(self): | ||
729 | 990 | """A device can be updated from a dict.""" | ||
730 | 991 | value = 'The death star' | ||
731 | 992 | self.ui.update(device_name=value) | ||
732 | 993 | self.assertEqual(value, self.ui.device_name.get_text()) | ||
733 | 994 | |||
734 | 995 | def test_update_unicode_device_name(self): | ||
735 | 996 | """A device can be updated from a dict.""" | ||
736 | 997 | value = u'Ñoño Ñandú' | ||
737 | 998 | self.ui.update(device_name=value) | ||
738 | 999 | self.assertEqual(value, self.ui.device_name.get_text()) | ||
739 | 1000 | |||
740 | 1001 | def test_update_device_type_computer(self): | ||
741 | 1002 | """A device can be updated from a dict.""" | ||
742 | 1003 | dtype = gui.DEVICE_TYPE_COMPUTER | ||
743 | 1004 | self.ui.update(device_type=dtype) | ||
744 | 1005 | self.assertEqual((dtype.lower(), gui.gtk.ICON_SIZE_BUTTON), | ||
745 | 1006 | self.ui.device_type.get_icon_name()) | ||
746 | 1007 | |||
747 | 1008 | def test_update_device_type_phone(self): | ||
748 | 1009 | """A device can be updated from a dict.""" | ||
749 | 1010 | dtype = gui.DEVICE_TYPE_PHONE | ||
750 | 1011 | self.ui.update(device_type=dtype) | ||
751 | 1012 | self.assertEqual((dtype.lower(), gui.gtk.ICON_SIZE_BUTTON), | ||
752 | 1013 | self.ui.device_type.get_icon_name()) | ||
753 | 1014 | |||
754 | 1015 | def test_update_configurable(self): | ||
755 | 1016 | """A device can be updated from a dict.""" | ||
756 | 1017 | self.ui.update(configurable='') | ||
757 | 1018 | self.assertFalse(self.ui.configurable) | ||
758 | 1019 | self.assertFalse(self.ui.throttling.get_visible()) | ||
759 | 1020 | |||
760 | 1021 | def test_update_non_configurable(self): | ||
761 | 1022 | """A device can be updated from a dict.""" | ||
762 | 1023 | self.ui.update(configurable='True') | ||
763 | 1024 | self.assertTrue(self.ui.configurable) | ||
764 | 1025 | self.assertTrue(self.ui.throttling.get_visible()) | ||
765 | 1026 | |||
766 | 1027 | def test_update_limit_bandwidth(self): | ||
767 | 1028 | """A device can be updated from a dict.""" | ||
768 | 1029 | self.ui.update(limit_bandwidth='') | ||
769 | 1030 | self.assertFalse(self.ui.limit_bandwidth.get_active()) | ||
770 | 1031 | |||
771 | 1032 | self.ui.update(limit_bandwidth='True') | ||
772 | 1033 | self.assertTrue(self.ui.limit_bandwidth.get_active()) | ||
773 | 1034 | |||
774 | 1035 | def test_update_upload_speed(self): | ||
775 | 1036 | """A device can be updated from a dict.""" | ||
776 | 1037 | value = '12345' | ||
777 | 1038 | self.ui.update(max_upload_speed=value) | ||
778 | 1039 | self.assertEqual(int(value) // gui.KILOBYTES, | ||
779 | 1040 | self.ui.max_upload_speed.get_value_as_int()) | ||
780 | 1041 | |||
781 | 1042 | def test_update_download_speed(self): | ||
782 | 1043 | """A device can be updated from a dict.""" | ||
783 | 1044 | value = '987654' | ||
784 | 1045 | self.ui.update(max_download_speed=value) | ||
785 | 1046 | self.assertEqual(int(value) // gui.KILOBYTES, | ||
786 | 1047 | self.ui.max_download_speed.get_value_as_int()) | ||
787 | 1048 | |||
788 | 1049 | def test_update_does_not_call_backend(self): | ||
789 | 1050 | """When updating, the backend is not called.""" | ||
790 | 1051 | self.ui.update(**FAKE_DEVICE_INFO) | ||
791 | 1052 | self.assertEqual(self.ui.backend._called, {}) | ||
792 | 1053 | self.assert_device_equal(self.ui, FAKE_DEVICE_INFO) | ||
793 | 1054 | |||
794 | 1055 | def test_on_limit_bandwidth_toggled(self): | ||
795 | 1056 | """When toggling limit_bandwidth, backend is updated.""" | ||
796 | 1057 | self.ui.limit_bandwidth.toggled() | ||
797 | 1058 | self.assert_device_settings_changed() | ||
798 | 1059 | |||
799 | 1060 | def test_on_max_upload_speed_value_changed(self): | ||
800 | 1061 | """When setting max_upload_speed, backend is updated.""" | ||
801 | 1062 | self.ui.max_upload_speed.set_value(25) | ||
802 | 1063 | self.assert_device_settings_changed() | ||
803 | 1064 | |||
804 | 1065 | def test_on_max_download_speed_value_changed(self): | ||
805 | 1066 | """When setting max_download_speed, backend is updated.""" | ||
806 | 1067 | self.ui.max_download_speed.set_value(52) | ||
807 | 1068 | self.assert_device_settings_changed() | ||
808 | 1069 | |||
809 | 1070 | def test_backend_signals(self): | ||
810 | 1071 | """The proper signals are connected to the backend.""" | ||
811 | 1072 | self.assertEqual(self.ui.backend._signals['DeviceSettingsChanged'], | ||
812 | 1073 | [self.ui.on_device_settings_changed]) | ||
813 | 1074 | self.assertEqual(self.ui.backend._signals['DeviceSettingsChangeError'], | ||
814 | 1075 | [self.ui.on_device_settings_change_error]) | ||
815 | 1076 | |||
816 | 1077 | def test_on_device_settings_changed(self): | ||
817 | 1078 | """When settings were changed for this device, enable it.""" | ||
818 | 1079 | self.modify_settings() | ||
819 | 1080 | did = self.ui.device_id.get_text() | ||
820 | 1081 | self.ui.on_device_settings_changed(device_id=did) | ||
821 | 1082 | |||
822 | 1083 | self.assertTrue(self.ui.get_sensitive()) | ||
823 | 1084 | self.assertEqual(self.ui.warning_label.get_text(), '') | ||
824 | 1085 | self.assertEqual(self.ui.__dict__, self.ui._last_settings) | ||
825 | 1086 | |||
826 | 1087 | def test_on_device_settings_change_after_error(self): | ||
827 | 1088 | """Change success after error.""" | ||
828 | 1089 | self.modify_settings() | ||
829 | 1090 | did = self.ui.device_id.get_text() | ||
830 | 1091 | self.ui.on_device_settings_change_error(device_id=did) # change failed | ||
831 | 1092 | |||
832 | 1093 | self.test_on_device_settings_changed() | ||
833 | 1094 | |||
834 | 1095 | def test_on_device_settings_changed_different_id(self): | ||
835 | 1096 | """When settings were changed for other device, nothing changes.""" | ||
836 | 1097 | self.modify_settings() | ||
837 | 1098 | self.ui.on_device_settings_changed(device_id='yadda') | ||
838 | 1099 | |||
839 | 1100 | self.assertEqual(self.ui.warning_label.get_text(), '') | ||
840 | 1101 | |||
841 | 1102 | def test_on_device_settings_change_error(self): | ||
842 | 1103 | """When settings were not changed for this device, notify the user. | ||
843 | 1104 | |||
844 | 1105 | Also, confirm that old values were restored. | ||
845 | 1106 | |||
846 | 1107 | """ | ||
847 | 1108 | self.ui.update(**FAKE_DEVICE_INFO) # use known values | ||
848 | 1109 | |||
849 | 1110 | self.modify_settings() | ||
850 | 1111 | |||
851 | 1112 | did = self.ui.device_id.get_text() | ||
852 | 1113 | self.ui.on_device_settings_change_error(device_id=did) # change failed | ||
853 | 1114 | |||
854 | 1115 | self.assertTrue(self.ui.get_sensitive()) | ||
855 | 1116 | self.assert_warning_correct(self.ui.warning_label, | ||
856 | 1117 | self.ui.DEVICE_CHANGE_ERROR) | ||
857 | 1118 | self.assert_device_equal(self.ui, FAKE_DEVICE_INFO) # restored info | ||
858 | 1119 | |||
859 | 1120 | def test_on_device_settings_change_error_after_success(self): | ||
860 | 1121 | """Change error after success.""" | ||
861 | 1122 | self.modify_settings() | ||
862 | 1123 | did = self.ui.device_id.get_text() | ||
863 | 1124 | self.ui.on_device_settings_changed(device_id=did) | ||
864 | 1125 | |||
865 | 1126 | self.test_on_device_settings_change_error() | ||
866 | 1127 | |||
867 | 1128 | def test_on_device_settings_change_error_different_id(self): | ||
868 | 1129 | """When settings were not changed for other device, do nothing.""" | ||
869 | 1130 | self.modify_settings() | ||
870 | 1131 | self.ui.on_device_settings_change_error(device_id='yudo') | ||
871 | 1132 | self.assertEqual(self.ui.warning_label.get_text(), '') | ||
872 | 1133 | |||
873 | 1134 | |||
874 | 884 | class DevicesTestCase(ControlPanelMixinTestCase): | 1135 | class DevicesTestCase(ControlPanelMixinTestCase): |
875 | 885 | """The test suite for the devices panel.""" | 1136 | """The test suite for the devices panel.""" |
876 | 886 | 1137 | ||
877 | @@ -899,6 +1150,50 @@ | |||
878 | 899 | """Is visible.""" | 1150 | """Is visible.""" |
879 | 900 | self.assertTrue(self.ui.get_visible()) | 1151 | self.assertTrue(self.ui.get_visible()) |
880 | 901 | 1152 | ||
881 | 1153 | def test_backend_signals(self): | ||
882 | 1154 | """The proper signals are connected to the backend.""" | ||
883 | 1155 | self.assertEqual(self.ui.backend._signals['DevicesInfoReady'], | ||
884 | 1156 | [self.ui.on_devices_info_ready]) | ||
885 | 1157 | self.assertEqual(self.ui.backend._signals['DevicesInfoError'], | ||
886 | 1158 | [self.ui.on_devices_info_error]) | ||
887 | 1159 | |||
888 | 1160 | def test_devices_info_is_requested(self): | ||
889 | 1161 | """The devices info is requested to the backend.""" | ||
890 | 1162 | self.assert_backend_called('devices_info', ()) | ||
891 | 1163 | |||
892 | 1164 | def test_on_devices_info_ready(self): | ||
893 | 1165 | """The devices info is processed when ready.""" | ||
894 | 1166 | self.ui.on_devices_info_ready(FAKE_DEVICES_INFO) | ||
895 | 1167 | |||
896 | 1168 | children = self.ui.devices.get_children() | ||
897 | 1169 | self.assertEqual(len(children), len(FAKE_DEVICES_INFO)) | ||
898 | 1170 | |||
899 | 1171 | for child, device in zip(children, FAKE_DEVICES_INFO): | ||
900 | 1172 | self.assertIsInstance(child, gui.Device) | ||
901 | 1173 | |||
902 | 1174 | self.assertEqual(device['device_id'], | ||
903 | 1175 | child.device_id.get_text()) | ||
904 | 1176 | self.assertEqual(device['device_name'], | ||
905 | 1177 | child.device_name.get_text()) | ||
906 | 1178 | self.assertEqual(device['device_type'].lower(), | ||
907 | 1179 | child.device_type.get_icon_name()[0]) | ||
908 | 1180 | self.assertEqual(bool(device['configurable']), | ||
909 | 1181 | child.configurable) | ||
910 | 1182 | |||
911 | 1183 | if bool(device['configurable']): | ||
912 | 1184 | self.assertEqual(bool(device['limit_bandwidth']), | ||
913 | 1185 | child.limit_bandwidth.get_active()) | ||
914 | 1186 | value = int(device['max_upload_speed']) // gui.KILOBYTES | ||
915 | 1187 | self.assertEqual(value, | ||
916 | 1188 | child.max_upload_speed.get_value_as_int()) | ||
917 | 1189 | value = int(device['max_download_speed']) // gui.KILOBYTES | ||
918 | 1190 | self.assertEqual(value, | ||
919 | 1191 | child.max_download_speed.get_value_as_int()) | ||
920 | 1192 | |||
921 | 1193 | def test_on_devices_info_error(self): | ||
922 | 1194 | """The devices info couldn't be retrieved.""" | ||
923 | 1195 | self.ui.on_devices_info_error() | ||
924 | 1196 | |||
925 | 902 | 1197 | ||
926 | 903 | class ApplicationsTestCase(ControlPanelMixinTestCase): | 1198 | class ApplicationsTestCase(ControlPanelMixinTestCase): |
927 | 904 | """The test suite for the applications panel.""" | 1199 | """The test suite for the applications panel.""" |
I am probably missing a lot of context, but when blindly trying to test this, I get:
beuno@beuno- laptop: ~$ bzr branch lp:~nataliabidart/ubuntuone-control-panel/devices laptop: ~$ cd devices/ laptop: ~/devices$ EBUG=True PYTHONPATH=. ./bin/ubuntuone -control- panel-backend ubuntuone- control- panel-backend" , line 24, in <module> controlpanel import dbus_service beuno/devices/ ubuntuone/ controlpanel/ dbus_service. py", line 32, in <module> controlpanel. backend import ( beuno/devices/ ubuntuone/ controlpanel/ backend. py", line 24, in <module> controlpanel import dbus_client beuno/devices/ ubuntuone/ controlpanel/ dbus_client. py", line 28, in <module> platform. linux import dbus_interface as sd_dbus_iface
Branched 44 revision(s).
beuno@beuno-
beuno@beuno-
Traceback (most recent call last):
File "./bin/
from ubuntuone.
File "/home/
from ubuntuone.
File "/home/
from ubuntuone.
File "/home/
from ubuntuone.
ImportError: No module named platform.linux