1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
import pytest
from wtforms import Form, IntegerField, StringField
from wtforms.validators import Optional
class MyForm(Form):
a = IntegerField(validators=[Optional()])
b = StringField()
c = StringField(default='c')
class MyCallableForm(Form):
a = IntegerField(validators=[Optional()])
b = StringField()
c = StringField(default=lambda: 'c')
@pytest.mark.parametrize('cls', [MyForm, MyCallableForm])
def test_object_defaults(cls):
class SomeClass(object):
a = 1
b = 'someone'
form = cls.from_json(obj=SomeClass())
assert form.data == {'a': 1, 'b': 'someone', 'c': 'c'}
@pytest.mark.parametrize('cls', [MyForm, MyCallableForm])
def test_formdata_defaults(cls):
form = cls.from_json({'a': 1, 'b': 'something'})
assert form.data == {'a': 1, 'b': 'something', 'c': 'c'}
|