我想单元测试一个django视图通过提交表单。问题是这个表单有一个验证码字段(基于django-simple-captcha)。如何使用django中的验证码字段单元测试表单?
from django import forms
from captcha.fields import CaptchaField
class ContactForm(forms.forms.Form):
"""
The information needed for being able to download
"""
lastname = forms.CharField(max_length=30, label='Last name')
firstname = forms.CharField(max_length=30, label='First name')
...
captcha = CaptchaField()
测试代码:
class ContactFormTest(TestCase):
def test_submitform(self):
"""Test that the contact page"""
url = reverse('contact_form')
form_data = {}
form_data['firstname'] = 'Paul'
form_data['lastname'] = 'Macca'
form_data['captcha'] = '28if'
response = self.client.post(url, form_data, follow=True)
有什么方法来单元测试代码并进行测试时摆脱Captcha验证码?
在此先感谢
如果其他人最终在这里像我一样,我偶然发现这篇文章试图找到类似的答案'django-recaptcha'包;原来他们也有一个设置。他们的文档描述了它的使用:https://github.com/praekelt/django-recaptcha – 2016-03-23 14:43:13