各位大侠
在, self.client.post 时,如何确认提交那个按钮?
我的form,有两个按钮:
class ApplicationForm(MyBaseForm):
comments = TextAreaField('备注')
save_submit = SubmitField('保存')
send_submit = SubmitField('提交')
我的视图:
@volunteer_bp.route('/application', methods=['GET', 'POST'])
@login_required
def application():
"""
填表,编辑表格,和
:return:
"""
form = ApplicationForm()
if form.validate_on_submit():
# 如果用户点击的是保存,则保存,状态为填表中
if form.save_submit.data:
pass
# 如果用户点击的是提交,则提交,状态为待保存
if form.send_submit.data:
pass
return render_template('/')
测试数据:
volunteer_application_data = dict(
volunteer_name='张三',
age=11,
gender=1,
save_submit=True,
send_submit=None
)
测试函数:
def test_post_volunteer_application_with_wrong_data(self):
"""
测试提交表单,但是没有提供必填数据
:return:
"""
self.login('zhangsan', 'something')
response = self.client.post(url_for('volunteer.application'), data=volunteer_application_data,
follow_redirects=True)
data = response.get_data(as_text=True)