Commit 8a7bbc3c authored by Russell Keith-Magee's avatar Russell Keith-Magee
Browse files

Fixed #5836 -- Corrected the logic in the Test Client when an exception raised...

Fixed #5836 -- Corrected the logic in the Test Client when an exception raised by a view is caught and re-raised. Thanks for the report, test case, and fix, Chris Wagner.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@7583 bcc190cf-cafb-0310-a4f2-bffc1f526a37
parent 5b9d907a
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -367,6 +367,7 @@ answer newbie questions, and generally made Django that much better:
    George Vilches <gav@thataddress.com>
    Vlado <vlado@labath.org>
    Milton Waddams
    Chris Wagner <cw264701@ohio.edu>
    wam-djangobug@wamber.net
    Wang Chun <wangchun@exoweb.net>
    Filip Wasilewski <filip.wasilewski@gmail.com>
+8 −3
Original line number Diff line number Diff line
@@ -179,9 +179,14 @@ class Client:
            if e.args != ('500.html',):
                raise

        # Look for a signalled exception and reraise it
        # Look for a signalled exception, clear the current context
        # exception data, then re-raise the signalled exception.
        # Also make sure that the signalled exception is cleared from
        # the local cache!
        if self.exc_info:
            raise self.exc_info[1], None, self.exc_info[2]
            exc_info = self.exc_info
            self.exc_info = None
            raise exc_info[1], None, exc_info[2]
            
        # Save the client and request that stimulated the response
        response.client = self
+18 −0
Original line number Diff line number Diff line
@@ -34,5 +34,23 @@
            "email": "testclient@example.com", 
            "date_joined": "2006-12-17 07:03:31"
        }
    },
    {
        "pk": "3", 
        "model": "auth.user", 
        "fields": {
            "username": "staff", 
            "first_name": "Staff", 
            "last_name": "Member", 
            "is_active": true, 
            "is_superuser": false, 
            "is_staff": true, 
            "last_login": "2006-12-17 07:03:31", 
            "groups": [], 
            "user_permissions": [], 
            "password": "sha1$6efc0$f93efe9fd7542f25a7be94871ea45aa95de57161", 
            "email": "testclient@example.com", 
            "date_joined": "2006-12-17 07:03:31"
        }
    }
]
 No newline at end of file
+36 −0
Original line number Diff line number Diff line
@@ -16,5 +16,41 @@
            "email": "testclient@example.com", 
            "date_joined": "2006-12-17 07:03:31"
        }
    },
    {
        "pk": "2", 
        "model": "auth.user", 
        "fields": {
            "username": "inactive", 
            "first_name": "Inactive", 
            "last_name": "User", 
            "is_active": false, 
            "is_superuser": false, 
            "is_staff": false, 
            "last_login": "2006-12-17 07:03:31", 
            "groups": [], 
            "user_permissions": [], 
            "password": "sha1$6efc0$f93efe9fd7542f25a7be94871ea45aa95de57161", 
            "email": "testclient@example.com", 
            "date_joined": "2006-12-17 07:03:31"
        }
    },
    {
        "pk": "3", 
        "model": "auth.user", 
        "fields": {
            "username": "staff", 
            "first_name": "Staff", 
            "last_name": "Member", 
            "is_active": true, 
            "is_superuser": false, 
            "is_staff": true, 
            "last_login": "2006-12-17 07:03:31", 
            "groups": [], 
            "user_permissions": [], 
            "password": "sha1$6efc0$f93efe9fd7542f25a7be94871ea45aa95de57161", 
            "email": "testclient@example.com", 
            "date_joined": "2006-12-17 07:03:31"
        }
    }
]
 No newline at end of file
+23 −0
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ Regression tests for the Test Client, especially the customized assertions.
"""
from django.test import Client, TestCase
from django.core.urlresolvers import reverse
from django.core.exceptions import SuspiciousOperation
import os

class AssertContainsTests(TestCase):
@@ -294,4 +295,26 @@ class URLEscapingTests(TestCase):
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.content, 'Hi, Arthur')

class ExceptionTests(TestCase):
    fixtures = ['testdata.json']
    
    def test_exception_cleared(self):
        "#5836 - A stale user exception isn't re-raised by the test client."

        login = self.client.login(username='testclient',password='password')
        self.failUnless(login, 'Could not log in')
        try:
            response = self.client.get("/test_client_regress/staff_only/")
            self.fail("General users should not be able to visit this page")
        except SuspiciousOperation:
            pass

        # At this point, an exception has been raised, and should be cleared.
        
        # This next operation should be successful; if it isn't we have a problem.
        login = self.client.login(username='staff', password='password')
        self.failUnless(login, 'Could not log in')
        try:
            self.client.get("/test_client_regress/staff_only/")
        except SuspiciousOperation:
            self.fail("Staff should be able to visit this page")
Loading