def validate(value): try: return strutils.bool_from_string(value, strict=True) except ValueError as e: # raise Invalid to return 400 (BadRequest) in the API raise exception.Invalid(e)
def test_Invalid(self): self.assertRaises(exception.Invalid, lambda: self.raise_(exception.Invalid()))