Example #1
0
def test_validate_one_of():
    validator = validate_one_of(('a', 'b', 'c'))

    for value in ('1', '', [1, 2, 3, 4, 5]):
        field.value = value
        with pytest.raises(ValidationError):
            validator(field, {})

    for value in (None, 'a', 'b', 'c'):
        field.value = value
        validator(field, {})
def test_validate_one_of():
    validator = validate_one_of(('a', 'b', 'c'))

    for value in ('1', '', [1, 2, 3, 4, 5]):
        field.value = value
        with pytest.raises(ValidationError):
            validator(field, {})

    for value in (None, 'a', 'b', 'c'):
        field.value = value
        validator(field, {})
Example #3
0
class SimpleValidator(Validator):
    name = StringField(validators=[
        validate_not_empty(),
        validate_length(3, 99),
        validate_regexp('^[a-zA-Z ]*$')
    ])
    email = StringField(validators=[validate_email()])
    art_name = StringField(
        validators=[validate_not_empty(),
                    validate_length(3, 99)])
    art_price = DecimalField(
        validators=[validate_not_empty(),
                    validate_range(1, 9999)])
    availability = StringField(validators=[validate_one_of(['yes', 'no'])])
 class TestValidator(Validator):
     first_name = StringField(validators=[validate_one_of(getchoices)])
 class TestValidator(Validator):
     int_field = IntegerField(validators=[validate_one_of((1, 2, 3))])
 class TestValidator(Validator):
     first_name = StringField(validators=[validate_one_of(('tim', 'bob'))])