我想编写测试时,我想在Django中模拟我的观点请求.这主要是为了测试表格.这是一个简单测试请求的片段:
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
Run Code Online (Sandbox Code Playgroud)
无论是否存在表单错误,页面始终返回200的响应.如何检查我的表单失败以及特定字段(soemthing)是否有错误?