def test_valid_outputs(self):
     field = fields.List(fields.Integer())
     self._dump_equal(field, [], [])
     self._dump_equal(field, [1, 2, 3], [1, 2, 3])
     self._dump_equal(field, ['1', '2', '3'], [1, 2, 3])
     self._dump_equal(field, {1, 2, 3}, [1, 2, 3])
     self._dump_equal(field, ('1', '2', '3'), [1, 2, 3])
 def test_valid_inputs(self):
     field = fields.List(fields.Integer())
     self._load_equal(field, [], [])
     self._load_equal(field, [1, 2, 3], [1, 2, 3])
     self._load_equal(field, ['1', '2', '3'], [1, 2, 3])
     self._load_equal(field, {1, 2}, [1, 2])
     self._load_equal(field, (1, 2), [1, 2])
Ejemplo n.º 3
0
class MyContract(Contract):
    property1 = fields.Boolean()
    # property2 = fields.Date()
    property3 = fields.Integer()
    property4 = fields.String()
    property5 = fields.List(fields.Integer())
    # property6 = fields.UUID()
    # property7 = fields.DateTime()
    property8 = fields.Float()
    property9 = fields.Nested(NestedContract)
 def test_disallow_empty(self):
     field = fields.List(fields.Integer(), allow_empty=False)
     self._load_raises(field, [], ['This list may not be empty.'])
 def test_invalid_inputs(self):
     field = fields.List(fields.Integer())
     self._load_raises(field, 'not a list', ['Not a valid list.'])
     self._load_raises(field, [1, 2, 'error'], [{
         2: ['A valid integer is required.']
     }])