def test_validate_on_correct_content(self): for f in self.fields: for val in self.valid_values: self.assertIsNone(f.validate(val), msg=" on content %s (type %s)" % (val, type(val))) # unreqired fields for f in (api.PhoneField(False, False), api.PhoneField(False, True)): self.assertIsNone(f.validate(None), msg="on None") # could be empty fields for f in (api.PhoneField(False, True), api.PhoneField(True, True)): for val in self.null_values: self.assertIsNone(f.validate(val), msg="on empty(null) values")
def test_validate_on_incorrect_content(self): for f in self.fields: for val in self.invalid_values: with self.assertRaises(api.ValidationError, msg=" on content %s (type %s)" % (val, type(val))): f.validate(val) # required fields for f in (api.PhoneField(True, False), api.PhoneField(True, True)): with self.assertRaises(api.ValidationError, msg=" on None"): f.validate(None) # empty fields for f in (api.PhoneField(False, False), api.PhoneField(True, False)): for val in self.null_values: with self.assertRaises(api.ValidationError, msg=" on empty content"): f.validate(val)
class TestRequest(api.Request): f = api.PhoneField(required=False, nullable=False)
def setUp(self): self.fields = [api.PhoneField(False, False), api.PhoneField(False, True), api.PhoneField(True, False), api.PhoneField(True, True)]
class TestRequest(api.Request): f = api.PhoneField(required=True, nullable=True)