531
531
self.assertEqual(called[1:],
532
532
['AQ_DIR_NEW_ERROR', params, failure, 'marker'])
534
def test_AQ_MOVE_OK_with_node(self):
535
"""Handle AQ_MOVE_OK having a node."""
538
self.patch(SyncStateMachineRunner, 'clean_move_limbo',
539
lambda *a: called.extend(a))
542
somepath = os.path.join(self.root, 'somepath')
543
self.fsm.create(somepath, '', node_id='node_id')
545
self.sync.handle_AQ_MOVE_OK('', 'node_id', 123)
546
self.assertEqual(called[1:], ['AQ_MOVE_OK', {}, '', 'node_id'])
548
def test_AQ_MOVE_OK_no_node(self):
549
"""Handle AQ_MOVE_OK not having a node."""
552
self.patch(SyncStateMachineRunner, 'clean_move_limbo',
553
lambda *a: called.extend(a))
555
self.sync.handle_AQ_MOVE_OK('', 'node_id', 123)
556
self.assertEqual(called[1:], ['AQ_MOVE_OK', {}, '', 'node_id'])
558
def test_AQ_MOVE_ERROR_with_node(self):
559
"""Handle AQ_MOVE_ERROR having a node."""
562
self.patch(SyncStateMachineRunner, 'clean_move_limbo',
563
lambda *a: called.extend(a))
566
somepath = os.path.join(self.root, 'somepath')
567
self.fsm.create(somepath, '', node_id='node_id')
569
self.sync.handle_AQ_MOVE_ERROR('', 'node_id', 'parent', 'error')
570
self.assertEqual(called[1:], ['AQ_MOVE_ERROR', {}, '', 'node_id'])
572
def test_AQ_MOVE_ERROR_no_node(self):
573
"""Handle AQ_MOVE_ERROR not having a node."""
576
self.patch(SyncStateMachineRunner, 'clean_move_limbo',
577
lambda *a: called.extend(a))
579
self.sync.handle_AQ_MOVE_ERROR('', 'node_id', 'parent', 'error')
580
self.assertEqual(called[1:], ['AQ_MOVE_ERROR', {}, '', 'node_id'])
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')
722
# patch to control the call to dereference the limbos
724
self.fsm.dereference_ok_limbos = lambda *a: called.append(a)
674
726
# create context and call
675
727
key = FSKey(self.main.fs)
676
728
ssmr = SyncStateMachineRunner(fsm=self.fsm, main=self.main,
718
771
# set up the DeferredMap
719
772
map_d = self.aq.uuid_map.get('mrker')
774
# patch to control the call to dereference the limbos
776
self.fsm.dereference_err_limbos = lambda *a: called.append(a)
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',)])
735
793
# no exception? fail!!
736
794
self.fail("The marker was released without failure!")
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')
803
# patch HQ to don't hash the file
804
self.main.hash_q.insert = lambda *a: None
808
self.main.fs.add_to_move_limbo = lambda *a: called.append(a)
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)
817
def test_clean_move_limbo(self):
818
"""Clean the move limbo with what was called."""
820
self.main.fs.remove_from_move_limbo = lambda *a: called.append(a)
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')])
739
830
class FakedState(object):
740
831
"""A faked state."""
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)
1072
1164
full=True, free_bytes=10)
1073
1165
self.sync.handle_AQ_DELTA_OK(**kwargs)
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)
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)
1177
# flag the SV_FILE_NEW calling
1179
self.sync._handle_SV_FILE_NEW = lambda *a: called.append(True)
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)
1185
# check that we didn't call the method
1186
self.assertFalse(called)
1079
1188
def test_existing_file_dead(self):
1080
1189
"""The handler for SV_FILE_DELETED is called"""
1081
1190
# send a new delta
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)