From 993612c84d3c04c516486a99fa813cec1caa5488 Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Mon, 17 Jan 2011 14:03:19 +0000 Subject: [PATCH] Fixed #15026 -- Added cleanup to the invalid key session tests; when using Memcached as a cache backend, the cache-backed session backends would fail on the second run due to leftover cache artefacts. Thanks to jsdalton for the report and patch. git-svn-id: http://code.djangoproject.com/svn/django/trunk@15235 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/contrib/sessions/tests.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/django/contrib/sessions/tests.py b/django/contrib/sessions/tests.py index e8aad0f05f..9b669211db 100644 --- a/django/contrib/sessions/tests.py +++ b/django/contrib/sessions/tests.py @@ -160,11 +160,16 @@ class SessionTestsMixin(object): def test_invalid_key(self): # Submitting an invalid session key (either by guessing, or if the db has # removed the key) results in a new key being generated. - session = self.backend('1') - session.save() - self.assertNotEqual(session.session_key, '1') - self.assertEqual(session.get('cat'), None) - session.delete() + try: + session = self.backend('1') + session.save() + self.assertNotEqual(session.session_key, '1') + self.assertEqual(session.get('cat'), None) + session.delete() + finally: + # Some backends leave a stale cache entry for the invalid + # session key; make sure that entry is manually deleted + session.delete('1') # Custom session expiry def test_default_expiry(self):