Commit 9bbf9411 authored by Gary Wilson Jr's avatar Gary Wilson Jr
Browse files

[1.0.X]: Fixed #9978 -- Fixed a KeyError exception that was being raised when...

[1.0.X]: Fixed #9978 -- Fixed a KeyError exception that was being raised when using the logout method on the test client on an unauthenticated user, based on patch from ericholscher.

Backport of r10228 from trunk.


git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@10236 bcc190cf-cafb-0310-a4f2-bffc1f526a37
parent 22ac97b1
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -334,10 +334,12 @@ class Client(object):

    def logout(self):
        """
        Removes the authenticated user's cookies.
        Removes the authenticated user's cookies and session object.

        Causes the authenticated user to be logged out.
        """
        session = __import__(settings.SESSION_ENGINE, {}, {}, ['']).SessionStore()
        session.delete(session_key=self.cookies[settings.SESSION_COOKIE_NAME].value)
        session_cookie = self.cookies.get(settings.SESSION_COOKIE_NAME)
        if session_cookie:
            session.delete(session_key=session_cookie.value)
        self.cookies = SimpleCookie()
+0 −1
Original line number Diff line number Diff line
@@ -411,4 +411,3 @@ class ClientTest(TestCase):
        self.assertEqual(mail.outbox[1].from_email, 'from@example.com')
        self.assertEqual(mail.outbox[1].to[0], 'second@example.com')
        self.assertEqual(mail.outbox[1].to[1], 'third@example.com')
+13 −6
Original line number Diff line number Diff line
@@ -383,3 +383,10 @@ class SessionTests(TestCase):
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.content, 'YES')

    def test_logout(self):
        """Logout should work whether the user is logged in or not (#9978)."""
        self.client.logout()
        login = self.client.login(username='testclient',password='password')
        self.failUnless(login, 'Could not log in')
        self.client.logout()
        self.client.logout()