mirror of
https://github.com/django/django.git
synced 2025-07-19 00:59:17 +00:00
[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
This commit is contained in:
parent
22ac97b17c
commit
9bbf94112f
@ -334,10 +334,12 @@ class Client(object):
|
|||||||
|
|
||||||
def logout(self):
|
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.
|
Causes the authenticated user to be logged out.
|
||||||
"""
|
"""
|
||||||
session = __import__(settings.SESSION_ENGINE, {}, {}, ['']).SessionStore()
|
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()
|
self.cookies = SimpleCookie()
|
||||||
|
@ -411,4 +411,3 @@ class ClientTest(TestCase):
|
|||||||
self.assertEqual(mail.outbox[1].from_email, 'from@example.com')
|
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[0], 'second@example.com')
|
||||||
self.assertEqual(mail.outbox[1].to[1], 'third@example.com')
|
self.assertEqual(mail.outbox[1].to[1], 'third@example.com')
|
||||||
|
|
||||||
|
@ -309,17 +309,17 @@ class ExceptionTests(TestCase):
|
|||||||
self.client.get("/test_client_regress/staff_only/")
|
self.client.get("/test_client_regress/staff_only/")
|
||||||
except SuspiciousOperation:
|
except SuspiciousOperation:
|
||||||
self.fail("Staff should be able to visit this page")
|
self.fail("Staff should be able to visit this page")
|
||||||
|
|
||||||
class TemplateExceptionTests(TestCase):
|
class TemplateExceptionTests(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.old_templates = settings.TEMPLATE_DIRS
|
self.old_templates = settings.TEMPLATE_DIRS
|
||||||
settings.TEMPLATE_DIRS = ()
|
settings.TEMPLATE_DIRS = ()
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
settings.TEMPLATE_DIRS = self.old_templates
|
settings.TEMPLATE_DIRS = self.old_templates
|
||||||
|
|
||||||
def test_no_404_template(self):
|
def test_no_404_template(self):
|
||||||
"Missing templates are correctly reported by test client"
|
"Missing templates are correctly reported by test client"
|
||||||
try:
|
try:
|
||||||
response = self.client.get("/no_such_view/")
|
response = self.client.get("/no_such_view/")
|
||||||
self.fail("Should get error about missing template")
|
self.fail("Should get error about missing template")
|
||||||
@ -334,7 +334,7 @@ class TemplateExceptionTests(TestCase):
|
|||||||
self.fail("Should get error about syntax error in template")
|
self.fail("Should get error about syntax error in template")
|
||||||
except TemplateSyntaxError:
|
except TemplateSyntaxError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# We need two different tests to check URLconf substitution - one to check
|
# We need two different tests to check URLconf substitution - one to check
|
||||||
# it was changed, and another one (without self.urls) to check it was reverted on
|
# it was changed, and another one (without self.urls) to check it was reverted on
|
||||||
# teardown. This pair of tests relies upon the alphabetical ordering of test execution.
|
# teardown. This pair of tests relies upon the alphabetical ordering of test execution.
|
||||||
@ -382,4 +382,11 @@ class SessionTests(TestCase):
|
|||||||
response = self.client.get('/test_client_regress/check_session/')
|
response = self.client.get('/test_client_regress/check_session/')
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertEqual(response.content, 'YES')
|
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()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user