I cannot access the context
attribute of an HttpResponse
object from ipython. But the unit test accesses context
.
Here is the unit test. The test run passes properly:
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')
Here is the code that I used in the 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'>
response.context
is none in the shell whereas response.context
exists in the unit test.
Why does HttpResponse
behave inconsistently between the shell and unit test?