def test_len(self): # test batch = Batch() batch.items = [1, 2] # validation self.assertEqual(len(batch), len(batch.items))
def test_reset(self): # test batch = Batch() batch.items = {'A': 1} batch.reset() # validation self.assertEqual(batch.items, {})
def test_call(self, relink, migrate, reset): # test batch = Batch() batch.items = [12] batch() # validate relink.assert_called_once_with() migrate.assert_called_once_with() reset.assert_called_once_with()
def test_migrate(self): plan = Mock() items = [ Item(plan, '1', 'path-1', 'new-path-1', []), Item(plan, '2', 'path-2', 'new-path-2', []), Item(plan, '3', 'path-3', 'new-path-3', []), ] # test batch = Batch() batch.items = items batch._migrate() # validate for i in items: expected_call = call(i.unit_id, i.storage_path, i.new_path) self.assertTrue(expected_call in plan.migrate.call_args_list)
def test_migrate(self): plan = Mock() items = [ Item(plan, '1', 'path-1', 'new-path-1', []), Item(plan, '2', 'path-2', 'new-path-2', []), Item(plan, '3', 'path-3', 'new-path-3', []), ] # test batch = Batch() batch.items = items batch._migrate() # validate for i in items: expected_call = call(i.unit_id, i.storage_path, i.new_path) self.assertIn(expected_call, plan.migrate.call_args_list)
def test_migrate(self): plan = Mock() items = [ Item(plan, '1', 'path-1', 'new-path-1', []), Item(plan, '2', 'path-2', 'new-path-2', []), Item(plan, '3', 'path-3', 'new-path-3', []), ] # test batch = Batch() batch.items = items batch._migrate() # validate self.assertEqual( plan.migrate.call_args_list, [ call(i.unit_id, i.storage_path, i.new_path) for i in items ])
def test_migrate(self, unit_migrate): items = [ Item(Mock(), '1', 'path-1', 'new-path-1'), Item(Mock(), '2', 'path-2', 'new-path-2'), Item(Mock(), '3', 'path-3', 'new-path-3'), ] _dict = Mock() _dict.itervalues.return_value = iter(items) # test batch = Batch() batch.items = _dict batch._migrate() # validate self.assertEqual( unit_migrate.call_args_list, [ call(i.plan, i.unit_id, i.storage_path, i.new_path) for i in items ])
def test_relink(self, islink, symlink, unlink, readlink, walk): def read_link(path): return path.upper() readlink.side_effect = read_link def is_link(path): return os.path.basename(path)[0] == 'l' islink.side_effect = is_link items = { 'D0/L2': Item(1, '1', 'd0/l2', 'new-path-1'), 'D1/L3': Item(2, '2', 'd1/l3', 'new-path-2'), 'D2/L6': Item(3, '3', 'd2/l6', 'new-path-3'), } walk.return_value = [ ('d0', ['d1', 'd2'], ['f1', 'l2']), ('d1', [], ['l3', 'f4']), ('d2', [], ['f5', 'l6', 'l7']) ] # test batch = Batch() batch.items = items batch._relink() # validation self.assertEqual( unlink.call_args_list, [ call(items[k].storage_path) for k in sorted(items) ]) self.assertEqual( symlink.call_args_list, [ call(items[k].new_path, k.lower()) for k in sorted(items) ])