I have a form as following:
from flask_wtf import Form
class MyForm(Form):
domain = StringField('domain')
hosts = StringField('hosts')
startdate = StringField('Start Date', validators=[InputRequired()])
enddate = StringField('End Date', validators=[InputRequired()] )
starthour = SelectField('Start Hour',coerce=int, choices=[(i, i) for i in range(0, 24)], default=0)
endhour = SelectField('End Hour',coerce=int, choices=[(i, i) for i in range(0, 24)], default=23)
submit1 = SubmitField('Submit1')
submit2 = SubmitField('Submit2')
I try to test it using unittest:
def test_form(self):
form = {
"domain": "fake",
"hosts": "fake",
"startdate": "fake",
"enddate": "fake",
"starthour": 1,
"endhour": 2,
'submit1': True,
'submit2': False
}
response = self.client.post(url_for('/'), data=form)
But though the printed received data looks correct, the function form.validate_on_submit() can never pass. Does anyone here know the write way to feed the form data for post request?
Thanks,
Aucun commentaire:
Enregistrer un commentaire