Esempio n. 1
0
def test_validation_multiline():
    validator = validators.Regex('^s.*e$')
    validator.validate('some')
    with pytest.raises(errors.ValidationError):
        validator.validate('some\nso more')

    validator = validators.Regex('^s.*e$', multiline=True)
    validator.validate('some')
    validator.validate('some\nso more')
Esempio n. 2
0
def test_validation_ignorecase():
    validator = validators.Regex('^some$')
    validator.validate('some')
    with pytest.raises(errors.ValidationError):
        validator.validate('sOmE')

    validator = validators.Regex('^some$', ignorecase=True)
    validator.validate('some')
    validator.validate('SoMe')
Esempio n. 3
0
def test_regex_validation_for_wrong_type():

    validator = validators.Regex('some')
    assert 'some' == validator.pattern

    with pytest.raises(errors.ValidationError):
        validator.validate(1)
Esempio n. 4
0
def test_regex_validation_flags():
    # Invalid flags ignored
    validator = validators.Regex("foo", bla=True, ble=False, ignorecase=True)
    assert validator.flags == [validators.Regex.FLAGS["ignorecase"]]

    # Flag kwargs must be True-y
    validator = validators.Regex("foo", ignorecase=False, multiline=True)
    assert validator.flags == [validators.Regex.FLAGS["multiline"]]

    # ECMA pattern flags recognized
    validator = validators.Regex("/foo/im")
    assert sorted(validator.flags) == sorted([
        validators.Regex.FLAGS["multiline"],
        validators.Regex.FLAGS["ignorecase"],
    ])

    # ECMA pattern overrides flags kwargs
    validator = validators.Regex("/foo/", ignorecase=True, multiline=True)
    assert validator.flags == []
Esempio n. 5
0
def test_regex_validation():

    validator = validators.Regex('some')
    assert 'some' == validator.pattern

    validator.validate('some string')
    validator.validate('get some chips')
    with pytest.raises(errors.ValidationError):
        validator.validate('asdf')
    with pytest.raises(errors.ValidationError):
        validator.validate('trololo')
Esempio n. 6
0
def test_validation_2():

    validator = validators.Regex('^some[0-9]$')
    assert '^some[0-9]$' == validator.pattern

    validator.validate('some0')
    with pytest.raises(errors.ValidationError):
        validator.validate('some')
    with pytest.raises(errors.ValidationError):
        validator.validate(' some')
    with pytest.raises(errors.ValidationError):
        validator.validate('asdf')
    with pytest.raises(errors.ValidationError):
        validator.validate('trololo')
Esempio n. 7
0
    class Person(models.Base):

        name = fields.StringField(
            validators=validators.Regex('^some pattern$', ignorecase=True))
Esempio n. 8
0
    class Person(models.Base):

        name = fields.StringField(
            validators=validators.Regex('/^some pattern$/'))
Esempio n. 9
0
    class Person(models.Base):

        name = fields.StringField(
            validators=validators.Regex('/^[a-z]+$/i', ignorecase=False))