mirror of
https://github.com/django/django.git
synced 2025-11-02 04:48:33 +00:00
Fixed #10482 -- Unified access to response.context when inspecting responses from the test client. Thanks to James Bennett for the design, and Julien Phalip for the patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@10084 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
61a2708c41
commit
ee2f04d79e
7 changed files with 58 additions and 5 deletions
|
|
@ -5,9 +5,10 @@ import os
|
|||
from django.conf import settings
|
||||
|
||||
from django.test import Client, TestCase
|
||||
from django.test.utils import ContextList
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.core.exceptions import SuspiciousOperation
|
||||
from django.template import TemplateDoesNotExist, TemplateSyntaxError
|
||||
from django.template import TemplateDoesNotExist, TemplateSyntaxError, Context
|
||||
|
||||
class AssertContainsTests(TestCase):
|
||||
def test_contains(self):
|
||||
|
|
@ -455,6 +456,26 @@ class zzUrlconfSubstitutionTests(TestCase):
|
|||
url = reverse('arg_view', args=['somename'])
|
||||
self.assertEquals(url, '/test_client_regress/arg_view/somename/')
|
||||
|
||||
class ContextTests(TestCase):
|
||||
fixtures = ['testdata']
|
||||
|
||||
def test_single_context(self):
|
||||
"Context variables can be retrieved from a single context"
|
||||
response = self.client.get("/test_client_regress/request_data/", data={'foo':'whiz'})
|
||||
self.assertEqual(response.context.__class__, Context)
|
||||
self.assertEqual(response.context['get-foo'], 'whiz')
|
||||
self.assertEqual(response.context['request-foo'], 'whiz')
|
||||
self.assertEqual(response.context['data'], 'sausage')
|
||||
|
||||
def test_inherited_context(self):
|
||||
"Context variables can be retrieved from a list of contexts"
|
||||
response = self.client.get("/test_client_regress/request_data_extended/", data={'foo':'whiz'})
|
||||
self.assertEqual(response.context.__class__, ContextList)
|
||||
self.assertEqual(len(response.context), 2)
|
||||
self.assertEqual(response.context['get-foo'], 'whiz')
|
||||
self.assertEqual(response.context['request-foo'], 'whiz')
|
||||
self.assertEqual(response.context['data'], 'bacon')
|
||||
|
||||
class SessionTests(TestCase):
|
||||
fixtures = ['testdata.json']
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue