Example #1
0
def test_regex():
    v = V.regex('shrubbery\d{3}$', 'regex')
    assert v.__name__ == "regex"
    assert v('shrubbery222') == 'shrubbery222'
    assert_invalid(
        lambda: v('buy a shrubbery333, ok?'),
        {None: 'regex'})
Example #2
0
def test_schema_1():
    s = V.Schema(
        dict(username=(V.strip,
                       V.regex('[a-z][a-z0-9]+',
                               'invalid username'),
                       V.clamp_length(max=16,
                                      msg='username is too long'),
                       ),
             user_id=V.either(V.empty(),
                              V.all_of(V.to_integer('not an integer'),
                                        V.clamp(min=1, max=9999, msg='out of range')
                                        )
                              ),
             department=(V.strip,
                         V.belongs(['interactive', 'programming'],
                                   'department not recognized')
                         ),
             ),
        "there were errors with your submission"
        )
    data = dict(username='******',
                user_id='1',
                department='interactive')
    newdata = s(data)
    assert data['username'] == newdata['username']
    assert int(data['user_id']) == newdata['user_id']
    assert data['department'] == newdata['department']
Example #3
0
def test_schema_1():
    s = V.Schema(
        dict(
            username=(
                V.strip,
                V.regex('[a-z][a-z0-9]+', 'invalid username'),
                V.clamp_length(max=16, msg='username is too long'),
            ),
            user_id=V.either(
                V.empty(),
                V.all_of(V.to_integer('not an integer'),
                         V.clamp(min=1, max=9999, msg='out of range'))),
            department=(V.strip,
                        V.belongs(['interactive', 'programming'],
                                  'department not recognized')),
        ), "there were errors with your submission")
    data = dict(username='******', user_id='1', department='interactive')
    newdata = s(data)
    assert data['username'] == newdata['username']
    assert int(data['user_id']) == newdata['user_id']
    assert data['department'] == newdata['department']
Example #4
0
def test_regex():
    v = V.regex('shrubbery\d{3}$', 'regex')
    assert v.__name__ == "regex"
    assert v('shrubbery222') == 'shrubbery222'
    assert_invalid(lambda: v('buy a shrubbery333, ok?'), {None: 'regex'})
Example #5
0
def test_regex():
    v=V.regex('shrubbery\d{3}$', 'regex')
    assert v('shrubbery222')=='shrubbery222'
    assert_invalid(lambda: v('buy a shrubbery333, ok?'), 'regex')