示例#1
0
    def test_bad_tuple_field(self):
        class ASchema(Schema):
            id = fields.Int()

        with pytest.raises(ValueError):
            fields.Tuple(["string"])
        with pytest.raises(ValueError):
            fields.Tuple(fields.String)
        with pytest.raises(ValueError) as excinfo:
            fields.Tuple([ASchema])
        expected_msg = ('Elements of "tuple_fields" must be subclasses or '
                        "instances of marshmallow_muffin.base.FieldABC.")
        assert expected_msg in str(excinfo)
示例#2
0
 class MySchema(Schema):
     foo = fields.Field()
     bar = fields.List(fields.Str())
     baz = fields.Tuple([fields.Str(), fields.Int()])
示例#3
0
 def test_tuple_field_with_error(self, obj):
     field = fields.Tuple([fields.DateTime, fields.Integer])
     with pytest.raises(ValidationError):
         field.serialize("dtime_int", obj)
示例#4
0
 def test_tuple_field_serialize_none_returns_none(self):
     obj = DateTimeIntegerTuple(None)
     field = fields.Tuple([fields.DateTime, fields.Integer])
     assert field.serialize("dtime_int", obj) is None
示例#5
0
 def test_datetime_integer_tuple_field(self):
     obj = DateTimeIntegerTuple((dt.datetime.utcnow(), 42))
     field = fields.Tuple([fields.DateTime, fields.Integer])
     result = field.serialize("dtime_int", obj)
     assert type(result[0]) == str
     assert type(result[1]) == int