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
6
from distutils.spawn import find_executable
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
14
class ZeitgeistTestCase(DBusTwistedTestCase):
15
"""Tests for the zeitgeist logging module."""
19
- super(ZeitgeistTestCase, self).setUp()
20
+ yield super(ZeitgeistTestCase, self).setUp()
21
zgdaemon = find_executable("zeitgeist-daemon")
23
raise NotFoundError("zeitgeist-daemon was not found.")
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
32
+ @defer.inlineCallbacks
34
os.environ['HOME'] = self._old_home
35
- return DBusTwistedTestCase.tearDown(self)
36
+ yield super(FolderTests, self).tearDown()
38
def _create_udf(self, id, node_id, suggested_path, subscribed=True):
39
"""Create an UDF and returns it and the volume."""
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
48
-from mocker import Mocker, ANY
49
-from twisted.trial.unittest import TestCase
50
+from mocker import ANY, MockerTestCase as TestCase
52
from ubuntuone.platform.linux.messaging import Messaging, _server_callback
55
class MessagingTestCase(TestCase):
56
"""Test the Messaging API."""
59
- self.mocker = Mocker()
62
- self.mocker.restore()
63
- self.mocker.verify()
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):
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
76
-from mocker import Mocker
77
-from twisted.trial.unittest import TestCase
78
+from mocker import MockerTestCase as TestCase
80
from ubuntuone.platform.linux.notification import Notification, ICON_NAME
83
class NotificationTestCase(TestCase):
84
"""Test the Messaging API."""
87
- self.mocker = Mocker()
90
- self.mocker.restore()
91
- self.mocker.verify()
93
def test_send_notification(self):
94
"""On notification, pynotify receives the proper calls."""
95
mock_notify = self.mocker.replace("pynotify")
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
102
"""Tests for the liblauncher interface."""
104
+from twisted.internet import defer
105
from twisted.trial.unittest import TestCase
107
from ubuntuone.platform.linux import launcher
110
skip = None if launcher.use_libunity else "libunity not installed."
112
+ @defer.inlineCallbacks
114
"""Initialize this test instance."""
115
+ yield super(LauncherTestCase, self).setUp()
116
self.patch(launcher.Unity, "LauncherEntry", FakeLauncherEntry)
117
self.launcher = launcher.UbuntuOneLauncher()
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
127
+from twisted.internet import defer
129
from contrib.testing.testcase import FakeMain, environ
130
from tests.syncdaemon.test_vm import MetadataTestCase, BaseVolumeManagerTests
131
from ubuntuone.storageprotocol import request
133
class MetadataOldLayoutTests(MetadataTestCase):
134
"""Tests for 'old' layouts and metadata upgrade"""
136
+ @defer.inlineCallbacks
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
144
class MetadataNewLayoutTests(MetadataTestCase):
145
"""Test for 'new' layout and metadata upgrade."""
147
+ @defer.inlineCallbacks
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')
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
159
"""Test that the interaction_interfaces are correctly called."""
161
from mocker import MockerTestCase, MATCH
162
+from twisted.internet import defer
164
from tests.platform import IPCTestCase
167
class TestStatusIPC(MockerTestCase, IPCTestCase):
168
"""Ensure that calls are correctly fowarded."""
170
+ @defer.inlineCallbacks
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
179
class TestEventsIPC(MockerTestCase, IPCTestCase):
180
"""Ensure that calls are correctly fowarded."""
182
+ @defer.inlineCallbacks
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
191
class TestSyncDaemonIPC(MockerTestCase, IPCTestCase):
192
"""Ensure that calls are correctly fowarded."""
194
+ @defer.inlineCallbacks
197
- super(TestSyncDaemonIPC, self).setUp()
198
+ yield super(TestSyncDaemonIPC, self).setUp()
199
self.service = self.mocker.mock()
200
self.sync.service = self.service
203
class TestFileSystemIPC(MockerTestCase, IPCTestCase):
204
"""Ensure that calls are correctly fowarded."""
206
+ @defer.inlineCallbacks
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
215
class TestSharesIPC(MockerTestCase, IPCTestCase):
216
"""Ensure that calls are correctly fowarded."""
218
+ @defer.inlineCallbacks
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
227
class TestConfigIPC(MockerTestCase, IPCTestCase):
228
"""Ensure that calls are correctly fowarded."""
230
+ @defer.inlineCallbacks
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
239
class TestFoldersIPC(MockerTestCase, IPCTestCase):
240
"""Ensure that calls are correctly fowarded."""
242
+ @defer.inlineCallbacks
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
251
class TestPublicFilesIPC(MockerTestCase, IPCTestCase):
252
"""Ensure that calls are correctly fowarded."""
254
+ @defer.inlineCallbacks
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
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
270
+ @defer.inlineCallbacks
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)
281
+ @defer.inlineCallbacks
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,
289
class ToggleableNotificationTestCase(TestCase):
290
"""Test the ToggleableNotification class."""
292
+ @defer.inlineCallbacks
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()
300
class NotificationSwitchTestCase(TestCase):
301
"""Test the NotificationSwitch class."""
303
+ @defer.inlineCallbacks
305
"""Initialize this test instance."""
306
+ yield super(NotificationSwitchTestCase, self).setUp()
307
self.notification_switch = aggregator.NotificationSwitch()
309
def test_get_notification(self):
311
class FileDiscoveryBubbleTestCase(TestCase):
312
"""Test the FileDiscoveryBubble class."""
314
+ @defer.inlineCallbacks
316
"""Initialize this test instance."""
317
+ yield super(FileDiscoveryBubbleTestCase, self).setUp()
318
self.patch(aggregator, "ToggleableNotification",
319
FakeNotificationSingleton())
320
self.clock = PatchedClock()
322
class FinalBubbleTestCase(TestCase):
323
"""Test for the final status notification bubble."""
325
+ @defer.inlineCallbacks
327
"""Initialize this test instance."""
328
+ yield super(FinalBubbleTestCase, self).setUp()
329
self.patch(aggregator, "ToggleableNotification",
330
FakeNotificationSingleton())
331
self.clock = PatchedClock()
333
class ProgressBarTestCase(TestCase):
334
"""Tests for the progress bar."""
336
+ @defer.inlineCallbacks
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)
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))
354
def connection_made(self):
355
"""The client made the connection to the server."""
356
@@ -1033,8 +1047,10 @@
360
+ @defer.inlineCallbacks
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)
367
@@ -1177,8 +1193,10 @@
368
class StatusAggregatorTestCase(TestCase):
369
"""Test the backend of the status aggregator."""
371
+ @defer.inlineCallbacks
373
"""Initialize this test instance."""
374
+ yield super(StatusAggregatorTestCase, self).setUp()
375
self.patch(aggregator, "FileDiscoveryBubble",
376
FakeFileDiscoveryBubble)
377
self.patch(aggregator, "FinalStatusBubble",
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)
386
+class FakeMagicHash(object):
387
+ """Fake magic hash."""
388
+ _magic_hash = '666'
391
class FakeTempFile(object):
392
"""Fake temporary file."""
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)
401
class FakeCommand(object):
404
class FakeRequest(object):
406
- def __init__(self):
407
+ def __init__(self, *a, **k):
408
self.deferred = defer.succeed(True)
409
self.cancelled = False
412
class TestRequestQueue(TwistedTestCase):
413
"""Tests for the RequestQueue."""
415
+ @defer.inlineCallbacks
418
+ yield super(TestRequestQueue, self).setUp()
420
class FakeAQ(object):
423
class TestDeferredMap(TwistedTestCase):
424
"""Test the deferred map."""
426
+ @defer.inlineCallbacks
429
+ yield super(TestDeferredMap, self).setUp()
430
self.dm = DeferredMap()
432
def test_one_get_returns_stored_deferred(self):
434
class TestZipQueue(TwistedTestCase):
435
"""Test the zipping queue."""
437
+ @defer.inlineCallbacks
440
+ yield super(TestZipQueue, self).setUp()
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()
450
- self.action_queue.client.get_content_request = lambda *a, **k: obj
451
+ self.action_queue.client.get_content_request = FakeRequest
453
class FakeFileObjFactory(object):
454
"""Fake class to check behaviour."""
455
@@ -3099,10 +3111,6 @@
457
yield super(UploadUnconnectedTestCase, self).setUp()
459
- class FakeMagicHash(object):
460
- """Fake magic hash."""
461
- _magic_hash = '666'
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()
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)
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
485
+ self.command.finish()
486
+ self.assertEqual(1, self.command.tempfile.closed)
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)
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))
499
+ def test_finish_handles_temp_file_none(self):
500
+ """Test temp file can be None when calling finish."""
501
+ self.command.tempfile = None
503
+ self.command.finish()
504
+ self.assertEqual(self.command.tempfile, None) # nothing changed
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')
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()
520
+ self.command.tempfile = StringIO()
521
+ self.command.tempfile.seek = lambda *a: called.extend(a)
522
+ self.command._run()
523
+ self.assertEqual(called, [0])
526
class CreateShareTestCase(ConnectedBaseTestCase):
527
"""Test for CreateShare ActionQueueCommand."""
528
@@ -4919,8 +4953,10 @@
529
class ActionQueueProtocolTests(TwistedTestCase):
530
"""Test the ACQ class."""
532
+ @defer.inlineCallbacks
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)
543
+ @defer.inlineCallbacks
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."""
554
+ @defer.inlineCallbacks
557
+ yield super(ConditionsLockerTests, self).setUp()
558
self.cl = ConditionsLocker()
560
def test_get_locking_deferred_returns_deferred(self):
561
@@ -5664,8 +5704,11 @@
562
class PingManagerTestCase(TwistedTestCase):
563
"""Test the Ping manager."""
565
+ @defer.inlineCallbacks
568
+ yield super(PingManagerTestCase, self).setUp()
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)
577
+ @defer.inlineCallbacks
580
+ yield super(PingManagerTestCase, self).tearDown()
581
self.fake_aqp.log.removeHandler(self.handler)
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
592
+from twisted.internet import defer
593
from twisted.trial import unittest
595
from ubuntuone.devtools.handlers import MementoHandler
597
class DebugCaptureTest(unittest.TestCase):
598
"""Tests for DebugCapture context manager."""
600
+ @defer.inlineCallbacks
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)
609
+ @defer.inlineCallbacks
611
"""close the handler and restore the logger (Logger's are global)"""
612
+ yield super(DebugCaptureTest, self).tearDown()
614
self.logger.removeHandler(self.handler)
615
self.logger.setLevel(logging.DEBUG)
617
class FilterTests(unittest.TestCase):
618
"""Tests log filters"""
620
+ @defer.inlineCallbacks
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"""
631
+ @defer.inlineCallbacks
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)
640
+ @defer.inlineCallbacks
642
"""close the handler and restore the logger (Logger's are global)"""
643
+ yield super(MultiFilterTest, self).tearDown()
645
self.logger.removeHandler(self.handler)
646
self.logger.setLevel(logging.DEBUG)
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
652
class InternalDeferredTests(TwistedTestCase):
653
"""Test the internal deferreds handling functionality."""
655
+ @defer.inlineCallbacks
658
+ yield super(InternalDeferredTests, self).setUp()
659
self.plt = PathLockingTree()
661
def test_single_element_old(self):
663
class LockingTests(TwistedTestCase):
664
"""Test the locking between elements."""
666
+ @defer.inlineCallbacks
669
+ yield super(LockingTests, self).setUp()
670
self.plt = PathLockingTree()
672
@defer.inlineCallbacks
674
class CleaningTests(TwistedTestCase):
675
"""Test that the releases clean the tree."""
677
+ @defer.inlineCallbacks
680
+ yield super(CleaningTests, self).setUp()
681
self.plt = PathLockingTree()
683
@defer.inlineCallbacks
685
class LoggingTests(TwistedTestCase):
686
"""Test the logging."""
688
+ @defer.inlineCallbacks
691
+ yield super(LoggingTests, self).setUp()
692
self.plt = PathLockingTree()
694
self.handler = MementoHandler()
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
700
class Base(TwistedTestCase):
701
"""Base class for state tests."""
703
+ @defer.inlineCallbacks
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)
713
+ @defer.inlineCallbacks
715
+ yield super(Base, self).tearDown()
716
self.sm.connection.shutdown()
719
class QueueBase(Base):
720
"""Basic setup for QueueManager."""
722
+ @defer.inlineCallbacks
725
+ yield super(QueueBase, self).setUp()
726
self.sm.state = StateManager.QUEUE_MANAGER
730
class TestConnectionManager(Base):
731
"""Test the "internal network" transitions."""
733
+ @defer.inlineCallbacks
736
+ yield super(TestConnectionManager, self).setUp()
738
# put SM on some state that does not generate further
739
# transition-related efforts for this CM
741
class TestConnectionManagerTimings(Base):
742
"""Times handled by ConnectionManager."""
744
+ @defer.inlineCallbacks
747
+ yield super(TestConnectionManagerTimings, self).setUp()
749
# set timeout values to really low, to make tests run quicker
750
self.sm.connection.handshake_timeout = 0
752
class TestStateManagerPassToNetworkManager(Base):
753
"""All network events should go to NetworkManager."""
755
+ @defer.inlineCallbacks
758
+ yield super(TestStateManagerPassToNetworkManager,
761
# put a function in the middle to log calls
762
self.called_events = []
764
class TestStateManagerPassToQueueManager(Base):
765
"""All queue events should go to QueueManager."""
767
+ @defer.inlineCallbacks
770
+ yield super(TestStateManagerPassToQueueManager,
773
# put a function in the middle to log calls
774
self.called_events = []
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
780
class StatusListenerTestCase(FakeMainTestCase):
781
"""Tests for StatusListener."""
783
+ @defer.inlineCallbacks
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)
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
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
805
EREGEX = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$"
807
# progress threshold to emit a download/upload progress event: 64Kb
808
-TRANSFER_PROGRESS_THRESHOLD = 64*1024*1024
811
- """Pass the value on for the next deferred, while calling func with it."""
820
+TRANSFER_PROGRESS_THRESHOLD = 64 * 1024 * 1024
823
class DeferredInterrupted(Exception):
825
self.errback(DeferredInterrupted())
829
class PathLockingTree(object):
830
"""Tree that stores deferreds in the nodes."""
833
node, element = branch.pop()
834
del node['children_nodes'][element]
837
# finally, log and release the deferred
838
logger.debug("pathlock releasing %s; remaining: %d", elements,
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',
852
magic_hasher.update(data)
853
upload.deflated_size = f.tell()
855
- # keep the file open, but reset its position
856
- # to zero, ready to be read later
859
upload.magic_hash = magic_hasher.content_hash()
860
- except Exception, e: # pylint: disable-msg=W0703
861
+ except Exception, e: # pylint: disable-msg=W0703
863
reactor.callFromThread(deferred.errback, e)
865
@@ -705,10 +688,10 @@
869
- self.client = None # an instance of self.protocol
870
+ self.client = None # an instance of self.protocol
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)
894
class ChangePublicAccess(ActionQueueCommand):
895
"""Change the public access of a file."""
897
@@ -2498,6 +2480,11 @@
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)
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,
914
+ self.tempfile.seek(0)
915
f = UploadProgressWrapper(self.tempfile, self)
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
923
- d.addBoth(passit(lambda _: self.tempfile.close()))
925
+ return req.deferred
927
def _upload_id_cb(self, upload_id):
928
"""Handle the received upload_id, save it in the metadata."""
929
@@ -2545,9 +2530,6 @@
931
def handle_success(self, request):
932
"""It worked! Push the event."""
933
- # remove the temporary file
934
- remove_file(self.tempfile.name)
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 @@
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,