~didrocks/ubuntuone-client/use_result_var

« back to all changes in this revision

Viewing changes to tests/syncdaemon/test_sync.py

  • Committer: Bazaar Package Importer
  • Author(s): Rodrigo Moya
  • Date: 2010-09-15 22:17:37 UTC
  • mto: This revision was merged to the branch mainline in revision 55.
  • Revision ID: james.westby@ubuntu.com-20100915221737-l0sy32v8vh0c9coj
Tags: upstream-1.4.1
ImportĀ upstreamĀ versionĀ 1.4.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
531
531
        self.assertEqual(called[1:],
532
532
                        ['AQ_DIR_NEW_ERROR', params, failure, 'marker'])
533
533
 
 
534
    def test_AQ_MOVE_OK_with_node(self):
 
535
        """Handle AQ_MOVE_OK having a node."""
 
536
        # fake method
 
537
        called = []
 
538
        self.patch(SyncStateMachineRunner, 'clean_move_limbo',
 
539
                   lambda *a: called.extend(a))
 
540
 
 
541
        # create the node
 
542
        somepath = os.path.join(self.root, 'somepath')
 
543
        self.fsm.create(somepath, '', node_id='node_id')
 
544
 
 
545
        self.sync.handle_AQ_MOVE_OK('', 'node_id', 123)
 
546
        self.assertEqual(called[1:], ['AQ_MOVE_OK', {}, '', 'node_id'])
 
547
 
 
548
    def test_AQ_MOVE_OK_no_node(self):
 
549
        """Handle AQ_MOVE_OK not having a node."""
 
550
        # fake method
 
551
        called = []
 
552
        self.patch(SyncStateMachineRunner, 'clean_move_limbo',
 
553
                   lambda *a: called.extend(a))
 
554
 
 
555
        self.sync.handle_AQ_MOVE_OK('', 'node_id', 123)
 
556
        self.assertEqual(called[1:], ['AQ_MOVE_OK', {}, '', 'node_id'])
 
557
 
 
558
    def test_AQ_MOVE_ERROR_with_node(self):
 
559
        """Handle AQ_MOVE_ERROR having a node."""
 
560
        # fake method
 
561
        called = []
 
562
        self.patch(SyncStateMachineRunner, 'clean_move_limbo',
 
563
                   lambda *a: called.extend(a))
 
564
 
 
565
        # create the node
 
566
        somepath = os.path.join(self.root, 'somepath')
 
567
        self.fsm.create(somepath, '', node_id='node_id')
 
568
 
 
569
        self.sync.handle_AQ_MOVE_ERROR('', 'node_id', 'parent', 'error')
 
570
        self.assertEqual(called[1:], ['AQ_MOVE_ERROR', {}, '', 'node_id'])
 
571
 
 
572
    def test_AQ_MOVE_ERROR_no_node(self):
 
573
        """Handle AQ_MOVE_ERROR not having a node."""
 
574
        # fake method
 
575
        called = []
 
576
        self.patch(SyncStateMachineRunner, 'clean_move_limbo',
 
577
                   lambda *a: called.extend(a))
 
578
 
 
579
        self.sync.handle_AQ_MOVE_ERROR('', 'node_id', 'parent', 'error')
 
580
        self.assertEqual(called[1:], ['AQ_MOVE_ERROR', {}, '', 'node_id'])
 
581
 
534
582
 
535
583
class SyncStateMachineRunnerTestCase(BaseSync):
536
584
    """Tests for the SyncStateMachineRunner."""
671
719
        # set up the DeferredMap
672
720
        map_d = self.aq.uuid_map.get('marker')
673
721
 
 
722
        # patch to control the call to dereference the limbos
 
723
        called = []
 
724
        self.fsm.dereference_ok_limbos = lambda *a: called.append(a)
 
725
 
674
726
        # create context and call
675
727
        key = FSKey(self.main.fs)
676
728
        ssmr = SyncStateMachineRunner(fsm=self.fsm, main=self.main,
680
732
        # check
681
733
        result = yield map_d
682
734
        self.assertEqual(result, 'new_id')
 
735
        self.assertEqual(called, [('marker', 'new_id')])
683
736
 
684
737
    @defer.inlineCallbacks
685
738
    def test_filedir_error_in_creation(self):
718
771
        # set up the DeferredMap
719
772
        map_d = self.aq.uuid_map.get('mrker')
720
773
 
 
774
        # patch to control the call to dereference the limbos
 
775
        called = []
 
776
        self.fsm.dereference_err_limbos = lambda *a: called.append(a)
 
777
 
721
778
        # create context and call
722
779
        key = FSKey(self.main.fs)
723
780
        ssmr = SyncStateMachineRunner(fsm=self.fsm, main=self.main,
731
788
        except Exception, e:
732
789
            # silence the received exception
733
790
            self.assertEqual(e, exc)
 
791
            self.assertEqual(called, [('mrker',)])
734
792
        else:
735
793
            # no exception? fail!!
736
794
            self.fail("The marker was released without failure!")
737
795
 
 
796
    def test_client_moved_file(self):
 
797
        """Client moved a file."""
 
798
        # set up FSM and the DeferredMap
 
799
        somepath1 = os.path.join(self.root, 'foo')
 
800
        somepath2 = os.path.join(self.root, 'bar')
 
801
        self.fsm.create(somepath1, '', 'node_id')
 
802
 
 
803
        # patch HQ to don't hash the file
 
804
        self.main.hash_q.insert = lambda *a: None
 
805
 
 
806
        # record the call
 
807
        called = []
 
808
        self.main.fs.add_to_move_limbo = lambda *a: called.append(a)
 
809
 
 
810
        # create context and call
 
811
        key = FSKey(self.main.fs, path=somepath1)
 
812
        ssmr = SyncStateMachineRunner(fsm=self.fsm, main=self.main,
 
813
                                      key=key, logger=None)
 
814
        ssmr.client_moved('some event', {}, somepath1, somepath2)
 
815
        self.assertTrue(called)
 
816
 
 
817
    def test_clean_move_limbo(self):
 
818
        """Clean the move limbo with what was called."""
 
819
        called = []
 
820
        self.main.fs.remove_from_move_limbo = lambda *a: called.append(a)
 
821
 
 
822
        # create context and call
 
823
        key = FSKey(self.main.fs)
 
824
        ssmr = SyncStateMachineRunner(fsm=self.fsm, main=self.main,
 
825
                                      key=key, logger=None)
 
826
        ssmr.clean_move_limbo('some event', {}, 'share_id', 'node_id')
 
827
        self.assertEqual(called, [('share_id', 'node_id')])
 
828
 
738
829
 
739
830
class FakedState(object):
740
831
    """A faked state."""
983
1074
            is_dir=False)
984
1075
        node = self.main.fs.get_by_node_id(dt.share_id, dt.node_id)
985
1076
        self.main.fs.set_by_mdid(node.mdid, generation=dt.generation)
 
1077
        return node
986
1078
 
987
1079
    def create_dir(self):
988
1080
        """Create a directory based on self.dirdelta."""
1057
1149
 
1058
1150
        # check that the file is created
1059
1151
        node = self.main.fs.get_by_node_id(ROOT, self.filetxtdelta.node_id)
1060
 
        self.assertEqual(node.path, self.filetxtdelta.name)
 
1152
        self.assertEqual(node.path, self.filetxtdelta.name.encode('utf8'))
1061
1153
        self.assertEqual(node.is_dir, False)
1062
1154
        self.assertEqual(node.generation, self.filetxtdelta.generation)
1063
1155
 
1072
1164
                      full=True, free_bytes=10)
1073
1165
        self.sync.handle_AQ_DELTA_OK(**kwargs)
1074
1166
 
1075
 
        # check that the file is created
 
1167
        # check that the file is still there
1076
1168
        node = self.main.fs.get_by_node_id(ROOT, self.filetxtdelta.node_id)
1077
1169
        self.assertEqual(node.generation, dt2.generation)
1078
1170
 
 
1171
    def test_not_new_file_while_in_trash(self):
 
1172
        """Don't issue SV_FILE_NEW if file is in trash."""
 
1173
        # create the file and move it to trash
 
1174
        node = self.create_filetxt()
 
1175
        self.main.fs.delete_to_trash(node.mdid, self.root_id)
 
1176
 
 
1177
        # flag the SV_FILE_NEW calling
 
1178
        called = []
 
1179
        self.sync._handle_SV_FILE_NEW = lambda *a: called.append(True)
 
1180
 
 
1181
        kwargs = dict(volume_id=ROOT, delta_content=[self.filetxtdelta],
 
1182
                      end_generation=11, full=True, free_bytes=10)
 
1183
        self.sync.handle_AQ_DELTA_OK(**kwargs)
 
1184
 
 
1185
        # check that we didn't call the method
 
1186
        self.assertFalse(called)
 
1187
 
1079
1188
    def test_existing_file_dead(self):
1080
1189
        """The handler for SV_FILE_DELETED is called"""
1081
1190
        # send a new delta
1102
1211
 
1103
1212
        # check that the dir is created
1104
1213
        node = self.main.fs.get_by_node_id(ROOT, self.dirdelta.node_id)
1105
 
        self.assertEqual(node.path, self.dirdelta.name)
 
1214
        self.assertEqual(node.path, self.dirdelta.name.encode('utf8'))
1106
1215
        self.assertEqual(node.is_dir, True)
1107
1216
        self.assertEqual(node.generation, self.dirdelta.generation)
1108
1217