=== modified file 'django/test/testcases.py'
--- django/test/testcases.py	2007-09-03 23:14:51 +0000
+++ django/test/testcases.py	2007-09-04 04:46:14 +0000
@@ -149,7 +149,27 @@
                                 (form, i, err, list(context[form].non_field_errors())))
         if not found_form:
             self.fail("The form '%s' was not used to render the response" % form)
-            
+
+    def assertContext(self, response, variable_name, value):
+        """
+        Asserts that one of the contexts used to render the response
+        contains the context variable variable_name equal to value.
+        """
+        # Put context(s) into a list to simplify processing.
+        contexts = to_list(response.context)
+        if not contexts:
+            self.fail('Response did not use any contexts to render the'
+                      ' response')
+        test_passed = False
+        for context in contexts:
+            if context.get(variable_name) == value:
+                test_passed = True
+                break
+        if not test_passed:
+            self.fail("The context variable '%s' with value '%s' was not"
+                      " found in the context(s) used to render the"
+                      " response" % (variable_name, value))
+
     def assertTemplateUsed(self, response, template_name):
         "Assert that the template with the provided name was used in rendering the response"
         template_names = [t.name for t in to_list(response.template)]

=== modified file 'tests/regressiontests/test_client_regress/models.py'
--- tests/regressiontests/test_client_regress/models.py	2007-09-03 23:14:51 +0000
+++ tests/regressiontests/test_client_regress/models.py	2007-09-04 04:58:39 +0000
@@ -31,12 +31,12 @@
             self.assertContains(response, 'once', 2)
         except AssertionError, e:
             self.assertEquals(str(e), "Found 1 instances of 'once' in response (expected 2)")
-        
+
         try:
             self.assertContains(response, 'twice', 1)
         except AssertionError, e:
             self.assertEquals(str(e), "Found 2 instances of 'twice' in response (expected 1)")
-        
+
         try:
             self.assertContains(response, 'thrice')
         except AssertionError, e:
@@ -46,37 +46,37 @@
             self.assertContains(response, 'thrice', 3)
         except AssertionError, e:
             self.assertEquals(str(e), "Found 0 instances of 'thrice' in response (expected 3)")
-        
+
 class AssertTemplateUsedTests(TestCase):
     fixtures = ['testdata.json']
-    
+
     def test_no_context(self):
         "Template usage assertions work then templates aren't in use"
         response = self.client.get('/test_client_regress/no_template_view/')
 
         # Check that the no template case doesn't mess with the template assertions
         self.assertTemplateNotUsed(response, 'GET Template')
-        
+
         try:
             self.assertTemplateUsed(response, 'GET Template')
         except AssertionError, e:
             self.assertEquals(str(e), "No templates used to render the response")
 
-    def test_single_context(self):        
+    def test_single_context(self):
         "Template assertions work when there is a single context"
         response = self.client.get('/test_client/post_view/', {})
 
-        # 
+        #
         try:
             self.assertTemplateNotUsed(response, 'Empty GET Template')
         except AssertionError, e:
             self.assertEquals(str(e), "Template 'Empty GET Template' was used unexpectedly in rendering the response")
-            
+
         try:
-            self.assertTemplateUsed(response, 'Empty POST Template')        
+            self.assertTemplateUsed(response, 'Empty POST Template')
         except AssertionError, e:
             self.assertEquals(str(e), "Template 'Empty POST Template' was not a template used to render the response. Actual template(s) used: Empty GET Template")
-    
+
     def test_multiple_context(self):
         "Template assertions work when there are multiple contexts"
         post_data = {
@@ -99,20 +99,20 @@
             self.assertEquals(str(e), "Template 'base.html' was used unexpectedly in rendering the response")
 
         try:
-            self.assertTemplateUsed(response, "Valid POST Template")        
+            self.assertTemplateUsed(response, "Valid POST Template")
         except AssertionError, e:
             self.assertEquals(str(e), "Template 'Valid POST Template' was not a template used to render the response. Actual template(s) used: form_view.html, base.html")
 
 class AssertRedirectsTests(TestCase):
     def test_redirect_page(self):
-        "An assertion is raised if the original page couldn't be retrieved as expected"        
+        "An assertion is raised if the original page couldn't be retrieved as expected"
         # This page will redirect with code 301, not 302
-        response = self.client.get('/test_client/permanent_redirect_view/')        
+        response = self.client.get('/test_client/permanent_redirect_view/')
         try:
             self.assertRedirects(response, '/test_client/get_view/')
         except AssertionError, e:
             self.assertEquals(str(e), "Response didn't redirect as expected: Response code was 301 (expected 302)")
-    
+
     def test_lost_query(self):
         "An assertion is raised if the redirect location doesn't preserve GET parameters"
         response = self.client.get('/test_client/redirect_view/', {'var': 'value'})
@@ -123,13 +123,13 @@
 
     def test_incorrect_target(self):
         "An assertion is raised if the response redirects to another target"
-        response = self.client.get('/test_client/permanent_redirect_view/')        
+        response = self.client.get('/test_client/permanent_redirect_view/')
         try:
             # Should redirect to get_view
             self.assertRedirects(response, '/test_client/some_view/')
         except AssertionError, e:
             self.assertEquals(str(e), "Response didn't redirect as expected: Response code was 301 (expected 302)")
-        
+
     def test_target_page(self):
         "An assertion is raised if the response redirect target cannot be retrieved as expected"
         response = self.client.get('/test_client/double_redirect_view/')
@@ -138,7 +138,7 @@
             self.assertRedirects(response, '/test_client/permanent_redirect_view/')
         except AssertionError, e:
             self.assertEquals(str(e), "Couldn't retrieve redirection page '/test_client/permanent_redirect_view/': response code was 301 (expected 200)")
-            
+
 class AssertFormErrorTests(TestCase):
     def test_unknown_form(self):
         "An assertion is raised if the form name is unknown"
@@ -157,7 +157,7 @@
             self.assertFormError(response, 'wrong_form', 'some_field', 'Some error.')
         except AssertionError, e:
             self.assertEqual(str(e), "The form 'wrong_form' was not used to render the response")
-        
+
     def test_unknown_field(self):
         "An assertion is raised if the field name is unknown"
         post_data = {
@@ -175,7 +175,7 @@
             self.assertFormError(response, 'form', 'some_field', 'Some error.')
         except AssertionError, e:
             self.assertEqual(str(e), "The form 'form' in context 0 does not contain the field 'some_field'")
-        
+
     def test_noerror_field(self):
         "An assertion is raised if the field doesn't have any errors"
         post_data = {
@@ -193,7 +193,7 @@
             self.assertFormError(response, 'form', 'value', 'Some error.')
         except AssertionError, e:
             self.assertEqual(str(e), "The field 'value' on form 'form' in context 0 contains no errors")
-        
+
     def test_unknown_error(self):
         "An assertion is raised if the field doesn't contain the provided error"
         post_data = {
@@ -212,6 +212,41 @@
         except AssertionError, e:
             self.assertEqual(str(e), "The field 'email' on form 'form' in context 0 does not contain the error 'Some error.' (actual errors: [u'Enter a valid e-mail address.'])")
 
+class AssertContextTests(TestCase):
+    """Tests for the assertContext method."""
+
+    def setUp(self):
+        self.response = self.client.get(
+            '/test_client_regress/context_variable_view/')
+        self.assertEqual(self.response.status_code, 200)
+        self.assertTemplateUsed(self.response, "Context Variable Template")
+
+    def test_unknown_variable(self):
+        """
+        Checks that an assertion is raised if the variable does not exist.
+        """
+        try:
+            self.assertContext(self.response, 'editor', 'A Knight')
+        except AssertionError, e:
+            self.assertEqual(str(e), "The context variable 'editor' with value 'A Knight' was not found in the context(s) used to render the response")
+
+    def test_wrong_value(self):
+        """
+        Checks that an assertion is raised if the context variable's value
+        does not equal the specified value.
+        """
+        try:
+            self.assertContext(self.response, 'author', 'Real McCoy')
+        except AssertionError, e:
+            self.assertEqual(str(e), "The context variable 'author' with value 'Real McCoy' was not found in the context(s) used to render the response")
+
+    def test_correct_value(self):
+        """
+        Checks that no assertion is raised if the context variable's value
+        matches the specified value.
+        """
+        self.assertContext(self.response, 'title', 'Run Away')
+
 class FileUploadTests(TestCase):
     def test_simple_upload(self):
         fd = open(os.path.join(os.path.dirname(__file__), "views.py"))
@@ -235,8 +270,8 @@
 
         # Get a redirection page with the second client.
         response = c.get("/test_client_regress/login_protected_redirect_view/")
-        
-        # At this points, the self.client isn't logged in. 
-        # Check that assertRedirects uses the original client, not the 
+
+        # At this points, the self.client isn't logged in.
+        # Check that assertRedirects uses the original client, not the
         # default client.
         self.assertRedirects(response, "/test_client_regress/get_view/")

=== modified file 'tests/regressiontests/test_client_regress/urls.py'
--- tests/regressiontests/test_client_regress/urls.py	2007-09-03 11:21:40 +0000
+++ tests/regressiontests/test_client_regress/urls.py	2007-09-04 01:46:59 +0000
@@ -5,5 +5,6 @@
     (r'^no_template_view/$', views.no_template_view),
     (r'^file_upload/$', views.file_upload_view),
     (r'^get_view/$', views.get_view),
-    (r'^login_protected_redirect_view/$', views.login_protected_redirect_view)
+    (r'^login_protected_redirect_view/$', views.login_protected_redirect_view),
+    (r'^context_variable_view/$', views.context_variable_view),
 )

=== modified file 'tests/regressiontests/test_client_regress/views.py'
--- tests/regressiontests/test_client_regress/views.py	2007-09-03 11:21:40 +0000
+++ tests/regressiontests/test_client_regress/views.py	2007-09-04 01:46:59 +0000
@@ -2,6 +2,7 @@
 from django.core.mail import EmailMessage, SMTPConnection
 from django.http import HttpResponse, HttpResponseRedirect, HttpResponseServerError
 from django.shortcuts import render_to_response
+from django.template import Context, Template
 
 def no_template_view(request):
     "A simple view that expects a GET request, and returns a rendered template"
@@ -27,4 +28,12 @@
 def login_protected_redirect_view(request):
     "A view that redirects all requests to the GET view"
     return HttpResponseRedirect('/test_client_regress/get_view/')
-login_protected_redirect_view = login_required(login_protected_redirect_view)
\ No newline at end of file
+login_protected_redirect_view = login_required(login_protected_redirect_view)
+
+def context_variable_view(request):
+    "A view that uses context variables."
+    t = Template('{{ title }} by {{ author }}',
+                 name='Context Variable Template')
+    c = Context({'title': 'Run Away',
+                 'author': 'Brave Sir Robin'})
+    return HttpResponse(t.render(c))

