def choose_sync_strategies(self): """Determines the sync strategy for the command. It defaults to the default sync strategies but a customizable sync strategy can overide the default strategy if it returns the instance of its self when the event is emitted. """ sync_strategies = {} # Set the default strategies. sync_strategies['file_at_src_and_dest_sync_strategy'] = \ SizeAndLastModifiedSync() sync_strategies['file_not_at_dest_sync_strategy'] = MissingFileSync() sync_strategies['file_not_at_src_sync_strategy'] = NeverSync() # Determine what strategies to overide if any. responses = self.session.emit('choosing-s3-sync-strategy', params=self.parameters) if responses is not None: for response in responses: override_sync_strategy = response[1] if override_sync_strategy is not None: sync_type = override_sync_strategy.sync_type sync_type += '_sync_strategy' sync_strategies[sync_type] = override_sync_strategy return sync_strategies
class TestMissingFileSync(unittest.TestCase): def setUp(self): self.sync_strategy = MissingFileSync() def test_constructor(self): self.assertEqual(self.sync_strategy.sync_type, 'file_not_at_dest') def test_determine_should_sync(self): time_src = datetime.datetime.now() src_file = FileStat(src='', dest='', compare_key='test.py', size=10, last_update=time_src, src_type='s3', dest_type='local', operation_name='') should_sync = self.sync_strategy.determine_should_sync( src_file, None) self.assertTrue(should_sync)
class TestMissingFileSync(unittest.TestCase): def setUp(self): self.sync_strategy = MissingFileSync() def test_constructor(self): self.assertEqual(self.sync_strategy.sync_type, 'file_not_at_dest') def test_determine_should_sync(self): time_src = datetime.datetime.now() src_file = FileStat(src='', dest='', compare_key='test.py', size=10, last_update=time_src, src_type='s3', dest_type='local', operation_name='') should_sync = self.sync_strategy.determine_should_sync(src_file, None) self.assertTrue(should_sync)
def setUp(self): self.sync_strategy = MissingFileSync()