def test_init(self): valid_sync_types = [ 'file_at_src_and_dest', 'file_not_at_dest', 'file_not_at_src' ] for sync_type in valid_sync_types: strategy = BaseSync(sync_type) self.assertEqual(strategy.sync_type, sync_type) # Check for invalid ``sync_type`` options. with self.assertRaises(ValueError): BaseSync('wrong_sync_type')
def setUp(self): self.sync_strategy = BaseSync()
class TestBaseSync(unittest.TestCase): def setUp(self): self.sync_strategy = BaseSync() def test_init(self): valid_sync_types = ['file_at_src_and_dest', 'file_not_at_dest', 'file_not_at_src'] for sync_type in valid_sync_types: strategy = BaseSync(sync_type) self.assertEqual(strategy.sync_type, sync_type) # Check for invalid ``sync_type`` options. with self.assertRaises(ValueError): BaseSync('wrong_sync_type') def test_register_strategy(self): """ Ensures that the class registers all of the necessary handlers """ session = Mock() self.sync_strategy.register_strategy(session) register_args = session.register.call_args_list self.assertEqual(register_args[0][0][0], 'building-arg-table.sync') self.assertEqual(register_args[0][0][1], self.sync_strategy.add_sync_argument) self.assertEqual(register_args[1][0][0], 'choosing-s3-sync-strategy') self.assertEqual(register_args[1][0][1], self.sync_strategy.use_sync_strategy) def test_determine_should_sync(self): """ Ensure that this class cannot be directly used as the sync strategy. """ with self.assertRaises(NotImplementedError): self.sync_strategy.determine_should_sync(None, None) def test_arg_name(self): """ Ensure that the ``arg_name`` property works as expected. """ self.assertEqual(self.sync_strategy.arg_name, None) self.sync_strategy.ARGUMENT = {'name': 'my-sync-strategy'} self.assertEqual(self.sync_strategy.arg_name, 'my-sync-strategy') def test_arg_dest(self): """ Ensure that the ``arg_dest`` property works as expected. """ self.assertEqual(self.sync_strategy.arg_dest, None) self.sync_strategy.ARGUMENT = {'dest': 'my-dest'} self.assertEqual(self.sync_strategy.arg_dest, 'my-dest') def test_add_sync_argument(self): """ Ensures the sync argument is properly added to the the command's ``arg_table``. """ arg_table = [{'name': 'original_argument'}] self.sync_strategy.ARGUMENT = {'name': 'sync_argument'} self.sync_strategy.add_sync_argument(arg_table) self.assertEqual(arg_table, [{'name': 'original_argument'}, {'name': 'sync_argument'}]) def test_no_add_sync_argument_for_no_argument_specified(self): """ Ensures nothing is added to the command's ``arg_table`` if no ``ARGUMENT`` table is specified. """ arg_table = [{'name': 'original_argument'}] self.sync_strategy.add_sync_argument(arg_table) self.assertEqual(arg_table, [{'name': 'original_argument'}]) def test_no_use_sync_strategy_for_no_argument_specified(self): """ Test if that the sync strategy is not returned if it has no argument. """ params = {'my_sync_strategy': True} self.assertEqual(self.sync_strategy.use_sync_strategy(params), None) def test_use_sync_strategy_for_name_and_no_dest(self): """ Test if sync strategy argument has ``name`` but no ``dest`` and the strategy was called in ``params``. """ self.sync_strategy.ARGUMENT = {'name': 'my-sync-strategy'} params = {'my_sync_strategy': True} self.assertEqual(self.sync_strategy.use_sync_strategy(params), self.sync_strategy) def test_no_use_sync_strategy_for_name_and_no_dest(self): """ Test if sync strategy argument has ``name`` but no ``dest`` but the strategy was not called in ``params``. """ self.sync_strategy.ARGUMENT = {'name': 'my-sync-strategy'} params = {'my_sync_strategy': False} self.assertEqual(self.sync_strategy.use_sync_strategy(params), None) def test_no_use_sync_strategy_for_not_in_params(self): """ Test if sync strategy argument has a ``name`` but for whatever reason the strategy is not in ``params``. """ self.sync_strategy.ARGUMENT = {'name': 'my-sync-strategy'} self.assertEqual(self.sync_strategy.use_sync_strategy({}), None) def test_use_sync_strategy_for_name_and_dest(self): """ Test if sync strategy argument has ``name`` and ``dest`` and the strategy was called in ``params``. """ self.sync_strategy.ARGUMENT = {'name': 'my-sync-strategy', 'dest': 'my-dest'} params = {'my-dest': True} self.assertEqual(self.sync_strategy.use_sync_strategy(params), self.sync_strategy) def test_no_use_sync_strategy_for_name_and_dest(self): """ Test if sync strategy argument has ``name`` and ``dest`` but the the strategy was not called in ``params``. """ self.sync_strategy.ARGUMENT = {'name': 'my-sync-strategy', 'dest': 'my-dest'} params = {'my-dest': False} self.assertEqual(self.sync_strategy.use_sync_strategy(params), None) def test_no_use_sync_strategy_for_dest_but_only_name_in_params(self): """ Test if sync strategy argument has ``name`` and ``dest`` but the the strategy was not called in ``params`` even though the ``name`` was called in ``params``. """ self.sync_strategy.ARGUMENT = {'name': 'my-sync-strategy', 'dest': 'my-dest'} params = {'my-sync-strategy': True} self.assertEqual(self.sync_strategy.use_sync_strategy(params), None)
class TestBaseSync(unittest.TestCase): def setUp(self): self.sync_strategy = BaseSync() def test_init(self): valid_sync_types = [ 'file_at_src_and_dest', 'file_not_at_dest', 'file_not_at_src' ] for sync_type in valid_sync_types: strategy = BaseSync(sync_type) self.assertEqual(strategy.sync_type, sync_type) # Check for invalid ``sync_type`` options. with self.assertRaises(ValueError): BaseSync('wrong_sync_type') def test_register_strategy(self): """ Ensures that the class registers all of the necessary handlers """ session = Mock() self.sync_strategy.register_strategy(session) register_args = session.register.call_args_list self.assertEqual(register_args[0][0][0], 'building-arg-table.sync') self.assertEqual(register_args[0][0][1], self.sync_strategy.add_sync_argument) self.assertEqual(register_args[1][0][0], 'choosing-s3-sync-strategy') self.assertEqual(register_args[1][0][1], self.sync_strategy.use_sync_strategy) def test_determine_should_sync(self): """ Ensure that this class cannot be directly used as the sync strategy. """ with self.assertRaises(NotImplementedError): self.sync_strategy.determine_should_sync(None, None) def test_arg_name(self): """ Ensure that the ``arg_name`` property works as expected. """ self.assertEqual(self.sync_strategy.arg_name, None) self.sync_strategy.ARGUMENT = {'name': 'my-sync-strategy'} self.assertEqual(self.sync_strategy.arg_name, 'my-sync-strategy') def test_arg_dest(self): """ Ensure that the ``arg_dest`` property works as expected. """ self.assertEqual(self.sync_strategy.arg_dest, None) self.sync_strategy.ARGUMENT = {'dest': 'my-dest'} self.assertEqual(self.sync_strategy.arg_dest, 'my-dest') def test_add_sync_argument(self): """ Ensures the sync argument is properly added to the the command's ``arg_table``. """ arg_table = [{'name': 'original_argument'}] self.sync_strategy.ARGUMENT = {'name': 'sync_argument'} self.sync_strategy.add_sync_argument(arg_table) self.assertEqual(arg_table, [{ 'name': 'original_argument' }, { 'name': 'sync_argument' }]) def test_no_add_sync_argument_for_no_argument_specified(self): """ Ensures nothing is added to the command's ``arg_table`` if no ``ARGUMENT`` table is specified. """ arg_table = [{'name': 'original_argument'}] self.sync_strategy.add_sync_argument(arg_table) self.assertEqual(arg_table, [{'name': 'original_argument'}]) def test_no_use_sync_strategy_for_no_argument_specified(self): """ Test if that the sync strategy is not returned if it has no argument. """ params = {'my_sync_strategy': True} self.assertEqual(self.sync_strategy.use_sync_strategy(params), None) def test_use_sync_strategy_for_name_and_no_dest(self): """ Test if sync strategy argument has ``name`` but no ``dest`` and the strategy was called in ``params``. """ self.sync_strategy.ARGUMENT = {'name': 'my-sync-strategy'} params = {'my_sync_strategy': True} self.assertEqual(self.sync_strategy.use_sync_strategy(params), self.sync_strategy) def test_no_use_sync_strategy_for_name_and_no_dest(self): """ Test if sync strategy argument has ``name`` but no ``dest`` but the strategy was not called in ``params``. """ self.sync_strategy.ARGUMENT = {'name': 'my-sync-strategy'} params = {'my_sync_strategy': False} self.assertEqual(self.sync_strategy.use_sync_strategy(params), None) def test_no_use_sync_strategy_for_not_in_params(self): """ Test if sync strategy argument has a ``name`` but for whatever reason the strategy is not in ``params``. """ self.sync_strategy.ARGUMENT = {'name': 'my-sync-strategy'} self.assertEqual(self.sync_strategy.use_sync_strategy({}), None) def test_use_sync_strategy_for_name_and_dest(self): """ Test if sync strategy argument has ``name`` and ``dest`` and the strategy was called in ``params``. """ self.sync_strategy.ARGUMENT = { 'name': 'my-sync-strategy', 'dest': 'my-dest' } params = {'my-dest': True} self.assertEqual(self.sync_strategy.use_sync_strategy(params), self.sync_strategy) def test_no_use_sync_strategy_for_name_and_dest(self): """ Test if sync strategy argument has ``name`` and ``dest`` but the the strategy was not called in ``params``. """ self.sync_strategy.ARGUMENT = { 'name': 'my-sync-strategy', 'dest': 'my-dest' } params = {'my-dest': False} self.assertEqual(self.sync_strategy.use_sync_strategy(params), None) def test_no_use_sync_strategy_for_dest_but_only_name_in_params(self): """ Test if sync strategy argument has ``name`` and ``dest`` but the the strategy was not called in ``params`` even though the ``name`` was called in ``params``. """ self.sync_strategy.ARGUMENT = { 'name': 'my-sync-strategy', 'dest': 'my-dest' } params = {'my-sync-strategy': True} self.assertEqual(self.sync_strategy.use_sync_strategy(params), None)