Code

Ticket #4729: ticket_4729__rev_6447.diff

File ticket_4729__rev_6447.diff, 1.7 KB (added by __hawkeye__, 7 years ago)

Patch for new session implementation, including tests

Line 
1Index: django/contrib/sessions/tests.py
2===================================================================
3--- django/contrib/sessions/tests.py    (revision 6447)
4+++ django/contrib/sessions/tests.py    (working copy)
5@@ -3,6 +3,7 @@
6 >>> from django.contrib.sessions.backends.db import SessionStore as DatabaseSession
7 >>> from django.contrib.sessions.backends.cache import SessionStore as CacheSession
8 >>> from django.contrib.sessions.backends.file import SessionStore as FileSession
9+>>> from django.contrib.sessions.backends.base import SessionBase
10 
11 >>> db_session = DatabaseSession()
12 >>> db_session.modified
13@@ -52,6 +53,28 @@
14 >>> cache_session.delete(cache_session.session_key)
15 >>> cache_session.exists(cache_session.session_key)
16 False
17+
18+>>> s = SessionBase()
19+>>> s._session['some key'] = 'exists' # Pre-populate the session with some data
20+>>> s.accessed = False   # Reset to pretend this wasn't accessed previously
21+
22+>>> s.accessed, s.modified
23+(False, False)
24+
25+>>> s.pop('non existant key', 'does not exist')
26+'does not exist'
27+>>> s.accessed, s.modified
28+(True, False)
29+
30+>>> s.accessed = False  # Reset the accessed flag
31+
32+>>> s.pop('some key')
33+'exists'
34+>>> s.accessed, s.modified
35+(True, True)
36+
37+>>> s.pop('some key', 'does not exist')
38+'does not exist'
39 """
40 
41 if __name__ == '__main__':
42Index: django/contrib/sessions/backends/base.py
43===================================================================
44--- django/contrib/sessions/backends/base.py    (revision 6447)
45+++ django/contrib/sessions/backends/base.py    (working copy)
46@@ -48,6 +48,7 @@
47         return self._session.get(key, default)
48 
49     def pop(self, key, *args):
50+        self.modified = self.modified or key in self._session
51         return self._session.pop(key, *args)
52 
53     def set_test_cookie(self):