コード例 #1
0
ファイル: test_scalars.py プロジェクト: mbr/flatland0
def test_values_equal_three():
    v = ValuesEqual('x', 'y', 'z')
    el = form(dict(x='a', y='a', z='a'))
    assert v.validate(el, None)

    el = form(dict(x='a', y='b', z='c'))
    assert not v.validate(el, None)
    assert el.errors == ['x, y and z do not match.']

    el = form(dict(x='a'))
    assert not v.validate(el, None)
    assert el.errors == ['x, y and z do not match.']
コード例 #2
0
ファイル: test_scalars.py プロジェクト: gaconnet/flatland
def test_values_equal_two():
    v = ValuesEqual('x', 'y')
    el = form(dict(x='a', y='a', z='a'))
    assert v.validate(el, None)

    el = form(dict(x='a', y='b', z='c'))
    assert not v.validate(el, None)
    eq_(el.errors, ['x and y do not match.'])

    el = form(dict(x='a'))
    assert not v.validate(el, None)
    eq_(el.errors, ['x and y do not match.'])
コード例 #3
0
ファイル: test_scalars.py プロジェクト: orutherfurd/flatland
def test_values_equal_three():
    v = ValuesEqual(u'x', u'y', u'z')
    el = form(dict(x=u'a', y=u'a', z=u'a'))
    assert v.validate(el, None)

    el = form(dict(x=u'a', y=u'b', z=u'c'))
    assert not v.validate(el, None)
    eq_(el.errors, [u'x, y and z do not match.'])

    el = form(dict(x=u'a'))
    assert not v.validate(el, None)
    eq_(el.errors, [u'x, y and z do not match.'])
コード例 #4
0
ファイル: test_scalars.py プロジェクト: gaconnet/flatland
def test_values_equal_two():
    v = ValuesEqual('x', 'y')
    el = form(dict(x='a', y='a', z='a'))
    assert v.validate(el, None)

    el = form(dict(x='a', y='b', z='c'))
    assert not v.validate(el, None)
    eq_(el.errors, ['x and y do not match.'])

    el = form(dict(x='a'))
    assert not v.validate(el, None)
    eq_(el.errors, ['x and y do not match.'])
コード例 #5
0
ファイル: test_scalars.py プロジェクト: dag/flatland
def test_values_equal_resolution():
    v = ValuesEqual('x', '/sub/xx')
    el = form(dict(x='a', sub=dict(xx='a')))
    assert v.validate(el, None)

    v = ValuesEqual('/x', 'xx')
    el = form(dict(x='a', sub=dict(xx='a')))
    assert v.validate(el['sub'], None)

    # unhashable
    v = ValuesEqual('a', 'b')
    schema = Dict.of(List.named('a').of(String.named('x')),
                     List.named('b').of(String.named('x')))

    el = schema(dict(a=['a', 'b'], b=['a', 'b']))
    assert v.validate(el, None)

    el = schema(dict(a=['a', 'b'], b=['x', 'y']))
    assert not v.validate(el, None)
コード例 #6
0
class SignupForm(Form):
    username = String.using(label='Username', validators=[Present()])
    password = String.using(label='Password',
                            validators=[
                                Present(),
                                LengthBetween(5, 25),
                                ValuesEqual('.', '../confirmPassword')
                            ])
    confirmPassword = String.using(label='Confirm Password',
                                   validators=[Present()])
    email = String.using(label='Email', validators=[Present(), IsEmail()])
    firstname = String.using(label='First Name', validators=[Present()])
    lastname = String.using(label='Last Name', validators=[Present()])
    output_schema = [
        'username', 'password', 'confirmPassword', 'email', 'firstname',
        'lastname'
    ]
コード例 #7
0
ファイル: test_scalars.py プロジェクト: mbr/flatland0
def test_values_equal_resolution():
    v = ValuesEqual('x', '/sub/xx')
    el = form(dict(x='a', sub=dict(xx='a')))
    assert v.validate(el, None)

    v = ValuesEqual('/x', 'xx')
    el = form(dict(x='a', sub=dict(xx='a')))
    assert v.validate(el['sub'], None)

    # unhashable
    v = ValuesEqual('a', 'b')
    schema = Dict.of(List.named('a').of(String.named('x')),
                     List.named('b').of(String.named('x')))

    el = schema(dict(a=['a', 'b'], b=['a', 'b']))
    assert v.validate(el, None)

    el = schema(dict(a=['a', 'b'], b=['x', 'y']))
    assert not v.validate(el, None)