def test_invalid_values(value): class S(Schema): foo = String() schema = S() with pytest.raises(ValidationError): schema.serialize({'foo': value}) assert schema._raw_errors['foo'].message == String().message.invalid
def test_not_allowed_empty_with_whitespace(): class S(Schema): foo = String(allow_empty=False) schema = S() with pytest.raises(ValidationError): schema.serialize({'foo': ' '}) assert schema._raw_errors['foo'].message == String().message.empty
def test_schema_validation(): class S(Schema): foo = SubSchema(FooSchema) schema = S() with pytest.raises(ValidationError): schema.validate({'foo': {}}) assert schema._raw_errors['foo'].errors['a'].message == String( ).message.required
def test_nested_schema_validation(): class S(Schema): foo = SubSchema(FooSchema, required=True) class Node(Schema): label = String(required=True) sub = SubSchema(S, required=True) class Root(Schema): node = SubSchema(Node, required=True) schema = Root() with pytest.raises(ValidationError): schema.validate({'node': {'label': 'test', 'sub': {'foo': {}}}}) assert schema._raw_errors['node'].errors['sub'].errors['foo'].errors[ 'a'].message == String().message.required
class Node(Schema): id = String() label = String()
class CarBrand(Schema): label = String(required=True) desc = String(required=True)
class Node(Schema): id = String(required=True) label = String() nodes = List(SubSchema(Stuff, allow_none=True))
class Stuff(Schema): id = String(required=True) label = String()
class A(Schema): a = Any([Float(), String()]) b = Any([Float(), String()])
class Node(Schema): label = String(required=True) id = String(pre_serialize=[upper])
class Root(PolySchema): node = SubSchema(Node, allow_none=True) enabled = Boolean(default=False) category = String(required=True) __poly_on__ = category
class FooSchema(Schema): bar = String()
class S(Schema): foo = String()
class S(Schema): foo = String(allow_empty=False)
class Node(Schema): class Meta: options = SchemaOptions(output_missing=True) id = String() label = String()
class Node(Schema): id = String(required=True) node = List(SubSchema('Node'), allow_none=True)
class FooSchema(Schema): a = String(required=True)
class Node(Schema): label = String(required=True) sub = SubSchema(S, required=True)
class Node(Schema): id = String(required=True) node = SelfReference(allow_none=True)
class Node(Schema): label = String(required=True) id = String()
class A(Schema): a = Any([Float(strict=True), String()])