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_valid_outputs(self): field = fields.String(min_length=1, max_length=3) self._dump_equal(field, '', '') self._dump_equal(field, '12345', '12345')
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.'])
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')
def test_allow_none_with_empty_value(self): field = fields.String(allow_none=True) self._load_equal(field, '', None)
def test_allow_blank(self): field = fields.String(allow_blank=True) self._load_equal(field, '', '')
def test_trim_whitespace_with_space_value(self): field = fields.String(trim_whitespace=True) self._load_raises(field, ' ', ['This field may not be blank.'])
def test_trim_whitespace(self): field = fields.String(trim_whitespace=True) self._load_equal(field, ' abc ', 'abc')
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')
def test_invalid_inputs(self): field = fields.String() self._load_raises(field, '', ['This field may not be blank.'])
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 ')
class NestedContract(Contract): property1 = fields.String() property2 = fields.String()