से खाली है, मैं HttpResponse
ऑब्जेक्टन से ऑब्जेक्ट का उपयोग नहीं कर सकता। लेकिन इकाई परीक्षण context
तक पहुंचता है।Django: टेस्ट क्लाइंट का संदर्भ शेल
यहां यूनिट परीक्षण है। परीक्षण चालन ठीक से गुजरता है:
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')
यहाँ कोड है कि मैं खोल में प्रयोग किया जाता है:
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
खोल में से कोई भी, जबकि response.context
इकाई परीक्षण में मौजूद है।
HttpResponse
शैल और यूनिट परीक्षण के बीच असंगत व्यवहार क्यों करता है?
मैंने यह कोशिश की और न तो संदर्भ और न ही टेम्पलेट Django खोल में सेट है। मुझे लगता है कि क्लाइंट का उद्देश्य इंटरेक्टिव शैल में नहीं किया जाना है। परीक्षण धावक परीक्षण चलाने से पहले कुछ उपकरण बनाता है, जो खोल के माध्यम से ट्रिगर नहीं किया जाएगा। 'Django.test.testcases' देखें – muhuk