Merge lp:~nataliabidart/ubuntuone-client/yield-around into lp:ubuntuone-client

Proposed by Natalia Bidart
Status: Merged
Approved by: Natalia Bidart
Approved revision: 838
Merged at revision: 836
Proposed branch: lp:~nataliabidart/ubuntuone-client/yield-around
Merge into: lp:ubuntuone-client
Diff against target: 2089 lines (+383/-282)
10 files modified
tests/eventlog/test_zg_listener.py (+9/-7)
tests/platform/linux/test_dbus.py (+150/-106)
tests/platform/linux/test_filesystem_notifications.py (+14/-7)
tests/platform/linux/test_tools.py (+4/-3)
tests/syncdaemon/test_eq_inotify.py (+10/-7)
tests/syncdaemon/test_fsm.py (+113/-84)
tests/syncdaemon/test_localrescan.py (+61/-44)
tests/syncdaemon/test_status_listener.py (+5/-5)
tests/syncdaemon/test_sync.py (+8/-9)
tests/syncdaemon/test_u1sdtool.py (+9/-10)
To merge this branch: bzr merge lp:~nataliabidart/ubuntuone-client/yield-around
Reviewer Review Type Date Requested Status
Roberto Alsina (community) Approve
Eric Casteleijn (community) Approve
Review via email: mp+48504@code.launchpad.net

Commit message

- volume_manager.add_share returns a deferred now, yield on it (part of bug LP: #708335).

- Fix tests that were finishing before the dbus call was completed (LP: #689677).

To post a comment you must log in.
837. By Natalia Bidart

Merged trunk in.

838. By Natalia Bidart

ZG tests should also yield on vm.add_share.

Revision history for this message
Eric Casteleijn (thisfred) wrote :

Looks good!

review: Approve
Revision history for this message
Roberto Alsina (ralsina) wrote :

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'tests/eventlog/test_zg_listener.py'
--- tests/eventlog/test_zg_listener.py 2011-01-28 15:23:20 +0000
+++ tests/eventlog/test_zg_listener.py 2011-02-03 17:29:42 +0000
@@ -213,7 +213,7 @@
213 self.main.fs.set_node_id(path, sample_node_id)213 self.main.fs.set_node_id(path, sample_node_id)
214 share = Shared(path=path, volume_id=sample_share_id,214 share = Shared(path=path, volume_id=sample_share_id,
215 node_id=sample_node_id, other_username=fake_username)215 node_id=sample_node_id, other_username=fake_username)
216 self.vm.add_shared(share)216 yield self.vm.add_shared(share)
217217
218 def fake_delete_share(share_id):218 def fake_delete_share(share_id):
219 """Fake delete_share."""219 """Fake delete_share."""
@@ -250,6 +250,7 @@
250 self.assertEqual(other_user.manifestation,250 self.assertEqual(other_user.manifestation,
251 MANIFESTATION_U1_CONTACT_DATA_OBJECT)251 MANIFESTATION_U1_CONTACT_DATA_OBJECT)
252252
253 @defer.inlineCallbacks
253 def test_share_accepted_is_logged(self):254 def test_share_accepted_is_logged(self):
254 """Test that an accepted share event is logged."""255 """Test that an accepted share event is logged."""
255 # initialize the the root256 # initialize the the root
@@ -260,7 +261,7 @@
260 share_path = os.path.join(self.shares_dir, 'fake_share')261 share_path = os.path.join(self.shares_dir, 'fake_share')
261 share = Share(path=share_path, volume_id='volume_id', node_id="node_id",262 share = Share(path=share_path, volume_id='volume_id', node_id="node_id",
262 other_username=fake_username)263 other_username=fake_username)
263 self.vm.add_share(share)264 yield self.vm.add_share(share)
264265
265 self.assertEqual(len(self.listener.zg.events), 1)266 self.assertEqual(len(self.listener.zg.events), 1)
266 event = self.listener.zg.events[0]267 event = self.listener.zg.events[0]
@@ -300,7 +301,8 @@
300 fake_username,301 fake_username,
301 u'visible_name', 'Read')302 u'visible_name', 'Read')
302303
303 self.main.vm.add_share(Share.from_notify_holder(holder, share_path))304 share = Share.from_notify_holder(holder, share_path)
305 yield self.main.vm.add_share(share)
304 self._listen_for('VM_VOLUME_DELETED', d.callback, 1, collect=True)306 self._listen_for('VM_VOLUME_DELETED', d.callback, 1, collect=True)
305 self.main.event_q.push('SV_SHARE_DELETED', share_id=holder.share_id)307 self.main.event_q.push('SV_SHARE_DELETED', share_id=holder.share_id)
306 yield d308 yield d
@@ -1092,8 +1094,8 @@
1092 public_url = 'http://example.com/foo.mp3'1094 public_url = 'http://example.com/foo.mp3'
10931095
1094 share_path = os.path.join(self.shares_dir, 'share')1096 share_path = os.path.join(self.shares_dir, 'share')
1095 self.main.vm.add_share(Share(path=share_path, volume_id='share',1097 yield self.main.vm.add_share(Share(path=share_path, volume_id='share',
1096 other_username='other username'))1098 other_username='other username'))
1097 path = os.path.join(share_path, "foo.mp3")1099 path = os.path.join(share_path, "foo.mp3")
1098 self.main.fs.create(path, str(share_id))1100 self.main.fs.create(path, str(share_id))
1099 self.main.fs.set_node_id(path, str(node_id))1101 self.main.fs.set_node_id(path, str(node_id))
@@ -1132,8 +1134,8 @@
1132 public_url = 'http://example.com/foo.mp3'1134 public_url = 'http://example.com/foo.mp3'
11331135
1134 share_path = os.path.join(self.shares_dir, 'share')1136 share_path = os.path.join(self.shares_dir, 'share')
1135 self.main.vm.add_share(Share(path=share_path, volume_id='share',1137 yield self.main.vm.add_share(Share(path=share_path, volume_id='share',
1136 other_username='other username'))1138 other_username='other username'))
1137 path = os.path.join(share_path, "foo.mp3")1139 path = os.path.join(share_path, "foo.mp3")
1138 self.main.fs.create(path, str(share_id))1140 self.main.fs.create(path, str(share_id))
1139 self.main.fs.set_node_id(path, str(node_id))1141 self.main.fs.set_node_id(path, str(node_id))
11401142
=== modified file 'tests/platform/linux/test_dbus.py'
--- tests/platform/linux/test_dbus.py 2011-02-02 13:10:59 +0000
+++ tests/platform/linux/test_dbus.py 2011-02-03 17:29:42 +0000
@@ -424,10 +424,11 @@
424424
425 return d425 return d
426426
427 @defer.inlineCallbacks
427 def test_get_metadata_path(self):428 def test_get_metadata_path(self):
428 """Test the FileSystem Object, getting MD by path."""429 """Test the FileSystem Object, getting MD by path."""
429 share_path = os.path.join(self.shares_dir, 'share')430 share_path = os.path.join(self.shares_dir, 'share')
430 self.main.vm.add_share(Share(path=share_path, volume_id='share'))431 yield self.main.vm.add_share(Share(path=share_path, volume_id='share'))
431 path = os.path.join(share_path, "foo")432 path = os.path.join(share_path, "foo")
432 self.fs_manager.create(path, "share")433 self.fs_manager.create(path, "share")
433 self.fs_manager.set_node_id(path, "node_id")434 self.fs_manager.set_node_id(path, "node_id")
@@ -446,12 +447,13 @@
446 client = DBusClient(self.bus, '/filesystem', DBUS_IFACE_FS_NAME)447 client = DBusClient(self.bus, '/filesystem', DBUS_IFACE_FS_NAME)
447 client.call_method('get_metadata', path, reply_handler=handler,448 client.call_method('get_metadata', path, reply_handler=handler,
448 error_handler=self.error_handler)449 error_handler=self.error_handler)
449 return d450 yield d
450451
452 @defer.inlineCallbacks
451 def test_get_metadata_path_symlink(self):453 def test_get_metadata_path_symlink(self):
452 """Test the FileSystem Object, getting MD by path in a symlink."""454 """Test the FileSystem Object, getting MD by path in a symlink."""
453 share_path = os.path.join(self.shares_dir, 'share')455 share_path = os.path.join(self.shares_dir, 'share')
454 self.main.vm.add_share(Share(path=share_path, volume_id='share'))456 yield self.main.vm.add_share(Share(path=share_path, volume_id='share'))
455 path = os.path.join(share_path, "foo")457 path = os.path.join(share_path, "foo")
456 symlink_path = os.path.join(self.shares_dir, "share_symlink")458 symlink_path = os.path.join(self.shares_dir, "share_symlink")
457 share_context = self.main.fs._enable_share_write('share',459 share_context = self.main.fs._enable_share_write('share',
@@ -468,7 +470,8 @@
468470
469 def callback(result):471 def callback(result):
470 """Callback to check the result."""472 """Callback to check the result."""
471 self.assertEquals(os.path.join(symlink_path, 'foo'), str(result['path']))473 self.assertEquals(os.path.join(symlink_path, 'foo'),
474 str(result['path']))
472 self.assertEquals('share', result['share_id'])475 self.assertEquals('share', result['share_id'])
473 self.assertEquals('node_id', result['node_id'])476 self.assertEquals('node_id', result['node_id'])
474477
@@ -477,12 +480,13 @@
477 client.call_method('get_metadata', os.path.join(symlink_path, 'foo'),480 client.call_method('get_metadata', os.path.join(symlink_path, 'foo'),
478 reply_handler=handler,481 reply_handler=handler,
479 error_handler=self.error_handler)482 error_handler=self.error_handler)
480 return d483 yield d
481484
485 @defer.inlineCallbacks
482 def test_get_metadata_share_node(self):486 def test_get_metadata_share_node(self):
483 """Test the FileSystem Object, getting MD by share and node."""487 """Test the FileSystem Object, getting MD by share and node."""
484 share_path = os.path.join(self.shares_dir, 'share')488 share_path = os.path.join(self.shares_dir, 'share')
485 self.main.vm.add_share(Share(path=share_path, volume_id='share'))489 yield self.main.vm.add_share(Share(path=share_path, volume_id='share'))
486 path = os.path.join(share_path, "foo")490 path = os.path.join(share_path, "foo")
487 self.fs_manager.create(path, "share")491 self.fs_manager.create(path, "share")
488 self.fs_manager.set_node_id(path, "node_id")492 self.fs_manager.set_node_id(path, "node_id")
@@ -502,7 +506,7 @@
502 client.call_method('get_metadata_by_node', 'share', 'node_id',506 client.call_method('get_metadata_by_node', 'share', 'node_id',
503 reply_handler=handler,507 reply_handler=handler,
504 error_handler=self.error_handler)508 error_handler=self.error_handler)
505 return d509 yield d
506510
507 def test_push_event(self):511 def test_push_event(self):
508 """Test the exposed method: push_event."""512 """Test the exposed method: push_event."""
@@ -540,6 +544,7 @@
540 self.event_q.add_empty_event_queue_callback(empty_queue_cb)544 self.event_q.add_empty_event_queue_callback(empty_queue_cb)
541 return push_deferred545 return push_deferred
542546
547 @defer.inlineCallbacks
543 def test_waiting_content(self):548 def test_waiting_content(self):
544 """Test Status.waiting_content.549 """Test Status.waiting_content.
545550
@@ -552,7 +557,8 @@
552557
553 # prepare the VM so it lies for us558 # prepare the VM so it lies for us
554 share_path = os.path.join(self.shares_dir, 'share')559 share_path = os.path.join(self.shares_dir, 'share')
555 self.main.vm.add_share(Share(path=share_path, volume_id='share_id'))560 share = Share(path=share_path, volume_id='share_id')
561 yield self.main.vm.add_share(share)
556 b_path = os.path.join(share_path, "path_b")562 b_path = os.path.join(share_path, "path_b")
557 c_path = os.path.join(share_path, "path_c")563 c_path = os.path.join(share_path, "path_c")
558 self.fs_manager.create(b_path, "share_id")564 self.fs_manager.create(b_path, "share_id")
@@ -582,13 +588,15 @@
582 client.call_method('waiting_content',588 client.call_method('waiting_content',
583 reply_handler=waiting_handler,589 reply_handler=waiting_handler,
584 error_handler=self.error_handler)590 error_handler=self.error_handler)
585 return d591 yield d
586592
593 @defer.inlineCallbacks
587 def test_waiting_metadata(self):594 def test_waiting_metadata(self):
588 """Test Status.waiting_metadata with fake data in the AQ."""595 """Test Status.waiting_metadata with fake data in the AQ."""
589 # prepare the VM so it lies for us596 # prepare the VM so it lies for us
590 share_path = os.path.join(self.shares_dir, 'share')597 share_path = os.path.join(self.shares_dir, 'share')
591 self.main.vm.add_share(Share(path=share_path, volume_id='share_id'))598 share = Share(path=share_path, volume_id='share_id')
599 yield self.main.vm.add_share(share)
592 b_path = os.path.join(share_path, "path_b")600 b_path = os.path.join(share_path, "path_b")
593 c_path = os.path.join(share_path, "path_c")601 c_path = os.path.join(share_path, "path_c")
594 d_path = os.path.join(share_path, "path_d")602 d_path = os.path.join(share_path, "path_d")
@@ -635,15 +643,17 @@
635 client.call_method('waiting_metadata',643 client.call_method('waiting_metadata',
636 reply_handler=waiting_handler,644 reply_handler=waiting_handler,
637 error_handler=self.error_handler)645 error_handler=self.error_handler)
638 return d646 yield d
639647
648 @defer.inlineCallbacks
640 def test_get_metadata_and_quick_tree_not_synced(self):649 def test_get_metadata_and_quick_tree_not_synced(self):
641 """Test Status.get_metadata_and_quick_tree_status.650 """Test Status.get_metadata_and_quick_tree_status.
642651
643 Fake data in the AQ is used.652 Fake data in the AQ is used.
644 """653 """
645 share_path = os.path.join(self.shares_dir, 'share')654 share_path = os.path.join(self.shares_dir, 'share')
646 self.main.vm.add_share(Share(path=share_path, volume_id='share'))655 share = Share(path=share_path, volume_id='share')
656 yield self.main.vm.add_share(share)
647 path = os.path.join(share_path, u'ñoño'.encode('utf-8'))657 path = os.path.join(share_path, u'ñoño'.encode('utf-8'))
648 self.fs_manager.create(path, "share")658 self.fs_manager.create(path, "share")
649 self.fs_manager.set_node_id(path, "node_id")659 self.fs_manager.set_node_id(path, "node_id")
@@ -669,15 +679,16 @@
669 client.call_method('get_metadata_and_quick_tree_synced',679 client.call_method('get_metadata_and_quick_tree_synced',
670 path, reply_handler=handler,680 path, reply_handler=handler,
671 error_handler=self.error_handler)681 error_handler=self.error_handler)
672 return d682 yield d
673683
684 @defer.inlineCallbacks
674 def test_get_metadata_and_quick_tree_no_blow_up_kthxbye(self):685 def test_get_metadata_and_quick_tree_no_blow_up_kthxbye(self):
675 """Test Status.get_metadata_and_quick_tree_status.686 """Test Status.get_metadata_and_quick_tree_status.
676687
677 Fake data in the AQ is used.688 Fake data in the AQ is used.
678 """689 """
679 share_path = os.path.join(self.shares_dir, 'share')690 share_path = os.path.join(self.shares_dir, 'share')
680 self.main.vm.add_share(Share(path=share_path, volume_id='share'))691 yield self.main.vm.add_share(Share(path=share_path, volume_id='share'))
681 path = os.path.join(share_path, u'ñoño'.encode('utf-8'))692 path = os.path.join(share_path, u'ñoño'.encode('utf-8'))
682 self.fs_manager.create(path, "share")693 self.fs_manager.create(path, "share")
683 self.fs_manager.set_node_id(path, "node_id")694 self.fs_manager.set_node_id(path, "node_id")
@@ -704,15 +715,16 @@
704 client.call_method('get_metadata_and_quick_tree_synced',715 client.call_method('get_metadata_and_quick_tree_synced',
705 path, reply_handler=handler,716 path, reply_handler=handler,
706 error_handler=self.error_handler)717 error_handler=self.error_handler)
707 return d718 yield d
708719
720 @defer.inlineCallbacks
709 def test_get_metadata_and_quick_tree_not_synced_2(self):721 def test_get_metadata_and_quick_tree_not_synced_2(self):
710 """Test Status.get_metadata_and_quick_tree_status.722 """Test Status.get_metadata_and_quick_tree_status.
711723
712 Fake data in the AQ is used.724 Fake data in the AQ is used.
713 """725 """
714 share_path = os.path.join(self.shares_dir, 'share')726 share_path = os.path.join(self.shares_dir, 'share')
715 self.main.vm.add_share(Share(path=share_path, volume_id='share'))727 yield self.main.vm.add_share(Share(path=share_path, volume_id='share'))
716 path = os.path.join(share_path, u'ñoño'.encode('utf-8'))728 path = os.path.join(share_path, u'ñoño'.encode('utf-8'))
717 self.fs_manager.create(path, "share")729 self.fs_manager.create(path, "share")
718 self.fs_manager.set_node_id(path, "node_id")730 self.fs_manager.set_node_id(path, "node_id")
@@ -738,13 +750,14 @@
738 client.call_method('get_metadata_and_quick_tree_synced',750 client.call_method('get_metadata_and_quick_tree_synced',
739 path, reply_handler=handler,751 path, reply_handler=handler,
740 error_handler=self.error_handler)752 error_handler=self.error_handler)
741 return d753 yield d
742754
755 @defer.inlineCallbacks
743 def test_get_metadata_and_quick_tree_synced(self):756 def test_get_metadata_and_quick_tree_synced(self):
744 """Test Status.get_metadata_and_quick_tree_status757 """Test Status.get_metadata_and_quick_tree_status
745 without fake data in the AQ."""758 without fake data in the AQ."""
746 share_path = os.path.join(self.shares_dir, 'share')759 share_path = os.path.join(self.shares_dir, 'share')
747 self.main.vm.add_share(Share(path=share_path, volume_id='share'))760 yield self.main.vm.add_share(Share(path=share_path, volume_id='share'))
748 path = os.path.join(share_path, u'ñoño'.encode('utf-8'))761 path = os.path.join(share_path, u'ñoño'.encode('utf-8'))
749 self.fs_manager.create(path, "share")762 self.fs_manager.create(path, "share")
750 self.fs_manager.set_node_id(path, "node_id")763 self.fs_manager.set_node_id(path, "node_id")
@@ -766,13 +779,14 @@
766 client.call_method('get_metadata_and_quick_tree_synced',779 client.call_method('get_metadata_and_quick_tree_synced',
767 path, reply_handler=handler,780 path, reply_handler=handler,
768 error_handler=self.error_handler)781 error_handler=self.error_handler)
769 return d782 yield d
770783
784 @defer.inlineCallbacks
771 def test_get_metadata_and_quick_tree_synced_symlink(self):785 def test_get_metadata_and_quick_tree_synced_symlink(self):
772 """Test Status.get_metadata_and_quick_tree_status786 """Test Status.get_metadata_and_quick_tree_status
773 without fake data in the AQ."""787 without fake data in the AQ."""
774 share_path = os.path.join(self.shares_dir, 'share')788 share_path = os.path.join(self.shares_dir, 'share')
775 self.main.vm.add_share(Share(path=share_path, volume_id='share'))789 yield self.main.vm.add_share(Share(path=share_path, volume_id='share'))
776 path = os.path.join(share_path, u'ñoño'.encode('utf-8'))790 path = os.path.join(share_path, u'ñoño'.encode('utf-8'))
777 self.fs_manager.create(path, "share")791 self.fs_manager.create(path, "share")
778 self.fs_manager.set_node_id(path, "node_id")792 self.fs_manager.set_node_id(path, "node_id")
@@ -801,7 +815,7 @@
801 client.call_method('get_metadata_and_quick_tree_synced',815 client.call_method('get_metadata_and_quick_tree_synced',
802 expected_path, reply_handler=handler,816 expected_path, reply_handler=handler,
803 error_handler=self.error_handler)817 error_handler=self.error_handler)
804 return d818 yield d
805819
806 def test_content_queue_added(self):820 def test_content_queue_added(self):
807 """Test the signal because a command was added to the queue."""821 """Test the signal because a command was added to the queue."""
@@ -831,10 +845,12 @@
831 self.main.event_q.push('SYS_QUEUE_REMOVED', FakeCommand())845 self.main.event_q.push('SYS_QUEUE_REMOVED', FakeCommand())
832 return d846 return d
833847
848 @defer.inlineCallbacks
834 def test_current_downloads(self):849 def test_current_downloads(self):
835 """Test Status.current_downloads with fake data in the AQ."""850 """Test Status.current_downloads with fake data in the AQ."""
836 share_path = os.path.join(self.shares_dir, 'share')851 share_path = os.path.join(self.shares_dir, 'share')
837 self.main.vm.add_share(Share(path=share_path, volume_id='share_id'))852 share = Share(path=share_path, volume_id='share_id')
853 yield self.main.vm.add_share(share)
838 down_path = os.path.join(share_path, "down_path")854 down_path = os.path.join(share_path, "down_path")
839 self.fs_manager.create(down_path, "share_id")855 self.fs_manager.create(down_path, "share_id")
840 self.fs_manager.set_node_id(down_path, "node_id")856 self.fs_manager.set_node_id(down_path, "node_id")
@@ -853,12 +869,14 @@
853 client.call_method('current_downloads',869 client.call_method('current_downloads',
854 reply_handler=downloads_handler,870 reply_handler=downloads_handler,
855 error_handler=self.error_handler)871 error_handler=self.error_handler)
856 return d872 yield d
857873
874 @defer.inlineCallbacks
858 def test_current_uploads(self):875 def test_current_uploads(self):
859 """Test Status.current_uploads with fake data in the AQ."""876 """Test Status.current_uploads with fake data in the AQ."""
860 share_path = os.path.join(self.shares_dir, 'share')877 share_path = os.path.join(self.shares_dir, 'share')
861 self.main.vm.add_share(Share(path=share_path, volume_id='share_id'))878 share = Share(path=share_path, volume_id='share_id')
879 yield self.main.vm.add_share(share)
862 up_path = os.path.join(share_path, "up_path")880 up_path = os.path.join(share_path, "up_path")
863 self.fs_manager.create(up_path, "share_id")881 self.fs_manager.create(up_path, "share_id")
864 self.fs_manager.set_node_id(up_path, "node_id")882 self.fs_manager.set_node_id(up_path, "node_id")
@@ -877,7 +895,7 @@
877895
878 client.call_method('current_uploads', reply_handler=uploads_handler,896 client.call_method('current_uploads', reply_handler=uploads_handler,
879 error_handler=self.error_handler)897 error_handler=self.error_handler)
880 return d898 yield d
881899
882 def test_current_uploads_with_marker(self):900 def test_current_uploads_with_marker(self):
883 """Test Status.current_uploads with fake data in the AQ."""901 """Test Status.current_uploads with fake data in the AQ."""
@@ -895,17 +913,20 @@
895 error_handler=self.error_handler)913 error_handler=self.error_handler)
896 return d914 return d
897915
916 @defer.inlineCallbacks
898 def test_two_current_downloads(self):917 def test_two_current_downloads(self):
899 """Test Status.current_downloads with fake data in the AQ."""918 """Test Status.current_downloads with fake data in the AQ."""
900 share_path = os.path.join(self.shares_dir, 'share')919 share_path = os.path.join(self.shares_dir, 'share')
901 self.main.vm.add_share(Share(path=share_path, volume_id='share_id'))920 share = Share(path=share_path, volume_id='share_id')
921 yield self.main.vm.add_share(share)
902 down_path = os.path.join(share_path, "down_path")922 down_path = os.path.join(share_path, "down_path")
903 self.fs_manager.create(down_path, "share_id")923 self.fs_manager.create(down_path, "share_id")
904 self.fs_manager.set_node_id(down_path, "node_id")924 self.fs_manager.set_node_id(down_path, "node_id")
905 self.action_q.downloading[('share_id', 'node_id')] = dict(925 self.action_q.downloading[('share_id', 'node_id')] = dict(
906 deflated_size=10, size=100, n_bytes_read=8)926 deflated_size=10, size=100, n_bytes_read=8)
907 share1_path = os.path.join(self.shares_dir, 'share1')927 share1_path = os.path.join(self.shares_dir, 'share1')
908 self.main.vm.add_share(Share(path=share1_path, volume_id='share_id_1'))928 share1 = Share(path=share1_path, volume_id='share_id_1')
929 yield self.main.vm.add_share(share1)
909 down_path_1 = os.path.join(share1_path, "down_path_1")930 down_path_1 = os.path.join(share1_path, "down_path_1")
910 self.fs_manager.create(down_path_1, "share_id_1")931 self.fs_manager.create(down_path_1, "share_id_1")
911 self.fs_manager.set_node_id(down_path_1, "node_id_1")932 self.fs_manager.set_node_id(down_path_1, "node_id_1")
@@ -927,19 +948,22 @@
927 client.call_method('current_downloads',948 client.call_method('current_downloads',
928 reply_handler=downloads_handler,949 reply_handler=downloads_handler,
929 error_handler=self.error_handler)950 error_handler=self.error_handler)
930 return d951 yield d
931952
953 @defer.inlineCallbacks
932 def test_two_current_uploads(self):954 def test_two_current_uploads(self):
933 """Test Status.current_uploads with fake data in the AQ."""955 """Test Status.current_uploads with fake data in the AQ."""
934 share_path = os.path.join(self.shares_dir, 'share')956 share_path = os.path.join(self.shares_dir, 'share')
935 self.main.vm.add_share(Share(path=share_path, volume_id='share_id'))957 share = Share(path=share_path, volume_id='share_id')
958 yield self.main.vm.add_share(share)
936 up_path = os.path.join(share_path, "up_path")959 up_path = os.path.join(share_path, "up_path")
937 self.fs_manager.create(up_path, "share_id")960 self.fs_manager.create(up_path, "share_id")
938 self.fs_manager.set_node_id(up_path, "node_id")961 self.fs_manager.set_node_id(up_path, "node_id")
939 self.action_q.uploading[('share_id', 'node_id')] = dict(962 self.action_q.uploading[('share_id', 'node_id')] = dict(
940 deflated_size=100, n_bytes_written=10)963 deflated_size=100, n_bytes_written=10)
941 share1_path = os.path.join(self.shares_dir, 'share1')964 share1_path = os.path.join(self.shares_dir, 'share1')
942 self.main.vm.add_share(Share(path=share1_path, volume_id='share_id_1'))965 share1 = Share(path=share1_path, volume_id='share_id_1')
966 yield self.main.vm.add_share(share1)
943 up_path_1 = os.path.join(share1_path, "up_path_1")967 up_path_1 = os.path.join(share1_path, "up_path_1")
944 self.fs_manager.create(up_path_1, "share_id_1")968 self.fs_manager.create(up_path_1, "share_id_1")
945 self.fs_manager.set_node_id(up_path_1, "node_id_1")969 self.fs_manager.set_node_id(up_path_1, "node_id_1")
@@ -961,12 +985,14 @@
961985
962 client.call_method('current_uploads', reply_handler=uploads_handler,986 client.call_method('current_uploads', reply_handler=uploads_handler,
963 error_handler=self.error_handler)987 error_handler=self.error_handler)
964 return d988 yield d
965989
990 @defer.inlineCallbacks
966 def test_current_downloads_deflated_size_NA(self):991 def test_current_downloads_deflated_size_NA(self):
967 """Test Status.current_downloads with fake data in the AQ."""992 """Test Status.current_downloads with fake data in the AQ."""
968 share_path = os.path.join(self.shares_dir, 'share')993 share_path = os.path.join(self.shares_dir, 'share')
969 self.main.vm.add_share(Share(path=share_path, volume_id='share_id'))994 share = Share(path=share_path, volume_id='share_id')
995 yield self.main.vm.add_share(share)
970 down_path = os.path.join(share_path, "down_path")996 down_path = os.path.join(share_path, "down_path")
971 self.fs_manager.create(down_path, "share_id")997 self.fs_manager.create(down_path, "share_id")
972 self.fs_manager.set_node_id(down_path, "node_id")998 self.fs_manager.set_node_id(down_path, "node_id")
@@ -984,12 +1010,14 @@
984 client.call_method('current_downloads',1010 client.call_method('current_downloads',
985 reply_handler=downloads_handler,1011 reply_handler=downloads_handler,
986 error_handler=self.error_handler)1012 error_handler=self.error_handler)
987 return d1013 yield d
9881014
1015 @defer.inlineCallbacks
989 def test_current_uploads_deflated_size_NA(self):1016 def test_current_uploads_deflated_size_NA(self):
990 """Test Status.current_uploads with fake data in the AQ."""1017 """Test Status.current_uploads with fake data in the AQ."""
991 share_path = os.path.join(self.shares_dir, 'share')1018 share_path = os.path.join(self.shares_dir, 'share')
992 self.main.vm.add_share(Share(path=share_path, volume_id='share_id'))1019 share = Share(path=share_path, volume_id='share_id')
1020 yield self.main.vm.add_share(share)
993 up_path = os.path.join(share_path, "up_path")1021 up_path = os.path.join(share_path, "up_path")
994 self.fs_manager.create(up_path, "share_id")1022 self.fs_manager.create(up_path, "share_id")
995 self.fs_manager.set_node_id(up_path, "node_id")1023 self.fs_manager.set_node_id(up_path, "node_id")
@@ -1007,7 +1035,7 @@
10071035
1008 client.call_method('current_uploads', reply_handler=uploads_handler,1036 client.call_method('current_uploads', reply_handler=uploads_handler,
1009 error_handler=self.error_handler)1037 error_handler=self.error_handler)
1010 return d1038 yield d
10111039
1012 def test_nm_signals(self):1040 def test_nm_signals(self):
1013 """Test that NM signals are received and handled properly."""1041 """Test that NM signals are received and handled properly."""
@@ -1036,11 +1064,13 @@
1036 self.event_q.add_empty_event_queue_callback(empty_queue_cb)1064 self.event_q.add_empty_event_queue_callback(empty_queue_cb)
1037 return d1065 return d
10381066
1067 @defer.inlineCallbacks
1039 def test_get_shares(self):1068 def test_get_shares(self):
1040 """Test Shares.get_shares method."""1069 """Test Shares.get_shares method."""
1041 share_path = os.path.join(self.main.shares_dir, 'share')1070 share_path = os.path.join(self.main.shares_dir, 'share')
1042 self.main.vm.add_share(Share(path=share_path, volume_id='share_id',1071 share = Share(path=share_path, volume_id='share_id',
1043 access_level='Read', accepted=False))1072 access_level='Read', accepted=False)
1073 yield self.main.vm.add_share(share)
1044 client = DBusClient(self.bus, '/shares', DBUS_IFACE_SHARES_NAME)1074 client = DBusClient(self.bus, '/shares', DBUS_IFACE_SHARES_NAME)
1045 d = defer.Deferred()1075 d = defer.Deferred()
1046 def check(shares):1076 def check(shares):
@@ -1056,19 +1086,21 @@
1056 self.assertEquals('share_id', str(share['volume_id']))1086 self.assertEquals('share_id', str(share['volume_id']))
1057 self.assertEquals(share_path, str(share['path']))1087 self.assertEquals(share_path, str(share['path']))
1058 self.assertEquals('Read', str(share['access_level']))1088 self.assertEquals('Read', str(share['access_level']))
1059 self.assertEquals('False', str(share['accepted']))1089 self.assertEquals('', str(share['accepted']))
10601090
1061 def shares_handler(shares):1091 def shares_handler(shares):
1062 d.callback(shares)1092 d.callback(shares)
10631093
1064 client.call_method('get_shares', reply_handler=shares_handler,1094 client.call_method('get_shares', reply_handler=shares_handler,
1065 error_handler=self.error_handler)1095 error_handler=self.error_handler)
1066 return d1096 d.addCallback(check)
1097 yield d
10671098
1099 @defer.inlineCallbacks
1068 def test_accept_share(self):1100 def test_accept_share(self):
1069 """Test the accept_share method in dbus_interface.Share."""1101 """Test the accept_share method in dbus_interface.Share."""
1070 share_path = os.path.join(self.main.shares_dir, 'share')1102 share_path = os.path.join(self.main.shares_dir, 'share')
1071 self.main.vm.add_share(Share(path=share_path, volume_id='share_id',1103 yield self.main.vm.add_share(Share(path=share_path, volume_id='share_id',
1072 access_level='Read', accepted=False,1104 access_level='Read', accepted=False,
1073 node_id="node_id"))1105 node_id="node_id"))
1074 self.assertEquals(False, self.main.vm.shares['share_id'].accepted)1106 self.assertEquals(False, self.main.vm.shares['share_id'].accepted)
@@ -1088,12 +1120,13 @@
1088 self.assertEquals(True, self.main.vm.shares['share_id'].accepted)1120 self.assertEquals(True, self.main.vm.shares['share_id'].accepted)
10891121
1090 d.addCallback(check)1122 d.addCallback(check)
1091 return d1123 yield d
10921124
1125 @defer.inlineCallbacks
1093 def test_reject_share(self):1126 def test_reject_share(self):
1094 """Test the reject_share method in dbus_interface.Share."""1127 """Test the reject_share method in dbus_interface.Share."""
1095 share_path = os.path.join(self.main.shares_dir, 'share')1128 share_path = os.path.join(self.main.shares_dir, 'share')
1096 self.main.vm.add_share(Share(path=share_path, volume_id='share_id',1129 yield self.main.vm.add_share(Share(path=share_path, volume_id='share_id',
1097 access_level='Read', accepted=False))1130 access_level='Read', accepted=False))
1098 self.assertEquals(False, self.main.vm.shares['share_id'].accepted)1131 self.assertEquals(False, self.main.vm.shares['share_id'].accepted)
1099 client = DBusClient(self.bus, '/shares', DBUS_IFACE_SHARES_NAME)1132 client = DBusClient(self.bus, '/shares', DBUS_IFACE_SHARES_NAME)
@@ -1112,7 +1145,7 @@
1112 self.assertEquals(False, self.main.vm.shares['share_id'].accepted)1145 self.assertEquals(False, self.main.vm.shares['share_id'].accepted)
11131146
1114 d.addCallback(check)1147 d.addCallback(check)
1115 return d1148 yield d
11161149
1117 def test_get_root(self):1150 def test_get_root(self):
1118 """Check SycnDaemon.get_root exposed method."""1151 """Check SycnDaemon.get_root exposed method."""
@@ -1349,18 +1382,20 @@
1349 share = Share(path=share_path, volume_id=str(uuid.uuid4()),1382 share = Share(path=share_path, volume_id=str(uuid.uuid4()),
1350 access_level='Modify', accepted=True,1383 access_level='Modify', accepted=True,
1351 node_id=str(uuid.uuid4()))1384 node_id=str(uuid.uuid4()))
1352 self.main.vm.add_share(share)1385 yield self.main.vm.add_share(share)
1353 client = DBusClient(self.bus, '/', DBUS_IFACE_SYNC_NAME)1386 client = DBusClient(self.bus, '/', DBUS_IFACE_SYNC_NAME)
1387
1388 rescan_d = defer.Deferred()
1389 self.main.action_q.rescan_from_scratch = rescan_d.callback
1390
1354 d = defer.Deferred()1391 d = defer.Deferred()
1355 def fake_rescan_from_scratch(volume_id):
1356 """Stub method."""
1357 d.callback(volume_id)
1358 self.main.action_q.rescan_from_scratch = fake_rescan_from_scratch
1359 d.addCallback(self.assertTrue)
1360 client.call_method('rescan_from_scratch', share.volume_id,1392 client.call_method('rescan_from_scratch', share.volume_id,
1361 reply_handler=lambda _: None,1393 reply_handler=d.callback,
1362 error_handler=d.errback)1394 error_handler=d.errback)
1363 vol_id = yield d1395
1396 yield d
1397
1398 vol_id = yield rescan_d
1364 self.assertEqual(vol_id, share.volume_id)1399 self.assertEqual(vol_id, share.volume_id)
13651400
1366 @defer.inlineCallbacks1401 @defer.inlineCallbacks
@@ -1422,13 +1457,14 @@
1422class DBusInterfaceUnicodeTests(DBusTwistedTestCase):1457class DBusInterfaceUnicodeTests(DBusTwistedTestCase):
1423 """Unicode variant of basic tests to the objects exposed with D-Bus."""1458 """Unicode variant of basic tests to the objects exposed with D-Bus."""
14241459
1460 @defer.inlineCallbacks
1425 def test_filesystem_unicode(self):1461 def test_filesystem_unicode(self):
1426 """Test the FileSystem Object, registering it to the session bus.1462 """Test the FileSystem Object, registering it to the session bus.
14271463
1428 Excercise the API.1464 Excercise the API.
1429 """1465 """
1430 share_path = os.path.join(self.shares_dir, 'share')1466 share_path = os.path.join(self.shares_dir, 'share')
1431 self.main.vm.add_share(Share(path=share_path, volume_id='share'))1467 yield self.main.vm.add_share(Share(path=share_path, volume_id='share'))
1432 path = os.path.join(share_path, u'ñoño'.encode('utf-8'))1468 path = os.path.join(share_path, u'ñoño'.encode('utf-8'))
1433 self.fs_manager.create(path, "share")1469 self.fs_manager.create(path, "share")
1434 self.fs_manager.set_node_id(path, "node_id")1470 self.fs_manager.set_node_id(path, "node_id")
@@ -1447,7 +1483,7 @@
1447 client = DBusClient(self.bus, '/filesystem', DBUS_IFACE_FS_NAME)1483 client = DBusClient(self.bus, '/filesystem', DBUS_IFACE_FS_NAME)
1448 client.call_method('get_metadata', path, reply_handler=handler,1484 client.call_method('get_metadata', path, reply_handler=handler,
1449 error_handler=self.error_handler)1485 error_handler=self.error_handler)
1450 return d1486 yield d
14511487
1452 def test_create_share_unicode(self):1488 def test_create_share_unicode(self):
1453 """Test share offering."""1489 """Test share offering."""
@@ -1480,6 +1516,7 @@
1480 error_handler=self.error_handler)1516 error_handler=self.error_handler)
1481 return d1517 return d
14821518
1519 @defer.inlineCallbacks
1483 def test_get_shared_unicode(self):1520 def test_get_shared_unicode(self):
1484 """Test that list_shared method behaves with unicode data."""1521 """Test that list_shared method behaves with unicode data."""
1485 a_dir = os.path.join(self.root_dir, u'ñoño'.encode('utf-8'))1522 a_dir = os.path.join(self.root_dir, u'ñoño'.encode('utf-8'))
@@ -1488,7 +1525,7 @@
1488 share = Shared(path=a_dir, volume_id='shared_id', name=u'ñoño_shared',1525 share = Shared(path=a_dir, volume_id='shared_id', name=u'ñoño_shared',
1489 access_level='View', other_username=u'test_username',1526 access_level='View', other_username=u'test_username',
1490 node_id='node_id')1527 node_id='node_id')
1491 self.main.vm.add_shared(share)1528 yield self.main.vm.add_shared(share)
1492 client = DBusClient(self.bus, '/shares', DBUS_IFACE_SHARES_NAME)1529 client = DBusClient(self.bus, '/shares', DBUS_IFACE_SHARES_NAME)
1493 d = defer.Deferred()1530 d = defer.Deferred()
14941531
@@ -1504,7 +1541,7 @@
1504 d.addCallback(check)1541 d.addCallback(check)
1505 client.call_method('get_shared',1542 client.call_method('get_shared',
1506 reply_handler=d.callback, error_handler=d.errback)1543 reply_handler=d.callback, error_handler=d.errback)
1507 return d1544 yield d
15081545
15091546
1510class DBusSignalTest(DBusTwistedTestCase):1547class DBusSignalTest(DBusTwistedTestCase):
@@ -1823,6 +1860,7 @@
1823 node_id='node', path=None, mdid=None)1860 node_id='node', path=None, mdid=None)
1824 return d1861 return d
18251862
1863 @defer.inlineCallbacks
1826 def test_share_changed(self):1864 def test_share_changed(self):
1827 """Test the ShareChanged signal."""1865 """Test the ShareChanged signal."""
1828 share_path = os.path.join(self.main.shares_dir, 'share')1866 share_path = os.path.join(self.main.shares_dir, 'share')
@@ -1831,7 +1869,7 @@
1831 u'test_username',1869 u'test_username',
1832 u'visible_name', 'Write')1870 u'visible_name', 'Write')
18331871
1834 self.main.vm.add_share(Share(path=share_path,1872 yield self.main.vm.add_share(Share(path=share_path,
1835 volume_id=str(share_holder.share_id),1873 volume_id=str(share_holder.share_id),
1836 node_id=str(share_holder.subtree),1874 node_id=str(share_holder.subtree),
1837 access_level='Read', accepted=False))1875 access_level='Read', accepted=False))
@@ -1850,8 +1888,9 @@
1850 signal_name='ShareChanged')1888 signal_name='ShareChanged')
1851 self.signal_receivers.add(match)1889 self.signal_receivers.add(match)
1852 self.main.event_q.push('SV_SHARE_CHANGED', info=share_holder)1890 self.main.event_q.push('SV_SHARE_CHANGED', info=share_holder)
1853 return d1891 yield d
18541892
1893 @defer.inlineCallbacks
1855 def test_share_deleted(self):1894 def test_share_deleted(self):
1856 """Test the ShareDeleted signal."""1895 """Test the ShareDeleted signal."""
1857 share_path = os.path.join(self.main.shares_dir, 'share')1896 share_path = os.path.join(self.main.shares_dir, 'share')
@@ -1859,15 +1898,11 @@
1859 u'fake_share',1898 u'fake_share',
1860 u'test_username',1899 u'test_username',
1861 u'visible_name', 'Read')1900 u'visible_name', 'Read')
18621901 share = Share.from_notify_holder(share_holder, share_path)
1863 self.main.vm.add_share(Share.from_notify_holder(share_holder, share_path))1902 yield self.main.vm.add_share(share)
1864 d = defer.Deferred()1903 d = defer.Deferred()
1865 def share_handler(share_dict):1904 match = self.bus.add_signal_receiver(d.callback,
1866 """Handler for ShareDeletedsignal."""1905 signal_name='ShareDeleted')
1867 d.callback(share_dict)
1868
1869 match = self.bus.add_signal_receiver(share_handler,
1870 signal_name='ShareDeleted')
1871 self.signal_receivers.add(match)1906 self.signal_receivers.add(match)
18721907
1873 def check(share_dict):1908 def check(share_dict):
@@ -1888,13 +1923,9 @@
1888 self.assertEquals(expected_dict[str(k)], str(v))1923 self.assertEquals(expected_dict[str(k)], str(v))
1889 d.addCallback(check)1924 d.addCallback(check)
18901925
1891 match = self.bus.add_signal_receiver(share_handler,
1892 signal_name='ShareDeleted')
1893 self.signal_receivers.add(match)
1894
1895 self.main.event_q.push('SV_SHARE_DELETED',1926 self.main.event_q.push('SV_SHARE_DELETED',
1896 share_id=share_holder.share_id)1927 share_id=share_holder.share_id)
1897 return d1928 yield d
18981929
1899 def test_share_created(self):1930 def test_share_created(self):
1900 """Test the ShareCreated signal."""1931 """Test the ShareCreated signal."""
@@ -1960,6 +1991,7 @@
1960 new_generation='new_generation')1991 new_generation='new_generation')
1961 return d1992 return d
19621993
1994 @defer.inlineCallbacks
1963 def test_new_share(self):1995 def test_new_share(self):
1964 """Test the NewShare signal."""1996 """Test the NewShare signal."""
1965 share_path = os.path.join(self.main.shares_dir, 'share')1997 share_path = os.path.join(self.main.shares_dir, 'share')
@@ -1996,9 +2028,10 @@
1996 for k, v in share_dict.items():2028 for k, v in share_dict.items():
1997 self.assertEquals(expected_dict[str(k)], str(v))2029 self.assertEquals(expected_dict[str(k)], str(v))
1998 d.addCallback(check)2030 d.addCallback(check)
1999 self.main.vm.add_share(share)2031 yield self.main.vm.add_share(share)
2000 return d2032 yield d
20012033
2034 @defer.inlineCallbacks
2002 def test_public_access_changed(self):2035 def test_public_access_changed(self):
2003 """Test the PublicAccessChanged signal."""2036 """Test the PublicAccessChanged signal."""
2004 d = defer.Deferred()2037 d = defer.Deferred()
@@ -2016,7 +2049,7 @@
2016 public_url = 'http://example.com'2049 public_url = 'http://example.com'
20172050
2018 share_path = os.path.join(self.shares_dir, 'share')2051 share_path = os.path.join(self.shares_dir, 'share')
2019 self.main.vm.add_share(Share(path=share_path, volume_id='share'))2052 yield self.main.vm.add_share(Share(path=share_path, volume_id='share'))
2020 path = os.path.join(share_path, "foo")2053 path = os.path.join(share_path, "foo")
2021 self.fs_manager.create(path, str(share_id))2054 self.fs_manager.create(path, str(share_id))
2022 self.fs_manager.set_node_id(path, str(node_id))2055 self.fs_manager.set_node_id(path, str(node_id))
@@ -2033,8 +2066,9 @@
2033 self.event_q.push('AQ_CHANGE_PUBLIC_ACCESS_OK',2066 self.event_q.push('AQ_CHANGE_PUBLIC_ACCESS_OK',
2034 share_id=share_id, node_id=node_id,2067 share_id=share_id, node_id=node_id,
2035 is_public=is_public, public_url=public_url)2068 is_public=is_public, public_url=public_url)
2036 return d2069 yield d
20372070
2071 @defer.inlineCallbacks
2038 def test_public_access_change_error(self):2072 def test_public_access_change_error(self):
2039 """Test the PublicAccessChangeError signal."""2073 """Test the PublicAccessChangeError signal."""
2040 d = defer.Deferred()2074 d = defer.Deferred()
@@ -2051,7 +2085,7 @@
2051 expected_error = 'error message'2085 expected_error = 'error message'
20522086
2053 share_path = os.path.join(self.shares_dir, 'share')2087 share_path = os.path.join(self.shares_dir, 'share')
2054 self.main.vm.add_share(Share(path=share_path, volume_id='share'))2088 yield self.main.vm.add_share(Share(path=share_path, volume_id='share'))
2055 path = os.path.join(share_path, "foo")2089 path = os.path.join(share_path, "foo")
2056 self.fs_manager.create(path, str(share_id))2090 self.fs_manager.create(path, str(share_id))
2057 self.fs_manager.set_node_id(path, str(node_id))2091 self.fs_manager.set_node_id(path, str(node_id))
@@ -2067,7 +2101,7 @@
2067 self.event_q.push('AQ_CHANGE_PUBLIC_ACCESS_ERROR',2101 self.event_q.push('AQ_CHANGE_PUBLIC_ACCESS_ERROR',
2068 share_id=share_id, node_id=node_id,2102 share_id=share_id, node_id=node_id,
2069 error=expected_error)2103 error=expected_error)
2070 return d2104 yield d
20712105
2072 def test_root_mismatch(self):2106 def test_root_mismatch(self):
2073 """Test RootMismatch signal."""2107 """Test RootMismatch signal."""
@@ -2089,6 +2123,7 @@
2089 self.main.vm._got_root('another_root_id')2123 self.main.vm._got_root('another_root_id')
2090 return d2124 return d
20912125
2126 @defer.inlineCallbacks
2092 def test_public_files_list(self):2127 def test_public_files_list(self):
2093 """Test the PublicAccessChanged signal."""2128 """Test the PublicAccessChanged signal."""
2094 d = defer.Deferred()2129 d = defer.Deferred()
@@ -2105,7 +2140,8 @@
2105 public_url = 'http://example.com'2140 public_url = 'http://example.com'
21062141
2107 share_path = os.path.join(self.shares_dir, 'share')2142 share_path = os.path.join(self.shares_dir, 'share')
2108 self.main.vm.add_share(Share(path=share_path, volume_id=volume_id))2143 share = Share(path=share_path, volume_id=volume_id)
2144 yield self.main.vm.add_share(share)
2109 path = os.path.join(share_path, "foo")2145 path = os.path.join(share_path, "foo")
2110 self.fs_manager.create(path, str(volume_id))2146 self.fs_manager.create(path, str(volume_id))
2111 self.fs_manager.set_node_id(path, str(node_id))2147 self.fs_manager.set_node_id(path, str(node_id))
@@ -2120,7 +2156,7 @@
2120 d.addCallback(check)2156 d.addCallback(check)
2121 pf = dict(volume_id=volume_id, node_id=node_id, public_url=public_url)2157 pf = dict(volume_id=volume_id, node_id=node_id, public_url=public_url)
2122 self.event_q.push('AQ_PUBLIC_FILES_LIST_OK', public_files=[pf])2158 self.event_q.push('AQ_PUBLIC_FILES_LIST_OK', public_files=[pf])
2123 return d2159 yield d
21242160
2125 def test_public_files_list_error(self):2161 def test_public_files_list_error(self):
2126 """Test the PublicFilesListError signal."""2162 """Test the PublicFilesListError signal."""
@@ -2164,16 +2200,17 @@
2164 volume_id=volume_id, free_bytes=123)2200 volume_id=volume_id, free_bytes=123)
2165 return d2201 return d
21662202
2203 @defer.inlineCallbacks
2167 def test_quota_exceeded_for_share(self):2204 def test_quota_exceeded_for_share(self):
2168 """Test QuotaExceeded signal for share."""2205 """Test QuotaExceeded signal for share."""
2169 volume_id = 'test this please'2206 volume_id = 'test this please'
2170 path = 'test/path/bla'2207 path = 'test/path/bla'
2171 name = 'Beatiful Stranger'2208 name = 'Beatiful Stranger'
2172 a_share = Share(volume_id=volume_id, node_id=None, path=path, name=name,2209 share = Share(volume_id=volume_id, node_id=None, path=path, name=name,
2173 other_username=None, other_visible_name=None,2210 other_username=None, other_visible_name=None,
2174 accepted=False, access_level='View', free_bytes=None)2211 accepted=False, access_level='View', free_bytes=None)
2175 self.main.vm.add_share(a_share)2212 yield self.main.vm.add_share(share)
2176 return self.assert_quota_exceeded(volume_id, _get_share_dict(a_share))2213 yield self.assert_quota_exceeded(volume_id, _get_share_dict(share))
21772214
2178 def test_quota_exceeded_for_udf(self):2215 def test_quota_exceeded_for_udf(self):
2179 """Test QuotaExceeded signal for UDF."""2216 """Test QuotaExceeded signal for UDF."""
@@ -2972,11 +3009,12 @@
2972 'VM_UDF_CREATE_ERROR', path=path, error="I'm broken")3009 'VM_UDF_CREATE_ERROR', path=path, error="I'm broken")
2973 return d3010 return d
29743011
3012 @defer.inlineCallbacks
2975 def test_delete(self):3013 def test_delete(self):
2976 """Test for Folders.delete."""3014 """Test for Folders.delete."""
2977 suggested_path = u'~/ñoño'3015 suggested_path = u'~/ñoño'
2978 udf = self._create_udf(uuid.uuid4(), 'node_id', suggested_path)3016 udf = self._create_udf(uuid.uuid4(), 'node_id', suggested_path)
2979 self.main.vm.add_udf(udf)3017 yield self.main.vm.add_udf(udf)
2980 d = defer.Deferred()3018 d = defer.Deferred()
2981 def delete_volume(volume_id, path):3019 def delete_volume(volume_id, path):
2982 """Fake delete_volume."""3020 """Fake delete_volume."""
@@ -3001,13 +3039,14 @@
3001 self.folders_client.call_method('delete', udf.volume_id,3039 self.folders_client.call_method('delete', udf.volume_id,
3002 reply_handler=check_deleted,3040 reply_handler=check_deleted,
3003 error_handler=self.error_handler)3041 error_handler=self.error_handler)
3004 return d3042 yield d
30053043
3044 @defer.inlineCallbacks
3006 def test_delete_error_signal(self):3045 def test_delete_error_signal(self):
3007 """Test for FolderDeleteError."""3046 """Test for FolderDeleteError."""
3008 suggested_path = u'~/ñoño'3047 suggested_path = u'~/ñoño'
3009 udf = self._create_udf(uuid.uuid4(), 'node_id', suggested_path)3048 udf = self._create_udf(uuid.uuid4(), 'node_id', suggested_path)
3010 self.main.vm.add_udf(udf)3049 yield self.main.vm.add_udf(udf)
3011 d = defer.Deferred()3050 d = defer.Deferred()
3012 # patch delete_volume to fail3051 # patch delete_volume to fail
3013 def delete_volume(volume_id, path):3052 def delete_volume(volume_id, path):
@@ -3026,8 +3065,8 @@
3026 self.folders_client.call_method('delete', udf.volume_id,3065 self.folders_client.call_method('delete', udf.volume_id,
3027 reply_handler=lambda *args: None,3066 reply_handler=lambda *args: None,
3028 error_handler=self.error_handler)3067 error_handler=self.error_handler)
3029 d.addCallback(lambda _: self.main.vm.udf_deleted(udf.volume_id))3068 yield d
3030 return d3069 self.main.vm.udf_deleted(udf.volume_id)
30313070
3032 @defer.inlineCallbacks3071 @defer.inlineCallbacks
3033 def test_delete_error_signal_folder_id(self):3072 def test_delete_error_signal_folder_id(self):
@@ -3120,36 +3159,38 @@
3120 d.addCallback(lambda _: self.main.vm.udf_deleted(udf.volume_id))3159 d.addCallback(lambda _: self.main.vm.udf_deleted(udf.volume_id))
3121 yield d3160 yield d
31223161
3162 @defer.inlineCallbacks
3123 def test_refresh_volumes(self):3163 def test_refresh_volumes(self):
3124 """Just check that refresh_volumes method works."""3164 """Just check that refresh_volumes method works."""
3125 client = DBusClient(self.bus, '/folders', DBUS_IFACE_FOLDERS_NAME)3165 client = DBusClient(self.bus, '/folders', DBUS_IFACE_FOLDERS_NAME)
3166 list_volumes_d = defer.Deferred()
3167 self.main.action_q.list_volumes = lambda: list_volumes_d.callback(True)
3168
3126 d = defer.Deferred()3169 d = defer.Deferred()
3127 def list_volumes():
3128 """Stub list_volumes."""
3129 d.callback(True)
3130 self.main.action_q.list_volumes = list_volumes
3131 client.call_method('refresh_volumes',3170 client.call_method('refresh_volumes',
3132 reply_handler=lambda _: None,3171 reply_handler=d.callback,
3133 error_handler=self.error_handler)3172 error_handler=self.error_handler)
3134 return d3173 yield list_volumes_d
3174 yield d
31353175
31363176
3137class ShareTests(DBusTwistedTestCase):3177class ShareTests(DBusTwistedTestCase):
3138 """Share specific tests."""3178 """Share specific tests."""
31393179
3180 @defer.inlineCallbacks
3140 def test_delete_share(self):3181 def test_delete_share(self):
3141 """Test for Shares.delete_share."""3182 """Test for Shares.delete_share."""
3142 share_path = os.path.join(self.main.shares_dir, 'share')3183 share_path = os.path.join(self.main.shares_dir, 'share')
3143 share = Share(path=share_path, volume_id='share_id',3184 share = Share(path=share_path, volume_id='share_id',
3144 node_id='node_id', accepted=True)3185 node_id='node_id', accepted=True)
3145 self.main.vm.add_share(share)3186 yield self.main.vm.add_share(share)
3146 d = defer.Deferred()3187 d = defer.Deferred()
3147 def delete_volume(volume_id, path):3188 def delete_volume(volume_id, path):
3148 """Fake delete_volume."""3189 """Fake delete_volume."""
3149 self.main.event_q.push("AQ_DELETE_VOLUME_OK", volume_id=volume_id)3190 self.main.event_q.push("AQ_DELETE_VOLUME_OK", volume_id=volume_id)
3150 self.main.action_q.delete_volume = delete_volume3191 self.main.action_q.delete_volume = delete_volume
3151 def deleted_handler(info):3192 def deleted_handler(info):
3152 """FolderDeleted handler."""3193 """ShareDeleted handler."""
3153 self.assertRaises(KeyError, self.main.fs.get_by_path,3194 self.assertRaises(KeyError, self.main.fs.get_by_path,
3154 info['path'].decode('utf-8'))3195 info['path'].decode('utf-8'))
3155 self.assertRaises(VolumeDoesNotExist,3196 self.assertRaises(VolumeDoesNotExist,
@@ -3168,14 +3209,15 @@
3168 client.call_method('delete_share', share.volume_id,3209 client.call_method('delete_share', share.volume_id,
3169 reply_handler=check_deleted,3210 reply_handler=check_deleted,
3170 error_handler=self.error_handler)3211 error_handler=self.error_handler)
3171 return d3212 yield d
31723213
3214 @defer.inlineCallbacks
3173 def test_delete_share_from_me(self):3215 def test_delete_share_from_me(self):
3174 """Test for Shares.delete_share with share from_me."""3216 """Test for Shares.delete_share with share from_me."""
3175 share_path = os.path.join(self.main.shares_dir, 'share')3217 share_path = os.path.join(self.main.shares_dir, 'share')
3176 share = Shared(path=share_path, volume_id='share_id',3218 share = Shared(path=share_path, volume_id='share_id',
3177 node_id='node_id', accepted=True)3219 node_id='node_id', accepted=True)
3178 self.main.vm.add_shared(share)3220 yield self.main.vm.add_shared(share)
3179 d = defer.Deferred()3221 d = defer.Deferred()
3180 def delete_share(volume_id):3222 def delete_share(volume_id):
3181 """Fake delete_volume."""3223 """Fake delete_volume."""
@@ -3193,14 +3235,15 @@
3193 client.call_method('delete_share', share.volume_id,3235 client.call_method('delete_share', share.volume_id,
3194 reply_handler=lambda _: None,3236 reply_handler=lambda _: None,
3195 error_handler=self.error_handler)3237 error_handler=self.error_handler)
3196 return d3238 yield d
31973239
3240 @defer.inlineCallbacks
3198 def test_delete_share_error_signal(self):3241 def test_delete_share_error_signal(self):
3199 """Test for Shares.delete_share with an error."""3242 """Test for Shares.delete_share with an error."""
3200 share_path = os.path.join(self.main.shares_dir, 'share')3243 share_path = os.path.join(self.main.shares_dir, 'share')
3201 share = Share(path=share_path, volume_id='share_id',3244 share = Share(path=share_path, volume_id='share_id',
3202 node_id='node_id', accepted=True)3245 node_id='node_id', accepted=True)
3203 self.main.vm.add_share(share)3246 yield self.main.vm.add_share(share)
3204 d = defer.Deferred()3247 d = defer.Deferred()
3205 # patch delete_volume to fail3248 # patch delete_volume to fail
3206 def delete_volume(volume_id, path):3249 def delete_volume(volume_id, path):
@@ -3209,7 +3252,7 @@
3209 volume_id=volume_id, error="I'm broken")3252 volume_id=volume_id, error="I'm broken")
3210 self.main.action_q.delete_volume = delete_volume3253 self.main.action_q.delete_volume = delete_volume
3211 def deleted_error_handler(info, error):3254 def deleted_error_handler(info, error):
3212 """FolderDeleteError handler."""3255 """ShareDeleteError handler."""
3213 self.assertEquals(info['volume_id'], share.volume_id)3256 self.assertEquals(info['volume_id'], share.volume_id)
3214 self.assertEquals(error, "I'm broken")3257 self.assertEquals(error, "I'm broken")
3215 d.callback(True)3258 d.callback(True)
@@ -3220,14 +3263,15 @@
3220 client.call_method('delete_share', share.volume_id,3263 client.call_method('delete_share', share.volume_id,
3221 reply_handler=lambda *args: None,3264 reply_handler=lambda *args: None,
3222 error_handler=self.error_handler)3265 error_handler=self.error_handler)
3223 return d3266 yield d
32243267
3268 @defer.inlineCallbacks
3225 def test_delete_share_from_me_error(self):3269 def test_delete_share_from_me_error(self):
3226 """Test failure of Shares.delete_share with a share from_me."""3270 """Test failure of Shares.delete_share with a share from_me."""
3227 share_path = os.path.join(self.main.shares_dir, 'share')3271 share_path = os.path.join(self.main.shares_dir, 'share')
3228 share = Shared(path=share_path, volume_id='share_id',3272 share = Shared(path=share_path, volume_id='share_id',
3229 node_id='node_id', accepted=True)3273 node_id='node_id', accepted=True)
3230 self.main.vm.add_shared(share)3274 yield self.main.vm.add_shared(share)
3231 d = defer.Deferred()3275 d = defer.Deferred()
3232 # patch delete_share to fail3276 # patch delete_share to fail
3233 def delete_share(share_id):3277 def delete_share(share_id):
@@ -3236,7 +3280,7 @@
3236 share_id=share_id, error="I'm broken")3280 share_id=share_id, error="I'm broken")
3237 self.patch(self.main.action_q, 'delete_share', delete_share)3281 self.patch(self.main.action_q, 'delete_share', delete_share)
3238 def deleted_error_handler(info, error):3282 def deleted_error_handler(info, error):
3239 """FolderDeleteError handler."""3283 """ShareDeleteError handler."""
3240 self.assertEquals(info['volume_id'], share.volume_id)3284 self.assertEquals(info['volume_id'], share.volume_id)
3241 self.assertEquals(error, "I'm broken")3285 self.assertEquals(error, "I'm broken")
3242 d.callback(True)3286 d.callback(True)
@@ -3247,14 +3291,14 @@
3247 client.call_method('delete_share', share.volume_id,3291 client.call_method('delete_share', share.volume_id,
3248 reply_handler=lambda *args: None,3292 reply_handler=lambda *args: None,
3249 error_handler=self.error_handler)3293 error_handler=self.error_handler)
3250 return d3294 yield d
32513295
3252 def test_delete_share_from_me_doesnotexist(self):3296 def test_delete_share_from_me_doesnotexist(self):
3253 """Test failure of Shares.delete_share with a share from_me."""3297 """Test failure of Shares.delete_share with a share from_me."""
3254 d = defer.Deferred()3298 d = defer.Deferred()
3255 # patch delete_share to fail3299 # patch delete_share to fail
3256 def deleted_error_handler(info, error):3300 def deleted_error_handler(info, error):
3257 """FolderDeleteError handler."""3301 """ShareDeleteError handler."""
3258 self.assertEquals(info['volume_id'], 'missing_share_id')3302 self.assertEquals(info['volume_id'], 'missing_share_id')
3259 self.assertEquals(error, "DOES_NOT_EXIST")3303 self.assertEquals(error, "DOES_NOT_EXIST")
3260 d.callback(True)3304 d.callback(True)
32613305
=== modified file 'tests/platform/linux/test_filesystem_notifications.py'
--- tests/platform/linux/test_filesystem_notifications.py 2011-01-20 21:27:24 +0000
+++ tests/platform/linux/test_filesystem_notifications.py 2011-02-03 17:29:42 +0000
@@ -291,12 +291,13 @@
291class WatchTests(BaseFSMonitorTestCase):291class WatchTests(BaseFSMonitorTestCase):
292 """Test the EQ API to add and remove watchs."""292 """Test the EQ API to add and remove watchs."""
293293
294 @defer.inlineCallbacks
294 def _create_udf(self, path):295 def _create_udf(self, path):
295 """Create an UDF and returns it and the volume"""296 """Create an UDF and returns it and the volume"""
296 os.makedirs(path)297 os.makedirs(path)
297 udf = volume_manager.UDF("vol_id", "node_id", path.decode('utf-8'),298 udf = volume_manager.UDF("vol_id", "node_id", path.decode('utf-8'),
298 path, True)299 path, True)
299 self.vm.add_udf(udf)300 yield self.vm.add_udf(udf)
300301
301 def test_add_general_watch(self):302 def test_add_general_watch(self):
302 """Test that general watchs can be added."""303 """Test that general watchs can be added."""
@@ -311,11 +312,12 @@
311 # nothing in the udf ancestors watch312 # nothing in the udf ancestors watch
312 self.assertEqual(self.monitor._ancestors_watchs, {})313 self.assertEqual(self.monitor._ancestors_watchs, {})
313314
315 @defer.inlineCallbacks
314 def test_add_watch_on_udf_ancestor(self):316 def test_add_watch_on_udf_ancestor(self):
315 """Test that ancestors watchs can be added."""317 """Test that ancestors watchs can be added."""
316 # create the udf and add the watch318 # create the udf and add the watch
317 path_udf = os.path.join(self.home_dir, "path/to/UDF")319 path_udf = os.path.join(self.home_dir, "path/to/UDF")
318 self._create_udf(path_udf)320 yield self._create_udf(path_udf)
319 path_ancestor = os.path.join(self.home_dir, "path")321 path_ancestor = os.path.join(self.home_dir, "path")
320 self.monitor.add_watch(path_ancestor)322 self.monitor.add_watch(path_ancestor)
321323
@@ -327,22 +329,24 @@
327 # nothing in the general watch329 # nothing in the general watch
328 self.assertEqual(self.monitor._general_watchs, {})330 self.assertEqual(self.monitor._general_watchs, {})
329331
332 @defer.inlineCallbacks
330 def test_add_watch_on_udf_exact(self):333 def test_add_watch_on_udf_exact(self):
331 """Test adding the watch exactly on UDF."""334 """Test adding the watch exactly on UDF."""
332 # create the udf and add the watch335 # create the udf and add the watch
333 path_udf = os.path.join(self.home_dir, "path/to/UDF")336 path_udf = os.path.join(self.home_dir, "path/to/UDF")
334 self._create_udf(path_udf)337 yield self._create_udf(path_udf)
335 self.monitor.add_watch(path_udf)338 self.monitor.add_watch(path_udf)
336339
337 # pylint: disable-msg=W0212340 # pylint: disable-msg=W0212
338 self.assertTrue(path_udf in self.monitor._general_watchs)341 self.assertTrue(path_udf in self.monitor._general_watchs)
339 self.assertEqual(self.monitor._ancestors_watchs, {})342 self.assertEqual(self.monitor._ancestors_watchs, {})
340343
344 @defer.inlineCallbacks
341 def test_add_watch_on_udf_child(self):345 def test_add_watch_on_udf_child(self):
342 """Test adding the watch inside UDF."""346 """Test adding the watch inside UDF."""
343 # create the udf and add the watch347 # create the udf and add the watch
344 path_udf = os.path.join(self.home_dir, "path/to/UDF")348 path_udf = os.path.join(self.home_dir, "path/to/UDF")
345 self._create_udf(path_udf)349 yield self._create_udf(path_udf)
346 path_ancestor = os.path.join(self.home_dir, "path/to/UDF/inside")350 path_ancestor = os.path.join(self.home_dir, "path/to/UDF/inside")
347 os.mkdir(path_ancestor)351 os.mkdir(path_ancestor)
348 self.monitor.add_watch(path_ancestor)352 self.monitor.add_watch(path_ancestor)
@@ -364,12 +368,13 @@
364 self.monitor.rm_watch(not_existing_dir)368 self.monitor.rm_watch(not_existing_dir)
365 self.assertFalse(self.monitor.has_watch(not_existing_dir))369 self.assertFalse(self.monitor.has_watch(not_existing_dir))
366370
371 @defer.inlineCallbacks
367 def test_rm_watch_wrong(self):372 def test_rm_watch_wrong(self):
368 """Test that general watchs can be removed."""373 """Test that general watchs can be removed."""
369 # add two types of watchs374 # add two types of watchs
370 self.monitor.add_watch(self.root_dir)375 self.monitor.add_watch(self.root_dir)
371 path_udf = os.path.join(self.home_dir, "path/to/UDF")376 path_udf = os.path.join(self.home_dir, "path/to/UDF")
372 self._create_udf(path_udf)377 yield self._create_udf(path_udf)
373 path_ancestor = os.path.join(self.home_dir, "path")378 path_ancestor = os.path.join(self.home_dir, "path")
374 self.monitor.add_watch(path_ancestor)379 self.monitor.add_watch(path_ancestor)
375380
@@ -388,11 +393,12 @@
388 self.assertEqual(self.monitor._general_watchs, {})393 self.assertEqual(self.monitor._general_watchs, {})
389 self.assertEqual(self.monitor._ancestors_watchs, {})394 self.assertEqual(self.monitor._ancestors_watchs, {})
390395
396 @defer.inlineCallbacks
391 def test_rm_watch_ancestor(self):397 def test_rm_watch_ancestor(self):
392 """Test that ancestor watchs can be removed."""398 """Test that ancestor watchs can be removed."""
393 # create the udf and add the watch399 # create the udf and add the watch
394 path_udf = os.path.join(self.home_dir, "path/to/UDF")400 path_udf = os.path.join(self.home_dir, "path/to/UDF")
395 self._create_udf(path_udf)401 yield self._create_udf(path_udf)
396 path_ancestor = os.path.join(self.home_dir, "path")402 path_ancestor = os.path.join(self.home_dir, "path")
397 self.monitor.add_watch(path_ancestor)403 self.monitor.add_watch(path_ancestor)
398404
@@ -414,10 +420,11 @@
414 self.monitor.rm_watch(self.root_dir)420 self.monitor.rm_watch(self.root_dir)
415 self.assertFalse(self.monitor.has_watch(self.root_dir))421 self.assertFalse(self.monitor.has_watch(self.root_dir))
416422
423 @defer.inlineCallbacks
417 def test_has_watch_ancestor(self):424 def test_has_watch_ancestor(self):
418 """Test that an ancestor path is watched."""425 """Test that an ancestor path is watched."""
419 path_udf = os.path.join(self.home_dir, "path/to/UDF")426 path_udf = os.path.join(self.home_dir, "path/to/UDF")
420 self._create_udf(path_udf)427 yield self._create_udf(path_udf)
421 path_ancestor = os.path.join(self.home_dir, "path")428 path_ancestor = os.path.join(self.home_dir, "path")
422429
423 self.assertFalse(self.monitor.has_watch(path_ancestor))430 self.assertFalse(self.monitor.has_watch(path_ancestor))
424431
=== modified file 'tests/platform/linux/test_tools.py'
--- tests/platform/linux/test_tools.py 2011-01-17 20:14:09 +0000
+++ tests/platform/linux/test_tools.py 2011-02-03 17:29:42 +0000
@@ -48,14 +48,15 @@
48 self.rmtree(self.home_dir)48 self.rmtree(self.home_dir)
49 return DBusTwistedTestCase.tearDown(self)49 return DBusTwistedTestCase.tearDown(self)
5050
51 @defer.inlineCallbacks
51 def create_file(self, path):52 def create_file(self, path):
52 """ creates a test file in fsm """53 """ creates a test file in fsm """
53 share_path = os.path.join(self.shares_dir, 'share_tools')54 share_path = os.path.join(self.shares_dir, 'share_tools')
54 self.main.vm.add_share(volume_manager.Share(share_path,55 share = volume_manager.Share(share_path, volume_id='tools_share_id')
55 volume_id='tools_share_id'))56 yield self.main.vm.add_share(share)
56 self.fs_manager.create(path, "tools_share_id")57 self.fs_manager.create(path, "tools_share_id")
57 self.fs_manager.set_node_id(path, "node_id")58 self.fs_manager.set_node_id(path, "node_id")
58 return 'tools_share_id', 'node_id'59 defer.returnValue(('tools_share_id', 'node_id'))
5960
6061
61class TestToolsBasic(TestToolsBase):62class TestToolsBasic(TestToolsBase):
6263
=== modified file 'tests/syncdaemon/test_eq_inotify.py'
--- tests/syncdaemon/test_eq_inotify.py 2011-01-12 13:30:03 +0000
+++ tests/syncdaemon/test_eq_inotify.py 2011-02-03 17:29:42 +0000
@@ -1745,23 +1745,25 @@
1745 self._deferred.addCallback(check)1745 self._deferred.addCallback(check)
1746 return self._deferred1746 return self._deferred
17471747
1748 @defer.inlineCallbacks
1748 def _create_udf(self, vol_id, path):1749 def _create_udf(self, vol_id, path):
1749 """Create an UDF and returns it and the volume"""1750 """Create an UDF and returns it and the volume"""
1750 os.makedirs(path)1751 os.makedirs(path)
1751 udf = volume_manager.UDF(vol_id, "node_id", path.decode('utf-8'),1752 udf = volume_manager.UDF(vol_id, "node_id", path.decode('utf-8'),
1752 path, True)1753 path, True)
1753 self.vm.add_udf(udf)1754 yield self.vm.add_udf(udf)
17541755
1756 @defer.inlineCallbacks
1755 def test_move_dir_across_volumes(self):1757 def test_move_dir_across_volumes(self):
1756 """Dir move between volumes is deletion and creation."""1758 """Dir move between volumes is deletion and creation."""
1757 # base dir 11759 # base dir 1
1758 base1 = os.path.join(self.home_dir, "dir1")1760 base1 = os.path.join(self.home_dir, "dir1")
1759 self._create_udf('vol1', base1)1761 yield self._create_udf('vol1', base1)
1760 self.fs.create(path=base1, share_id='vol1', is_dir=True)1762 self.fs.create(path=base1, share_id='vol1', is_dir=True)
17611763
1762 # base dir 21764 # base dir 2
1763 base2 = os.path.join(self.home_dir, "dir2")1765 base2 = os.path.join(self.home_dir, "dir2")
1764 self._create_udf('vol2', base2)1766 yield self._create_udf('vol2', base2)
1765 self.fs.create(path=base2, share_id='vol2', is_dir=True)1767 self.fs.create(path=base2, share_id='vol2', is_dir=True)
17661768
1767 # working stuff1769 # working stuff
@@ -1779,18 +1781,19 @@
17791781
1780 # generate the event1782 # generate the event
1781 os.rename(moving1, moving2)1783 os.rename(moving1, moving2)
1782 return self._deferred1784 yield self._deferred
17831785
1786 @defer.inlineCallbacks
1784 def test_move_file_across_volumes(self):1787 def test_move_file_across_volumes(self):
1785 """File ove between volumes is deletion and creation (and write)."""1788 """File ove between volumes is deletion and creation (and write)."""
1786 # base dir 11789 # base dir 1
1787 base1 = os.path.join(self.home_dir, "dir1")1790 base1 = os.path.join(self.home_dir, "dir1")
1788 self._create_udf('vol1', base1)1791 yield self._create_udf('vol1', base1)
1789 self.fs.create(path=base1, share_id='vol1', is_dir=True)1792 self.fs.create(path=base1, share_id='vol1', is_dir=True)
17901793
1791 # base dir 21794 # base dir 2
1792 base2 = os.path.join(self.home_dir, "dir2")1795 base2 = os.path.join(self.home_dir, "dir2")
1793 self._create_udf('vol2', base2)1796 yield self._create_udf('vol2', base2)
1794 self.fs.create(path=base2, share_id='vol2', is_dir=True)1797 self.fs.create(path=base2, share_id='vol2', is_dir=True)
17951798
1796 # working stuff1799 # working stuff
@@ -1809,7 +1812,7 @@
18091812
1810 # generate the event1813 # generate the event
1811 os.rename(moving1, moving2)1814 os.rename(moving1, moving2)
1812 return self._deferred1815 yield self._deferred
18131816
18141817
1815def test_suite():1818def test_suite():
18161819
=== modified file 'tests/syncdaemon/test_fsm.py'
--- tests/syncdaemon/test_fsm.py 2011-01-20 21:27:24 +0000
+++ tests/syncdaemon/test_fsm.py 2011-02-03 17:29:42 +0000
@@ -26,6 +26,8 @@
26import time26import time
27import unittest27import unittest
2828
29from twisted.internet import defer
30
29from contrib.testing.testcase import (31from contrib.testing.testcase import (
30 BaseTwistedTestCase,32 BaseTwistedTestCase,
31 FakeVolumeManager,33 FakeVolumeManager,
@@ -56,9 +58,21 @@
56BROKEN_PICKLE = '\axb80\x02}q\x01(U\x01aU\x04testq\x02U\x01bU\x06brokenq\x03u.'58BROKEN_PICKLE = '\axb80\x02}q\x01(U\x01aU\x04testq\x02U\x01bU\x06brokenq\x03u.'
5759
5860
61@defer.inlineCallbacks
62def _create_share(share_id, share_name, fsm, shares_dir, access_level='Modify'):
63 """Create a share."""
64 share_path = os.path.join(shares_dir, share_name)
65 os.makedirs(share_path)
66 share = Share(path=share_path, volume_id=share_id,
67 access_level=access_level)
68 yield fsm.vm.add_share(share)
69 defer.returnValue(share)
70
71
59class FSMTestCase(unittest.TestCase):72class FSMTestCase(unittest.TestCase):
60 """ Base test case for FSM """73 """ Base test case for FSM """
6174
75 @defer.inlineCallbacks
62 def setUp(self):76 def setUp(self):
63 """ Setup the test """77 """ Setup the test """
64 unittest.TestCase.setUp(self)78 unittest.TestCase.setUp(self)
@@ -80,8 +94,7 @@
80 FakeVolumeManager(self.root_dir), self.db)94 FakeVolumeManager(self.root_dir), self.db)
81 self.eq = EventQueue(self.fsm)95 self.eq = EventQueue(self.fsm)
82 self.fsm.register_eq(self.eq)96 self.fsm.register_eq(self.eq)
83 self.share = self.create_share('share', 'share_name',97 self.share = yield self.create_share('share', 'share_name')
84 self.fsm, self.shares_dir)
85 self.share_path = self.share.path98 self.share_path = self.share.path
8699
87 # add a in-memory logger handler100 # add a in-memory logger handler
@@ -109,16 +122,17 @@
109 os.chmod(os.path.join(dirpath, dir), 0777)122 os.chmod(os.path.join(dirpath, dir), 0777)
110 shutil.rmtree(path)123 shutil.rmtree(path)
111124
112 @staticmethod125 @defer.inlineCallbacks
113 def create_share(share_id, share_name, fsm, shares_dir,126 def create_share(self, share_id, share_name, fsm=None, shares_dir=None,
114 access_level='Modify'):127 access_level='Modify'):
115 """ creates a share """128 """Create a share."""
116 share_path = os.path.join(shares_dir, share_name)129 if fsm is None:
117 os.makedirs(share_path)130 fsm = self.fsm
118 share = Share(path=share_path, volume_id=share_id,131 if shares_dir is None:
119 access_level=access_level)132 shares_dir = self.shares_dir
120 fsm.vm.add_share(share)133 share = yield _create_share(share_id, share_name, fsm, shares_dir,
121 return share134 access_level)
135 defer.returnValue(share)
122136
123 def create_node(self, name, is_dir=False, share=None):137 def create_node(self, name, is_dir=False, share=None):
124 """Create a node."""138 """Create a node."""
@@ -162,6 +176,7 @@
162 self.assertTrue(os.path.exists(fsmdir))176 self.assertTrue(os.path.exists(fsmdir))
163 db.shutdown()177 db.shutdown()
164178
179 @defer.inlineCallbacks
165 def test_complex_startup(self):180 def test_complex_startup(self):
166 """Test startup after having data."""181 """Test startup after having data."""
167 # pylint: disable-msg=W0212182 # pylint: disable-msg=W0212
@@ -172,8 +187,8 @@
172 db = Tritcask(fsmdir)187 db = Tritcask(fsmdir)
173 fsm = FileSystemManager(fsmdir, partials_dir,188 fsm = FileSystemManager(fsmdir, partials_dir,
174 FakeVolumeManager(fsmdir), db)189 FakeVolumeManager(fsmdir), db)
175 share = FSMTestCase.create_share('share', 'share_name',190 share = yield _create_share('share', 'share_name',
176 fsm, fsmdir)191 fsm=fsm, shares_dir=fsmdir)
177 self.assertEqual(fsm._idx_path, {})192 self.assertEqual(fsm._idx_path, {})
178 self.assertEqual(fsm._idx_node_id, {})193 self.assertEqual(fsm._idx_node_id, {})
179194
@@ -299,6 +314,7 @@
299 md_version = open(os.path.join(self.fsmdir, "metadata_version")).read()314 md_version = open(os.path.join(self.fsmdir, "metadata_version")).read()
300 self.assertEqual(md_version, METADATA_VERSION)315 self.assertEqual(md_version, METADATA_VERSION)
301316
317 @defer.inlineCallbacks
302 def test_old_metadata_None(self):318 def test_old_metadata_None(self):
303 """Test old metadata situation, in None."""319 """Test old metadata situation, in None."""
304 # create some stuff320 # create some stuff
@@ -307,8 +323,7 @@
307 mdid = self.fsm.create(path, "share")323 mdid = self.fsm.create(path, "share")
308 self.fsm.set_node_id(path, "uuid")324 self.fsm.set_node_id(path, "uuid")
309 # create a path with the old layout325 # create a path with the old layout
310 other_share = self.create_share('share1', 'share1_name',326 other_share = yield self.create_share('share1', 'share1_name')
311 self.fsm, self.shares_dir)
312 share_mdid = self.fsm.create(other_share.path, "share1")327 share_mdid = self.fsm.create(other_share.path, "share1")
313 self.fsm.set_node_id(other_share.path, "uuid1")328 self.fsm.set_node_id(other_share.path, "uuid1")
314 os.makedirs(os.path.join(self.root_dir, 'Ubuntu One'))329 os.makedirs(os.path.join(self.root_dir, 'Ubuntu One'))
@@ -358,6 +373,7 @@
358 self.assertFalse(old_path in newfsm._idx_path)373 self.assertFalse(old_path in newfsm._idx_path)
359 db.shutdown()374 db.shutdown()
360375
376 @defer.inlineCallbacks
361 def test_old_metadata_1(self):377 def test_old_metadata_1(self):
362 """Test old metadata situation, in v1."""378 """Test old metadata situation, in v1."""
363 # create some stuff379 # create some stuff
@@ -369,8 +385,7 @@
369 self.fsm.set_node_id(path2, "uuid2")385 self.fsm.set_node_id(path2, "uuid2")
370386
371 # create a path with the old layout387 # create a path with the old layout
372 other_share = self.create_share('share1', 'share1_name',388 other_share = yield self.create_share('share1', 'share1_name')
373 self.fsm, self.shares_dir)
374 share_mdid = self.fsm.create(other_share.path, "share1")389 share_mdid = self.fsm.create(other_share.path, "share1")
375 self.fsm.set_node_id(other_share.path, "uuid1")390 self.fsm.set_node_id(other_share.path, "uuid1")
376 os.makedirs(os.path.join(self.root_dir, 'Ubuntu One'))391 os.makedirs(os.path.join(self.root_dir, 'Ubuntu One'))
@@ -423,6 +438,7 @@
423 self.assertFalse(old_path in newfsm._idx_path)438 self.assertFalse(old_path in newfsm._idx_path)
424 db.shutdown()439 db.shutdown()
425440
441 @defer.inlineCallbacks
426 def test_old_metadata_2(self):442 def test_old_metadata_2(self):
427 """Test old metadata situation, in v2."""443 """Test old metadata situation, in v2."""
428 # create some stuff444 # create some stuff
@@ -430,8 +446,7 @@
430 mdid = self.fsm.create(path, "share")446 mdid = self.fsm.create(path, "share")
431 self.fsm.set_node_id(path, "uuid")447 self.fsm.set_node_id(path, "uuid")
432 # create a path with the old layout448 # create a path with the old layout
433 other_share = self.create_share('share1', 'share1_name',449 other_share = yield self.create_share('share1', 'share1_name')
434 self.fsm, self.shares_dir)
435 share_mdid = self.fsm.create(other_share.path, "share1")450 share_mdid = self.fsm.create(other_share.path, "share1")
436 self.fsm.set_node_id(other_share.path, "uuid1")451 self.fsm.set_node_id(other_share.path, "uuid1")
437 os.makedirs(os.path.join(self.root_dir, 'Ubuntu One'))452 os.makedirs(os.path.join(self.root_dir, 'Ubuntu One'))
@@ -480,6 +495,7 @@
480 self.assertFalse(old_path in newfsm._idx_path)495 self.assertFalse(old_path in newfsm._idx_path)
481 db.shutdown()496 db.shutdown()
482497
498 @defer.inlineCallbacks
483 def test_old_metadata_3(self):499 def test_old_metadata_3(self):
484 """Test old metadata situation, in v3."""500 """Test old metadata situation, in v3."""
485 # create a path with the old layout and metadata501 # create a path with the old layout and metadata
@@ -487,8 +503,7 @@
487 root_mdid = self.fsm.create(self.root_dir, "")503 root_mdid = self.fsm.create(self.root_dir, "")
488 self.fsm.set_node_id(self.root_dir, "uuid")504 self.fsm.set_node_id(self.root_dir, "uuid")
489 # a share505 # a share
490 other_share = self.create_share('share1', 'share1_name',506 other_share = yield self.create_share('share1', 'share1_name')
491 self.fsm, self.shares_dir)
492 share_mdid = self.fsm.create(other_share.path, "share1")507 share_mdid = self.fsm.create(other_share.path, "share1")
493 self.fsm.set_node_id(other_share.path, "uuid1")508 self.fsm.set_node_id(other_share.path, "uuid1")
494 os.makedirs(os.path.join(self.root_dir, 'Ubuntu One'))509 os.makedirs(os.path.join(self.root_dir, 'Ubuntu One'))
@@ -1263,13 +1278,14 @@
1263 mdobj = self.fsm.get_by_node_id("share", "uuid")1278 mdobj = self.fsm.get_by_node_id("share", "uuid")
1264 self.assertEquals(self.share_path, mdobj.path)1279 self.assertEquals(self.share_path, mdobj.path)
12651280
1281 @defer.inlineCallbacks
1266 def test_get_all_by_share(self):1282 def test_get_all_by_share(self):
1267 """ Test that it returns all the mdids in a share. """1283 """ Test that it returns all the mdids in a share. """
1268 # create the shares1284 # create the shares
1269 share1 = self.create_share('share_id1', 'share_name1', self.fsm,1285 share1 = yield self.create_share('share_id1', 'share_name1',
1270 self.shares_dir, access_level='View')1286 access_level='View')
1271 share2 = self.create_share('share_id2', 'share_name2', self.fsm,1287 share2 = yield self.create_share('share_id2', 'share_name2',
1272 self.shares_dir, access_level='View')1288 access_level='View')
1273 self.fsm.create(share1.path, "share_id1", is_dir=True)1289 self.fsm.create(share1.path, "share_id1", is_dir=True)
1274 self.fsm.set_node_id(share1.path, "uuid1")1290 self.fsm.set_node_id(share1.path, "uuid1")
1275 self.fsm.create(share2.path, "share_id2", is_dir=True)1291 self.fsm.create(share2.path, "share_id2", is_dir=True)
@@ -1330,11 +1346,12 @@
1330 self.assertTrue(mdid7 not in all)1346 self.assertTrue(mdid7 not in all)
1331 self.assertTrue(mdid8 not in all)1347 self.assertTrue(mdid8 not in all)
13321348
1349 @defer.inlineCallbacks
1333 def test_get_all_by_share_mixed(self):1350 def test_get_all_by_share_mixed(self):
1334 """Test that it returns all the mdids in a share with mixed nodes."""1351 """Test that it returns all the mdids in a share with mixed nodes."""
1335 # create the shares1352 # create the shares
1336 share = self.create_share('share_id', 'sharetest', self.fsm,1353 share = yield self.create_share('share_id', 'sharetest',
1337 self.shares_dir, access_level='View')1354 access_level='View')
1338 self.fsm.create(share.path, "share_id", is_dir=True)1355 self.fsm.create(share.path, "share_id", is_dir=True)
1339 self.fsm.set_node_id(share.path, "uuid")1356 self.fsm.set_node_id(share.path, "uuid")
13401357
@@ -1441,10 +1458,10 @@
1441 os.path.join(self.share.path, 'a', 'b'))])1458 os.path.join(self.share.path, 'a', 'b'))])
1442 self.assertEqual(expected, actual)1459 self.assertEqual(expected, actual)
14431460
1461 @defer.inlineCallbacks
1444 def test_with_two_shares(self):1462 def test_with_two_shares(self):
1445 """Test having 2 shares."""1463 """Test having 2 shares."""
1446 second_share = self.create_share('second_share', 'the_second',1464 second_share = yield self.create_share('second_share', 'the_second')
1447 self.fsm, self.shares_dir)
1448 self.create_some_contents(second_share)1465 self.create_some_contents(second_share)
14491466
1450 expected = ['a']1467 expected = ['a']
@@ -1452,10 +1469,10 @@
1452 self.fsm.get_mdobjs_in_dir(second_share.path)])1469 self.fsm.get_mdobjs_in_dir(second_share.path)])
1453 self.assertEqual(expected, actual)1470 self.assertEqual(expected, actual)
14541471
1472 @defer.inlineCallbacks
1455 def test_both_shares(self):1473 def test_both_shares(self):
1456 """Test having 2 shares and asking for mdobjs in shares_dir."""1474 """Test having 2 shares and asking for mdobjs in shares_dir."""
1457 second_share = self.create_share('second_share', 'the_second',1475 second_share = yield self.create_share('second_share', 'the_second')
1458 self.fsm, self.shares_dir)
1459 self.create_some_contents(second_share)1476 self.create_some_contents(second_share)
14601477
1461 expected = []1478 expected = []
@@ -1750,14 +1767,14 @@
1750 # it has no partial!1767 # it has no partial!
1751 self.fsm.remove_partial("uuid", "share")1768 self.fsm.remove_partial("uuid", "share")
17521769
1770 @defer.inlineCallbacks
1753 def test_ro_share(self):1771 def test_ro_share(self):
1754 """Test creating a partial of a RO share.1772 """Test creating a partial of a RO share.
17551773
1756 It should leave the partials dir permissions intact.1774 It should leave the partials dir permissions intact.
1757 """1775 """
1758 share = self.create_share('ro_share', 'ro_share_name',1776 share = yield self.create_share('ro_share', 'ro_share_name',
1759 self.fsm, self.shares_dir,1777 access_level='View')
1760 access_level='View')
1761 testdir = os.path.join(share.path, "path")1778 testdir = os.path.join(share.path, "path")
1762 mdid = self.fsm.create(testdir, share.volume_id, is_dir=False)1779 mdid = self.fsm.create(testdir, share.volume_id, is_dir=False)
1763 self.fsm.set_node_id(testdir, "uuid")1780 self.fsm.set_node_id(testdir, "uuid")
@@ -2638,22 +2655,24 @@
2638 self.fsm.make_dir(mdid)2655 self.fsm.make_dir(mdid)
2639 self.assertTrue(os.path.exists(local_dir))2656 self.assertTrue(os.path.exists(local_dir))
26402657
2658 @defer.inlineCallbacks
2641 def test_make_dir_in_ro_share(self):2659 def test_make_dir_in_ro_share(self):
2642 """Also works in a read only share."""2660 """Also works in a read only share."""
2643 share = self.create_share('ro_share_id', 'ro', self.fsm,2661 share = yield self.create_share('ro_share_id', 'ro',
2644 self.shares_dir, access_level='View')2662 access_level='View')
2645 testdir = os.path.join(share.path, "foo")2663 testdir = os.path.join(share.path, "foo")
2646 mdid = self.fsm.create(testdir, 'ro_share_id', is_dir=True)2664 mdid = self.fsm.create(testdir, 'ro_share_id', is_dir=True)
2647 self.fsm.make_dir(mdid)2665 self.fsm.make_dir(mdid)
2648 self.assertTrue(os.path.exists(testdir))2666 self.assertTrue(os.path.exists(testdir))
26492667
2668 @defer.inlineCallbacks
2650 def test_make_dir_ro_watch(self):2669 def test_make_dir_ro_watch(self):
2651 """Don't add the watch nor the mute on a RO share."""2670 """Don't add the watch nor the mute on a RO share."""
2652 called = []2671 called = []
2653 self.eq.add_watch = lambda p: called.append(p)2672 self.eq.add_watch = lambda p: called.append(p)
2654 self.eq.add_to_mute_filter = lambda *a: called.append(a)2673 self.eq.add_to_mute_filter = lambda *a: called.append(a)
2655 share = self.create_share('ro_share_id', 'ro', self.fsm,2674 share = yield self.create_share('ro_share_id', 'ro',
2656 self.shares_dir, access_level='View')2675 access_level='View')
2657 testdir = os.path.join(share.path, "foo")2676 testdir = os.path.join(share.path, "foo")
2658 mdid = self.fsm.create(testdir, 'ro_share_id', is_dir=True)2677 mdid = self.fsm.create(testdir, 'ro_share_id', is_dir=True)
26592678
@@ -2862,17 +2881,19 @@
2862 os.chmod(os.path.join(dirpath, file), 0666)2881 os.chmod(os.path.join(dirpath, file), 0666)
2863 FSMTestCase.tearDown(self)2882 FSMTestCase.tearDown(self)
28642883
2884 @defer.inlineCallbacks
2865 def test_file_ro_share_fail(self):2885 def test_file_ro_share_fail(self):
2866 """ Test that manual creation of a file, fails on a ro-share. """2886 """ Test that manual creation of a file, fails on a ro-share. """
2867 share = self.create_share('ro_share', 'ro_share_name', self.fsm,2887 share = yield self.create_share('ro_share', 'ro_share_name',
2868 self.shares_dir, access_level='View')2888 access_level='View')
2869 testfile = os.path.join(share.path, "a_file")2889 testfile = os.path.join(share.path, "a_file")
2870 self.assertRaises(IOError, open, testfile, 'w')2890 self.assertRaises(IOError, open, testfile, 'w')
28712891
2892 @defer.inlineCallbacks
2872 def test_dir_ro_share(self):2893 def test_dir_ro_share(self):
2873 """ Test that the creation of a file using fsm, works on a ro-share."""2894 """ Test that the creation of a file using fsm, works on a ro-share."""
2874 share = self.create_share('ro_share', 'ro_share_name', self.fsm,2895 share = yield self.create_share('ro_share', 'ro_share_name',
2875 self.shares_dir, access_level='View')2896 access_level='View')
2876 testdir = os.path.join(share.path, "path2")2897 testdir = os.path.join(share.path, "path2")
2877 self.fsm.create(testdir, share.volume_id, is_dir=True)2898 self.fsm.create(testdir, share.volume_id, is_dir=True)
2878 self.fsm.set_node_id(testdir, "uuid2")2899 self.fsm.set_node_id(testdir, "uuid2")
@@ -2882,10 +2903,11 @@
2882 fd.close()2903 fd.close()
2883 self.assertTrue(os.path.exists(testdir))2904 self.assertTrue(os.path.exists(testdir))
28842905
2906 @defer.inlineCallbacks
2885 def test_file_ro_share(self):2907 def test_file_ro_share(self):
2886 """ Test that the creation of a file using fsm, works on a ro-share."""2908 """ Test that the creation of a file using fsm, works on a ro-share."""
2887 self.share = self.create_share('ro_share', 'ro_share_name', self.fsm,2909 self.share = yield self.create_share('ro_share', 'ro_share_name',
2888 self.shares_dir, access_level='View')2910 access_level='View')
2889 testfile = os.path.join(self.share.path, "a_file")2911 testfile = os.path.join(self.share.path, "a_file")
2890 self.fsm.create(testfile, self.share.volume_id, is_dir=False)2912 self.fsm.create(testfile, self.share.volume_id, is_dir=False)
2891 self.fsm.set_node_id(testfile, "uuid3")2913 self.fsm.set_node_id(testfile, "uuid3")
@@ -2896,10 +2918,11 @@
2896 self.fsm.commit_partial('uuid3', self.share.volume_id, None)2918 self.fsm.commit_partial('uuid3', self.share.volume_id, None)
2897 self.assertTrue(os.path.exists(testfile))2919 self.assertTrue(os.path.exists(testfile))
28982920
2921 @defer.inlineCallbacks
2899 def test_delete_dir_ro_share(self):2922 def test_delete_dir_ro_share(self):
2900 """ Test that fsm is able to delete a dir in a ro.share. """2923 """ Test that fsm is able to delete a dir in a ro.share. """
2901 share = self.create_share('ro_share', 'ro_share_name', self.fsm,2924 share = yield self.create_share('ro_share', 'ro_share_name',
2902 self.shares_dir, access_level='View')2925 access_level='View')
2903 testdir = os.path.join(share.path, "path2")2926 testdir = os.path.join(share.path, "path2")
2904 self.fsm.create(testdir, share.volume_id, is_dir=True)2927 self.fsm.create(testdir, share.volume_id, is_dir=True)
2905 self.fsm.set_node_id(testdir, "uuid2")2928 self.fsm.set_node_id(testdir, "uuid2")
@@ -2912,10 +2935,11 @@
2912 self.fsm.delete_file(testdir)2935 self.fsm.delete_file(testdir)
2913 self.assertFalse(os.path.exists(testdir))2936 self.assertFalse(os.path.exists(testdir))
29142937
2938 @defer.inlineCallbacks
2915 def test_delete_non_empty_dir_ro_share(self):2939 def test_delete_non_empty_dir_ro_share(self):
2916 """Test that fsm is able to delete a non-empty dir in a ro.share."""2940 """Test that fsm is able to delete a non-empty dir in a ro.share."""
2917 share = self.create_share('ro_share', 'ro_share_name', self.fsm,2941 share = yield self.create_share('ro_share', 'ro_share_name',
2918 self.shares_dir, access_level='View')2942 access_level='View')
2919 testdir = os.path.join(share.path, "path2")2943 testdir = os.path.join(share.path, "path2")
2920 mdid = self.fsm.create(testdir, share.volume_id, is_dir=True)2944 mdid = self.fsm.create(testdir, share.volume_id, is_dir=True)
2921 self.fsm.set_node_id(testdir, "uuid2")2945 self.fsm.set_node_id(testdir, "uuid2")
@@ -2941,10 +2965,11 @@
2941 self.assertFalse(os.path.exists(testdir))2965 self.assertFalse(os.path.exists(testdir))
2942 self.assertFalse(os.path.exists(testfile))2966 self.assertFalse(os.path.exists(testfile))
29432967
2968 @defer.inlineCallbacks
2944 def test_delete_non_empty_dir_rw_share(self):2969 def test_delete_non_empty_dir_rw_share(self):
2945 """Test that fsm is able to delete a non-empty dir in a rw.share."""2970 """Test that fsm is able to delete a non-empty dir in a rw.share."""
2946 share = self.create_share('rw_share', 'rw_share_name', self.fsm,2971 share = yield self.create_share('rw_share', 'rw_share_name',
2947 self.shares_dir, access_level='Modify')2972 access_level='Modify')
2948 testdir = os.path.join(share.path, "path2")2973 testdir = os.path.join(share.path, "path2")
2949 mdid = self.fsm.create(testdir, share.volume_id, is_dir=True)2974 mdid = self.fsm.create(testdir, share.volume_id, is_dir=True)
2950 self.fsm.set_node_id(testdir, "uuid2")2975 self.fsm.set_node_id(testdir, "uuid2")
@@ -2970,10 +2995,11 @@
2970 self.assertFalse(os.path.exists(testdir))2995 self.assertFalse(os.path.exists(testdir))
2971 self.assertFalse(os.path.exists(testfile))2996 self.assertFalse(os.path.exists(testfile))
29722997
2998 @defer.inlineCallbacks
2973 def test_delete_non_empty_dir_bad_perms_rw_share(self):2999 def test_delete_non_empty_dir_bad_perms_rw_share(self):
2974 """Test that fsm is able to delete a non-empty dir in a rw.share."""3000 """Test that fsm is able to delete a non-empty dir in a rw.share."""
2975 share = self.create_share('rw_share', 'rw_share_name', self.fsm,3001 share = yield self.create_share('rw_share', 'rw_share_name',
2976 self.shares_dir, access_level='Modify')3002 access_level='Modify')
2977 testdir = os.path.join(share.path, "path2")3003 testdir = os.path.join(share.path, "path2")
2978 mdid = self.fsm.create(testdir, share.volume_id, is_dir=True)3004 mdid = self.fsm.create(testdir, share.volume_id, is_dir=True)
2979 self.fsm.set_node_id(testdir, "uuid2")3005 self.fsm.set_node_id(testdir, "uuid2")
@@ -3001,10 +3027,11 @@
3001 self.assertTrue(os.path.exists(testdir))3027 self.assertTrue(os.path.exists(testdir))
3002 self.assertTrue(os.path.exists(testfile))3028 self.assertTrue(os.path.exists(testfile))
30033029
3030 @defer.inlineCallbacks
3004 def test_delete_file_ro_share(self):3031 def test_delete_file_ro_share(self):
3005 """ Test that fsm is able to delete a file in a ro-share. """3032 """ Test that fsm is able to delete a file in a ro-share. """
3006 self.share = self.create_share('ro_share', 'ro_share_name', self.fsm,3033 self.share = yield self.create_share('ro_share', 'ro_share_name',
3007 self.shares_dir, access_level='View')3034 access_level='View')
3008 testfile = os.path.join(self.share.path, "a_file")3035 testfile = os.path.join(self.share.path, "a_file")
3009 self.fsm.create(testfile, self.share.volume_id, is_dir=False)3036 self.fsm.create(testfile, self.share.volume_id, is_dir=False)
3010 self.fsm.set_node_id(testfile, "uuid3")3037 self.fsm.set_node_id(testfile, "uuid3")
@@ -3017,10 +3044,11 @@
3017 self.fsm.delete_file(testfile)3044 self.fsm.delete_file(testfile)
3018 self.assertFalse(os.path.exists(testfile))3045 self.assertFalse(os.path.exists(testfile))
30193046
3047 @defer.inlineCallbacks
3020 def test_move_to_conflict_ro_share(self):3048 def test_move_to_conflict_ro_share(self):
3021 """ Test that fsm is able to handle move_to_conflict in a ro-share. """3049 """ Test that fsm is able to handle move_to_conflict in a ro-share. """
3022 self.share = self.create_share('ro_share', 'ro_share_name', self.fsm,3050 self.share = yield self.create_share('ro_share', 'ro_share_name',
3023 self.shares_dir, access_level='View')3051 access_level='View')
3024 testfile = os.path.join(self.share.path, "a_file")3052 testfile = os.path.join(self.share.path, "a_file")
3025 file_mdid = self.fsm.create(testfile, self.share.volume_id,3053 file_mdid = self.fsm.create(testfile, self.share.volume_id,
3026 is_dir=False)3054 is_dir=False)
@@ -3034,18 +3062,18 @@
3034 self.fsm.move_to_conflict(file_mdid)3062 self.fsm.move_to_conflict(file_mdid)
3035 self.assertTrue(os.path.exists(testfile + self.fsm.CONFLICT_SUFFIX))3063 self.assertTrue(os.path.exists(testfile + self.fsm.CONFLICT_SUFFIX))
30363064
3065 @defer.inlineCallbacks
3037 def test_file_rw_share_no_fail(self):3066 def test_file_rw_share_no_fail(self):
3038 """ Test that manual creation of a file, ona rw-share. """3067 """ Test that manual creation of a file, ona rw-share. """
3039 share = self.create_share('ro_share', 'ro_share_name', self.fsm,3068 share = yield self.create_share('ro_share', 'ro_share_name')
3040 self.shares_dir)
3041 testfile = os.path.join(share.path, "a_file")3069 testfile = os.path.join(share.path, "a_file")
3042 open(testfile, 'w').close()3070 open(testfile, 'w').close()
3043 self.assertTrue(os.path.exists(testfile))3071 self.assertTrue(os.path.exists(testfile))
30443072
3073 @defer.inlineCallbacks
3045 def test_dir_rw_share(self):3074 def test_dir_rw_share(self):
3046 """ Test that the creation of a file using fsm, works on a rw-share."""3075 """ Test that the creation of a file using fsm, works on a rw-share."""
3047 share = self.create_share('ro_share', 'ro_share_name', self.fsm,3076 share = yield self.create_share('ro_share', 'ro_share_name')
3048 self.shares_dir)
3049 testdir = os.path.join(share.path, "path2")3077 testdir = os.path.join(share.path, "path2")
3050 self.fsm.create(testdir, share.volume_id, is_dir=True)3078 self.fsm.create(testdir, share.volume_id, is_dir=True)
3051 self.fsm.set_node_id(testdir, "uuid2")3079 self.fsm.set_node_id(testdir, "uuid2")
@@ -3055,10 +3083,10 @@
3055 fd.close()3083 fd.close()
3056 self.assertTrue(os.path.exists(testdir))3084 self.assertTrue(os.path.exists(testdir))
30573085
3086 @defer.inlineCallbacks
3058 def test_file_rw_share(self):3087 def test_file_rw_share(self):
3059 """ Test that the creation of a file using fsm, works on a rw-share."""3088 """ Test that the creation of a file using fsm, works on a rw-share."""
3060 self.share = self.create_share('ro_share', 'ro_share_name', self.fsm,3089 self.share = yield self.create_share('ro_share', 'ro_share_name')
3061 self.shares_dir)
3062 testfile = os.path.join(self.share.path, "a_file")3090 testfile = os.path.join(self.share.path, "a_file")
3063 self.fsm.create(testfile, self.share.volume_id, is_dir=False)3091 self.fsm.create(testfile, self.share.volume_id, is_dir=False)
3064 self.fsm.set_node_id(testfile, "uuid3")3092 self.fsm.set_node_id(testfile, "uuid3")
@@ -3094,13 +3122,13 @@
3094class TestEnableShareWrite(FSMTestCase):3122class TestEnableShareWrite(FSMTestCase):
3095 """Tests for EnableShareWrite context manager"""3123 """Tests for EnableShareWrite context manager"""
30963124
3125 @defer.inlineCallbacks
3097 def setUp(self):3126 def setUp(self):
3098 """Test setup"""3127 """Test setup"""
3099 FSMTestCase.setUp(self)3128 FSMTestCase.setUp(self)
3100 # create a ro share3129 # create a ro share
3101 self.share_ro = self.create_share('share_ro', 'share_ro_name',3130 self.share_ro = yield self.create_share('share_ro', 'share_ro_name',
3102 self.fsm, self.shares_dir,3131 access_level='View')
3103 access_level='View')
3104 self.share_ro_path = self.share_ro.path3132 self.share_ro_path = self.share_ro.path
31053133
3106 def test_write_in_ro_share(self):3134 def test_write_in_ro_share(self):
@@ -3140,6 +3168,7 @@
31403168
3141class RealVMTestCase(FSMTestCase):3169class RealVMTestCase(FSMTestCase):
31423170
3171 @defer.inlineCallbacks
3143 def setUp(self):3172 def setUp(self):
3144 """ Setup the test """3173 """ Setup the test """
3145 unittest.TestCase.setUp(self)3174 unittest.TestCase.setUp(self)
@@ -3158,8 +3187,7 @@
3158 self.main = FakeMain(self.root_dir, self.shares_dir,3187 self.main = FakeMain(self.root_dir, self.shares_dir,
3159 self.data_dir, self.partials_dir)3188 self.data_dir, self.partials_dir)
3160 self.fsm = self.main.fs3189 self.fsm = self.main.fs
3161 self.share = self.create_share('share', 'share_name',3190 self.share = yield self.create_share('share', 'share_name')
3162 self.fsm, self.shares_dir)
3163 self.share_path = self.share.path3191 self.share_path = self.share.path
31643192
3165 def tearDown(self):3193 def tearDown(self):
@@ -3167,14 +3195,16 @@
3167 self.main.shutdown()3195 self.main.shutdown()
3168 self.rmtree(TESTS_DIR)3196 self.rmtree(TESTS_DIR)
31693197
31703198 @defer.inlineCallbacks
3171 @staticmethod3199 def create_share(self, share_id, share_name,
3172 def create_share(share_id, share_name, fsm, shares_dir,
3173 access_level='Modify'):3200 access_level='Modify'):
3174 with allow_writes(shares_dir):3201 with allow_writes(self.shares_dir):
3175 return FSMTestCase.create_share(share_id, share_name, fsm,3202 share = yield _create_share(share_id, share_name, self.fsm,
3176 shares_dir, access_level)3203 self.shares_dir, access_level)
31773204
3205 defer.returnValue(share)
3206
3207 @defer.inlineCallbacks
3178 def test_old_metadata_None_missing_share(self):3208 def test_old_metadata_None_missing_share(self):
3179 """test loading metadata v0. that points to a share that3209 """test loading metadata v0. that points to a share that
3180 we don't have3210 we don't have
@@ -3185,8 +3215,7 @@
3185 mdid = self.fsm.create(path, "share")3215 mdid = self.fsm.create(path, "share")
3186 self.fsm.set_node_id(path, "uuid")3216 self.fsm.set_node_id(path, "uuid")
3187 # create a path with the old layout3217 # create a path with the old layout
3188 other_share = self.create_share('share1', 'share1_name',3218 other_share = yield self.create_share('share1', 'share1_name')
3189 self.fsm, self.shares_dir)
3190 share_mdid = self.fsm.create(other_share.path, "share1")3219 share_mdid = self.fsm.create(other_share.path, "share1")
3191 self.fsm.set_node_id(other_share.path, "uuid1")3220 self.fsm.set_node_id(other_share.path, "uuid1")
3192 os.makedirs(os.path.join(self.root_dir, 'Ubuntu One'))3221 os.makedirs(os.path.join(self.root_dir, 'Ubuntu One'))
@@ -3238,6 +3267,7 @@
3238 self.assertRaises(KeyError, newfsm.get_by_mdid, share_mdid)3267 self.assertRaises(KeyError, newfsm.get_by_mdid, share_mdid)
3239 db.shutdown()3268 db.shutdown()
32403269
3270 @defer.inlineCallbacks
3241 def test_old_metadata_1_missing_share(self):3271 def test_old_metadata_1_missing_share(self):
3242 """test loading metadata v1. that points to a share that3272 """test loading metadata v1. that points to a share that
3243 we don't have3273 we don't have
@@ -3251,8 +3281,7 @@
3251 self.fsm.set_node_id(path2, "uuid2")3281 self.fsm.set_node_id(path2, "uuid2")
32523282
3253 # create a path with the old layout3283 # create a path with the old layout
3254 other_share = self.create_share('share1', 'share1_name',3284 other_share = yield self.create_share('share1', 'share1_name')
3255 self.fsm, self.shares_dir)
3256 share_mdid = self.fsm.create(other_share.path, "share1")3285 share_mdid = self.fsm.create(other_share.path, "share1")
3257 self.fsm.set_node_id(other_share.path, "uuid3")3286 self.fsm.set_node_id(other_share.path, "uuid3")
3258 os.makedirs(os.path.join(self.root_dir, 'Ubuntu One'))3287 os.makedirs(os.path.join(self.root_dir, 'Ubuntu One'))
@@ -3303,6 +3332,7 @@
3303 self.assertRaises(KeyError, newfsm.get_by_mdid, share_mdid)3332 self.assertRaises(KeyError, newfsm.get_by_mdid, share_mdid)
3304 db.shutdown()3333 db.shutdown()
33053334
3335 @defer.inlineCallbacks
3306 def test_old_metadata_2_missing_share(self):3336 def test_old_metadata_2_missing_share(self):
3307 """test loading metadata v2. that points to a share that3337 """test loading metadata v2. that points to a share that
3308 we don't have3338 we don't have
@@ -3312,8 +3342,7 @@
3312 mdid = self.fsm.create(path, "share")3342 mdid = self.fsm.create(path, "share")
3313 self.fsm.set_node_id(path, "uuid")3343 self.fsm.set_node_id(path, "uuid")
3314 # create a path with the old layout3344 # create a path with the old layout
3315 other_share = self.create_share('share1', 'share1_name',3345 other_share = yield self.create_share('share1', 'share1_name')
3316 self.fsm, self.shares_dir)
3317 share_mdid = self.fsm.create(other_share.path, "share1")3346 share_mdid = self.fsm.create(other_share.path, "share1")
3318 self.fsm.set_node_id(other_share.path, "uuid3")3347 self.fsm.set_node_id(other_share.path, "uuid3")
3319 os.makedirs(os.path.join(self.root_dir, 'Ubuntu One'))3348 os.makedirs(os.path.join(self.root_dir, 'Ubuntu One'))
@@ -3360,6 +3389,7 @@
3360 self.assertRaises(KeyError, newfsm.get_by_mdid, share_mdid)3389 self.assertRaises(KeyError, newfsm.get_by_mdid, share_mdid)
3361 db.shutdown()3390 db.shutdown()
33623391
3392 @defer.inlineCallbacks
3363 def test_old_metadata_3_missing_share(self):3393 def test_old_metadata_3_missing_share(self):
3364 """test loading metadata v3. that points to a share that3394 """test loading metadata v3. that points to a share that
3365 we don't have3395 we don't have
@@ -3369,8 +3399,7 @@
3369 root_mdid = self.fsm.get_by_path(self.root_dir).mdid3399 root_mdid = self.fsm.get_by_path(self.root_dir).mdid
3370 self.fsm.set_node_id(self.root_dir, "uuid")3400 self.fsm.set_node_id(self.root_dir, "uuid")
3371 # a share3401 # a share
3372 other_share = self.create_share('share1', 'share1_name',3402 other_share = yield self.create_share('share1', 'share1_name')
3373 self.fsm, self.shares_dir)
3374 share_mdid = self.fsm.create(other_share.path, "share1")3403 share_mdid = self.fsm.create(other_share.path, "share1")
3375 self.fsm.set_node_id(other_share.path, "uuid1")3404 self.fsm.set_node_id(other_share.path, "uuid1")
3376 os.makedirs(os.path.join(self.root_dir, 'Ubuntu One'))3405 os.makedirs(os.path.join(self.root_dir, 'Ubuntu One'))
@@ -3416,6 +3445,7 @@
3416 self.assertRaises(KeyError, newfsm.get_by_mdid, share_mdid)3445 self.assertRaises(KeyError, newfsm.get_by_mdid, share_mdid)
3417 db.shutdown()3446 db.shutdown()
34183447
3448 @defer.inlineCallbacks
3419 def test_metadata_missing_share(self):3449 def test_metadata_missing_share(self):
3420 """test loading current metadata that points to a share3450 """test loading current metadata that points to a share
3421 that we don't have3451 that we don't have
@@ -3425,8 +3455,7 @@
3425 self.assertEqual(md_version, METADATA_VERSION)3455 self.assertEqual(md_version, METADATA_VERSION)
3426 path = os.path.join(self.share.path, 'path')3456 path = os.path.join(self.share.path, 'path')
3427 path1 = os.path.join(self.share.path, 'path1')3457 path1 = os.path.join(self.share.path, 'path1')
3428 other_share = self.create_share('share1', 'share1_name',3458 other_share = yield self.create_share('share1', 'share1_name')
3429 self.fsm, self.shares_dir)
34303459
3431 path2 = os.path.join(other_share.path, 'broken_path2')3460 path2 = os.path.join(other_share.path, 'broken_path2')
3432 for p in [path, path1, path2]:3461 for p in [path, path1, path2]:
34333462
=== modified file 'tests/syncdaemon/test_localrescan.py'
--- tests/syncdaemon/test_localrescan.py 2011-02-01 14:33:46 +0000
+++ tests/syncdaemon/test_localrescan.py 2011-02-03 17:29:42 +0000
@@ -119,19 +119,20 @@
119 self.rmtree(self.tmpdir)119 self.rmtree(self.tmpdir)
120 testcase.BaseTwistedTestCase.tearDown(self)120 testcase.BaseTwistedTestCase.tearDown(self)
121121
122 @staticmethod122 @defer.inlineCallbacks
123 def create_share(share_id, share_name, fsm, shares_dir,123 def create_share(self, share_id, share_name,
124 access_level='Modify', accepted=True, subscribed=True):124 access_level='Modify', accepted=True, subscribed=True):
125 """Create a share."""125 """Create a share."""
126 share_path = os.path.join(shares_dir, share_name)126 share_path = os.path.join(self.shares_dir, share_name)
127 os.makedirs(share_path)127 os.makedirs(share_path)
128 share = volume_manager.Share(path=share_path, volume_id=share_id,128 share = volume_manager.Share(path=share_path, volume_id=share_id,
129 access_level=access_level,129 access_level=access_level,
130 accepted=accepted,130 accepted=accepted,
131 subscribed=subscribed)131 subscribed=subscribed)
132 fsm.vm.add_share(share)132 yield self.fsm.vm.add_share(share)
133 return share133 defer.returnValue(share)
134134
135 @defer.inlineCallbacks
135 def create_udf(self, udf_id, node_id, suggested_path, path, subscribed,136 def create_udf(self, udf_id, node_id, suggested_path, path, subscribed,
136 generation=None, free_bytes=100):137 generation=None, free_bytes=100):
137 """Create an UDF and add it to the volume manager."""138 """Create an UDF and add it to the volume manager."""
@@ -139,8 +140,8 @@
139 suggested_path.decode('utf-8'))140 suggested_path.decode('utf-8'))
140 udf = volume_manager.UDF.from_udf_volume(volume, path)141 udf = volume_manager.UDF.from_udf_volume(volume, path)
141 udf.subscribed = subscribed142 udf.subscribed = subscribed
142 self.fsm.vm.add_udf(udf)143 yield self.fsm.vm.add_udf(udf)
143 return udf144 defer.returnValue(udf)
144145
145 def create_node(self, path, is_dir, real=True, which_share=None):146 def create_node(self, path, is_dir, real=True, which_share=None):
146 """Creates a node, really (maybe) and in the metadata."""147 """Creates a node, really (maybe) and in the metadata."""
@@ -189,11 +190,12 @@
189 lr.start()190 lr.start()
190 self.assertEqual(toscan, [self.vm.root.path])191 self.assertEqual(toscan, [self.vm.root.path])
191192
193 @defer.inlineCallbacks
192 def test_empty_rw(self):194 def test_empty_rw(self):
193 """Test with one empty Modify share."""195 """Test with one empty Modify share."""
194 # create the share196 # create the share
195 share = self.create_share('share_id', 'rw_share', self.fsm,197 share = yield self.create_share('share_id', 'rw_share',
196 self.shares_dir, access_level='Modify')198 access_level='Modify')
197 self.fsm.create(share.path, "share_id", is_dir=True)199 self.fsm.create(share.path, "share_id", is_dir=True)
198 self.fsm.set_node_id(share.path, "uuid")200 self.fsm.set_node_id(share.path, "uuid")
199201
@@ -210,11 +212,12 @@
210 lr.start()212 lr.start()
211 self.assertEqual(sorted(toscan), [share.path, self.vm.root.path])213 self.assertEqual(sorted(toscan), [share.path, self.vm.root.path])
212214
215 @defer.inlineCallbacks
213 def test_not_empty_rw(self):216 def test_not_empty_rw(self):
214 """Test with a Modify share with info."""217 """Test with a Modify share with info."""
215 # create the share218 # create the share
216 share = self.create_share('share_id', 'ro_share', self.fsm,219 share = yield self.create_share('share_id', 'ro_share',
217 self.shares_dir, access_level='Modify')220 access_level='Modify')
218 self.fsm.create(share.path, "share_id", is_dir=True)221 self.fsm.create(share.path, "share_id", is_dir=True)
219 self.fsm.set_node_id(share.path, "uuid1")222 self.fsm.set_node_id(share.path, "uuid1")
220223
@@ -237,11 +240,12 @@
237 lr.start()240 lr.start()
238 self.assertEqual(sorted(toscan), [share.path, self.vm.root.path])241 self.assertEqual(sorted(toscan), [share.path, self.vm.root.path])
239242
243 @defer.inlineCallbacks
240 def test_deleted_rw(self):244 def test_deleted_rw(self):
241 """Test with a deleted rw share."""245 """Test with a deleted rw share."""
242 # create the share246 # create the share
243 share = self.create_share('share_id', 'rw_share', self.fsm,247 share = yield self.create_share('share_id', 'rw_share',
244 self.shares_dir, access_level='Modify')248 access_level='Modify')
245 self.fsm.create(share.path, "share_id", is_dir=True)249 self.fsm.create(share.path, "share_id", is_dir=True)
246 self.fsm.set_node_id(share.path, "uuid")250 self.fsm.set_node_id(share.path, "uuid")
247251
@@ -266,11 +270,12 @@
266 self.assertEqual(vol_id, share.volume_id)270 self.assertEqual(vol_id, share.volume_id)
267 self.assertEqual(sorted(toscan), [self.vm.root.path])271 self.assertEqual(sorted(toscan), [self.vm.root.path])
268272
273 @defer.inlineCallbacks
269 def test_deleted_rw_not_empty(self):274 def test_deleted_rw_not_empty(self):
270 """Test with a deleted rw share with some nodes in it."""275 """Test with a deleted rw share with some nodes in it."""
271 # create the share276 # create the share
272 share = self.create_share('share_id', 'rw_share', self.fsm,277 share = yield self.create_share('share_id', 'rw_share',
273 self.shares_dir, access_level='Modify')278 access_level='Modify')
274 self.fsm.create(share.path, "share_id", is_dir=True)279 self.fsm.create(share.path, "share_id", is_dir=True)
275 self.fsm.set_node_id(share.path, "uuid")280 self.fsm.set_node_id(share.path, "uuid")
276281
@@ -307,7 +312,7 @@
307 """Test with a deleted udf."""312 """Test with a deleted udf."""
308 # create the udf313 # create the udf
309 udf_path = os.path.expanduser("~/myudf")314 udf_path = os.path.expanduser("~/myudf")
310 udf = self.create_udf('udf_id', 'udf_root_node_id', "~/myudf",315 udf = yield self.create_udf('udf_id', 'udf_root_node_id', "~/myudf",
311 udf_path, True)316 udf_path, True)
312 os.makedirs(udf.path)317 os.makedirs(udf.path)
313 self.fsm.create(udf.path, 'udf_id', is_dir=True)318 self.fsm.create(udf.path, 'udf_id', is_dir=True)
@@ -337,9 +342,10 @@
337class VolumeTestCase(BaseTestCase):342class VolumeTestCase(BaseTestCase):
338 """Test how LocalRescan manages volumes."""343 """Test how LocalRescan manages volumes."""
339344
345 @defer.inlineCallbacks
340 def setUp(self):346 def setUp(self):
341 """Init."""347 """Init."""
342 BaseTestCase.setUp(self)348 yield BaseTestCase.setUp(self)
343349
344 self.env_var = 'HOME'350 self.env_var = 'HOME'
345 self.old_value = os.environ.get(self.env_var, None)351 self.old_value = os.environ.get(self.env_var, None)
@@ -355,7 +361,8 @@
355 path = os.path.expanduser(suggested_path).encode("utf8")361 path = os.path.expanduser(suggested_path).encode("utf8")
356 os.makedirs(path)362 os.makedirs(path)
357 udf_id, node_id = 'udf_id%i' % i, 'node_id%i' % i363 udf_id, node_id = 'udf_id%i' % i, 'node_id%i' % i
358 udf = self.create_udf(udf_id, node_id, suggested_path, path, True)364 udf = yield self.create_udf(udf_id, node_id, suggested_path,
365 path, True)
359 self.volumes.append(udf)366 self.volumes.append(udf)
360367
361 # make FSM aware of it368 # make FSM aware of it
@@ -493,6 +500,7 @@
493500
494 timeout = 2501 timeout = 2
495502
503 @defer.inlineCallbacks
496 def setUp(self):504 def setUp(self):
497 """Set up the test."""505 """Set up the test."""
498 BaseTestCase.setUp(self)506 BaseTestCase.setUp(self)
@@ -500,8 +508,8 @@
500 self.lr = LocalRescan(self.vm, self.fsm, self.eq, self.aq)508 self.lr = LocalRescan(self.vm, self.fsm, self.eq, self.aq)
501509
502 # create a share510 # create a share
503 self.share = self.create_share('share_id', 'ro_share', self.fsm,511 self.share = yield self.create_share('share_id', 'ro_share',
504 self.shares_dir, access_level='Modify')512 access_level='Modify')
505 self.fsm.create(self.share.path, "share_id", is_dir=True)513 self.fsm.create(self.share.path, "share_id", is_dir=True)
506 self.fsm.set_node_id(self.share.path, "uuidshare")514 self.fsm.set_node_id(self.share.path, "uuidshare")
507 self.share.node_id = "uuidshare"515 self.share.node_id = "uuidshare"
@@ -535,14 +543,15 @@
535543
536 timeout = 20544 timeout = 20
537545
546 @defer.inlineCallbacks
538 def setUp(self):547 def setUp(self):
539 TwistedBase.setUp(self)548 yield TwistedBase.setUp(self)
540549
541 # create an udf550 # create an udf
542 udf_path = os.path.join(self.home_dir, "myudf")551 udf_path = os.path.join(self.home_dir, "myudf")
543 os.mkdir(udf_path)552 os.mkdir(udf_path)
544 self.udf = self.create_udf('udf_id', 'udf_root_node_id', "~/myudf",553 self.udf = yield self.create_udf('udf_id', 'udf_root_node_id',
545 udf_path, True)554 "~/myudf", udf_path, True)
546 self.fsm.create(self.udf.path, 'udf_id', is_dir=True)555 self.fsm.create(self.udf.path, 'udf_id', is_dir=True)
547 self.fsm.set_node_id(self.udf.path, 'udf_root_node_id')556 self.fsm.set_node_id(self.udf.path, 'udf_root_node_id')
548557
@@ -954,11 +963,12 @@
954 reactor.callLater(.2, self.deferred.callback, None)963 reactor.callLater(.2, self.deferred.callback, None)
955 return self.deferred964 return self.deferred
956965
966 @defer.inlineCallbacks
957 def test_one_dir_ro_share(self):967 def test_one_dir_ro_share(self):
958 """The dir is in a share that's RO, no error but no action."""968 """The dir is in a share that's RO, no error but no action."""
959 # create the share969 # create the share
960 share = self.create_share('share_id', 'ro_share2', self.fsm,970 share = yield self.create_share('share_id', 'ro_share2',
961 self.shares_dir, access_level='View')971 access_level='View')
962 self.fsm.create(share.path, "share_id", is_dir=True)972 self.fsm.create(share.path, "share_id", is_dir=True)
963 self.fsm.set_node_id(share.path, "uuidshare")973 self.fsm.set_node_id(share.path, "uuidshare")
964974
@@ -1155,20 +1165,21 @@
1155 """Test that simultaneus calls are queued."""1165 """Test that simultaneus calls are queued."""
1156 timeout = 21166 timeout = 2
11571167
1168 @defer.inlineCallbacks
1158 def setUp(self):1169 def setUp(self):
1159 """set up the test."""1170 """set up the test."""
1160 BaseTestCase.setUp(self)1171 yield BaseTestCase.setUp(self)
1161 self.deferred = defer.Deferred()1172 self.deferred = defer.Deferred()
1162 self.eq = event_queue.EventQueue(self.fsm)1173 self.eq = event_queue.EventQueue(self.fsm)
1163 self.lr = LocalRescan(self.vm, self.fsm, self.eq, self.aq)1174 self.lr = LocalRescan(self.vm, self.fsm, self.eq, self.aq)
11641175
1165 # create two shares1176 # create two shares
1166 self.share1 = self.create_share('share_id1', 'ro_share_1', self.fsm,1177 self.share1 = yield self.create_share('share_id1', 'ro_share_1',
1167 self.shares_dir, access_level='Modify')1178 access_level='Modify')
1168 self.fsm.create(self.share1.path, "share_id1", is_dir=True)1179 self.fsm.create(self.share1.path, "share_id1", is_dir=True)
1169 self.fsm.set_node_id(self.share1.path, "uuidshare1")1180 self.fsm.set_node_id(self.share1.path, "uuidshare1")
1170 self.share2 = self.create_share('share_id2', 'ro_share_2', self.fsm,1181 self.share2 = yield self.create_share('share_id2', 'ro_share_2',
1171 self.shares_dir, access_level='Modify')1182 access_level='Modify')
1172 self.fsm.create(self.share2.path, "share_id2", is_dir=True)1183 self.fsm.create(self.share2.path, "share_id2", is_dir=True)
1173 self.fsm.set_node_id(self.share2.path, "uuidshare2")1184 self.fsm.set_node_id(self.share2.path, "uuidshare2")
11741185
@@ -2007,11 +2018,12 @@
2007 self.startTest(check)2018 self.startTest(check)
2008 return self.deferred2019 return self.deferred
20092020
2021 @defer.inlineCallbacks
2010 def test_SERVER_file_ro_share(self):2022 def test_SERVER_file_ro_share(self):
2011 """We were downloading the file, but it was interrupted in RO share."""2023 """We were downloading the file, but it was interrupted in RO share."""
2012 # create the file in metadata2024 # create the file in metadata
2013 ro_share = self.create_share('share_ro_id', 'share_ro2', self.fsm,2025 ro_share = yield self.create_share('share_ro_id', 'share_ro2',
2014 self.shares_dir, access_level='View')2026 access_level='View')
2015 self.fsm.create(ro_share.path, ro_share.id, is_dir=True)2027 self.fsm.create(ro_share.path, ro_share.id, is_dir=True)
2016 self.fsm.set_node_id(ro_share.path, "uuidshare")2028 self.fsm.set_node_id(ro_share.path, "uuidshare")
2017 path = os.path.join(ro_share.path, "a")2029 path = os.path.join(ro_share.path, "a")
@@ -2040,16 +2052,17 @@
2040 self.assertTrue(self.handler.check_debug("comp yield", "SERVER"))2052 self.assertTrue(self.handler.check_debug("comp yield", "SERVER"))
20412053
2042 self.startTest(check)2054 self.startTest(check)
2043 return self.deferred2055 yield self.deferred
20442056
2057 @defer.inlineCallbacks
2045 def test_SERVER_dir_ro_share(self):2058 def test_SERVER_dir_ro_share(self):
2046 """Found a dir in SERVER in a ro_share.2059 """Found a dir in SERVER in a ro_share.
20472060
2048 This was valid before, but no more, so we just fix and log in warning.2061 This was valid before, but no more, so we just fix and log in warning.
2049 """2062 """
2050 # create the dir in metadata2063 # create the dir in metadata
2051 ro_share = self.create_share('share_ro_id', 'share_ro2', self.fsm,2064 ro_share = yield self.create_share('share_ro_id', 'share_ro2',
2052 self.shares_dir, access_level='View')2065 access_level='View')
2053 self.fsm.create(ro_share.path, ro_share.id, is_dir=True)2066 self.fsm.create(ro_share.path, ro_share.id, is_dir=True)
2054 self.fsm.set_node_id(ro_share.path, "uuidshare")2067 self.fsm.set_node_id(ro_share.path, "uuidshare")
20552068
@@ -2078,7 +2091,7 @@
2078 "Found a directory in SERVER"))2091 "Found a directory in SERVER"))
20792092
2080 self.startTest(check)2093 self.startTest(check)
2081 return self.deferred2094 yield self.deferred
20822095
2083 def test_check_stat_None(self):2096 def test_check_stat_None(self):
2084 """Test check_stat with oldstat = None."""2097 """Test check_stat with oldstat = None."""
@@ -2136,26 +2149,28 @@
2136 self.fsm.set_node_id(self.vm.root.path, self.vm.root.node_id)2149 self.fsm.set_node_id(self.vm.root.path, self.vm.root.node_id)
2137 return self._test_it(self.vm.root)2150 return self._test_it(self.vm.root)
21382151
2152 @defer.inlineCallbacks
2139 def test_SERVER_share(self):2153 def test_SERVER_share(self):
2140 """We were downloading the share root dir but it was interrupted."""2154 """We were downloading the share root dir but it was interrupted."""
2141 # create a share2155 # create a share
2142 share = self.create_share('share_id_1', 'rw_share', self.fsm,2156 share = yield self.create_share('share_id_1', 'rw_share',
2143 self.shares_dir, access_level='Modify')2157 access_level='Modify')
2144 self.fsm.create(share.path, "share_id_1", is_dir=True)2158 self.fsm.create(share.path, "share_id_1", is_dir=True)
2145 self.fsm.set_node_id(share.path, "uuid_share_1")2159 self.fsm.set_node_id(share.path, "uuid_share_1")
2146 share.node_id = "uuid_share_1"2160 share.node_id = "uuid_share_1"
2147 self.vm.shares['share_id_1'] = share2161 self.vm.shares['share_id_1'] = share
2148 return self._test_it(share)2162 yield self._test_it(share)
21492163
2164 @defer.inlineCallbacks
2150 def test_SERVER_udf(self):2165 def test_SERVER_udf(self):
2151 """We were downloading the udf root dir, but it was interrupted."""2166 """We were downloading the udf root dir, but it was interrupted."""
2152 udf_path = os.path.join(self.home_dir, "myudf")2167 udf_path = os.path.join(self.home_dir, "myudf")
2153 os.mkdir(udf_path)2168 os.mkdir(udf_path)
2154 udf = self.create_udf('udf_id', 'udf_root_node_id', "~/myudf",2169 udf = yield self.create_udf('udf_id', 'udf_root_node_id', "~/myudf",
2155 udf_path, True)2170 udf_path, True)
2156 self.fsm.create(udf.path, 'udf_id', is_dir=True)2171 self.fsm.create(udf.path, 'udf_id', is_dir=True)
2157 self.fsm.set_node_id(udf.path, 'udf_root_node_id')2172 self.fsm.set_node_id(udf.path, 'udf_root_node_id')
2158 return self._test_it(udf)2173 yield self._test_it(udf)
21592174
21602175
2161class LimboTests(TwistedBase):2176class LimboTests(TwistedBase):
@@ -2339,9 +2354,10 @@
23392354
2340 timeout = 22355 timeout = 2
23412356
2357 @defer.inlineCallbacks
2342 def setUp(self):2358 def setUp(self):
2343 """Init."""2359 """Init."""
2344 BaseTestCase.setUp(self)2360 yield BaseTestCase.setUp(self)
2345 self._deferred = defer.Deferred()2361 self._deferred = defer.Deferred()
2346 self.eq = event_queue.EventQueue(self.fsm)2362 self.eq = event_queue.EventQueue(self.fsm)
2347 self.original_add = self.eq.add_watch2363 self.original_add = self.eq.add_watch
@@ -2361,7 +2377,8 @@
2361 path = os.path.expanduser(suggested_path).encode("utf8")2377 path = os.path.expanduser(suggested_path).encode("utf8")
2362 os.makedirs(path)2378 os.makedirs(path)
2363 udf_id, node_id = 'udf_id', 'node_id'2379 udf_id, node_id = 'udf_id', 'node_id'
2364 self.udf = self.create_udf(udf_id, node_id, suggested_path, path, True)2380 self.udf = yield self.create_udf(udf_id, node_id, suggested_path,
2381 path, True)
2365 self.ancestors = self.udf.ancestors # need a fake HOME2382 self.ancestors = self.udf.ancestors # need a fake HOME
23662383
2367 # make FSM aware of it2384 # make FSM aware of it
23682385
=== modified file 'tests/syncdaemon/test_status_listener.py'
--- tests/syncdaemon/test_status_listener.py 2011-01-27 20:44:23 +0000
+++ tests/syncdaemon/test_status_listener.py 2011-02-03 17:29:42 +0000
@@ -120,8 +120,8 @@
120 public_url = 'http://example.com/foo.mp3'120 public_url = 'http://example.com/foo.mp3'
121121
122 share_path = os.path.join(self.shares_dir, 'share')122 share_path = os.path.join(self.shares_dir, 'share')
123 self.main.vm.add_share(Share(path=share_path, volume_id='share',123 yield self.main.vm.add_share(Share(path=share_path, volume_id='share',
124 other_username='other username'))124 other_username='other username'))
125 path = os.path.join(share_path, "foo.mp3")125 path = os.path.join(share_path, "foo.mp3")
126 self.main.fs.create(path, str(share_id))126 self.main.fs.create(path, str(share_id))
127 self.main.fs.set_node_id(path, str(node_id))127 self.main.fs.set_node_id(path, str(node_id))
@@ -144,8 +144,8 @@
144 public_url = 'http://example.com/foo.mp3'144 public_url = 'http://example.com/foo.mp3'
145145
146 share_path = os.path.join(self.shares_dir, 'share')146 share_path = os.path.join(self.shares_dir, 'share')
147 self.main.vm.add_share(Share(path=share_path, volume_id='share',147 yield self.main.vm.add_share(Share(path=share_path, volume_id='share',
148 other_username='other username'))148 other_username='other username'))
149 path = os.path.join(share_path, "foo.mp3")149 path = os.path.join(share_path, "foo.mp3")
150 self.main.fs.create(path, str(share_id))150 self.main.fs.create(path, str(share_id))
151 self.main.fs.set_node_id(path, str(node_id))151 self.main.fs.set_node_id(path, str(node_id))
@@ -210,7 +210,7 @@
210 SHARE_ID = "fake share id"210 SHARE_ID = "fake share id"
211 d = defer.Deferred()211 d = defer.Deferred()
212 share = Share(volume_id=SHARE_ID)212 share = Share(volume_id=SHARE_ID)
213 self.main.vm.add_share(share)213 yield self.main.vm.add_share(share)
214 self._listen_for('VM_SHARE_CREATED', d.callback)214 self._listen_for('VM_SHARE_CREATED', d.callback)
215 self.main.event_q.push('VM_SHARE_CREATED', share)215 self.main.event_q.push('VM_SHARE_CREATED', share)
216 yield d216 yield d
217217
=== modified file 'tests/syncdaemon/test_sync.py'
--- tests/syncdaemon/test_sync.py 2011-01-25 18:29:04 +0000
+++ tests/syncdaemon/test_sync.py 2011-02-03 17:29:42 +0000
@@ -75,6 +75,7 @@
75class FSKeyTestCase(BaseTwistedTestCase):75class FSKeyTestCase(BaseTwistedTestCase):
76 """ Base test case for FSKey """76 """ Base test case for FSKey """
7777
78 @defer.inlineCallbacks
78 def setUp(self):79 def setUp(self):
79 """ Setup the test """80 """ Setup the test """
80 unittest.TestCase.setUp(self)81 unittest.TestCase.setUp(self)
@@ -93,8 +94,7 @@
93 self.db)94 self.db)
94 self.eq = EventQueue(self.fsm)95 self.eq = EventQueue(self.fsm)
95 self.fsm.register_eq(self.eq)96 self.fsm.register_eq(self.eq)
96 self.share = self.create_share('share', 'share_name',97 self.share = yield self.create_share('share', 'share_name')
97 self.fsm, self.shares_dir)
98 self.share_path = self.share.path98 self.share_path = self.share.path
9999
100 def tearDown(self):100 def tearDown(self):
@@ -103,16 +103,15 @@
103 self.db.shutdown()103 self.db.shutdown()
104 shutil.rmtree(self.test_dir)104 shutil.rmtree(self.test_dir)
105105
106 @staticmethod106 @defer.inlineCallbacks
107 def create_share(share_id, share_name, fsm, shares_dir,107 def create_share(self, share_id, share_name, access_level='Modify'):
108 access_level='Modify'):108 """Create a share."""
109 """ creates a share """109 share_path = os.path.join(self.shares_dir, share_name)
110 share_path = os.path.join(shares_dir, share_name)
111 os.makedirs(share_path)110 os.makedirs(share_path)
112 share = Share(path=share_path, volume_id=share_id,111 share = Share(path=share_path, volume_id=share_id,
113 access_level=access_level)112 access_level=access_level)
114 fsm.vm.add_share(share)113 yield self.fsm.vm.add_share(share)
115 return share114 defer.returnValue(share)
116115
117116
118class FSKeyTests(FSKeyTestCase):117class FSKeyTests(FSKeyTestCase):
119118
=== modified file 'tests/syncdaemon/test_u1sdtool.py'
--- tests/syncdaemon/test_u1sdtool.py 2011-01-14 13:11:47 +0000
+++ tests/syncdaemon/test_u1sdtool.py 2011-02-03 17:29:42 +0000
@@ -179,12 +179,13 @@
179 d.addCallback(check)179 d.addCallback(check)
180 return d180 return d
181181
182 @defer.inlineCallbacks
182 def test_show_current_transfers(self):183 def test_show_current_transfers(self):
183 """test the output of --current_transfers option with transfers in184 """test the output of --current_transfers option with transfers in
184 progress.185 progress.
185 """186 """
186 share_path = os.path.join(self.shares_dir, 'share')187 share_path = os.path.join(self.shares_dir, 'share')
187 self.main.vm.add_share(Share(path=share_path, volume_id='share_id'))188 yield self.main.vm.add_share(Share(path=share_path, volume_id='share_id'))
188 # create a download189 # create a download
189 down_path = os.path.join(share_path, "down_path")190 down_path = os.path.join(share_path, "down_path")
190 self.fs_manager.create(down_path, "share_id")191 self.fs_manager.create(down_path, "share_id")
@@ -203,15 +204,13 @@
203 "downloads:\n path: %(down_path)s\n deflated size: " + \204 "downloads:\n path: %(down_path)s\n deflated size: " + \
204 "10\n bytes read: 1\n"205 "10\n bytes read: 1\n"
205 expected = expected % dict(up_path=up_path, down_path=down_path)206 expected = expected % dict(up_path=up_path, down_path=down_path)
206 d = self.tool.get_current_uploads()207 result = yield self.tool.get_current_uploads()
207 d.addCallback(lambda result: show_uploads(result, out))208 show_uploads(result, out)
208 d.addCallback(lambda _: self.tool.get_current_downloads())209
209 d.addCallback(lambda result: show_downloads(result, out))210 result = yield self.tool.get_current_downloads()
210 def check(result):211 show_downloads(result, out)
211 """check the output"""212
212 self.assertEquals(out.getvalue(), expected)213 self.assertEquals(out.getvalue(), expected)
213 d.addCallback(check)
214 return d
215214
216 def test_show_state(self):215 def test_show_state(self):
217 """test the output of --status """216 """test the output of --status """

Subscribers

People subscribed via source and target branches