예제 #1
0
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
예제 #2
0
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
예제 #3
0
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
예제 #4
0
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
예제 #5
0
 class Node(Schema):
     id = String()
     label = String()
예제 #6
0
 class CarBrand(Schema):
     label = String(required=True)
     desc = String(required=True)
예제 #7
0
 class Node(Schema):
     id = String(required=True)
     label = String()
     nodes = List(SubSchema(Stuff, allow_none=True))
예제 #8
0
 class Stuff(Schema):
     id = String(required=True)
     label = String()
예제 #9
0
 class A(Schema):
     a = Any([Float(), String()])
     b = Any([Float(), String()])
예제 #10
0
 class Node(Schema):
     label = String(required=True)
     id = String(pre_serialize=[upper])
예제 #11
0
    class Root(PolySchema):
        node = SubSchema(Node, allow_none=True)
        enabled = Boolean(default=False)
        category = String(required=True)

        __poly_on__ = category
예제 #12
0
 class FooSchema(Schema):
     bar = String()
예제 #13
0
 class S(Schema):
     foo = String()
예제 #14
0
 class S(Schema):
     foo = String(allow_empty=False)
예제 #15
0
    class Node(Schema):
        class Meta:
            options = SchemaOptions(output_missing=True)

        id = String()
        label = String()
예제 #16
0
 class Node(Schema):
     id = String(required=True)
     node = List(SubSchema('Node'), allow_none=True)
예제 #17
0
class FooSchema(Schema):
    a = String(required=True)
예제 #18
0
 class Node(Schema):
     label = String(required=True)
     sub = SubSchema(S, required=True)
예제 #19
0
 class Node(Schema):
     id = String(required=True)
     node = SelfReference(allow_none=True)
예제 #20
0
 class Node(Schema):
     label = String(required=True)
     id = String()
예제 #21
0
 class A(Schema):
     a = Any([Float(strict=True), String()])