def test_with_rollback_gen_type_3(self): """Get StopIteration exception""" self.obj0.return_value.next.side_effect = StopIteration with self.assertRaises(type(self.exc)): wrapped = cmd.with_rollback(self.obj0) wrapped(self.ctx_mock, "arg1", "arg2") self.assertEquals([mock.call(self.ctx_mock, "arg1", "arg2")], self.obj0.call_args_list) self.assertFalse(self.ctx_mock.add_rollback.called)
def test_with_rollback_gen_type_0(self): """Don't get any exception""" wrapped = cmd.with_rollback(self.obj0) wrapped(self.ctx_mock, "arg1", "arg2") self.assertEquals([mock.call(self.ctx_mock, "arg1", "arg2")], self.obj0.call_args_list) rollback_fn = self.ctx_mock.add_rollback.call_args[0][0] rollback_fn(True) self.assertTrue(self.ctx_mock.add_rollback.called) self.assertTrue(self.obj0.return_value.close.called)
def test_with_rollback_gen_type_2(self): """Get exception during rollback""" self.obj0.return_value.throw.side_effect = Exception() wrapped = cmd.with_rollback(self.obj0) wrapped(self.ctx_mock, "arg1", "arg2") self.assertEquals([mock.call(self.ctx_mock, "arg1", "arg2")], self.obj0.call_args_list) rollback_fn = self.ctx_mock.add_rollback.call_args[0][0] rollback_fn(False) self.assertTrue(self.ctx_mock.add_rollback.called) self.assertEquals(self.obj0.return_value.throw.call_args_list, [mock.call(cmd.Rollback)])
def test_with_rollback_non_gen_type(self): with self.assertRaises(type(self.exc)): wrapped = cmd.with_rollback(self.obj1) wrapped(self.ctx_mock, "arg1", "arg2")