class PersonSchema(Form): name = String age = Integer.using(validators=[ ValueAtLeast(minimum=18), ValueAtMost(maximum=120) ]) weight = Integer.using(validators=[ ValueAtLeast(minimum=0), ValueAtMost(maximum=300) ]) weight.render_options = dict( style='slider' ) friendly = Boolean address = String.using() address.render_options = dict( style='multiline' ) happy = Boolean.using() happy.render_options = dict( style='toggle' )
def test_set_with_all(): Int = Integer.using(optional=True) schema = (Dict.named(u'point').of( Int.named(u'x'), Int.named(u'y')).using(policy=None).validated_by(SetWithAllFields())) # no coverage of set_flat el = schema.from_flat([(u'point_x', u'1'), (u'point_Z', u'3')]) assert el.value == {u'x': 1, u'y': None} assert el.validate() el = schema({u'x': 1, u'Z': 3}) assert el.value == {u'x': 1, u'y': None} assert not el.validate() assert el.errors == [u'point must contain y and not contain Z'] el = schema({u'x': 1, u'y': 2, u'Z': 3, u'A': 4}) assert el.value == {u'x': 1, u'y': 2} assert not el.validate() assert el.errors == [u'point may not contain A, Z'] el = schema({u'x': 1}) assert el.value == {u'x': 1, u'y': None} assert not el.validate() assert el.errors == [u'point must contain y']
def test_shortcircuit_up(self): schema = (Dict.of( Integer.using(validators=[self.validator('2', True)])).using( descent_validators=[self.validator('1', True)], validators=[self.validator('3', SkipAll)])) el = schema() assert el.validate() eq_(self.canary, ['1', '2', '3']) assert el.valid assert el.all_valid
def test_paired3(self): schema = (Dict.of( Integer.using(validators=[self.validator('2', True)])).using( descent_validators=[self.validator('1', True)], validators=[self.validator('3', True)])) el = schema() assert el.validate() eq_(self.canary, ['1', '2', '3']) assert el.valid assert el.all_valid
class Schema(Form): i1 = Integer.using(default=0) d1 = Dict.of( Integer.named('d1i1').using(default=1), Integer.named('d1i2').using(default=2)) l1 = List.using(default=2).of(Integer.named('l1i1').using(default=3)) l2 = List.using(default=3).of( Integer.named('l2i1').using(default=4), Integer.named('l2i2').using(default=5)) l3 = List.using(default=2).of( List.named('l3l1').using(default=2).of(Integer.using(default=6))) a1 = Array.using(default=[10, 11, 12, 13, 14, 15]).of(Integer) dt1 = DateYYYYMMDD.using(default=date.today())
def test_shortcircuit_up(self): schema = ( Dict.of( Integer.using(validators=[self.validator('2', True)])). using( descent_validators=[self.validator('1', True)], validators=[self.validator('3', SkipAll)])) el = schema() assert el.validate() eq_(self.canary, ['1', '2', '3']) assert el.valid assert el.all_valid
def test_paired3(self): schema = ( Dict.of( Integer.using(validators=[self.validator('2', True)])). using( descent_validators=[self.validator('1', True)], validators=[self.validator('3', True)])) el = schema() assert el.validate() eq_(self.canary, ['1', '2', '3']) assert el.valid assert el.all_valid
def test_shortcircuit_down_true(self): schema = ( Dict.of( Integer.using(validators=[self.validator('2', False)])). using( descent_validators=[self.validator('1', SkipAll)], validators=[self.validator('3', True)])) el = schema() assert el.validate() assert self.canary == ['1', '3'] assert el.valid assert el.all_valid
def test_simple_validation_shortcircuit(): Regular = Dict.of(Integer.using(optional=False)) el = Regular() assert not el.validate() def boom(element, state): assert False all_ok = lambda element, state: SkipAll Boom = Integer.named(u'i').using(validators=[boom]) ShortCircuited = Dict.of(Boom).using(descent_validators=[all_ok]) el = ShortCircuited() assert el.validate()
class MyForm(Form): x = Integer.using(validators=[Present()]) d2 = Dict.of(Integer.named('x2').using(validators=[Present()]))
class MyForm(Form): x = Integer.using(validators=[Present()])