【发布时间】:2011-11-10 09:07:53
【问题描述】:
我想在编写测试时在 Django 中模拟对我的视图的请求。这主要是为了测试表格。这是一个简单测试请求的 sn-p:
from django.tests import TestCase
class MyTests(TestCase):
def test_forms(self):
response = self.client.post("/my/form/", {'something':'something'})
self.assertEqual(response.status_code, 200) # we get our page back with an error
无论是否存在表单错误,页面总是返回 200 响应。如何检查我的表单是否失败以及特定字段 (soemthing) 是否有错误?
【问题讨论】:
标签: python django django-testing