Merge lp:~diegosarmentero/ubuntuone-control-panel/menu-desktop-services-actions into lp:ubuntuone-control-panel
- menu-desktop-services-actions
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Diego Sarmentero |
Approved revision: | 349 |
Merged at revision: | 343 |
Proposed branch: | lp:~diegosarmentero/ubuntuone-control-panel/menu-desktop-services-actions |
Merge into: | lp:ubuntuone-control-panel |
Prerequisite: | lp:~diegosarmentero/ubuntuone-control-panel/refactor-sync-status |
Diff against target: |
539 lines (+397/-54) (has conflicts) 2 files modified
ubuntuone/controlpanel/gui/qt/systray.py (+194/-51) ubuntuone/controlpanel/gui/qt/tests/test_systray.py (+203/-3) Text conflict in ubuntuone/controlpanel/gui/qt/systray.py Text conflict in ubuntuone/controlpanel/gui/qt/tests/test_systray.py |
To merge this branch: | bzr merge lp:~diegosarmentero/ubuntuone-control-panel/menu-desktop-services-actions |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Brian Curtin (community) | Approve | ||
Manuel de la Peña (community) | Approve | ||
Review via email: mp+119370@code.launchpad.net |
Commit message
- Adding open (folder, program, url) actions to the menu (LP: #1034542)
Description of the change
Manuel de la Peña (mandel) wrote : | # |
Looks good to me.
Brian Curtin (brian.curtin) wrote : | # |
Agree on the last part with iterating over signal_pairs.
Brian Curtin (brian.curtin) wrote : | # |
You still have TODO's on lines 73, 79, and 81.
Diego Sarmentero (diegosarmentero) wrote : | # |
> You still have TODO's on lines 73, 79, and 81.
Yes, those are for the future branches i'm working right now
Brian Curtin (brian.curtin) : | # |
Ubuntu One Auto Pilot (otto-pilot) wrote : | # |
The attempt to merge lp:~diegosarmentero/ubuntuone-control-panel/menu-desktop-services-actions into lp:ubuntuone-control-panel failed. Below is the output from the failed tests.
*** Running DBus test suite ***
ubuntuone.
BaseTestCase
runTest ... [OK]
DBusServiceMa
test_
test_
DBusServiceTe
test_
test_
test_
test_
test_
test_
test_
test_
FileSyncTestCase
test_
test_
test_
test_
test_
test_
test_
test_
test_
test_
test_
test_
OperationsAut
test_
test_
test_
test_
test_
test_
test_
test_
test_
test_
test_
test_
Ubuntu One Auto Pilot (otto-pilot) wrote : | # |
The attempt to merge lp:~diegosarmentero/ubuntuone-control-panel/menu-desktop-services-actions into lp:ubuntuone-control-panel failed. Below is the output from the failed tests.
*** Running DBus test suite ***
ubuntuone.
BaseTestCase
runTest ... [OK]
DBusServiceMa
test_
test_
DBusServiceTe
test_
test_
test_
test_
test_
test_
test_
test_
FileSyncTestCase
test_
test_
test_
test_
test_
test_
test_
test_
test_
test_
test_
test_
OperationsAut
test_
test_
test_
test_
test_
test_
test_
test_
test_
test_
test_
test_
- 349. By Diego Sarmentero
-
fixing pep8 issue
Preview Diff
1 | === modified file 'ubuntuone/controlpanel/gui/qt/systray.py' | |||
2 | --- ubuntuone/controlpanel/gui/qt/systray.py 2012-08-13 12:08:15 +0000 | |||
3 | +++ ubuntuone/controlpanel/gui/qt/systray.py 2012-08-14 19:00:25 +0000 | |||
4 | @@ -15,13 +15,14 @@ | |||
5 | 15 | # with this program. If not, see <http://www.gnu.org/licenses/>. | 15 | # with this program. If not, see <http://www.gnu.org/licenses/>. |
6 | 16 | """System notification area icon.""" | 16 | """System notification area icon.""" |
7 | 17 | 17 | ||
9 | 18 | from PyQt4 import QtGui | 18 | from PyQt4 import QtGui, QtCore |
10 | 19 | from twisted.internet.defer import inlineCallbacks | 19 | from twisted.internet.defer import inlineCallbacks |
11 | 20 | from ubuntuone.platform.tools import SyncDaemonTool | 20 | from ubuntuone.platform.tools import SyncDaemonTool |
12 | 21 | 21 | ||
13 | 22 | from ubuntuone.controlpanel import backend, cache | 22 | from ubuntuone.controlpanel import backend, cache |
14 | 23 | from ubuntuone.controlpanel.logger import setup_logging | 23 | from ubuntuone.controlpanel.logger import setup_logging |
15 | 24 | from ubuntuone.controlpanel.gui import ( | 24 | from ubuntuone.controlpanel.gui import ( |
16 | 25 | <<<<<<< TREE | ||
17 | 25 | LOADING, | 26 | LOADING, |
18 | 26 | OPEN_UBUNTU_ONE, | 27 | OPEN_UBUNTU_ONE, |
19 | 27 | PLEASE_WAIT, | 28 | PLEASE_WAIT, |
20 | @@ -37,6 +38,29 @@ | |||
21 | 37 | 38 | ||
22 | 38 | 39 | ||
23 | 39 | class TrayIcon(QtGui.QSystemTrayIcon, cache.Cache): | 40 | class TrayIcon(QtGui.QSystemTrayIcon, cache.Cache): |
24 | 41 | ======= | ||
25 | 42 | DASHBOARD, | ||
26 | 43 | GET_HELP_ONLINE, | ||
27 | 44 | GET_MORE_STORAGE, | ||
28 | 45 | GET_STORAGE_LINK, | ||
29 | 46 | GET_SUPPORT_LINK, | ||
30 | 47 | GO_TO_WEB, | ||
31 | 48 | LOADING, | ||
32 | 49 | OPEN_UBUNTU_ONE, | ||
33 | 50 | OPEN_UBUNTU_ONE_FOLDER, | ||
34 | 51 | PLEASE_WAIT, | ||
35 | 52 | ) | ||
36 | 53 | from ubuntuone.controlpanel.gui.qt import ( | ||
37 | 54 | FILE_SYNC_STATUS, | ||
38 | 55 | icon_from_name, | ||
39 | 56 | ) | ||
40 | 57 | |||
41 | 58 | |||
42 | 59 | logger = setup_logging('qt.systray') | ||
43 | 60 | |||
44 | 61 | |||
45 | 62 | class TrayIcon(QtGui.QSystemTrayIcon, cache.Cache): | ||
46 | 63 | >>>>>>> MERGE-SOURCE | ||
47 | 40 | 64 | ||
48 | 41 | """System notification icon.""" | 65 | """System notification icon.""" |
49 | 42 | 66 | ||
50 | @@ -45,10 +69,20 @@ | |||
51 | 45 | self.setIcon(QtGui.QIcon(":/icon.png")) | 69 | self.setIcon(QtGui.QIcon(":/icon.png")) |
52 | 46 | self.setVisible(True) | 70 | self.setVisible(True) |
53 | 47 | self.window = window | 71 | self.window = window |
57 | 48 | self._backend_method = None | 72 | <<<<<<< TREE |
58 | 49 | 73 | self._backend_method = None | |
59 | 50 | # Items | 74 | |
60 | 75 | # Items | ||
61 | 76 | ======= | ||
62 | 77 | self.root_path = '' | ||
63 | 78 | self.recent_transfers = {} | ||
64 | 79 | self.uploading = {} | ||
65 | 80 | self._backend_method = None | ||
66 | 81 | |||
67 | 82 | # Items | ||
68 | 83 | >>>>>>> MERGE-SOURCE | ||
69 | 51 | self.context_menu = QtGui.QMenu() | 84 | self.context_menu = QtGui.QMenu() |
70 | 85 | <<<<<<< TREE | ||
71 | 52 | 86 | ||
72 | 53 | self.status = self.context_menu.addAction(LOADING) | 87 | self.status = self.context_menu.addAction(LOADING) |
73 | 54 | self.status.setEnabled(False) | 88 | self.status.setEnabled(False) |
74 | @@ -61,56 +95,165 @@ | |||
75 | 61 | 95 | ||
76 | 62 | self.quit = self.context_menu.addAction(QUIT_LABEL) | 96 | self.quit = self.context_menu.addAction(QUIT_LABEL) |
77 | 63 | 97 | ||
78 | 98 | ======= | ||
79 | 99 | |||
80 | 100 | self.status = self.context_menu.addAction(LOADING) | ||
81 | 101 | self.status.setEnabled(False) | ||
82 | 102 | self.status_action = self.context_menu.addAction(PLEASE_WAIT) | ||
83 | 103 | self.refresh_status() | ||
84 | 104 | self.context_menu.addSeparator() | ||
85 | 105 | |||
86 | 106 | self.open_u1 = self.context_menu.addAction(OPEN_UBUNTU_ONE) | ||
87 | 107 | # TODO: Share a file action when the Shares tab is ready in U1-CP | ||
88 | 108 | self.open_u1_folder = self.context_menu.addAction( | ||
89 | 109 | OPEN_UBUNTU_ONE_FOLDER) | ||
90 | 110 | self.go_to_web = self.context_menu.addAction(GO_TO_WEB) | ||
91 | 111 | self.context_menu.addSeparator() | ||
92 | 112 | |||
93 | 113 | # TODO: Shares | ||
94 | 114 | |||
95 | 115 | # TODO: Transfers | ||
96 | 116 | |||
97 | 117 | self.get_more_storage = self.context_menu.addAction(GET_MORE_STORAGE) | ||
98 | 118 | self.get_help_online = self.context_menu.addAction(GET_HELP_ONLINE) | ||
99 | 119 | self.quit = self.context_menu.addAction("Quit") | ||
100 | 120 | |||
101 | 121 | >>>>>>> MERGE-SOURCE | ||
102 | 64 | self.setContextMenu(self.context_menu) | 122 | self.setContextMenu(self.context_menu) |
103 | 65 | 123 | ||
109 | 66 | # Connect Signals | 124 | <<<<<<< TREE |
110 | 67 | self.status_action.triggered.connect(self.change_status) | 125 | # Connect Signals |
111 | 68 | self.open_u1.triggered.connect(self.restore_window) | 126 | self.status_action.triggered.connect(self.change_status) |
112 | 69 | self.quit.triggered.connect(self.stop) | 127 | self.open_u1.triggered.connect(self.restore_window) |
113 | 70 | 128 | self.quit.triggered.connect(self.stop) | |
114 | 129 | |||
115 | 130 | ======= | ||
116 | 131 | # Connect Signals | ||
117 | 132 | self.status_action.triggered.connect(self.change_status) | ||
118 | 133 | self.open_u1.triggered.connect(self.restore_window) | ||
119 | 134 | self.open_u1_folder.triggered.connect(self.open_u1_folder_action) | ||
120 | 135 | self.get_more_storage.triggered.connect(self.get_more_storage_action) | ||
121 | 136 | self.go_to_web.triggered.connect(self.go_to_web_action) | ||
122 | 137 | self.get_help_online.triggered.connect(self.get_help_action) | ||
123 | 138 | self.quit.triggered.connect(self.stop) | ||
124 | 139 | |||
125 | 140 | >>>>>>> MERGE-SOURCE | ||
126 | 71 | self.close_callback = close_callback | 141 | self.close_callback = close_callback |
169 | 72 | 142 | <<<<<<< TREE | |
170 | 73 | @inlineCallbacks | 143 | |
171 | 74 | def refresh_status(self): | 144 | @inlineCallbacks |
172 | 75 | """Update Ubuntu One status.""" | 145 | def refresh_status(self): |
173 | 76 | info = yield self.backend.file_sync_status() | 146 | """Update Ubuntu One status.""" |
174 | 77 | self._process_status(info) | 147 | info = yield self.backend.file_sync_status() |
175 | 78 | self.backend.status_changed_handler = self._process_status | 148 | self._process_status(info) |
176 | 79 | 149 | self.backend.status_changed_handler = self._process_status | |
177 | 80 | def _process_status(self, status): | 150 | |
178 | 81 | """Match status with signals.""" | 151 | def _process_status(self, status): |
179 | 82 | if status is None: | 152 | """Match status with signals.""" |
180 | 83 | return | 153 | if status is None: |
181 | 84 | try: | 154 | return |
182 | 85 | status_key = status[backend.STATUS_KEY] | 155 | try: |
183 | 86 | data = FILE_SYNC_STATUS[status_key] | 156 | status_key = status[backend.STATUS_KEY] |
184 | 87 | except (KeyError, TypeError): | 157 | data = FILE_SYNC_STATUS[status_key] |
185 | 88 | logger.exception( | 158 | except (KeyError, TypeError): |
186 | 89 | '_process_status: received unknown status dict %r', status) | 159 | logger.exception( |
187 | 90 | return | 160 | '_process_status: received unknown status dict %r', status) |
188 | 91 | 161 | return | |
189 | 92 | self.status_action.setEnabled(True) | 162 | |
190 | 93 | icon_name = data.get('icon') | 163 | self.status_action.setEnabled(True) |
191 | 94 | icon = QtGui.QIcon() | 164 | icon_name = data.get('icon') |
192 | 95 | if icon_name is not None: | 165 | icon = QtGui.QIcon() |
193 | 96 | icon = icon_from_name(icon_name) | 166 | if icon_name is not None: |
194 | 97 | text = data.get('msg') | 167 | icon = icon_from_name(icon_name) |
195 | 98 | self.status.setIcon(icon) | 168 | text = data.get('msg') |
196 | 99 | self.status.setText(text) | 169 | self.status.setIcon(icon) |
197 | 100 | 170 | self.status.setText(text) | |
198 | 101 | action = data.get('action') | 171 | |
199 | 102 | self._backend_method = getattr(self.backend, | 172 | action = data.get('action') |
200 | 103 | data['backend_method'], None) | 173 | self._backend_method = getattr(self.backend, |
201 | 104 | self.status_action.setText(action) | 174 | data['backend_method'], None) |
202 | 105 | 175 | self.status_action.setText(action) | |
203 | 106 | def change_status(self): | 176 | |
204 | 107 | """Change the Syncing status of syncdaemon.""" | 177 | def change_status(self): |
205 | 108 | if self._backend_method is not None: | 178 | """Change the Syncing status of syncdaemon.""" |
206 | 109 | self.status_action.setEnabled(False) | 179 | if self._backend_method is not None: |
207 | 110 | self._backend_method() | 180 | self.status_action.setEnabled(False) |
208 | 111 | else: | 181 | self._backend_method() |
209 | 112 | logger.error('on_sync_status_button_clicked: backend method is ' | 182 | else: |
210 | 113 | 'None!') | 183 | logger.error('on_sync_status_button_clicked: backend method is ' |
211 | 184 | 'None!') | ||
212 | 185 | ======= | ||
213 | 186 | self._get_volumes_info() | ||
214 | 187 | |||
215 | 188 | @inlineCallbacks | ||
216 | 189 | def refresh_status(self): | ||
217 | 190 | """Update Ubuntu One status.""" | ||
218 | 191 | info = yield self.backend.file_sync_status() | ||
219 | 192 | self._process_status(info) | ||
220 | 193 | self.backend.status_changed_handler = self._process_status | ||
221 | 194 | |||
222 | 195 | def _process_status(self, status): | ||
223 | 196 | """Match status with signals.""" | ||
224 | 197 | if status is None: | ||
225 | 198 | return | ||
226 | 199 | try: | ||
227 | 200 | status_key = status[backend.STATUS_KEY] | ||
228 | 201 | data = FILE_SYNC_STATUS[status_key] | ||
229 | 202 | except (KeyError, TypeError): | ||
230 | 203 | logger.exception( | ||
231 | 204 | '_process_status: received unknown status dict %r', status) | ||
232 | 205 | return | ||
233 | 206 | |||
234 | 207 | self.status_action.setEnabled(True) | ||
235 | 208 | icon_name = data.get('icon') | ||
236 | 209 | icon = QtGui.QIcon() | ||
237 | 210 | if icon_name is not None: | ||
238 | 211 | icon = icon_from_name(icon_name) | ||
239 | 212 | text = data.get('msg') | ||
240 | 213 | self.status.setIcon(icon) | ||
241 | 214 | self.status.setText(text) | ||
242 | 215 | |||
243 | 216 | action = data.get('action') | ||
244 | 217 | self._backend_method = getattr(self.backend, | ||
245 | 218 | data['backend_method'], None) | ||
246 | 219 | self.status_action.setText(action) | ||
247 | 220 | |||
248 | 221 | def change_status(self): | ||
249 | 222 | """Change the Syncing status of syncdaemon.""" | ||
250 | 223 | if self._backend_method is not None: | ||
251 | 224 | self.status_action.setEnabled(False) | ||
252 | 225 | self._backend_method() | ||
253 | 226 | else: | ||
254 | 227 | logger.error('on_sync_status_button_clicked: backend method is ' | ||
255 | 228 | 'None!') | ||
256 | 229 | |||
257 | 230 | @inlineCallbacks | ||
258 | 231 | def _get_volumes_info(self): | ||
259 | 232 | """Get the volumes info.""" | ||
260 | 233 | info = yield self.backend.volumes_info() | ||
261 | 234 | self._process_volumes_info(info) | ||
262 | 235 | |||
263 | 236 | def _process_volumes_info(self, info): | ||
264 | 237 | """Process the volumes info.""" | ||
265 | 238 | _, _, volumes = info[0] | ||
266 | 239 | self.root_path = u'file://%s' % unicode(volumes[0]['path']) | ||
267 | 240 | |||
268 | 241 | def open_u1_folder_action(self): | ||
269 | 242 | """Open the web to get more storage.""" | ||
270 | 243 | QtGui.QDesktopServices.openUrl(QtCore.QUrl(self.root_path)) | ||
271 | 244 | |||
272 | 245 | def get_more_storage_action(self): | ||
273 | 246 | """Open the web to get more storage.""" | ||
274 | 247 | QtGui.QDesktopServices.openUrl(QtCore.QUrl(GET_STORAGE_LINK)) | ||
275 | 248 | |||
276 | 249 | def go_to_web_action(self): | ||
277 | 250 | """Open the web in the dashboard.""" | ||
278 | 251 | QtGui.QDesktopServices.openUrl(QtCore.QUrl(DASHBOARD)) | ||
279 | 252 | |||
280 | 253 | def get_help_action(self): | ||
281 | 254 | """Open the web in the dashboard.""" | ||
282 | 255 | QtGui.QDesktopServices.openUrl(QtCore.QUrl(GET_SUPPORT_LINK)) | ||
283 | 256 | >>>>>>> MERGE-SOURCE | ||
284 | 114 | 257 | ||
285 | 115 | def restore_window(self): | 258 | def restore_window(self): |
286 | 116 | """Show the main window.""" | 259 | """Show the main window.""" |
287 | 117 | 260 | ||
288 | === modified file 'ubuntuone/controlpanel/gui/qt/tests/test_systray.py' | |||
289 | --- ubuntuone/controlpanel/gui/qt/tests/test_systray.py 2012-08-10 20:01:40 +0000 | |||
290 | +++ ubuntuone/controlpanel/gui/qt/tests/test_systray.py 2012-08-14 19:00:25 +0000 | |||
291 | @@ -18,13 +18,27 @@ | |||
292 | 18 | 18 | ||
293 | 19 | """Tests for the notification area icon.""" | 19 | """Tests for the notification area icon.""" |
294 | 20 | 20 | ||
296 | 21 | from PyQt4 import QtGui | 21 | from PyQt4 import QtGui, QtCore |
297 | 22 | from twisted.internet.defer import inlineCallbacks | 22 | from twisted.internet.defer import inlineCallbacks |
298 | 23 | 23 | ||
300 | 24 | from ubuntuone.controlpanel.gui import qt | 24 | <<<<<<< TREE |
301 | 25 | from ubuntuone.controlpanel.gui import qt | ||
302 | 26 | ======= | ||
303 | 27 | import ubuntuone.controlpanel.gui.qt.gui | ||
304 | 28 | from ubuntuone.controlpanel.gui import qt | ||
305 | 29 | >>>>>>> MERGE-SOURCE | ||
306 | 25 | from ubuntuone.controlpanel.gui.qt import systray | 30 | from ubuntuone.controlpanel.gui.qt import systray |
307 | 31 | <<<<<<< TREE | ||
308 | 26 | from ubuntuone.controlpanel.gui.qt.tests import BaseTestCase | 32 | from ubuntuone.controlpanel.gui.qt.tests import BaseTestCase |
309 | 27 | import ubuntuone.controlpanel.gui.qt.gui | 33 | import ubuntuone.controlpanel.gui.qt.gui |
310 | 34 | ======= | ||
311 | 35 | from ubuntuone.controlpanel.gui.qt.tests import BaseTestCase | ||
312 | 36 | from ubuntuone.controlpanel.tests import ROOT_PATH | ||
313 | 37 | |||
314 | 38 | |||
315 | 39 | # pylint: disable=C0103, W0212 | ||
316 | 40 | backend = systray.backend | ||
317 | 41 | >>>>>>> MERGE-SOURCE | ||
318 | 28 | 42 | ||
319 | 29 | 43 | ||
320 | 30 | backend = systray.backend # pylint: disable=C0103 | 44 | backend = systray.backend # pylint: disable=C0103 |
321 | @@ -50,10 +64,28 @@ | |||
322 | 50 | super(FakeMainWindow, self).__init__() | 64 | super(FakeMainWindow, self).__init__() |
323 | 51 | 65 | ||
324 | 52 | 66 | ||
326 | 53 | class SystrayTestCase(BaseTestCase): | 67 | <<<<<<< TREE |
327 | 68 | class SystrayTestCase(BaseTestCase): | ||
328 | 69 | ======= | ||
329 | 70 | class FakeDesktopService(object): | ||
330 | 71 | |||
331 | 72 | """Fake QDesktopService.""" | ||
332 | 73 | |||
333 | 74 | data = {} | ||
334 | 75 | |||
335 | 76 | @classmethod | ||
336 | 77 | def openUrl(cls, url): | ||
337 | 78 | """Fake openUrl.""" | ||
338 | 79 | FakeDesktopService.data['cls'] = cls | ||
339 | 80 | FakeDesktopService.data['url'] = url | ||
340 | 81 | |||
341 | 82 | |||
342 | 83 | class SystrayTestCase(BaseTestCase): | ||
343 | 84 | >>>>>>> MERGE-SOURCE | ||
344 | 54 | 85 | ||
345 | 55 | """Test the notification area icon.""" | 86 | """Test the notification area icon.""" |
346 | 56 | 87 | ||
347 | 88 | <<<<<<< TREE | ||
348 | 57 | class_ui = systray.TrayIcon | 89 | class_ui = systray.TrayIcon |
349 | 58 | 90 | ||
350 | 59 | # pylint: disable=W0212 | 91 | # pylint: disable=W0212 |
351 | @@ -182,6 +214,129 @@ | |||
352 | 182 | self.assertTrue(data['called']) | 214 | self.assertTrue(data['called']) |
353 | 183 | self.assertEqual(data['status'], []) | 215 | self.assertEqual(data['status'], []) |
354 | 184 | 216 | ||
355 | 217 | ======= | ||
356 | 218 | class_ui = systray.TrayIcon | ||
357 | 219 | |||
358 | 220 | @inlineCallbacks | ||
359 | 221 | def setUp(self): | ||
360 | 222 | yield super(SystrayTestCase, self).setUp() | ||
361 | 223 | self.patch(QtGui, "QDesktopServices", FakeDesktopService) | ||
362 | 224 | |||
363 | 225 | def assert_status_correct(self, status_bd, status_ui, action, | ||
364 | 226 | callback=None): | ||
365 | 227 | """The shown status is correct.""" | ||
366 | 228 | expected_text = status_ui | ||
367 | 229 | |||
368 | 230 | status = {backend.STATUS_KEY: status_bd} | ||
369 | 231 | self.ui._process_status(status) | ||
370 | 232 | |||
371 | 233 | actual_text = unicode(self.ui.status.text()) | ||
372 | 234 | self.assertEqual(expected_text, actual_text) | ||
373 | 235 | |||
374 | 236 | self.assertFalse(self.ui.status.isEnabled()) | ||
375 | 237 | self.assertEqual(unicode(self.ui.status_action.text()), action) | ||
376 | 238 | |||
377 | 239 | self.ui.status_action.trigger() | ||
378 | 240 | self.assertFalse(self.ui.status_action.isEnabled()) | ||
379 | 241 | self.assert_backend_called(callback) | ||
380 | 242 | |||
381 | 243 | def test_process_info_invalid_status(self): | ||
382 | 244 | """File sync status invalid, ignore event.""" | ||
383 | 245 | status = {backend.STATUS_KEY: backend.FILE_SYNC_STARTING, | ||
384 | 246 | backend.MSG_KEY: qt.FILE_SYNC_STARTING, | ||
385 | 247 | 'icon': backend.FILE_SYNC_STARTING} | ||
386 | 248 | self.ui._process_status(status) | ||
387 | 249 | self.ui._process_status(3) | ||
388 | 250 | |||
389 | 251 | actual_text = unicode(self.ui.status.text()) | ||
390 | 252 | self.assertEqual(qt.FILE_SYNC_STARTING, actual_text) | ||
391 | 253 | |||
392 | 254 | def test_process_info_changed(self): | ||
393 | 255 | """Backend's file sync status changed callback is connected.""" | ||
394 | 256 | self.ui.refresh_status() | ||
395 | 257 | self.assertEqual(self.ui.backend.status_changed_handler, | ||
396 | 258 | self.ui._process_status) | ||
397 | 259 | |||
398 | 260 | def test_process_info_disabled(self): | ||
399 | 261 | """File sync status disabled update the label.""" | ||
400 | 262 | self.ui.refresh_status() | ||
401 | 263 | self.assert_status_correct(status_bd=backend.FILE_SYNC_DISABLED, | ||
402 | 264 | status_ui=qt.FILE_SYNC_DISABLED, | ||
403 | 265 | action=qt.FILE_SYNC_ENABLE, | ||
404 | 266 | callback='enable_files') | ||
405 | 267 | |||
406 | 268 | def test_process_info_disconnected(self): | ||
407 | 269 | """File sync status disconnected update the label.""" | ||
408 | 270 | self.assert_status_correct(status_bd=backend.FILE_SYNC_DISCONNECTED, | ||
409 | 271 | status_ui=qt.FILE_SYNC_DISCONNECTED, | ||
410 | 272 | action=qt.FILE_SYNC_CONNECT, | ||
411 | 273 | callback='connect_files') | ||
412 | 274 | |||
413 | 275 | def test_process_info_error(self): | ||
414 | 276 | """File sync status error update the label.""" | ||
415 | 277 | msg = qt.WARNING_MARKUP % qt.FILE_SYNC_ERROR | ||
416 | 278 | self.assert_status_correct(status_bd=backend.FILE_SYNC_ERROR, | ||
417 | 279 | status_ui=msg, | ||
418 | 280 | action=qt.FILE_SYNC_RESTART, | ||
419 | 281 | callback='restart_files') | ||
420 | 282 | |||
421 | 283 | def test_process_info_idle(self): | ||
422 | 284 | """File sync status idle update the label.""" | ||
423 | 285 | self.assert_status_correct(status_bd=backend.FILE_SYNC_IDLE, | ||
424 | 286 | status_ui=qt.FILE_SYNC_IDLE, | ||
425 | 287 | action=qt.FILE_SYNC_DISCONNECT, | ||
426 | 288 | callback='disconnect_files') | ||
427 | 289 | |||
428 | 290 | def test_process_info_starting(self): | ||
429 | 291 | """File sync status starting update the label.""" | ||
430 | 292 | self.assert_status_correct(status_bd=backend.FILE_SYNC_STARTING, | ||
431 | 293 | status_ui=qt.FILE_SYNC_STARTING, | ||
432 | 294 | action=qt.FILE_SYNC_STOP, | ||
433 | 295 | callback='stop_files') | ||
434 | 296 | |||
435 | 297 | def test_process_info_stopped(self): | ||
436 | 298 | """File sync status stopped update the label.""" | ||
437 | 299 | self.assert_status_correct(status_bd=backend.FILE_SYNC_STOPPED, | ||
438 | 300 | status_ui=qt.FILE_SYNC_STOPPED, | ||
439 | 301 | action=qt.FILE_SYNC_START, | ||
440 | 302 | callback='start_files') | ||
441 | 303 | |||
442 | 304 | def test_process_info_syncing(self): | ||
443 | 305 | """File sync status syncing update the label.""" | ||
444 | 306 | self.assert_status_correct(status_bd=backend.FILE_SYNC_SYNCING, | ||
445 | 307 | status_ui=qt.FILE_SYNC_SYNCING, | ||
446 | 308 | action=qt.FILE_SYNC_DISCONNECT, | ||
447 | 309 | callback='disconnect_files') | ||
448 | 310 | |||
449 | 311 | def test_process_info_unknown(self): | ||
450 | 312 | """File sync status unknown update the label.""" | ||
451 | 313 | msg = qt.WARNING_MARKUP % qt.FILE_SYNC_ERROR | ||
452 | 314 | self.assert_status_correct(status_bd=backend.FILE_SYNC_UNKNOWN, | ||
453 | 315 | status_ui=msg, | ||
454 | 316 | action=qt.FILE_SYNC_RESTART, | ||
455 | 317 | callback='restart_files') | ||
456 | 318 | |||
457 | 319 | def test_backend(self): | ||
458 | 320 | """Backend is created.""" | ||
459 | 321 | self.assertIsInstance(self.ui.backend, | ||
460 | 322 | backend.ControlBackend) | ||
461 | 323 | |||
462 | 324 | def test_refresh_status_requested(self): | ||
463 | 325 | """test refresh_status was requested on initialized.""" | ||
464 | 326 | data = {} | ||
465 | 327 | |||
466 | 328 | def callback(status): | ||
467 | 329 | """Fake _process_status callback.""" | ||
468 | 330 | data['called'] = True | ||
469 | 331 | data['status'] = status | ||
470 | 332 | |||
471 | 333 | self.patch(self.ui, "_process_status", callback) | ||
472 | 334 | self.ui.refresh_status() | ||
473 | 335 | self.assert_backend_called('file_sync_status') | ||
474 | 336 | self.assertTrue(data['called']) | ||
475 | 337 | self.assertEqual(data['status'], []) | ||
476 | 338 | |||
477 | 339 | >>>>>>> MERGE-SOURCE | ||
478 | 185 | def test_quit(self): | 340 | def test_quit(self): |
479 | 186 | """Test the quit option in the menu.""" | 341 | """Test the quit option in the menu.""" |
480 | 187 | # Not done on setup, because if I patch stop | 342 | # Not done on setup, because if I patch stop |
481 | @@ -249,13 +404,58 @@ | |||
482 | 249 | tray.delete_window() | 404 | tray.delete_window() |
483 | 250 | self.assertEqual(tray.window, None) | 405 | self.assertEqual(tray.window, None) |
484 | 251 | 406 | ||
485 | 407 | def test_open_u1_folder_action(self): | ||
486 | 408 | """Test open_u1_folder_action.""" | ||
487 | 409 | self.ui.open_u1_folder.trigger() | ||
488 | 410 | self.assertEqual(FakeDesktopService.data['cls'], FakeDesktopService) | ||
489 | 411 | expected_url = QtCore.QUrl(u'file://%s' % ROOT_PATH) | ||
490 | 412 | self.assertEqual(FakeDesktopService.data['url'], expected_url) | ||
491 | 413 | |||
492 | 414 | def test_get_more_storage_action(self): | ||
493 | 415 | """Test get_more_storage.""" | ||
494 | 416 | self.ui.get_more_storage.trigger() | ||
495 | 417 | self.assertEqual(FakeDesktopService.data['cls'], FakeDesktopService) | ||
496 | 418 | expected_url = QtCore.QUrl(systray.GET_STORAGE_LINK) | ||
497 | 419 | self.assertEqual(FakeDesktopService.data['url'], expected_url) | ||
498 | 420 | |||
499 | 421 | def test_go_to_web_action(self): | ||
500 | 422 | """Test go_to_web.""" | ||
501 | 423 | self.ui.go_to_web.trigger() | ||
502 | 424 | self.assertEqual(FakeDesktopService.data['cls'], FakeDesktopService) | ||
503 | 425 | expected_url = QtCore.QUrl(systray.DASHBOARD) | ||
504 | 426 | self.assertEqual(FakeDesktopService.data['url'], expected_url) | ||
505 | 427 | |||
506 | 428 | def test_get_help_action(self): | ||
507 | 429 | """Test get_help_online.""" | ||
508 | 430 | self.ui.get_help_online.trigger() | ||
509 | 431 | self.assertEqual(FakeDesktopService.data['cls'], FakeDesktopService) | ||
510 | 432 | expected_url = QtCore.QUrl(systray.GET_SUPPORT_LINK) | ||
511 | 433 | self.assertEqual(FakeDesktopService.data['url'], expected_url) | ||
512 | 434 | |||
513 | 252 | def test_initialization(self): | 435 | def test_initialization(self): |
514 | 253 | """Test that everything initializes correctly.""" | 436 | """Test that everything initializes correctly.""" |
515 | 254 | tray = systray.TrayIcon() | 437 | tray = systray.TrayIcon() |
516 | 255 | self.assertTrue(tray.isVisible()) | 438 | self.assertTrue(tray.isVisible()) |
517 | 256 | self.assertEqual(tray.window, None) | 439 | self.assertEqual(tray.window, None) |
518 | 440 | self.assertNotEqual(tray.icon(), None) | ||
519 | 441 | self.assertEqual(tray.uploading, {}) | ||
520 | 442 | self.assertEqual(tray.recent_transfers, {}) | ||
521 | 257 | self.assertIsInstance(tray.context_menu, QtGui.QMenu) | 443 | self.assertIsInstance(tray.context_menu, QtGui.QMenu) |
522 | 444 | <<<<<<< TREE | ||
523 | 258 | self.assertIsInstance(tray.status, QtGui.QAction) | 445 | self.assertIsInstance(tray.status, QtGui.QAction) |
524 | 259 | self.assertIsInstance(tray.status_action, QtGui.QAction) | 446 | self.assertIsInstance(tray.status_action, QtGui.QAction) |
525 | 260 | self.assertIsInstance(tray.open_u1, QtGui.QAction) | 447 | self.assertIsInstance(tray.open_u1, QtGui.QAction) |
526 | 261 | self.assertNotEqual(tray.icon(), None) | 448 | self.assertNotEqual(tray.icon(), None) |
527 | 449 | ======= | ||
528 | 450 | self.assertIsInstance(tray.status, QtGui.QAction) | ||
529 | 451 | self.assertIsInstance(tray.status_action, QtGui.QAction) | ||
530 | 452 | self.assertIsInstance(tray.open_u1, QtGui.QAction) | ||
531 | 453 | self.assertIsInstance(tray.open_u1_folder, QtGui.QAction) | ||
532 | 454 | self.assertIsInstance(tray.go_to_web, QtGui.QAction) | ||
533 | 455 | self.assertIsInstance(tray.get_more_storage, QtGui.QAction) | ||
534 | 456 | self.assertIsInstance(tray.get_help_online, QtGui.QAction) | ||
535 | 457 | # This checks that _get_volumes_info and _process_volumes_info | ||
536 | 458 | # is being called correctly on initialization. | ||
537 | 459 | expected_home = u'file://%s' % ROOT_PATH | ||
538 | 460 | self.assertEqual(tray.root_path, expected_home) | ||
539 | 461 | >>>>>>> MERGE-SOURCE |
Some small fixes:
icon is always not None, I suppose it is icon_name
127 + icon = QtGui.QIcon() name(icon_ name) setIcon( icon) setText( text)
128 + if icon is not None:
129 + icon = icon_from_
130 + text = data.get('msg')
131 + self.status.
132 + self.status.
Possible attr error:
135 + self._backend_ method = getattr( self.backend, data['backend_ method' ])
A little cleaner way:
326 + @inlineCallbacks status( self): refresh_ status( )
327 + def test_refresh_
328 + """Test that it receives the proper information from syncdaemon."""
329 + yield self.ui.
do instead:
def test_refresh_ status( self): refresh_ status( )
"""Test that it receives the proper information from syncdaemon."""
return self.ui.
Tests can return deferreds so no need for the inlineCallbacks
The following is a personal thing, ignore it if you wish:
signal_pairs = ( status_ action, self.change_status) window) open_u1_ folder, self.open_ u1_folder_ action) get_more_ storage, self.get_ more_storage_ action) go_to_web, self.go_ to_web_ action) get_help_ online, self.get_ help_action)
(self.
(self.open_u1, self.restore_
(self.
(self.
(self.
(self.
(self.quit, self.stop)
)
for button, callback in signal_pairs: triggered. connect( callback)
button.
Instead of:
# Connect Signals action. triggered. connect( self.change_ status) u1.triggered. connect( self.restore_ window) u1_folder. triggered. connect( self.open_ u1_folder_ action) more_storage. triggered. connect( self.get_ more_storage_ action) to_web. triggered. connect( self.go_ to_web_ action) help_online. triggered. connect( self.get_ help_action) triggered. connect( self.stop)
self.status_
self.open_
self.open_
self.get_
self.go_
self.get_
self.quit.