我尝试通过执行以下操作来检查Django unittest中的响应主体是否有特定文本:
response = client.post('/path/to/form', form_data)
self.assertTrue('some text' in unicode(response, 'utf-8', 'ignore'))
但是,我得到了一个错误:
^{pr2}$如果我将unicode()
替换为str()
,它可以正常工作,但这会阻止我查找Unicode文本。为什么templaterresponse不能像str那样转换成unicode?在
使用
self.assertContains(response, 'some text')
如果您想检查响应的主体,那么典型的方法是使用
response.content
,而不是尝试调用unicode(response)
。在相关问题 更多 >
编程相关推荐