Merge lp:~mikemc/ubuntuone-client/add-downloads-to-menudata into lp:ubuntuone-client

Proposed by Mike McCracken on 2012-10-24
Status: Merged
Approved by: dobey on 2012-10-25
Approved revision: 1346
Merged at revision: 1354
Proposed branch: lp:~mikemc/ubuntuone-client/add-downloads-to-menudata
Merge into: lp:ubuntuone-client
Diff against target: 338 lines (+137/-33)
4 files modified
tests/status/test_aggregator.py (+119/-30)
ubuntuone/status/aggregator.py (+12/-2)
ubuntuone/syncdaemon/__init__.py (+1/-0)
ubuntuone/syncdaemon/status_listener.py (+5/-1)
To merge this branch: bzr merge lp:~mikemc/ubuntuone-client/add-downloads-to-menudata
Reviewer Review Type Date Requested Status
dobey (community) Approve on 2012-10-25
Diego Sarmentero (community) 2012-10-24 Approve on 2012-10-25
Review via email: mp+131231@code.launchpad.net

Commit Message

- Add current downloads to data for sync menu, and add downloads to recent transfers. (LP: #1067806)

Description of the Change

- Add current downloads to data for sync menu, and add downloads to recent transfers. (LP: #1067806)

Also adds tests for downloads. Tests changed are in tests/status/

No real way to test IRL, as menu clients don't use this yet.

To post a comment you must log in.
Diego Sarmentero (diegosarmentero) wrote :

+1

review: Approve
dobey (dobey) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/status/test_aggregator.py'
2--- tests/status/test_aggregator.py 2012-10-11 14:37:35 +0000
3+++ tests/status/test_aggregator.py 2012-10-24 16:06:50 +0000
4@@ -47,6 +47,7 @@
5 status_listener,
6 RECENT_TRANSFERS,
7 UPLOADING,
8+ DOWNLOADING
9 )
10 from ubuntuone.syncdaemon.volume_manager import Share, UDF, Root
11
12@@ -240,7 +241,7 @@
13
14 def build_discovery_message(self):
15 """Build the file discovery message."""
16- return "a lot of files found (%d).""" % self.discovered
17+ return "a lot of files found (%d)." % self.discovered
18
19 def get_progress_message(self):
20 """Return the progress message."""
21@@ -250,11 +251,11 @@
22 def build_progress_message(self):
23 """Build the progress message."""
24 params = (self.discovered, self.completed)
25- return "a lot of files transferring (%d/%d).""" % params
26+ return "a lot of files transferring (%d/%d)." % params
27
28 def get_final_status_message(self):
29 """Return the final status message."""
30- return "a lot of files completed."""
31+ return "a lot of files completed."
32
33 def get_notification(self):
34 """Create a new toggleable notification object."""
35@@ -713,9 +714,22 @@
36 self.node_id = path
37 self.deflated_size = 10000
38 self.size = 0
39+
40+
41+class FakeUploadCommand(FakeCommand):
42+ """A fake upload."""
43+ def __init__(self, path=''):
44+ super(FakeUploadCommand, self).__init__(path)
45 self.n_bytes_written = 0
46
47
48+class FakeDownloadCommand(FakeCommand):
49+ """A fake upload."""
50+ def __init__(self, path=''):
51+ super(FakeDownloadCommand, self).__init__(path)
52+ self.n_bytes_read = 0
53+
54+
55 class FakeVolumeManager(object):
56 """A fake vm."""
57
58@@ -760,6 +774,7 @@
59 """A download just finished."""
60 if command in self.files_downloading:
61 self.files_downloading.remove(command)
62+ self.recent_transfers.append(command.path)
63 self.queued_commands.discard(command)
64
65 def upload_started(self, command):
66@@ -808,14 +823,17 @@
67
68 def test_recent_transfers(self):
69 """Check that it generates a tuple with the recent transfers."""
70- self.patch(status_listener.action_queue, "Upload", FakeCommand)
71- fake_command = FakeCommand('path1')
72- self.listener.handle_SYS_QUEUE_ADDED(fake_command)
73- self.listener.handle_SYS_QUEUE_REMOVED(fake_command)
74- fake_command = FakeCommand('path2')
75- self.listener.handle_SYS_QUEUE_ADDED(fake_command)
76- self.listener.handle_SYS_QUEUE_REMOVED(fake_command)
77- fake_command = FakeCommand('path3')
78+ self.patch(status_listener.action_queue, "Upload", FakeUploadCommand)
79+ self.patch(status_listener.action_queue, "Download",
80+ FakeDownloadCommand)
81+
82+ fake_command = FakeUploadCommand('path1')
83+ self.listener.handle_SYS_QUEUE_ADDED(fake_command)
84+ self.listener.handle_SYS_QUEUE_REMOVED(fake_command)
85+ fake_command = FakeUploadCommand('path2')
86+ self.listener.handle_SYS_QUEUE_ADDED(fake_command)
87+ self.listener.handle_SYS_QUEUE_REMOVED(fake_command)
88+ fake_command = FakeDownloadCommand('path3')
89 self.listener.handle_SYS_QUEUE_ADDED(fake_command)
90 self.listener.handle_SYS_QUEUE_REMOVED(fake_command)
91 transfers = self.status_frontend.recent_transfers()
92@@ -824,11 +842,13 @@
93
94 menu_data = self.listener.menu_data()
95 self.assertEqual(menu_data,
96- {UPLOADING: [], RECENT_TRANSFERS: expected})
97+ {UPLOADING: [],
98+ DOWNLOADING: [],
99+ RECENT_TRANSFERS: expected})
100
101- def test_file_uploading(self):
102+ def test_files_uploading(self):
103 """Check that it returns a list with the path, size, and progress."""
104- fc = FakeCommand(path='testfile.txt')
105+ fc = FakeUploadCommand(path='testfile.txt')
106 fc.deflated_size = 200
107 self.status_frontend.upload_started(fc)
108 uploading = self.status_frontend.files_uploading()
109@@ -836,11 +856,13 @@
110 self.assertEqual(uploading, expected)
111 menu_data = self.listener.menu_data()
112 self.assertEqual(menu_data,
113- {UPLOADING: expected, RECENT_TRANSFERS: []})
114+ {UPLOADING: expected,
115+ DOWNLOADING: [],
116+ RECENT_TRANSFERS: []})
117
118 fc.deflated_size = 1000
119 fc.n_bytes_written = 200
120- fc2 = FakeCommand(path='testfile2.txt')
121+ fc2 = FakeUploadCommand(path='testfile2.txt')
122 fc2.deflated_size = 2000
123 fc2.n_bytes_written = 450
124 self.status_frontend.upload_started(fc2)
125@@ -850,38 +872,100 @@
126
127 menu_data = self.listener.menu_data()
128 self.assertEqual(menu_data,
129- {UPLOADING: expected, RECENT_TRANSFERS: []})
130+ {UPLOADING: expected,
131+ DOWNLOADING: [],
132+ RECENT_TRANSFERS: []})
133+
134+ def test_files_downloading(self):
135+ """Check that it returns a list with the path, size, and progress."""
136+ fc = FakeDownloadCommand(path='testfile.txt')
137+ fc.deflated_size = 200
138+ self.status_frontend.download_started(fc)
139+ downloading = self.status_frontend.files_downloading()
140+ expected = [('testfile.txt', 200, 0)]
141+ self.assertEqual(downloading, expected)
142+ menu_data = self.listener.menu_data()
143+ self.assertEqual(menu_data,
144+ {DOWNLOADING: expected,
145+ UPLOADING: [],
146+ RECENT_TRANSFERS: []})
147+
148+ fc.deflated_size = 1000
149+ fc.n_bytes_read = 200
150+ fc2 = FakeDownloadCommand(path='testfile2.txt')
151+ fc2.deflated_size = 2000
152+ fc2.n_bytes_read = 450
153+ self.status_frontend.download_started(fc2)
154+ downloading = self.status_frontend.files_downloading()
155+ expected = [('testfile.txt', 1000, 200), ('testfile2.txt', 2000, 450)]
156+ self.assertEqual(downloading, expected)
157+
158+ menu_data = self.listener.menu_data()
159+ self.assertEqual(menu_data,
160+ {DOWNLOADING: expected,
161+ UPLOADING: [],
162+ RECENT_TRANSFERS: []})
163
164 def test_files_uploading_empty(self):
165 """Check that empty files are ignored."""
166- fc = FakeCommand(path='testfile.txt')
167+ fc = FakeUploadCommand(path='testfile.txt')
168 fc.deflated_size = None
169 self.status_frontend.upload_started(fc)
170
171- fc2 = FakeCommand(path='testfile2.txt')
172+ fc2 = FakeUploadCommand(path='testfile2.txt')
173 fc2.deflated_size = 0
174 fc2.n_bytes_written = 450
175 self.status_frontend.upload_started(fc2)
176 uploading = self.status_frontend.files_uploading()
177 self.assertEqual(uploading, [])
178
179+ def test_files_downloading_empty(self):
180+ """Check that empty files are ignored."""
181+ fc = FakeDownloadCommand(path='testfile.txt')
182+ fc.deflated_size = None
183+ self.status_frontend.download_started(fc)
184+
185+ fc2 = FakeDownloadCommand(path='testfile2.txt')
186+ fc2.deflated_size = 0
187+ fc2.n_bytes_written = 450
188+ self.status_frontend.download_started(fc2)
189+ downloading = self.status_frontend.files_downloading()
190+ self.assertEqual(downloading, [])
191+
192 def test_menu_data_full_response(self):
193- """Check that listener.menu_data returns both uploading and recent."""
194- self.patch(status_listener.action_queue, "Upload", FakeCommand)
195- fake_command = FakeCommand('path1')
196- self.listener.handle_SYS_QUEUE_ADDED(fake_command)
197- self.listener.handle_SYS_QUEUE_REMOVED(fake_command)
198- fc = FakeCommand(path='testfile.txt')
199+ """listener.menu_data returns uploading, downloading, and recent."""
200+ self.patch(status_listener.action_queue, "Upload", FakeUploadCommand)
201+ fake_command = FakeUploadCommand('path1')
202+ self.listener.handle_SYS_QUEUE_ADDED(fake_command)
203+ self.listener.handle_SYS_QUEUE_REMOVED(fake_command)
204+
205+ self.patch(status_listener.action_queue, "Download",
206+ FakeDownloadCommand)
207+ fake_command = FakeDownloadCommand('path2')
208+ self.listener.handle_SYS_QUEUE_ADDED(fake_command)
209+ self.listener.handle_SYS_QUEUE_REMOVED(fake_command)
210+
211+ fc = FakeUploadCommand(path='testfile.txt')
212 fc.deflated_size = 1000
213 fc.n_bytes_written = 200
214 self.status_frontend.upload_started(fc)
215+
216+ fc = FakeDownloadCommand(path='download.pdf')
217+ fc.deflated_size = 10
218+ fc.n_bytes_read = 1
219+ self.status_frontend.download_started(fc)
220+
221 uploading = self.status_frontend.files_uploading()
222+ downloading = self.status_frontend.files_downloading()
223 transfers = self.status_frontend.recent_transfers()
224 expected = {UPLOADING: [('testfile.txt', 1000, 200)],
225- RECENT_TRANSFERS: ['path1']}
226+ DOWNLOADING: [('download.pdf', 10, 1)],
227+ RECENT_TRANSFERS: ['path1', 'path2']}
228
229- self.assertEqual(
230- {UPLOADING: uploading, RECENT_TRANSFERS: transfers}, expected)
231+ self.assertEqual({UPLOADING: uploading,
232+ DOWNLOADING: downloading,
233+ RECENT_TRANSFERS: transfers},
234+ expected)
235
236 def test_file_published(self):
237 """A file published event is processed."""
238@@ -1415,6 +1499,7 @@
239 self.assertEqual(
240 {(fc.share_id, fc.node_id): (fc.deflated_size)},
241 self.aggregator.progress)
242+ self.assertEqual(len(self.aggregator.recent_transfers), 1)
243
244 def test_file_upload_started(self):
245 """Test that a file has started upload."""
246@@ -1443,10 +1528,14 @@
247
248 def test_max_recent_files(self):
249 """Check that the queue doesn't exceed the 5 items."""
250- for i in range(15):
251- fc = FakeCommand()
252+ for i in range(10):
253+ fc = FakeUploadCommand()
254 self.status_frontend.upload_started(fc)
255 self.status_frontend.upload_finished(fc)
256+ for i in range(10):
257+ fc = FakeDownloadCommand()
258+ self.status_frontend.download_started(fc)
259+ self.status_frontend.download_finished(fc)
260 self.assertEqual(len(self.aggregator.recent_transfers), 5)
261
262 def test_progress_made(self):
263
264=== modified file 'ubuntuone/status/aggregator.py'
265--- ubuntuone/status/aggregator.py 2012-10-15 21:20:54 +0000
266+++ ubuntuone/status/aggregator.py 2012-10-24 16:06:50 +0000
267@@ -754,6 +754,7 @@
268 if command.deflated_size is not None:
269 self.progress[
270 (command.share_id, command.node_id)] = command.deflated_size
271+ self.recent_transfers.append(command.path)
272 logger.debug("unqueueing command: %s", command.__class__.__name__)
273 self.update_progressbar()
274
275@@ -836,11 +837,11 @@
276 self.sync_menu.update_transfers)
277
278 def recent_transfers(self):
279- """Return a tuple with the recent transfers paths."""
280+ """Return a list of paths of recently transferred files."""
281 return list(self.aggregator.recent_transfers)
282
283 def files_uploading(self):
284- """Return a list with the files being uploading."""
285+ """Return list with (path, size, written) per current upload."""
286 uploading = []
287 for upload in self.aggregator.files_uploading:
288 if upload.deflated_size not in (0, None):
289@@ -848,6 +849,15 @@
290 upload.n_bytes_written))
291 return uploading
292
293+ def files_downloading(self):
294+ """Returns list with (path, size, read) per current download."""
295+ downloading = []
296+ for download in self.aggregator.files_downloading:
297+ if download.deflated_size not in (0, None):
298+ downloading.append((download.path, download.deflated_size,
299+ download.n_bytes_read))
300+ return downloading
301+
302 def file_published(self, public_url):
303 """A file was published."""
304 status_event = FilePublishingStatus(new_public_url=public_url)
305
306=== modified file 'ubuntuone/syncdaemon/__init__.py'
307--- ubuntuone/syncdaemon/__init__.py 2012-08-10 12:49:46 +0000
308+++ ubuntuone/syncdaemon/__init__.py 2012-10-24 16:06:50 +0000
309@@ -41,3 +41,4 @@
310 #Sync Menu data constants
311 RECENT_TRANSFERS = 'recent-transfers'
312 UPLOADING = 'uploading'
313+DOWNLOADING = 'downloading'
314
315=== modified file 'ubuntuone/syncdaemon/status_listener.py'
316--- ubuntuone/syncdaemon/status_listener.py 2012-09-20 12:56:32 +0000
317+++ ubuntuone/syncdaemon/status_listener.py 2012-10-24 16:06:50 +0000
318@@ -36,6 +36,7 @@
319 config,
320 RECENT_TRANSFERS,
321 UPLOADING,
322+ DOWNLOADING
323 )
324 from ubuntuone.syncdaemon.interaction_interfaces import (
325 get_share_dict, get_udf_dict)
326@@ -74,8 +75,11 @@
327 def menu_data(self):
328 """Return the info necessary to construct the sync menu."""
329 uploading = self.status_frontend.files_uploading()
330+ downloading = self.status_frontend.files_downloading()
331 transfers = self.status_frontend.recent_transfers()
332- data = {RECENT_TRANSFERS: transfers, UPLOADING: uploading}
333+ data = {RECENT_TRANSFERS: transfers,
334+ UPLOADING: uploading,
335+ DOWNLOADING: downloading}
336 return data
337
338 def get_show_all_notifications(self):

Subscribers

People subscribed via source and target branches