Mer*_*glu 7 testing django unit-testing
我无法从ipython 访问对象的context属性HttpResponse.但单元测试访问context.
这是单元测试.测试运行正常:
from django.test import Client, TestCase
from django.core import mail
class ClientTest(TestCase):
def test_get_view(self):
data = {'var': u'\xf2'}
response = self.client.get('/test04/', data)
# Check some response details
self.assertContains(response, 'This is a test')
self.assertEqual(response.context['var'], u'\xf2')
Run Code Online (Sandbox Code Playgroud)
这是我在shell中使用的代码:
In [10]: from django.test import Client
In [11]: c = Client()
In [12]: r = c.get('/test04/', data)
In [13]: r.context
In [14]: type(r.context)
Out[14]: <type 'NoneType'>
Run Code Online (Sandbox Code Playgroud)
response.context在shell中没有,而response.context在单元测试中存在.
为什么HttpResponseshell和单元测试之间的行为不一致?
| 归档时间: |
|
| 查看次数: |
2450 次 |
| 最近记录: |