~ubuntu-branches/ubuntu/precise/ubuntuone-client/precise

« back to all changes in this revision

Viewing changes to debian/patches/02_value_io_error_fix.patch

  • Committer: Package Import Robot
  • Author(s): Natalia Bidart (nessita)
  • Date: 2011-11-14 11:16:03 UTC
  • Revision ID: package-import@ubuntu.com-20111114111603-5zq3wf22j7tcgxhn
Tags: 2.0.0-0ubuntu3
* debian/patches/02_value_io_error_fix.patch:
    - Make the Upload process do not close the tempfile until is finished
      (LP: #872924).
    - Reset the tempfile on every Upload _run() (LP: #884959).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
=== modified file 'tests/platform/linux/eventlog/test_zglog.py'
 
2
--- old/tests/platform/linux/eventlog/test_zglog.py     2011-06-15 21:14:06 +0000
 
3
+++ new/tests/platform/linux/eventlog/test_zglog.py     2011-11-07 18:00:17 +0000
 
4
@@ -25,7 +25,7 @@
 
5
 
 
6
 from distutils.spawn import find_executable
 
7
 
 
8
-from twisted.internet.defer import Deferred
 
9
+from twisted.internet.defer import Deferred, inlineCallbacks
 
10
 from zeitgeist.client import ZeitgeistClient
 
11
 from zeitgeist.datamodel import Event, Subject, Interpretation, Manifestation
 
12
 
 
13
@@ -92,8 +92,9 @@
 
14
 class ZeitgeistTestCase(DBusTwistedTestCase):
 
15
     """Tests for the zeitgeist logging module."""
 
16
 
 
17
+    @inlineCallbacks
 
18
     def setUp(self):
 
19
-        super(ZeitgeistTestCase, self).setUp()
 
20
+        yield super(ZeitgeistTestCase, self).setUp()
 
21
         zgdaemon = find_executable("zeitgeist-daemon")
 
22
         if not zgdaemon:
 
23
             raise NotFoundError("zeitgeist-daemon was not found.")
 
24
 
 
25
=== modified file 'tests/platform/linux/test_dbus.py'
 
26
--- old/tests/platform/linux/test_dbus.py       2011-08-03 20:20:02 +0000
 
27
+++ new/tests/platform/linux/test_dbus.py       2011-11-07 17:14:04 +0000
 
28
@@ -2909,9 +2909,10 @@
 
29
         self._old_home = os.environ['HOME']
 
30
         os.environ['HOME'] = self.home_dir
 
31
 
 
32
+    @defer.inlineCallbacks
 
33
     def tearDown(self):
 
34
         os.environ['HOME'] = self._old_home
 
35
-        return DBusTwistedTestCase.tearDown(self)
 
36
+        yield super(FolderTests, self).tearDown()
 
37
 
 
38
     def _create_udf(self, id, node_id, suggested_path, subscribed=True):
 
39
         """Create an UDF and returns it and the volume."""
 
40
 
 
41
=== modified file 'tests/platform/linux/test_messaging.py'
 
42
--- old/tests/platform/linux/test_messaging.py  2011-03-29 22:47:53 +0000
 
43
+++ new/tests/platform/linux/test_messaging.py  2011-11-07 18:00:17 +0000
 
44
@@ -22,8 +22,7 @@
 
45
 """
 
46
 
 
47
 
 
48
-from mocker import Mocker, ANY
 
49
-from twisted.trial.unittest import TestCase
 
50
+from mocker import ANY, MockerTestCase as TestCase
 
51
 
 
52
 from ubuntuone.platform.linux.messaging import Messaging, _server_callback
 
53
 
 
54
@@ -42,13 +41,6 @@
 
55
 class MessagingTestCase(TestCase):
 
56
     """Test the Messaging API."""
 
57
 
 
58
-    def setUp(self):
 
59
-        self.mocker = Mocker()
 
60
-
 
61
-    def tearDown(self):
 
62
-        self.mocker.restore()
 
63
-        self.mocker.verify()
 
64
-
 
65
     # pylint: disable=R0913
 
66
     def _show_message_setup(self, message_time=None, message_count=None,
 
67
                             icon=None, update_count=None, real_callback=False):
 
68
 
 
69
=== modified file 'tests/platform/linux/test_notification.py'
 
70
--- old/tests/platform/linux/test_notification.py       2011-03-03 23:29:37 +0000
 
71
+++ new/tests/platform/linux/test_notification.py       2011-11-07 17:14:04 +0000
 
72
@@ -22,8 +22,7 @@
 
73
 """
 
74
 
 
75
 
 
76
-from mocker import Mocker
 
77
-from twisted.trial.unittest import TestCase
 
78
+from mocker import MockerTestCase as TestCase
 
79
 
 
80
 from ubuntuone.platform.linux.notification import Notification, ICON_NAME
 
81
 
 
82
@@ -45,13 +44,6 @@
 
83
 class NotificationTestCase(TestCase):
 
84
     """Test the Messaging API."""
 
85
 
 
86
-    def setUp(self):
 
87
-        self.mocker = Mocker()
 
88
-
 
89
-    def tearDown(self):
 
90
-        self.mocker.restore()
 
91
-        self.mocker.verify()
 
92
-
 
93
     def test_send_notification(self):
 
94
         """On notification, pynotify receives the proper calls."""
 
95
         mock_notify = self.mocker.replace("pynotify")
 
96
 
 
97
=== modified file 'tests/platform/linux/test_unity.py'
 
98
--- old/tests/platform/linux/test_unity.py      2011-07-06 20:41:33 +0000
 
99
+++ new/tests/platform/linux/test_unity.py      2011-11-07 18:00:17 +0000
 
100
@@ -18,6 +18,7 @@
 
101
 
 
102
 """Tests for the liblauncher interface."""
 
103
 
 
104
+from twisted.internet import defer
 
105
 from twisted.trial.unittest import TestCase
 
106
 
 
107
 from ubuntuone.platform.linux import launcher
 
108
@@ -55,8 +56,10 @@
 
109
 
 
110
     skip = None if launcher.use_libunity else "libunity not installed."
 
111
 
 
112
+    @defer.inlineCallbacks
 
113
     def setUp(self):
 
114
         """Initialize this test instance."""
 
115
+        yield super(LauncherTestCase, self).setUp()
 
116
         self.patch(launcher.Unity, "LauncherEntry", FakeLauncherEntry)
 
117
         self.launcher = launcher.UbuntuOneLauncher()
 
118
 
 
119
 
 
120
=== modified file 'tests/platform/linux/test_vm.py'
 
121
--- old/tests/platform/linux/test_vm.py 2011-07-27 20:10:33 +0000
 
122
+++ new/tests/platform/linux/test_vm.py 2011-11-07 17:14:04 +0000
 
123
@@ -19,6 +19,8 @@
 
124
 import os
 
125
 import uuid
 
126
 
 
127
+from twisted.internet import defer
 
128
+
 
129
 from contrib.testing.testcase import FakeMain, environ
 
130
 from tests.syncdaemon.test_vm import MetadataTestCase, BaseVolumeManagerTests
 
131
 from ubuntuone.storageprotocol import request
 
132
@@ -44,8 +46,9 @@
 
133
 class MetadataOldLayoutTests(MetadataTestCase):
 
134
     """Tests for 'old' layouts and metadata upgrade"""
 
135
 
 
136
+    @defer.inlineCallbacks
 
137
     def setUp(self):
 
138
-        MetadataTestCase.setUp(self)
 
139
+        yield super(MetadataOldLayoutTests, self).setUp()
 
140
         self.root_dir = os.path.join(self.u1_dir, 'My Files')
 
141
         self.shares_dir = os.path.join(self.u1_dir, 'Shared With Me')
 
142
         self.new_root_dir = self.u1_dir
 
143
@@ -451,8 +454,9 @@
 
144
 class MetadataNewLayoutTests(MetadataTestCase):
 
145
     """Test for 'new' layout and metadata upgrade."""
 
146
 
 
147
+    @defer.inlineCallbacks
 
148
     def setUp(self):
 
149
-        MetadataTestCase.setUp(self)
 
150
+        yield super(MetadataNewLayoutTests, self).setUp()
 
151
         self.share_md_dir = os.path.join(self.vm_data_dir, 'shares')
 
152
         self.shared_md_dir = os.path.join(self.vm_data_dir, 'shared')
 
153
         self.home_dir = os.path.join(self.tmpdir, 'home', 'ubuntuonehacker')
 
154
 
 
155
=== modified file 'tests/platform/test_interaction_interfaces.py'
 
156
--- old/tests/platform/test_interaction_interfaces.py   2011-07-27 14:26:36 +0000
 
157
+++ new/tests/platform/test_interaction_interfaces.py   2011-11-07 17:14:04 +0000
 
158
@@ -18,15 +18,18 @@
 
159
 """Test that the interaction_interfaces are correctly called."""
 
160
 
 
161
 from mocker import MockerTestCase, MATCH
 
162
+from twisted.internet import defer
 
163
+
 
164
 from tests.platform import IPCTestCase
 
165
 
 
166
 
 
167
 class TestStatusIPC(MockerTestCase, IPCTestCase):
 
168
     """Ensure that calls are correctly fowarded."""
 
169
 
 
170
+    @defer.inlineCallbacks
 
171
     def setUp(self):
 
172
         """Set up tests."""
 
173
-        super(TestStatusIPC, self).setUp()
 
174
+        yield super(TestStatusIPC, self).setUp()
 
175
         self.syncdaemon_status = self.mocker.mock()
 
176
         self.status.syncdaemon_status = self.syncdaemon_status
 
177
 
 
178
@@ -82,9 +85,10 @@
 
179
 class TestEventsIPC(MockerTestCase, IPCTestCase):
 
180
     """Ensure that calls are correctly fowarded."""
 
181
 
 
182
+    @defer.inlineCallbacks
 
183
     def setUp(self):
 
184
         """Set up tests."""
 
185
-        super(TestEventsIPC, self).setUp()
 
186
+        yield super(TestEventsIPC, self).setUp()
 
187
         self.events_mock = self.mocker.mock()
 
188
         self.events.events = self.events_mock
 
189
 
 
190
@@ -100,9 +104,10 @@
 
191
 class TestSyncDaemonIPC(MockerTestCase, IPCTestCase):
 
192
     """Ensure that calls are correctly fowarded."""
 
193
 
 
194
+    @defer.inlineCallbacks
 
195
     def setUp(self):
 
196
         """Set up tests."""
 
197
-        super(TestSyncDaemonIPC, self).setUp()
 
198
+        yield super(TestSyncDaemonIPC, self).setUp()
 
199
         self.service = self.mocker.mock()
 
200
         self.sync.service = self.service
 
201
 
 
202
@@ -174,9 +179,10 @@
 
203
 class TestFileSystemIPC(MockerTestCase, IPCTestCase):
 
204
     """Ensure that calls are correctly fowarded."""
 
205
 
 
206
+    @defer.inlineCallbacks
 
207
     def setUp(self):
 
208
         """Set up tests."""
 
209
-        super(TestFileSystemIPC, self).setUp()
 
210
+        yield super(TestFileSystemIPC, self).setUp()
 
211
         self.syncdaemon_filesystem = self.mocker.mock()
 
212
         self.fs.syncdaemon_filesystem = self.syncdaemon_filesystem
 
213
 
 
214
@@ -221,9 +227,10 @@
 
215
 class TestSharesIPC(MockerTestCase, IPCTestCase):
 
216
     """Ensure that calls are correctly fowarded."""
 
217
 
 
218
+    @defer.inlineCallbacks
 
219
     def setUp(self):
 
220
         """Set up tests."""
 
221
-        super(TestSharesIPC, self).setUp()
 
222
+        yield super(TestSharesIPC, self).setUp()
 
223
         self.syncdaemon_shares = self.mocker.mock()
 
224
         self.shares.syncdaemon_shares = self.syncdaemon_shares
 
225
 
 
226
@@ -316,9 +323,10 @@
 
227
 class TestConfigIPC(MockerTestCase, IPCTestCase):
 
228
     """Ensure that calls are correctly fowarded."""
 
229
 
 
230
+    @defer.inlineCallbacks
 
231
     def setUp(self):
 
232
         """Set up tests."""
 
233
-        super(TestConfigIPC, self).setUp()
 
234
+        yield super(TestConfigIPC, self).setUp()
 
235
         self.syncdaemon_config = self.mocker.mock()
 
236
         self.config.syncdaemon_config = self.syncdaemon_config
 
237
 
 
238
@@ -467,9 +475,10 @@
 
239
 class TestFoldersIPC(MockerTestCase, IPCTestCase):
 
240
     """Ensure that calls are correctly fowarded."""
 
241
 
 
242
+    @defer.inlineCallbacks
 
243
     def setUp(self):
 
244
         """Set up tests."""
 
245
-        super(TestFoldersIPC, self).setUp()
 
246
+        yield super(TestFoldersIPC, self).setUp()
 
247
         self.syncdaemon_folders = self.mocker.mock()
 
248
         self.folders.syncdaemon_folders = self.syncdaemon_folders
 
249
 
 
250
@@ -528,9 +537,10 @@
 
251
 class TestPublicFilesIPC(MockerTestCase, IPCTestCase):
 
252
     """Ensure that calls are correctly fowarded."""
 
253
 
 
254
+    @defer.inlineCallbacks
 
255
     def setUp(self):
 
256
         """Set up tests."""
 
257
-        super(TestPublicFilesIPC, self).setUp()
 
258
+        yield super(TestPublicFilesIPC, self).setUp()
 
259
         self.syncdaemon_public_files = self.mocker.mock()
 
260
         self.public_files.syncdaemon_public_files =\
 
261
             self.syncdaemon_public_files
 
262
 
 
263
=== modified file 'tests/status/test_aggregator.py'
 
264
--- old/tests/status/test_aggregator.py 2011-07-27 13:27:22 +0000
 
265
+++ new/tests/status/test_aggregator.py 2011-11-07 17:14:04 +0000
 
266
@@ -50,8 +50,10 @@
 
267
 
 
268
     TIMEOUT = 3.0
 
269
 
 
270
+    @defer.inlineCallbacks
 
271
     def setUp(self):
 
272
         """Initialize this test instance."""
 
273
+        yield super(TimerTestCase, self).setUp()
 
274
         self.clock = PatchedClock()
 
275
         self.timer = aggregator.Timer(delay=3.0, clock=self.clock)
 
276
 
 
277
@@ -101,8 +103,10 @@
 
278
 
 
279
     DELAY = 0.5
 
280
 
 
281
+    @defer.inlineCallbacks
 
282
     def setUp(self):
 
283
         """Initialize this test instance."""
 
284
+        yield super(DeadlineTimerTestCase, self).setUp()
 
285
         self.clock = PatchedClock()
 
286
         self.timer = aggregator.DeadlineTimer(delay=0.5, timeout=3.0,
 
287
                                             clock=self.clock)
 
288
@@ -242,8 +246,10 @@
 
289
 class ToggleableNotificationTestCase(TestCase):
 
290
     """Test the ToggleableNotification class."""
 
291
 
 
292
+    @defer.inlineCallbacks
 
293
     def setUp(self):
 
294
         """Initialize this test instance."""
 
295
+        yield super(ToggleableNotificationTestCase, self).setUp()
 
296
         self.patch(aggregator, "Notification", FakeNotification)
 
297
         self.notification_switch = aggregator.NotificationSwitch()
 
298
         self.toggleable = self.notification_switch.get_notification()
 
299
@@ -282,8 +288,10 @@
 
300
 class NotificationSwitchTestCase(TestCase):
 
301
     """Test the NotificationSwitch class."""
 
302
 
 
303
+    @defer.inlineCallbacks
 
304
     def setUp(self):
 
305
         """Initialize this test instance."""
 
306
+        yield super(NotificationSwitchTestCase, self).setUp()
 
307
         self.notification_switch = aggregator.NotificationSwitch()
 
308
 
 
309
     def test_get_notification(self):
 
310
@@ -306,8 +314,10 @@
 
311
 class FileDiscoveryBubbleTestCase(TestCase):
 
312
     """Test the FileDiscoveryBubble class."""
 
313
 
 
314
+    @defer.inlineCallbacks
 
315
     def setUp(self):
 
316
         """Initialize this test instance."""
 
317
+        yield super(FileDiscoveryBubbleTestCase, self).setUp()
 
318
         self.patch(aggregator, "ToggleableNotification",
 
319
                    FakeNotificationSingleton())
 
320
         self.clock = PatchedClock()
 
321
@@ -487,8 +497,10 @@
 
322
 class FinalBubbleTestCase(TestCase):
 
323
     """Test for the final status notification bubble."""
 
324
 
 
325
+    @defer.inlineCallbacks
 
326
     def setUp(self):
 
327
         """Initialize this test instance."""
 
328
+        yield super(FinalBubbleTestCase, self).setUp()
 
329
         self.patch(aggregator, "ToggleableNotification",
 
330
                    FakeNotificationSingleton())
 
331
         self.clock = PatchedClock()
 
332
@@ -542,8 +554,10 @@
 
333
 class ProgressBarTestCase(TestCase):
 
334
     """Tests for the progress bar."""
 
335
 
 
336
+    @defer.inlineCallbacks
 
337
     def setUp(self):
 
338
         """Initialize this test instance."""
 
339
+        yield super(ProgressBarTestCase, self).setUp()
 
340
         self.patch(aggregator, "UbuntuOneLauncher", FakeLauncher)
 
341
         self.patch(aggregator.session, "Inhibitor", FakeInhibitor)
 
342
         self.clock = PatchedClock()
 
343
@@ -737,10 +751,10 @@
 
344
             self.files_uploading.remove(command)
 
345
         self.queued_commands.discard(command)
 
346
 
 
347
-    def progress_made(self, share_id, node_id, n_bytes_written, deflated_size):
 
348
+    def progress_made(self, share_id, node_id, n_bytes, deflated_size):
 
349
         """Progress made on up- or download."""
 
350
         self.progress_events.append(
 
351
-            (share_id, node_id, n_bytes_written, deflated_size))
 
352
+            (share_id, node_id, n_bytes, deflated_size))
 
353
 
 
354
     def connection_made(self):
 
355
         """The client made the connection to the server."""
 
356
@@ -1033,8 +1047,10 @@
 
357
     CLASS_KWARGS = {}
 
358
     status = None
 
359
 
 
360
+    @defer.inlineCallbacks
 
361
     def setUp(self):
 
362
         """Initialize this test instance."""
 
363
+        yield super(StatusEventTestCase, self).setUp()
 
364
         if type(self) == StatusEventTestCase:
 
365
             self.assertRaises(AssertionError, self.CLASS, **self.CLASS_KWARGS)
 
366
         else:
 
367
@@ -1177,8 +1193,10 @@
 
368
 class StatusAggregatorTestCase(TestCase):
 
369
     """Test the backend of the status aggregator."""
 
370
 
 
371
+    @defer.inlineCallbacks
 
372
     def setUp(self):
 
373
         """Initialize this test instance."""
 
374
+        yield super(StatusAggregatorTestCase, self).setUp()
 
375
         self.patch(aggregator, "FileDiscoveryBubble",
 
376
                    FakeFileDiscoveryBubble)
 
377
         self.patch(aggregator, "FinalStatusBubble",
 
378
 
 
379
=== modified file 'tests/syncdaemon/test_action_queue.py'
 
380
--- old/tests/syncdaemon/test_action_queue.py   2011-09-08 21:29:37 +0000
 
381
+++ new/tests/syncdaemon/test_action_queue.py   2011-11-07 17:14:04 +0000
 
382
@@ -104,11 +104,19 @@
 
383
         return self.check(logger.NOTE, *msgs)
 
384
 
 
385
 
 
386
+class FakeMagicHash(object):
 
387
+    """Fake magic hash."""
 
388
+    _magic_hash = '666'
 
389
+
 
390
+
 
391
 class FakeTempFile(object):
 
392
     """Fake temporary file."""
 
393
+
 
394
     def __init__(self, tmpdir):
 
395
+        self.closed = 0  # be able to count how may close calls we had
 
396
         self.name = os.path.join(tmpdir, 'remove-me.zip')
 
397
         open_file(self.name, 'w').close()
 
398
+        self.close = lambda: setattr(self, 'closed', self.closed + 1)
 
399
 
 
400
 
 
401
 class FakeCommand(object):
 
402
@@ -181,7 +189,7 @@
 
403
 
 
404
 class FakeRequest(object):
 
405
     """Fake Request."""
 
406
-    def __init__(self):
 
407
+    def __init__(self, *a, **k):
 
408
         self.deferred = defer.succeed(True)
 
409
         self.cancelled = False
 
410
 
 
411
@@ -442,8 +450,10 @@
 
412
 class TestRequestQueue(TwistedTestCase):
 
413
     """Tests for the RequestQueue."""
 
414
 
 
415
+    @defer.inlineCallbacks
 
416
     def setUp(self):
 
417
         """Set up."""
 
418
+        yield super(TestRequestQueue, self).setUp()
 
419
 
 
420
         class FakeAQ(object):
 
421
             """Fake AQ."""
 
422
@@ -765,8 +775,10 @@
 
423
 class TestDeferredMap(TwistedTestCase):
 
424
     """Test the deferred map."""
 
425
 
 
426
+    @defer.inlineCallbacks
 
427
     def setUp(self):
 
428
         """Set up."""
 
429
+        yield super(TestDeferredMap, self).setUp()
 
430
         self.dm = DeferredMap()
 
431
 
 
432
     def test_one_get_returns_stored_deferred(self):
 
433
@@ -853,8 +865,10 @@
 
434
 class TestZipQueue(TwistedTestCase):
 
435
     """Test the zipping queue."""
 
436
 
 
437
+    @defer.inlineCallbacks
 
438
     def setUp(self):
 
439
         """Set up."""
 
440
+        yield super(TestZipQueue, self).setUp()
 
441
         self.zq = ZipQueue()
 
442
 
 
443
     @defer.inlineCallbacks
 
444
@@ -3053,9 +3067,7 @@
 
445
     def test_fileobj_in_run(self):
 
446
         """Create it first time, reset after that."""
 
447
         # don't use the real protocol
 
448
-        obj = Mocker().mock()
 
449
-        obj.deferred
 
450
-        self.action_queue.client.get_content_request = lambda *a, **k: obj
 
451
+        self.action_queue.client.get_content_request = FakeRequest
 
452
 
 
453
         class FakeFileObjFactory(object):
 
454
             """Fake class to check behaviour."""
 
455
@@ -3099,10 +3111,6 @@
 
456
         """Init."""
 
457
         yield super(UploadUnconnectedTestCase, self).setUp()
 
458
 
 
459
-        class FakeMagicHash(object):
 
460
-            """Fake magic hash."""
 
461
-            _magic_hash = '666'
 
462
-
 
463
         self.rq = request_queue = RequestQueue(action_queue=self.action_queue)
 
464
         self.command = Upload(request_queue, share_id='a_share_id',
 
465
                               node_id='a_node_id', previous_hash='prev_hash',
 
466
@@ -3116,6 +3124,7 @@
 
467
     def test_upload_progress_wrapper_setup(self):
 
468
         """Test the setting up of the progress wrapper in ._run()."""
 
469
         self.command.action_queue.connect_in_progress = False
 
470
+        self.command.tempfile = StringIO()
 
471
         self.command._run()
 
472
 
 
473
         self.assertEqual(len(self.client.called), 1)
 
474
@@ -3306,16 +3315,29 @@
 
475
         events = [('AQ_UPLOAD_ERROR', kwargs)]
 
476
         self.assertEqual(events, self.command.action_queue.event_queue.events)
 
477
 
 
478
-    def test_handle_failure_removes_temp_file(self):
 
479
-        """Test temp file is removed on failure."""
 
480
+    def test_finish_closes_temp_file(self):
 
481
+        """Test temp file is closed when the command finishes."""
 
482
+        self.command.tempfile = FakeTempFile(self.tmpdir)
 
483
+        assert self.command.tempfile.closed == 0
 
484
+
 
485
+        self.command.finish()
 
486
+        self.assertEqual(1, self.command.tempfile.closed)
 
487
+
 
488
+    def test_finish_removes_temp_file(self):
 
489
+        """Test temp file is removed when the command finishes."""
 
490
         self.command.tempfile = FakeTempFile(self.tmpdir)
 
491
         assert path_exists(self.command.tempfile.name)
 
492
 
 
493
-        msg = 'Something went wrong'
 
494
-        failure = Failure(DefaultException(msg))
 
495
-        self.command.handle_failure(failure=failure)
 
496
+        self.command.finish()
 
497
         self.assertFalse(path_exists(self.command.tempfile.name))
 
498
 
 
499
+    def test_finish_handles_temp_file_none(self):
 
500
+        """Test temp file can be None when calling finish."""
 
501
+        self.command.tempfile = None
 
502
+
 
503
+        self.command.finish()
 
504
+        self.assertEqual(self.command.tempfile, None)  # nothing changed
 
505
+
 
506
     def test_retryable_failure_push_quota_exceeded_if_that_error(self):
 
507
         """Test SYS_QUOTA_EXCEEDED is pushed on QuotaExceededError."""
 
508
         protocol_msg = protocol_pb2.Message()
 
509
@@ -3641,6 +3663,18 @@
 
510
         tempfile = NamedTemporaryFile()
 
511
         self.assertEqual(tempfile.mode, 'w+b')
 
512
 
 
513
+    def test_fileobj_in_run(self):
 
514
+        """Create it first time, reset after that."""
 
515
+        # don't use the real protocol or magic hash
 
516
+        self.action_queue.client.put_content_request = FakeRequest
 
517
+        self.command.magic_hash = FakeMagicHash()
 
518
+
 
519
+        called = []
 
520
+        self.command.tempfile = StringIO()
 
521
+        self.command.tempfile.seek = lambda *a: called.extend(a)
 
522
+        self.command._run()
 
523
+        self.assertEqual(called, [0])
 
524
+
 
525
 
 
526
 class CreateShareTestCase(ConnectedBaseTestCase):
 
527
     """Test for CreateShare ActionQueueCommand."""
 
528
@@ -4919,8 +4953,10 @@
 
529
 class ActionQueueProtocolTests(TwistedTestCase):
 
530
     """Test the ACQ class."""
 
531
 
 
532
+    @defer.inlineCallbacks
 
533
     def setUp(self):
 
534
         """Set up."""
 
535
+        yield super(ActionQueueProtocolTests, self).setUp()
 
536
         # create an AQP and put a factory to it
 
537
         self.aqp = ActionQueueProtocol()
 
538
         obj = Mocker().mock()
 
539
@@ -4932,8 +4968,10 @@
 
540
         self.handler.setLevel(logging.DEBUG)
 
541
         self.aqp.log.addHandler(self.handler)
 
542
 
 
543
+    @defer.inlineCallbacks
 
544
     def tearDown(self):
 
545
         """Tear down."""
 
546
+        yield super(ActionQueueProtocolTests, self).tearDown()
 
547
         self.aqp.log.removeHandler(self.handler)
 
548
         if self.aqp.ping_manager is not None:
 
549
             self.aqp.ping_manager.stop()
 
550
@@ -5541,8 +5579,10 @@
 
551
 class ConditionsLockerTests(TwistedTestCase):
 
552
     """Test the ConditionsLocker."""
 
553
 
 
554
+    @defer.inlineCallbacks
 
555
     def setUp(self):
 
556
         """Set up."""
 
557
+        yield super(ConditionsLockerTests, self).setUp()
 
558
         self.cl = ConditionsLocker()
 
559
 
 
560
     def test_get_locking_deferred_returns_deferred(self):
 
561
@@ -5664,8 +5704,11 @@
 
562
 class PingManagerTestCase(TwistedTestCase):
 
563
     """Test the Ping manager."""
 
564
 
 
565
+    @defer.inlineCallbacks
 
566
     def setUp(self):
 
567
         """Set up."""
 
568
+        yield super(PingManagerTestCase, self).setUp()
 
569
+
 
570
         class FakeActionQueueProtocol(object):
 
571
             """Fake object for the tests."""
 
572
             log = logging.getLogger("ubuntuone.SyncDaemon.ActionQueue")
 
573
@@ -5677,8 +5720,10 @@
 
574
         self.fake_aqp.log.addHandler(self.handler)
 
575
         self.pm = PingManager(self.fake_aqp)
 
576
 
 
577
+    @defer.inlineCallbacks
 
578
     def tearDown(self):
 
579
         """Tear down."""
 
580
+        yield super(PingManagerTestCase, self).tearDown()
 
581
         self.fake_aqp.log.removeHandler(self.handler)
 
582
         self.pm.stop()
 
583
 
 
584
 
 
585
=== modified file 'tests/syncdaemon/test_logger.py'
 
586
--- old/tests/syncdaemon/test_logger.py 2011-08-10 12:01:01 +0000
 
587
+++ new/tests/syncdaemon/test_logger.py 2011-11-07 17:14:04 +0000
 
588
@@ -20,6 +20,7 @@
 
589
 
 
590
 import logging
 
591
 
 
592
+from twisted.internet import defer
 
593
 from twisted.trial import unittest
 
594
 
 
595
 from ubuntuone.devtools.handlers import MementoHandler
 
596
@@ -39,15 +40,19 @@
 
597
 class DebugCaptureTest(unittest.TestCase):
 
598
     """Tests for DebugCapture context manager."""
 
599
 
 
600
+    @defer.inlineCallbacks
 
601
     def setUp(self):
 
602
         """Setup the logger and the handler"""
 
603
+        yield super(DebugCaptureTest, self).setUp()
 
604
         self.handler = MementoHandler()
 
605
         self.logger = logging.getLogger(self.__class__.__name__)
 
606
         self.logger.addHandler(self.handler)
 
607
         self.logger.setLevel(logging.DEBUG)
 
608
 
 
609
+    @defer.inlineCallbacks
 
610
     def tearDown(self):
 
611
         """close the handler and restore the logger (Logger's are global)"""
 
612
+        yield super(DebugCaptureTest, self).tearDown()
 
613
         self.handler.close()
 
614
         self.logger.removeHandler(self.handler)
 
615
         self.logger.setLevel(logging.DEBUG)
 
616
@@ -222,8 +227,10 @@
 
617
 class FilterTests(unittest.TestCase):
 
618
     """Tests log filters"""
 
619
 
 
620
+    @defer.inlineCallbacks
 
621
     def setUp(self):
 
622
         """Setup the logger and the handler"""
 
623
+        yield super(FilterTests, self).setUp()
 
624
         self.handler = MementoHandler()
 
625
         self.handler.setLevel(logging.DEBUG)
 
626
         root_logger.addHandler(self.handler)
 
627
@@ -253,15 +260,19 @@
 
628
 class MultiFilterTest(unittest.TestCase):
 
629
     """Tests for logger.MultiFilter"""
 
630
 
 
631
+    @defer.inlineCallbacks
 
632
     def setUp(self):
 
633
         """Setup the logger and the handler"""
 
634
+        yield super(MultiFilterTest, self).setUp()
 
635
         self.handler = MementoHandler()
 
636
         self.logger = logging.getLogger(self.__class__.__name__)
 
637
         self.logger.addHandler(self.handler)
 
638
         self.logger.setLevel(logging.DEBUG)
 
639
 
 
640
+    @defer.inlineCallbacks
 
641
     def tearDown(self):
 
642
         """close the handler and restore the logger (Logger's are global)"""
 
643
+        yield super(MultiFilterTest, self).tearDown()
 
644
         self.handler.close()
 
645
         self.logger.removeHandler(self.handler)
 
646
         self.logger.setLevel(logging.DEBUG)
 
647
 
 
648
=== modified file 'tests/syncdaemon/test_pathlockingtree.py'
 
649
--- old/tests/syncdaemon/test_pathlockingtree.py        2011-01-20 21:27:24 +0000
 
650
+++ new/tests/syncdaemon/test_pathlockingtree.py        2011-11-07 17:14:04 +0000
 
651
@@ -29,8 +29,10 @@
 
652
 class InternalDeferredTests(TwistedTestCase):
 
653
     """Test the internal deferreds handling functionality."""
 
654
 
 
655
+    @defer.inlineCallbacks
 
656
     def setUp(self):
 
657
         """Set up."""
 
658
+        yield super(InternalDeferredTests, self).setUp()
 
659
         self.plt = PathLockingTree()
 
660
 
 
661
     def test_single_element_old(self):
 
662
@@ -217,8 +219,10 @@
 
663
 class LockingTests(TwistedTestCase):
 
664
     """Test the locking between elements."""
 
665
 
 
666
+    @defer.inlineCallbacks
 
667
     def setUp(self):
 
668
         """Set up."""
 
669
+        yield super(LockingTests, self).setUp()
 
670
         self.plt = PathLockingTree()
 
671
 
 
672
     @defer.inlineCallbacks
 
673
@@ -417,8 +421,10 @@
 
674
 class CleaningTests(TwistedTestCase):
 
675
     """Test that the releases clean the tree."""
 
676
 
 
677
+    @defer.inlineCallbacks
 
678
     def setUp(self):
 
679
         """Set up."""
 
680
+        yield super(CleaningTests, self).setUp()
 
681
         self.plt = PathLockingTree()
 
682
 
 
683
     @defer.inlineCallbacks
 
684
@@ -547,8 +553,10 @@
 
685
 class LoggingTests(TwistedTestCase):
 
686
     """Test the logging."""
 
687
 
 
688
+    @defer.inlineCallbacks
 
689
     def setUp(self):
 
690
         """Set up."""
 
691
+        yield super(LoggingTests, self).setUp()
 
692
         self.plt = PathLockingTree()
 
693
 
 
694
         self.handler = MementoHandler()
 
695
 
 
696
=== modified file 'tests/syncdaemon/test_states.py'
 
697
--- old/tests/syncdaemon/test_states.py 2011-01-18 20:25:54 +0000
 
698
+++ new/tests/syncdaemon/test_states.py 2011-11-07 17:14:04 +0000
 
699
@@ -107,7 +107,9 @@
 
700
 class Base(TwistedTestCase):
 
701
     """Base class for state tests."""
 
702
 
 
703
+    @defer.inlineCallbacks
 
704
     def setUp(self):
 
705
+        yield super(Base, self).setUp()
 
706
         # create fake classes
 
707
         self.eq = FakeEventQueue()
 
708
         self.aq = FakeActionQueue()
 
709
@@ -157,15 +159,18 @@
 
710
         reactor.callLater(.1, check, 0)
 
711
         return d
 
712
 
 
713
+    @defer.inlineCallbacks
 
714
     def tearDown(self):
 
715
+        yield super(Base, self).tearDown()
 
716
         self.sm.connection.shutdown()
 
717
 
 
718
 
 
719
 class QueueBase(Base):
 
720
     """Basic setup for QueueManager."""
 
721
 
 
722
+    @defer.inlineCallbacks
 
723
     def setUp(self):
 
724
-        Base.setUp(self)
 
725
+        yield super(QueueBase, self).setUp()
 
726
         self.sm.state = StateManager.QUEUE_MANAGER
 
727
 
 
728
 
 
729
@@ -223,8 +228,9 @@
 
730
 class TestConnectionManager(Base):
 
731
     """Test the "internal network" transitions."""
 
732
 
 
733
+    @defer.inlineCallbacks
 
734
     def setUp(self):
 
735
-        Base.setUp(self)
 
736
+        yield super(TestConnectionManager, self).setUp()
 
737
 
 
738
         # put SM on some state that does not generate further
 
739
         # transition-related efforts for this CM
 
740
@@ -341,8 +347,9 @@
 
741
 class TestConnectionManagerTimings(Base):
 
742
     """Times handled by ConnectionManager."""
 
743
 
 
744
+    @defer.inlineCallbacks
 
745
     def setUp(self):
 
746
-        Base.setUp(self)
 
747
+        yield super(TestConnectionManagerTimings, self).setUp()
 
748
 
 
749
         # set timeout values to really low, to make tests run quicker
 
750
         self.sm.connection.handshake_timeout = 0
 
751
@@ -843,8 +850,10 @@
 
752
 class TestStateManagerPassToNetworkManager(Base):
 
753
     """All network events should go to NetworkManager."""
 
754
 
 
755
+    @defer.inlineCallbacks
 
756
     def setUp(self):
 
757
-        Base.setUp(self)
 
758
+        yield super(TestStateManagerPassToNetworkManager,
 
759
+                    self).setUp()
 
760
 
 
761
         # put a function in the middle to log calls
 
762
         self.called_events = []
 
763
@@ -893,8 +902,10 @@
 
764
 class TestStateManagerPassToQueueManager(Base):
 
765
     """All queue events should go to QueueManager."""
 
766
 
 
767
+    @defer.inlineCallbacks
 
768
     def setUp(self):
 
769
-        Base.setUp(self)
 
770
+        yield super(TestStateManagerPassToQueueManager,
 
771
+                    self).setUp()
 
772
 
 
773
         # put a function in the middle to log calls
 
774
         self.called_events = []
 
775
 
 
776
=== modified file 'tests/syncdaemon/test_status_listener.py'
 
777
--- old/tests/syncdaemon/test_status_listener.py        2011-08-05 15:50:52 +0000
 
778
+++ new/tests/syncdaemon/test_status_listener.py        2011-11-07 17:14:04 +0000
 
779
@@ -96,9 +96,10 @@
 
780
 class StatusListenerTestCase(FakeMainTestCase):
 
781
     """Tests for StatusListener."""
 
782
 
 
783
+    @defer.inlineCallbacks
 
784
     def setUp(self):
 
785
         """Initialize this instance."""
 
786
-        super(StatusListenerTestCase, self).setUp()
 
787
+        yield super(StatusListenerTestCase, self).setUp()
 
788
         self.status_frontend = FakeStatusFrontend()
 
789
         self.listener = status_listener.StatusListener(self.fs, self.vm,
 
790
                                                        self.status_frontend)
 
791
 
 
792
=== modified file 'ubuntuone/syncdaemon/action_queue.py'
 
793
--- old/ubuntuone/syncdaemon/action_queue.py    2011-09-08 21:41:00 +0000
 
794
+++ new/ubuntuone/syncdaemon/action_queue.py    2011-11-07 17:14:04 +0000
 
795
@@ -37,7 +37,7 @@
 
796
 import zlib
 
797
 
 
798
 from collections import deque, defaultdict
 
799
-from functools import wraps, partial
 
800
+from functools import partial
 
801
 from urllib import urlencode
 
802
 from urllib2 import urlopen, Request, HTTPError
 
803
 from urlparse import urljoin
 
804
@@ -72,18 +72,7 @@
 
805
 EREGEX = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$"
 
806
 
 
807
 # progress threshold to emit a download/upload progress event: 64Kb
 
808
-TRANSFER_PROGRESS_THRESHOLD = 64*1024*1024
 
809
-
 
810
-def passit(func):
 
811
-    """Pass the value on for the next deferred, while calling func with it."""
 
812
-
 
813
-    @wraps(func)
 
814
-    def wrapper(a):
 
815
-        """Do it."""
 
816
-        func(a)
 
817
-        return a
 
818
-
 
819
-    return wrapper
 
820
+TRANSFER_PROGRESS_THRESHOLD = 64 * 1024 * 1024
 
821
 
 
822
 
 
823
 class DeferredInterrupted(Exception):
 
824
@@ -116,7 +105,6 @@
 
825
             self.errback(DeferredInterrupted())
 
826
 
 
827
 
 
828
-
 
829
 class PathLockingTree(object):
 
830
     """Tree that stores deferreds in the nodes."""
 
831
 
 
832
@@ -214,7 +202,6 @@
 
833
             node, element = branch.pop()
 
834
             del node['children_nodes'][element]
 
835
 
 
836
-
 
837
         # finally, log and release the deferred
 
838
         logger.debug("pathlock releasing %s; remaining: %d", elements,
 
839
                                                              self.count)
 
840
@@ -250,8 +237,8 @@
 
841
         return ('start - processMessage: id: %s, type: %s',
 
842
                 message.id, message.type)
 
843
     elif message.type == protocol_pb2.Message.PUT_CONTENT:
 
844
-        lines = [ line for line in str(message).split("\n")
 
845
-                if not line.strip().startswith("magic_hash:") ]
 
846
+        lines = [line for line in str(message).split("\n")
 
847
+                if not line.strip().startswith("magic_hash:")]
 
848
         return ('start - processMessage: %s',
 
849
                 " ".join(lines))
 
850
     else:
 
851
@@ -461,12 +448,8 @@
 
852
                 magic_hasher.update(data)
 
853
             upload.deflated_size = f.tell()
 
854
 
 
855
-            # keep the file open, but reset its position
 
856
-            # to zero, ready to be read later
 
857
-            f.seek(0)
 
858
-
 
859
             upload.magic_hash = magic_hasher.content_hash()
 
860
-        except Exception, e: # pylint: disable-msg=W0703
 
861
+        except Exception, e:  # pylint: disable-msg=W0703
 
862
             failed = True
 
863
             reactor.callFromThread(deferred.errback, e)
 
864
         finally:
 
865
@@ -705,10 +688,10 @@
 
866
         self.token = None
 
867
         self.consumer = None
 
868
 
 
869
-        self.client = None # an instance of self.protocol
 
870
+        self.client = None  # an instance of self.protocol
 
871
 
 
872
         # is a twisted.internet.tcp/ssl.Connector instance
 
873
-        self.connector = None # created on reactor.connectTCP/SSL
 
874
+        self.connector = None  # created on reactor.connectTCP/SSL
 
875
         # we need to track down if a connection is in progress
 
876
         # to avoid double connections
 
877
         self.connect_in_progress = False
 
878
@@ -1029,8 +1012,8 @@
 
879
     @defer.inlineCallbacks
 
880
     def authenticate(self):
 
881
         """Authenticate against the server using stored credentials."""
 
882
-        metadata = {'version':clientdefs.VERSION,
 
883
-                    'platform':platform}
 
884
+        metadata = {'version': clientdefs.VERSION,
 
885
+                    'platform': platform}
 
886
         authenticate_d = self._send_request_and_handle_errors(
 
887
             request=self.client.oauth_authenticate,
 
888
             request_error=protocol_errors.AuthenticationFailedError,
 
889
@@ -2078,7 +2061,6 @@
 
890
         self.log = mklog(logger, 'GetDeltaFromScratch', self.volume_id, None)
 
891
 
 
892
 
 
893
-
 
894
 class ChangePublicAccess(ActionQueueCommand):
 
895
     """Change the public access of a file."""
 
896
 
 
897
@@ -2498,6 +2480,11 @@
 
898
 
 
899
     def finish(self):
 
900
         """Release the semaphore if already acquired."""
 
901
+        if self.tempfile is not None:
 
902
+            # clean the temporary file
 
903
+            self.tempfile.close()
 
904
+            remove_file(self.tempfile.name)
 
905
+
 
906
         if self.tx_semaphore is not None:
 
907
             self.tx_semaphore = self.tx_semaphore.release()
 
908
             self.log.debug('semaphore released')
 
909
@@ -2509,7 +2496,7 @@
 
910
                                            share_id=self.share_id,
 
911
                                            node_id=self.node_id,
 
912
                                            hash=self.hash)
 
913
-
 
914
+        self.tempfile.seek(0)
 
915
         f = UploadProgressWrapper(self.tempfile, self)
 
916
 
 
917
         # access here the magic hash value, don't log anywhere, and
 
918
@@ -2521,9 +2508,7 @@
 
919
             upload_id=self.upload_id, upload_id_cb=self._upload_id_cb,
 
920
             magic_hash=magic_hash)
 
921
         self.upload_req = req
 
922
-        d = req.deferred
 
923
-        d.addBoth(passit(lambda _: self.tempfile.close()))
 
924
-        return d
 
925
+        return req.deferred
 
926
 
 
927
     def _upload_id_cb(self, upload_id):
 
928
         """Handle the received upload_id, save it in the metadata."""
 
929
@@ -2545,9 +2530,6 @@
 
930
 
 
931
     def handle_success(self, request):
 
932
         """It worked! Push the event."""
 
933
-        # remove the temporary file
 
934
-        remove_file(self.tempfile.name)
 
935
-
 
936
         # send the event
 
937
         d = dict(share_id=self.share_id, node_id=self.node_id, hash=self.hash,
 
938
                  new_generation=request.new_generation)
 
939
@@ -2563,7 +2545,6 @@
 
940
 
 
941
     def handle_failure(self, failure):
 
942
         """It didn't work! Push the event."""
 
943
-        remove_file(self.tempfile.name)
 
944
         self.action_queue.event_queue.push('AQ_UPLOAD_ERROR',
 
945
                                            error=failure.getErrorMessage(),
 
946
                                            share_id=self.share_id,
 
947