def test_integer_valid_1(): """5 is a valid integer""" test_string = Integer() test_string.validate(5) assert True
def test_integer_invalid_1(): """String is not a valid value""" test_string = Integer() with assert_raises(InvalidPropertyError) as cm: test_string.validate('foo') assert cm.exception.error == 'invalid'
class BlogPost(Model): id = Uuid(default_value=uuid4) title = String(validators=[ min_length(3), max_length(100), regex(r'^([A-Za-z0-9- !.]*)$') ]) body = String(default_value=u'Lorem ipsum', error_key='text') meta_data = Dict(mapping={'corrector': String(), 'reviewer': String()}) published = Boolean() likes = Integer(required=False) category = String(required=False) tags = List(property=String(validators=[min_length(3)]), error_key='category') author = Object(model_class=Author) created_on = DateTime(default_value=datetime.now) updated_on = DateTime(default_value=datetime.now) revisions = List(required=False, property=Object(model_class=Revision)) @model_validator(error_key='category') def category_or_tags(self): assert self.tags is not None or self.category is not None, ERROR_REQUIRED def __init__(self, **kwargs): super(BlogPost, self).__init__(**kwargs) self.foo = "bar"