Code

Ticket #15026: cleanup_session_records_after_invalid_key_test.diff

File cleanup_session_records_after_invalid_key_test.diff, 1.0 KB (added by jsdalton, 3 years ago)
Line 
1Index: django/contrib/sessions/tests.py
2===================================================================
3--- django/contrib/sessions/tests.py    (revision 15153)
4+++ django/contrib/sessions/tests.py    (working copy)
5@@ -160,11 +160,15 @@
6     def test_invalid_key(self):
7         # Submitting an invalid session key (either by guessing, or if the db has
8         # removed the key) results in a new key being generated.
9-        session = self.backend('1')
10-        session.save()
11-        self.assertNotEqual(session.session_key, '1')
12-        self.assertEqual(session.get('cat'), None)
13-        session.delete()
14+        try:
15+            session = self.backend('1')
16+            session.save()
17+            self.assertNotEqual(session.session_key, '1')
18+            self.assertEqual(session.get('cat'), None)
19+        finally:
20+            # Be sure to clean up both session records that are now stored in the backend
21+            session.delete()
22+            session.delete('1')
23 
24     # Custom session expiry
25     def test_default_expiry(self):