def setUp(self): self.fields = [ api.ClientIDsField(False, False), api.ClientIDsField(False, True), api.ClientIDsField(True, False), api.ClientIDsField(True, True) ]
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.ClientIDsField(False, False), api.ClientIDsField(False, True)): self.assertIsNone(f.validate(None), msg="on None") # could be empty fields for f in (api.ClientIDsField(False, True), api.ClientIDsField(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.ClientIDsField(True, False), api.ClientIDsField(True, True)): with self.assertRaises(api.ValidationError, msg=" on None"): f.validate(None) # empty fields for f in (api.ClientIDsField(False, False), api.ClientIDsField(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.ClientIDsField(required=False, nullable=False)
class TestRequest(api.Request): f = api.ClientIDsField(required=True, nullable=True)