コード例 #1
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)
コード例 #2
0
 def test_valid_outputs(self):
     field = fields.String(min_length=1, max_length=3)
     self._dump_equal(field, '', '')
     self._dump_equal(field, '12345', '12345')
コード例 #3
0
 def test_invalid_inputs(self):
     field = fields.String(min_length=2, max_length=4)
     self._load_raises(field, '1', ['Shorter than minimum length 2.'])
     self._load_raises(field, 'abcde', ['Longer than maximum length 4.'])
コード例 #4
0
 def test_valid_inputs(self):
     field = fields.String(min_length=2, max_length=4)
     self._load_equal(field, 12, '12')
     self._load_equal(field, 1.0, '1.0')
     self._load_equal(field, 'ab', 'ab')
     self._load_equal(field, 'abcd', 'abcd')
コード例 #5
0
 def test_allow_none_with_empty_value(self):
     field = fields.String(allow_none=True)
     self._load_equal(field, '', None)
コード例 #6
0
 def test_allow_blank(self):
     field = fields.String(allow_blank=True)
     self._load_equal(field, '', '')
コード例 #7
0
 def test_trim_whitespace_with_space_value(self):
     field = fields.String(trim_whitespace=True)
     self._load_raises(field, ' ', ['This field may not be blank.'])
コード例 #8
0
 def test_trim_whitespace(self):
     field = fields.String(trim_whitespace=True)
     self._load_equal(field, ' abc ', 'abc')
コード例 #9
0
 def test_valid_outputs(self):
     field = fields.String()
     self._dump_equal(field, 1, '1')
     self._dump_equal(field, 1.0, '1.0')
     self._dump_equal(field, 'abc', 'abc')
コード例 #10
0
 def test_invalid_inputs(self):
     field = fields.String()
     self._load_raises(field, '', ['This field may not be blank.'])
コード例 #11
0
 def test_valid_inputs(self):
     field = fields.String()
     self._load_equal(field, 1, '1')
     self._load_equal(field, 'abc', 'abc')
     self._load_equal(field, ' abc ', ' abc ')
コード例 #12
0
class NestedContract(Contract):
    property1 = fields.String()
    property2 = fields.String()