def test_string_validator(self): v = String() self.assertEqual("foo", v.validate("foo")) with self.assertRaises(ValidationError) as c: v.validate(1) self.assertEqual("Expected str got int instead.", str(c.exception))
def test_string_validator_max_len_kw(self): v = String(max_len=3) self.assertEqual("foo", v.validate("foo")) with self.assertRaises(ValidationError) as c: v.validate("foobar") self.assertEqual("String exceeds max length of 3.", str(c.exception))
class PersonSchema(ObjectSchema): id = Integer() name = String() dob = DateTime(format='%Y-%m-%dT%H:%M:%S') title = String(optional=True) address = EnsureType("Address") jobs = List(EnsureType("Job"))
def test_string_validator_min_len_kw(self): v = String(min_len=3) with self.assertRaises(ValidationError) as c: v.validate("fo") self.assertEqual("String must be at least length 3.", str(c.exception))
class _Notification(ObjectSchema): SignatureVersion = String() Timestamp = String() Signature = String() Type = String() SigningCertURL = String() MessageId = String() Message = String() UnsubscribeURL = String() TopicArn = String() Subject = String()
def test_create(self): schema_cls = ObjectSchema.create("MySchema", { "first-name": String(), "last-name": String(optional=True) }) self.assertEqual(type(schema_cls), SchemaMeta) self.assertIsInstance(schema_cls(), ObjectSchema) with self.assertRaises(ValidationError) as c: schema_cls().validate({'first-name': 1}) self.assertIn('first-name', c.exception.errors)
class Schema(ObjectSchema): title = String(min_len=1) thumbnail = String(min_len=1) body = String(min_len=1) #author = String(min_len=1) def get_defaults(self): return { 'id': uuid.uuid4().hex, 'created_at': time.time(), 'updated_at': time.time() }
class JobSchema(ObjectSchema): title = String() id = EnsureType(Foo)
class AddressSchema(ObjectSchema): number = Integer() street = String() suburb = String()
class _Message(ObjectSchema): StatusCode = String() AutoScalingGroupARN = String() Description = String() Service = String() Details = Dict(String()) AutoScalingGroupName = String() ActivityId = String() AccountId = String() RequestId = String() StartTime = DateTime(format='%Y-%m-%dT%H:%M:%S.%f') Time = DateTime(format='%Y-%m-%dT%H:%M:%S.%f') Progress = Integer() EndTime = DateTime(format='%Y-%m-%dT%H:%M:%S.%f') Cause = String() Event = String() StatusMessage = String() EC2InstanceId = String()
class PersonSchema(ObjectSchema): first_name = String() last_name = String() id = Integer() test = Float()
class JobSchema(ObjectSchema): title = String() id = Integer()
class BarSchema(BaseSchema): bar = String()
class BaseSchema(ObjectSchema): foo = String()
class PersonSchema(ObjectSchema): first_name = String() last_name = String(optional=True)
class PersonSchema(ObjectSchema): first_name = String() last_name = String() job = EnsureType("Job")
class JobSchema(ObjectSchema): role = String() active = Boolean(default=True)
class PersonSchema(ObjectSchema): first_name = String() last_name = String()
class PersonSchema(ObjectSchema): species = String(default="Human") first_name = String() last_name = String()
class TestRequestSchema(ObjectSchema): request_guid = String() players = List(EnsureType("Person"))