From 9bbf94112f011276d4e25b21676cfc2b74aaaef5 Mon Sep 17 00:00:00 2001 From: Gary Wilson Jr Date: Mon, 30 Mar 2009 23:20:10 +0000 Subject: [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 --- django/test/client.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'django') diff --git a/django/test/client.py b/django/test/client.py index f4435c090f..b144fe2fdb 100644 --- a/django/test/client.py +++ b/django/test/client.py @@ -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() -- cgit v1.3