Merge lp:~nataliabidart/ubuntuone-control-panel/letmeremove into lp:ubuntuone-control-panel
- letmeremove
- Merge into trunk
Proposed by
Natalia Bidart
Status: | Merged |
---|---|
Approved by: | Alejandro J. Cura |
Approved revision: | 189 |
Merged at revision: | 188 |
Proposed branch: | lp:~nataliabidart/ubuntuone-control-panel/letmeremove |
Merge into: | lp:ubuntuone-control-panel |
Diff against target: |
583 lines (+243/-131) 9 files modified
data/qt/device.ui (+8/-1) data/qt/devices.ui (+69/-105) ubuntuone/controlpanel/gui/qt/device.py (+36/-9) ubuntuone/controlpanel/gui/qt/devices.py (+5/-1) ubuntuone/controlpanel/gui/qt/loadingoverlay.py (+2/-1) ubuntuone/controlpanel/gui/qt/tests/__init__.py (+3/-0) ubuntuone/controlpanel/gui/qt/tests/test_device.py (+89/-4) ubuntuone/controlpanel/gui/qt/tests/test_devices.py (+14/-2) ubuntuone/controlpanel/gui/tests/__init__.py (+17/-8) |
To merge this branch: | bzr merge lp:~nataliabidart/ubuntuone-control-panel/letmeremove |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Alejandro J. Cura (community) | Approve | ||
Roberto Alsina (community) | Approve | ||
Review via email: mp+68444@code.launchpad.net |
Commit message
- Local device can now be removed (LP: #810662).
Description of the change
To post a comment you must log in.
- 188. By Natalia Bidart
-
Added code to remove local device once removed.
- 189. By Natalia Bidart
-
Merged trunk in.
Revision history for this message
Alejandro J. Cura (alecu) wrote : | # |
Clean code, tests pass, works irl. Approved!
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'data/qt/device.ui' | |||
2 | --- data/qt/device.ui 2011-07-11 11:19:09 +0000 | |||
3 | +++ data/qt/device.ui 2011-07-19 19:17:30 +0000 | |||
4 | @@ -24,7 +24,7 @@ | |||
5 | 24 | <item> | 24 | <item> |
6 | 25 | <widget class="QLabel" name="device_name_label"> | 25 | <widget class="QLabel" name="device_name_label"> |
7 | 26 | <property name="text"> | 26 | <property name="text"> |
9 | 27 | <string>Another device</string> | 27 | <string>Local device</string> |
10 | 28 | </property> | 28 | </property> |
11 | 29 | </widget> | 29 | </widget> |
12 | 30 | </item> | 30 | </item> |
13 | @@ -41,6 +41,13 @@ | |||
14 | 41 | </property> | 41 | </property> |
15 | 42 | </spacer> | 42 | </spacer> |
16 | 43 | </item> | 43 | </item> |
17 | 44 | <item> | ||
18 | 45 | <widget class="QPushButton" name="remove_device_button"> | ||
19 | 46 | <property name="text"> | ||
20 | 47 | <string>Delete device</string> | ||
21 | 48 | </property> | ||
22 | 49 | </widget> | ||
23 | 50 | </item> | ||
24 | 44 | </layout> | 51 | </layout> |
25 | 45 | </widget> | 52 | </widget> |
26 | 46 | <resources> | 53 | <resources> |
27 | 47 | 54 | ||
28 | === modified file 'data/qt/devices.ui' | |||
29 | --- data/qt/devices.ui 2011-07-11 11:19:09 +0000 | |||
30 | +++ data/qt/devices.ui 2011-07-19 19:17:30 +0000 | |||
31 | @@ -6,8 +6,8 @@ | |||
32 | 6 | <rect> | 6 | <rect> |
33 | 7 | <x>0</x> | 7 | <x>0</x> |
34 | 8 | <y>0</y> | 8 | <y>0</y> |
37 | 9 | <width>688</width> | 9 | <width>325</width> |
38 | 10 | <height>371</height> | 10 | <height>252</height> |
39 | 11 | </rect> | 11 | </rect> |
40 | 12 | </property> | 12 | </property> |
41 | 13 | <property name="windowTitle"> | 13 | <property name="windowTitle"> |
42 | @@ -21,111 +21,75 @@ | |||
43 | 21 | <number>0</number> | 21 | <number>0</number> |
44 | 22 | </property> | 22 | </property> |
45 | 23 | <item> | 23 | <item> |
149 | 24 | <widget class="QFrame" name="frame"> | 24 | <layout class="QVBoxLayout" name="local_device_box"/> |
150 | 25 | <property name="frameShape"> | 25 | </item> |
151 | 26 | <enum>QFrame::StyledPanel</enum> | 26 | <item> |
152 | 27 | </property> | 27 | <layout class="QHBoxLayout" name="horizontalLayout"> |
153 | 28 | <property name="frameShadow"> | 28 | <item> |
154 | 29 | <enum>QFrame::Raised</enum> | 29 | <widget class="QLabel" name="other_devices_label"> |
155 | 30 | </property> | 30 | <property name="text"> |
156 | 31 | <layout class="QVBoxLayout" name="verticalLayout_2"> | 31 | <string>Other devices</string> |
157 | 32 | <item> | 32 | </property> |
158 | 33 | <layout class="QHBoxLayout" name="horizontalLayout_2"> | 33 | </widget> |
159 | 34 | <item> | 34 | </item> |
160 | 35 | <layout class="QVBoxLayout" name="local_device_box"/> | 35 | <item> |
161 | 36 | </item> | 36 | <spacer name="horizontalSpacer"> |
162 | 37 | <item> | 37 | <property name="orientation"> |
163 | 38 | <spacer name="horizontalSpacer_2"> | 38 | <enum>Qt::Horizontal</enum> |
164 | 39 | <property name="orientation"> | 39 | </property> |
165 | 40 | <enum>Qt::Horizontal</enum> | 40 | <property name="sizeHint" stdset="0"> |
166 | 41 | </property> | 41 | <size> |
167 | 42 | <property name="sizeHint" stdset="0"> | 42 | <width>40</width> |
168 | 43 | <size> | 43 | <height>20</height> |
169 | 44 | <width>40</width> | 44 | </size> |
170 | 45 | <height>20</height> | 45 | </property> |
171 | 46 | </size> | 46 | </spacer> |
172 | 47 | </property> | 47 | </item> |
173 | 48 | </spacer> | 48 | </layout> |
174 | 49 | </item> | 49 | </item> |
175 | 50 | <item> | 50 | <item> |
176 | 51 | <widget class="QPushButton" name="delete_device_button"> | 51 | <widget class="QListWidget" name="list_devices"> |
177 | 52 | <property name="text"> | 52 | <property name="alternatingRowColors"> |
178 | 53 | <string>Delete device</string> | 53 | <bool>true</bool> |
179 | 54 | </property> | 54 | </property> |
180 | 55 | </widget> | 55 | <property name="iconSize"> |
181 | 56 | </item> | 56 | <size> |
182 | 57 | </layout> | 57 | <width>32</width> |
183 | 58 | </item> | 58 | <height>32</height> |
184 | 59 | <item> | 59 | </size> |
185 | 60 | <layout class="QHBoxLayout" name="horizontalLayout"> | 60 | </property> |
186 | 61 | <item> | 61 | <property name="spacing"> |
187 | 62 | <widget class="QLabel" name="other_devices_label"> | 62 | <number>0</number> |
188 | 63 | <property name="text"> | 63 | </property> |
189 | 64 | <string>Other devices</string> | 64 | <property name="selectionRectVisible"> |
190 | 65 | </property> | 65 | <bool>false</bool> |
191 | 66 | </widget> | 66 | </property> |
89 | 67 | </item> | ||
90 | 68 | <item> | ||
91 | 69 | <spacer name="horizontalSpacer"> | ||
92 | 70 | <property name="orientation"> | ||
93 | 71 | <enum>Qt::Horizontal</enum> | ||
94 | 72 | </property> | ||
95 | 73 | <property name="sizeHint" stdset="0"> | ||
96 | 74 | <size> | ||
97 | 75 | <width>40</width> | ||
98 | 76 | <height>20</height> | ||
99 | 77 | </size> | ||
100 | 78 | </property> | ||
101 | 79 | </spacer> | ||
102 | 80 | </item> | ||
103 | 81 | </layout> | ||
104 | 82 | </item> | ||
105 | 83 | <item> | ||
106 | 84 | <widget class="QListWidget" name="list_devices"> | ||
107 | 85 | <property name="alternatingRowColors"> | ||
108 | 86 | <bool>true</bool> | ||
109 | 87 | </property> | ||
110 | 88 | <property name="iconSize"> | ||
111 | 89 | <size> | ||
112 | 90 | <width>32</width> | ||
113 | 91 | <height>32</height> | ||
114 | 92 | </size> | ||
115 | 93 | </property> | ||
116 | 94 | <property name="spacing"> | ||
117 | 95 | <number>0</number> | ||
118 | 96 | </property> | ||
119 | 97 | <property name="selectionRectVisible"> | ||
120 | 98 | <bool>false</bool> | ||
121 | 99 | </property> | ||
122 | 100 | </widget> | ||
123 | 101 | </item> | ||
124 | 102 | <item> | ||
125 | 103 | <layout class="QHBoxLayout" name="horizontalLayout_3"> | ||
126 | 104 | <item> | ||
127 | 105 | <widget class="QPushButton" name="manage_devices_button"> | ||
128 | 106 | <property name="sizePolicy"> | ||
129 | 107 | <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> | ||
130 | 108 | <horstretch>0</horstretch> | ||
131 | 109 | <verstretch>0</verstretch> | ||
132 | 110 | </sizepolicy> | ||
133 | 111 | </property> | ||
134 | 112 | <property name="layoutDirection"> | ||
135 | 113 | <enum>Qt::RightToLeft</enum> | ||
136 | 114 | </property> | ||
137 | 115 | <property name="text"> | ||
138 | 116 | <string>Go to the web page to manage your other devices</string> | ||
139 | 117 | </property> | ||
140 | 118 | <property name="icon"> | ||
141 | 119 | <iconset resource="images.qrc"> | ||
142 | 120 | <normaloff>:/external_icon_white.png</normaloff>:/external_icon_white.png</iconset> | ||
143 | 121 | </property> | ||
144 | 122 | </widget> | ||
145 | 123 | </item> | ||
146 | 124 | </layout> | ||
147 | 125 | </item> | ||
148 | 126 | </layout> | ||
192 | 127 | </widget> | 67 | </widget> |
193 | 128 | </item> | 68 | </item> |
194 | 69 | <item> | ||
195 | 70 | <layout class="QHBoxLayout" name="horizontalLayout_3"> | ||
196 | 71 | <item> | ||
197 | 72 | <widget class="QPushButton" name="manage_devices_button"> | ||
198 | 73 | <property name="sizePolicy"> | ||
199 | 74 | <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> | ||
200 | 75 | <horstretch>0</horstretch> | ||
201 | 76 | <verstretch>0</verstretch> | ||
202 | 77 | </sizepolicy> | ||
203 | 78 | </property> | ||
204 | 79 | <property name="layoutDirection"> | ||
205 | 80 | <enum>Qt::RightToLeft</enum> | ||
206 | 81 | </property> | ||
207 | 82 | <property name="text"> | ||
208 | 83 | <string>Go to the web page to manage your other devices</string> | ||
209 | 84 | </property> | ||
210 | 85 | <property name="icon"> | ||
211 | 86 | <iconset resource="images.qrc"> | ||
212 | 87 | <normaloff>:/external_icon_white.png</normaloff>:/external_icon_white.png</iconset> | ||
213 | 88 | </property> | ||
214 | 89 | </widget> | ||
215 | 90 | </item> | ||
216 | 91 | </layout> | ||
217 | 92 | </item> | ||
218 | 129 | </layout> | 93 | </layout> |
219 | 130 | </widget> | 94 | </widget> |
220 | 131 | <resources> | 95 | <resources> |
221 | 132 | 96 | ||
222 | === modified file 'ubuntuone/controlpanel/gui/qt/device.py' | |||
223 | --- ubuntuone/controlpanel/gui/qt/device.py 2011-07-11 18:00:59 +0000 | |||
224 | +++ ubuntuone/controlpanel/gui/qt/device.py 2011-07-19 19:17:30 +0000 | |||
225 | @@ -18,22 +18,30 @@ | |||
226 | 18 | 18 | ||
227 | 19 | """The user interface for the control panel for Ubuntu One.""" | 19 | """The user interface for the control panel for Ubuntu One.""" |
228 | 20 | 20 | ||
231 | 21 | from PyQt4 import QtGui | 21 | from PyQt4 import QtGui, QtCore |
232 | 22 | 22 | ||
233 | 23 | from twisted.internet import defer | ||
234 | 24 | |||
235 | 25 | from ubuntuone.controlpanel.backend import ( | ||
236 | 26 | DEVICE_TYPE_COMPUTER, | ||
237 | 27 | DEVICE_TYPE_PHONE, | ||
238 | 28 | ) | ||
239 | 29 | from ubuntuone.controlpanel.gui import DEVICE_CONFIRM_REMOVE | ||
240 | 23 | from ubuntuone.controlpanel.gui.qt.ui import device_ui | 30 | from ubuntuone.controlpanel.gui.qt.ui import device_ui |
241 | 24 | 31 | ||
242 | 25 | COMPUTER_ICON = "computer" | 32 | COMPUTER_ICON = "computer" |
243 | 26 | PHONE_ICON = "phone" | 33 | PHONE_ICON = "phone" |
244 | 27 | DEFAULT_ICON = COMPUTER_ICON | 34 | DEFAULT_ICON = COMPUTER_ICON |
245 | 28 | 35 | ||
246 | 29 | COMPUTER_TYPE = "Computer" | ||
247 | 30 | PHONE_TYPE = "Phone" | ||
248 | 31 | |||
249 | 32 | DEVICE_TYPE_TO_ICON_MAP = { | 36 | DEVICE_TYPE_TO_ICON_MAP = { |
252 | 33 | COMPUTER_TYPE: COMPUTER_ICON, | 37 | DEVICE_TYPE_COMPUTER: COMPUTER_ICON, |
253 | 34 | PHONE_TYPE: PHONE_ICON, | 38 | DEVICE_TYPE_PHONE: PHONE_ICON, |
254 | 35 | } | 39 | } |
255 | 36 | 40 | ||
256 | 41 | CANCEL = QtGui.QMessageBox.Cancel | ||
257 | 42 | NO = QtGui.QMessageBox.No | ||
258 | 43 | YES = QtGui.QMessageBox.Yes | ||
259 | 44 | |||
260 | 37 | 45 | ||
261 | 38 | def icon_name_from_type(device_type): | 46 | def icon_name_from_type(device_type): |
262 | 39 | """Get the icon name for the device.""" | 47 | """Get the icon name for the device.""" |
263 | @@ -44,11 +52,16 @@ | |||
264 | 44 | class DeviceWidget(QtGui.QWidget): | 52 | class DeviceWidget(QtGui.QWidget): |
265 | 45 | """The widget for each device in the control panel.""" | 53 | """The widget for each device in the control panel.""" |
266 | 46 | 54 | ||
268 | 47 | def __init__(self, *args): | 55 | removed = QtCore.pyqtSignal() |
269 | 56 | removeCanceled = QtCore.pyqtSignal() | ||
270 | 57 | |||
271 | 58 | def __init__(self, backend, device_id, **kwargs): | ||
272 | 48 | """Initialize the UI of the widget.""" | 59 | """Initialize the UI of the widget.""" |
274 | 49 | QtGui.QWidget.__init__(self, *args) | 60 | QtGui.QWidget.__init__(self, **kwargs) |
275 | 50 | self.ui = device_ui.Ui_Form() | 61 | self.ui = device_ui.Ui_Form() |
276 | 51 | self.ui.setupUi(self) | 62 | self.ui.setupUi(self) |
277 | 63 | self.id = device_id | ||
278 | 64 | self.backend = backend | ||
279 | 52 | 65 | ||
280 | 53 | def update_device_info(self, device_info): | 66 | def update_device_info(self, device_info): |
281 | 54 | """Update the device info.""" | 67 | """Update the device info.""" |
282 | @@ -57,6 +70,20 @@ | |||
283 | 57 | pixmap = QtGui.QPixmap(pixmap_name) | 70 | pixmap = QtGui.QPixmap(pixmap_name) |
284 | 58 | self.ui.device_icon_label.setPixmap(pixmap) | 71 | self.ui.device_icon_label.setPixmap(pixmap) |
285 | 59 | 72 | ||
286 | 73 | @defer.inlineCallbacks | ||
287 | 74 | @QtCore.pyqtSlot() | ||
288 | 75 | def on_remove_device_button_clicked(self): | ||
289 | 76 | """The user wants to remove this device.""" | ||
290 | 77 | msg = DEVICE_CONFIRM_REMOVE | ||
291 | 78 | buttons = YES | NO | ||
292 | 79 | response = QtGui.QMessageBox.warning(self, '', msg, buttons, NO) | ||
293 | 80 | |||
294 | 81 | if response == YES: | ||
295 | 82 | yield self.backend.remove_device(device_id=self.id) | ||
296 | 83 | self.removed.emit() | ||
297 | 84 | else: | ||
298 | 85 | self.removeCanceled.emit() | ||
299 | 86 | |||
300 | 60 | 87 | ||
301 | 61 | def get_device_for_list_widget(device_info): | 88 | def get_device_for_list_widget(device_info): |
302 | 62 | """Return a QListWidgetItem representing a device with the proper info.""" | 89 | """Return a QListWidgetItem representing a device with the proper info.""" |
303 | 63 | 90 | ||
304 | === modified file 'ubuntuone/controlpanel/gui/qt/devices.py' | |||
305 | --- ubuntuone/controlpanel/gui/qt/devices.py 2011-07-10 21:35:02 +0000 | |||
306 | +++ ubuntuone/controlpanel/gui/qt/devices.py 2011-07-19 19:17:30 +0000 | |||
307 | @@ -81,8 +81,12 @@ | |||
308 | 81 | 81 | ||
309 | 82 | def update_local_device(self, device_info): | 82 | def update_local_device(self, device_info): |
310 | 83 | """Update the info for the local device.""" | 83 | """Update the info for the local device.""" |
312 | 84 | device_widget = device.DeviceWidget() | 84 | device_widget = device.DeviceWidget(backend=self.backend, |
313 | 85 | device_id=device_info['device_id']) | ||
314 | 85 | device_widget.update_device_info(device_info) | 86 | device_widget.update_device_info(device_info) |
315 | 87 | f = lambda: self.clear_device_info(self.ui.local_device_box) | ||
316 | 88 | device_widget.removed.connect(f) | ||
317 | 89 | |||
318 | 86 | self.ui.local_device_box.addWidget(device_widget) | 90 | self.ui.local_device_box.addWidget(device_widget) |
319 | 87 | 91 | ||
320 | 88 | def create_remote_device(self, device_info): | 92 | def create_remote_device(self, device_info): |
321 | 89 | 93 | ||
322 | === modified file 'ubuntuone/controlpanel/gui/qt/loadingoverlay.py' | |||
323 | --- ubuntuone/controlpanel/gui/qt/loadingoverlay.py 2011-07-12 18:47:13 +0000 | |||
324 | +++ ubuntuone/controlpanel/gui/qt/loadingoverlay.py 2011-07-19 19:17:30 +0000 | |||
325 | @@ -62,7 +62,8 @@ | |||
326 | 62 | 62 | ||
327 | 63 | def eventFilter(self, obj, event): | 63 | def eventFilter(self, obj, event): |
328 | 64 | """Filter events from Frame content to draw the dot animation.""" | 64 | """Filter events from Frame content to draw the dot animation.""" |
330 | 65 | if obj == self.ui.frm_box and event.type() == QtCore.QEvent.Paint: | 65 | if getattr(self, 'ui', None) is not None and \ |
331 | 66 | obj == self.ui.frm_box and event.type() == QtCore.QEvent.Paint: | ||
332 | 66 | painter = QtGui.QPainter() | 67 | painter = QtGui.QPainter() |
333 | 67 | painter.begin(obj) | 68 | painter.begin(obj) |
334 | 68 | painter.setRenderHint(QtGui.QPainter.Antialiasing, True) | 69 | painter.setRenderHint(QtGui.QPainter.Antialiasing, True) |
335 | 69 | 70 | ||
336 | === modified file 'ubuntuone/controlpanel/gui/qt/tests/__init__.py' | |||
337 | --- ubuntuone/controlpanel/gui/qt/tests/__init__.py 2011-07-13 18:45:43 +0000 | |||
338 | +++ ubuntuone/controlpanel/gui/qt/tests/__init__.py 2011-07-19 19:17:30 +0000 | |||
339 | @@ -40,6 +40,7 @@ | |||
340 | 40 | "name": "desktop i5", | 40 | "name": "desktop i5", |
341 | 41 | "is_local": False, | 41 | "is_local": False, |
342 | 42 | "configurable": False, | 42 | "configurable": False, |
343 | 43 | "device_id": '1258-6854', | ||
344 | 43 | } | 44 | } |
345 | 44 | 45 | ||
346 | 45 | SAMPLE_PHONE_INFO = { | 46 | SAMPLE_PHONE_INFO = { |
347 | @@ -47,6 +48,7 @@ | |||
348 | 47 | "name": "nokia 1100", | 48 | "name": "nokia 1100", |
349 | 48 | "is_local": False, | 49 | "is_local": False, |
350 | 49 | "configurable": False, | 50 | "configurable": False, |
351 | 51 | "device_id": '987456-2321', | ||
352 | 50 | } | 52 | } |
353 | 51 | 53 | ||
354 | 52 | SAMPLE_DEVICES_INFO = [ | 54 | SAMPLE_DEVICES_INFO = [ |
355 | @@ -55,6 +57,7 @@ | |||
356 | 55 | "name": "toshiba laptop", | 57 | "name": "toshiba laptop", |
357 | 56 | "is_local": True, | 58 | "is_local": True, |
358 | 57 | "configurable": False, | 59 | "configurable": False, |
359 | 60 | "device_id": '0000', | ||
360 | 58 | }, | 61 | }, |
361 | 59 | SAMPLE_COMPUTER_INFO, | 62 | SAMPLE_COMPUTER_INFO, |
362 | 60 | SAMPLE_PHONE_INFO, | 63 | SAMPLE_PHONE_INFO, |
363 | 61 | 64 | ||
364 | === modified file 'ubuntuone/controlpanel/gui/qt/tests/test_device.py' | |||
365 | --- ubuntuone/controlpanel/gui/qt/tests/test_device.py 2011-07-13 18:45:43 +0000 | |||
366 | +++ ubuntuone/controlpanel/gui/qt/tests/test_device.py 2011-07-19 19:17:30 +0000 | |||
367 | @@ -20,9 +20,20 @@ | |||
368 | 20 | 20 | ||
369 | 21 | from PyQt4 import QtGui | 21 | from PyQt4 import QtGui |
370 | 22 | 22 | ||
371 | 23 | from twisted.internet import defer | ||
372 | 24 | |||
373 | 23 | from ubuntuone.controlpanel.gui.qt import device as gui | 25 | from ubuntuone.controlpanel.gui.qt import device as gui |
376 | 24 | from ubuntuone.controlpanel.gui.qt.tests import (BaseTestCase, | 26 | from ubuntuone.controlpanel.gui.qt.tests import ( |
377 | 25 | SAMPLE_COMPUTER_INFO, SAMPLE_PHONE_INFO) | 27 | BaseTestCase, |
378 | 28 | FakedConfirmDialog, | ||
379 | 29 | FakedControlPanelBackend, | ||
380 | 30 | SAMPLE_COMPUTER_INFO, | ||
381 | 31 | SAMPLE_PHONE_INFO, | ||
382 | 32 | ) | ||
383 | 33 | |||
384 | 34 | # Access to a protected member | ||
385 | 35 | # Instance of 'ControlBackend' has no '_called' member | ||
386 | 36 | # pylint: disable=W0212, E1103 | ||
387 | 26 | 37 | ||
388 | 27 | 38 | ||
389 | 28 | class DeviceWidgetTestCase(BaseTestCase): | 39 | class DeviceWidgetTestCase(BaseTestCase): |
390 | @@ -31,6 +42,17 @@ | |||
391 | 31 | innerclass_ui = gui.device_ui | 42 | innerclass_ui = gui.device_ui |
392 | 32 | innerclass_name = "Ui_Form" | 43 | innerclass_name = "Ui_Form" |
393 | 33 | class_ui = gui.DeviceWidget | 44 | class_ui = gui.DeviceWidget |
394 | 45 | backend = FakedControlPanelBackend() | ||
395 | 46 | device_id = 'zaraza' | ||
396 | 47 | kwargs = {'backend': backend, 'device_id': device_id} | ||
397 | 48 | |||
398 | 49 | def test_has_id(self): | ||
399 | 50 | """The device as an id, None by default.""" | ||
400 | 51 | self.assertEqual(self.ui.id, self.device_id) | ||
401 | 52 | |||
402 | 53 | def test_has_backend(self): | ||
403 | 54 | """The device as a backend, None by default.""" | ||
404 | 55 | self.assertIs(self.ui.backend, self.backend) | ||
405 | 34 | 56 | ||
406 | 35 | def test_update_device_info(self): | 57 | def test_update_device_info(self): |
407 | 36 | """The widget is updated with the info.""" | 58 | """The widget is updated with the info.""" |
408 | @@ -48,8 +70,8 @@ | |||
409 | 48 | 70 | ||
410 | 49 | def test_icon_name_from_type(self): | 71 | def test_icon_name_from_type(self): |
411 | 50 | """Get the right icon name for a device type.""" | 72 | """Get the right icon name for a device type.""" |
414 | 51 | self.assertIconMatchesType(gui.COMPUTER_TYPE, gui.COMPUTER_ICON) | 73 | self.assertIconMatchesType(gui.DEVICE_TYPE_COMPUTER, gui.COMPUTER_ICON) |
415 | 52 | self.assertIconMatchesType(gui.PHONE_TYPE, gui.PHONE_ICON) | 74 | self.assertIconMatchesType(gui.DEVICE_TYPE_PHONE, gui.PHONE_ICON) |
416 | 53 | self.assertIconMatchesType("other random type", gui.COMPUTER_ICON) | 75 | self.assertIconMatchesType("other random type", gui.COMPUTER_ICON) |
417 | 54 | 76 | ||
418 | 55 | def _test_update_device_info_sets_right_icon(self, info): | 77 | def _test_update_device_info_sets_right_icon(self, info): |
419 | @@ -77,3 +99,66 @@ | |||
420 | 77 | info = SAMPLE_PHONE_INFO | 99 | info = SAMPLE_PHONE_INFO |
421 | 78 | item = gui.get_device_for_list_widget(info) | 100 | item = gui.get_device_for_list_widget(info) |
422 | 79 | self.assertEqual(item.text(), info["name"]) | 101 | self.assertEqual(item.text(), info["name"]) |
423 | 102 | |||
424 | 103 | |||
425 | 104 | class RemoveDeviceTestCase(DeviceWidgetTestCase): | ||
426 | 105 | """The test suite for the device deletion.""" | ||
427 | 106 | |||
428 | 107 | @defer.inlineCallbacks | ||
429 | 108 | def setUp(self): | ||
430 | 109 | yield super(RemoveDeviceTestCase, self).setUp() | ||
431 | 110 | FakedConfirmDialog.response = gui.NO | ||
432 | 111 | FakedConfirmDialog.args = None | ||
433 | 112 | FakedConfirmDialog.kwargs = None | ||
434 | 113 | self.patch(gui.QtGui, 'QMessageBox', FakedConfirmDialog) | ||
435 | 114 | |||
436 | 115 | def test_remove_device_opens_confirmation_dialog(self): | ||
437 | 116 | """A confirmation dialog is opened when user clicks 'delete device'.""" | ||
438 | 117 | self.ui.ui.remove_device_button.click() | ||
439 | 118 | |||
440 | 119 | msg = gui.DEVICE_CONFIRM_REMOVE | ||
441 | 120 | buttons = gui.YES | gui.NO | ||
442 | 121 | self.assertEqual(FakedConfirmDialog.args, | ||
443 | 122 | (self.ui, '', msg, buttons, gui.NO)) | ||
444 | 123 | self.assertEqual(FakedConfirmDialog.kwargs, {}) | ||
445 | 124 | |||
446 | 125 | def test_remove_device_does_not_remove_if_answer_is_no(self): | ||
447 | 126 | """The device is not removed is answer is No.""" | ||
448 | 127 | FakedConfirmDialog.response = gui.NO | ||
449 | 128 | self.ui.removed.connect(self._set_called) | ||
450 | 129 | self.ui.ui.remove_device_button.click() | ||
451 | 130 | |||
452 | 131 | self.assertNotIn('remove_device', self.ui.backend._called) | ||
453 | 132 | self.assertEqual(self._called, False) | ||
454 | 133 | |||
455 | 134 | def test_remove_device_does_remove_if_answer_is_yes(self): | ||
456 | 135 | """The device is removed is answer is Yes.""" | ||
457 | 136 | FakedConfirmDialog.response = gui.YES | ||
458 | 137 | self.ui.ui.remove_device_button.click() | ||
459 | 138 | |||
460 | 139 | self.assert_backend_called('remove_device', device_id=self.device_id) | ||
461 | 140 | |||
462 | 141 | @defer.inlineCallbacks | ||
463 | 142 | def test_remove_device_emits_signal_when_removed(self): | ||
464 | 143 | """The signal 'removed' is emitted when removed.""" | ||
465 | 144 | d = defer.Deferred() | ||
466 | 145 | |||
467 | 146 | def check(device_id): | ||
468 | 147 | """Fire deferred when the device was removed.""" | ||
469 | 148 | d.callback(device_id) | ||
470 | 149 | |||
471 | 150 | FakedConfirmDialog.response = gui.YES | ||
472 | 151 | self.ui.removed.connect(self._set_called) | ||
473 | 152 | self.patch(self.ui.backend, 'remove_device', check) | ||
474 | 153 | self.ui.ui.remove_device_button.click() | ||
475 | 154 | |||
476 | 155 | yield d | ||
477 | 156 | self.assertEqual(self._called, ((), {})) | ||
478 | 157 | |||
479 | 158 | def test_remove_device_emits_signal_when_not_removed(self): | ||
480 | 159 | """The signal 'removeCanceled' is emitted when user cancels removal.""" | ||
481 | 160 | FakedConfirmDialog.response = gui.NO | ||
482 | 161 | self.ui.removeCanceled.connect(self._set_called) | ||
483 | 162 | self.ui.ui.remove_device_button.click() | ||
484 | 163 | |||
485 | 164 | self.assertEqual(self._called, ((), {})) | ||
486 | 80 | 165 | ||
487 | === modified file 'ubuntuone/controlpanel/gui/qt/tests/test_devices.py' | |||
488 | --- ubuntuone/controlpanel/gui/qt/tests/test_devices.py 2011-07-11 11:19:09 +0000 | |||
489 | +++ ubuntuone/controlpanel/gui/qt/tests/test_devices.py 2011-07-19 19:17:30 +0000 | |||
490 | @@ -22,6 +22,7 @@ | |||
491 | 22 | 22 | ||
492 | 23 | from ubuntuone.controlpanel.gui.qt import devices as gui | 23 | from ubuntuone.controlpanel.gui.qt import devices as gui |
493 | 24 | from ubuntuone.controlpanel.gui.qt.tests import ( | 24 | from ubuntuone.controlpanel.gui.qt.tests import ( |
494 | 25 | FakedConfirmDialog, | ||
495 | 25 | SAMPLE_DEVICES_INFO, | 26 | SAMPLE_DEVICES_INFO, |
496 | 26 | ) | 27 | ) |
497 | 27 | from ubuntuone.controlpanel.gui.qt.tests.test_ubuntuonebin import ( | 28 | from ubuntuone.controlpanel.gui.qt.tests.test_ubuntuonebin import ( |
498 | @@ -40,6 +41,7 @@ | |||
499 | 40 | def setUp(self): | 41 | def setUp(self): |
500 | 41 | yield super(DevicesPanelTestCase, self).setUp() | 42 | yield super(DevicesPanelTestCase, self).setUp() |
501 | 42 | self.ui.backend.next_result = SAMPLE_DEVICES_INFO | 43 | self.ui.backend.next_result = SAMPLE_DEVICES_INFO |
502 | 44 | self.patch(gui.QtGui, 'QMessageBox', FakedConfirmDialog) | ||
503 | 43 | 45 | ||
504 | 44 | def test_is_processing_while_asking_info(self): | 46 | def test_is_processing_while_asking_info(self): |
505 | 45 | """The ui is processing while the contents are loaded.""" | 47 | """The ui is processing while the contents are loaded.""" |
506 | @@ -76,9 +78,10 @@ | |||
507 | 76 | local, remote = SAMPLE_DEVICES_INFO[0], SAMPLE_DEVICES_INFO[1:] | 78 | local, remote = SAMPLE_DEVICES_INFO[0], SAMPLE_DEVICES_INFO[1:] |
508 | 77 | 79 | ||
509 | 78 | self.assertEqual(self.ui.ui.local_device_box.count(), 1) | 80 | self.assertEqual(self.ui.ui.local_device_box.count(), 1) |
512 | 79 | local_device = self.ui.ui.local_device_box.itemAt(0) | 81 | local_device = self.ui.ui.local_device_box.itemAt(0).widget() |
513 | 80 | self.assertEqual(local_device.widget().ui.device_name_label.text(), | 82 | self.assertEqual(local_device.ui.device_name_label.text(), |
514 | 81 | local['name']) | 83 | local['name']) |
515 | 84 | self.assertEqual(local_device.id, local['device_id']) | ||
516 | 82 | 85 | ||
517 | 83 | self.assertEqual(self.ui.ui.list_devices.count(), | 86 | self.assertEqual(self.ui.ui.list_devices.count(), |
518 | 84 | len(remote)) | 87 | len(remote)) |
519 | @@ -97,3 +100,12 @@ | |||
520 | 97 | self.ui.ui.manage_devices_button.click() | 100 | self.ui.ui.manage_devices_button.click() |
521 | 98 | 101 | ||
522 | 99 | self.assertEqual(self._called, ((gui.EDIT_DEVICES_LINK,), {})) | 102 | self.assertEqual(self._called, ((gui.EDIT_DEVICES_LINK,), {})) |
523 | 103 | |||
524 | 104 | def test_remove_device_widget_after_removal(self): | ||
525 | 105 | """When a device widget was deleted, remove it from the UI.""" | ||
526 | 106 | self.ui.process_info(SAMPLE_DEVICES_INFO) | ||
527 | 107 | |||
528 | 108 | local_device = self.ui.ui.local_device_box.itemAt(0).widget() | ||
529 | 109 | local_device.removed.emit() | ||
530 | 110 | |||
531 | 111 | self.assertTrue(self.ui.ui.local_device_box.itemAt(0) is None) | ||
532 | 100 | 112 | ||
533 | === modified file 'ubuntuone/controlpanel/gui/tests/__init__.py' | |||
534 | --- ubuntuone/controlpanel/gui/tests/__init__.py 2011-07-01 12:39:37 +0000 | |||
535 | +++ ubuntuone/controlpanel/gui/tests/__init__.py 2011-07-19 19:17:30 +0000 | |||
536 | @@ -21,7 +21,11 @@ | |||
537 | 21 | import os | 21 | import os |
538 | 22 | 22 | ||
539 | 23 | from ubuntuone.controlpanel import gui | 23 | from ubuntuone.controlpanel import gui |
541 | 24 | from ubuntuone.controlpanel.backend import ControlBackend | 24 | from ubuntuone.controlpanel.backend import ( |
542 | 25 | ControlBackend, | ||
543 | 26 | DEVICE_TYPE_COMPUTER, | ||
544 | 27 | DEVICE_TYPE_PHONE, | ||
545 | 28 | ) | ||
546 | 25 | from ubuntuone.controlpanel.tests import USER_HOME, ROOT_PATH | 29 | from ubuntuone.controlpanel.tests import USER_HOME, ROOT_PATH |
547 | 26 | 30 | ||
548 | 27 | # Attribute 'yyy' defined outside __init__, access to a protected member | 31 | # Attribute 'yyy' defined outside __init__, access to a protected member |
549 | @@ -95,22 +99,27 @@ | |||
550 | 95 | FAKE_VOLUMES_MINIMAL_INFO = [(u'', u'147852369', [ROOT, MUSIC_FOLDER])] | 99 | FAKE_VOLUMES_MINIMAL_INFO = [(u'', u'147852369', [ROOT, MUSIC_FOLDER])] |
551 | 96 | 100 | ||
552 | 97 | FAKE_DEVICE_INFO = { | 101 | FAKE_DEVICE_INFO = { |
554 | 98 | 'device_id': '1258-6854', 'device_name': 'Baz', 'device_type': 'Computer', | 102 | 'device_id': '1258-6854', 'device_name': 'Baz', |
555 | 103 | 'device_type': DEVICE_TYPE_COMPUTER, | ||
556 | 99 | 'is_local': 'True', 'configurable': 'True', 'limit_bandwidth': 'True', | 104 | 'is_local': 'True', 'configurable': 'True', 'limit_bandwidth': 'True', |
557 | 100 | 'max_upload_speed': '1000', 'max_download_speed': '72548', | 105 | 'max_upload_speed': '1000', 'max_download_speed': '72548', |
558 | 101 | 'show_all_notifications': 'True', | 106 | 'show_all_notifications': 'True', |
559 | 102 | } | 107 | } |
560 | 103 | 108 | ||
561 | 104 | FAKE_DEVICES_INFO = [ | 109 | FAKE_DEVICES_INFO = [ |
567 | 105 | {'device_id': '0', 'name': 'Ubuntu One @ Foo', 'type': 'Computer', | 110 | {'device_id': '0', 'name': 'Ubuntu One @ Foo', |
568 | 106 | 'is_local': '', 'configurable': ''}, | 111 | 'type': DEVICE_TYPE_COMPUTER, |
569 | 107 | {'device_id': '1', 'name': 'Ubuntu One @ Bar', 'type': 'Phone', | 112 | 'is_local': '', 'configurable': ''}, |
570 | 108 | 'is_local': '', 'configurable': ''}, | 113 | {'device_id': '1', 'name': 'Ubuntu One @ Bar', |
571 | 109 | {'device_id': '2', 'name': 'Ubuntu One @ Z', 'type': 'Computer', | 114 | 'type': DEVICE_TYPE_PHONE, |
572 | 115 | 'is_local': '', 'configurable': ''}, | ||
573 | 116 | {'device_id': '2', 'name': 'Ubuntu One @ Z', | ||
574 | 117 | 'type': DEVICE_TYPE_COMPUTER, | ||
575 | 110 | 'is_local': '', 'configurable': 'True', 'limit_bandwidth': '', | 118 | 'is_local': '', 'configurable': 'True', 'limit_bandwidth': '', |
576 | 111 | 'max_upload_speed': '0', 'max_download_speed': '0', | 119 | 'max_upload_speed': '0', 'max_download_speed': '0', |
577 | 112 | 'show_all_notifications': ''}, | 120 | 'show_all_notifications': ''}, |
579 | 113 | {'device_id': '1258-6854', 'name': 'Ubuntu One @ Baz', 'type': 'Computer', | 121 | {'device_id': '1258-6854', 'name': 'Ubuntu One @ Baz', |
580 | 122 | 'type': DEVICE_TYPE_COMPUTER, | ||
581 | 114 | 'is_local': 'True', 'configurable': 'True', 'limit_bandwidth': 'True', | 123 | 'is_local': 'True', 'configurable': 'True', 'limit_bandwidth': 'True', |
582 | 115 | 'max_upload_speed': '1000', 'max_download_speed': '72548', | 124 | 'max_upload_speed': '1000', 'max_download_speed': '72548', |
583 | 116 | 'show_all_notifications': 'True'}, # local | 125 | 'show_all_notifications': 'True'}, # local |
+1