Ejemplo n.º 1
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'])])
Ejemplo n.º 2
0
def test_validate_length():
    validator = validate_length(low=2, high=None, equal=None)

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

    for value in (None, '22', 'longer', [1, 2]):
        field.value = value
        validator(field, {})

    validator = validate_length(low=None, high=2, equal=None)

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

    for value in (None, '22', '', [1, 2]):
        field.value = value
        validator(field, {})

    validator = validate_length(low=None, high=None, equal=2)

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

    for value in (None, '22', [1, 2]):
        field.value = value
        validator(field, {})

    validator = validate_length(low=2, high=4, equal=None)

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

    for value in (None, '22', '2222', [1, 2]):
        field.value = value
        validator(field, {})
Ejemplo n.º 3
0
def test_validate_length():
    validator = validate_length(low=2, high=None, equal=None)

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

    for value in (None, '22', 'longer', [1, 2]):
        field.value = value
        validator(field, {})

    validator = validate_length(low=None, high=2, equal=None)

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

    for value in (None, '22', '', [1, 2]):
        field.value = value
        validator(field, {})

    validator = validate_length(low=None, high=None, equal=2)

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

    for value in (None, '22', [1, 2]):
        field.value = value
        validator(field, {})

    validator = validate_length(low=2, high=4, equal=None)

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

    for value in (None, '22', '2222', [1, 2]):
        field.value = value
        validator(field, {})
Ejemplo n.º 4
0
 class TestValidator(Validator):
     max_field = StringField(max_length=5)
     min_field = StringField(min_length=5)
     len_field = StringField(validators=[validate_length(equal=10)])
Ejemplo n.º 5
0
 class TestValidator(Validator):
     max_field = Field(str, max_length=5)
     min_field = Field(str, min_length=5)
     len_field = Field(str, validators=[validate_length(10)])