Ticket #4729: ticket_4729__rev_6447.diff

File ticket_4729__rev_6447.diff, 1.7 KB (added by Ben Slavin, 17 years ago)

Patch for new session implementation, including tests

  • django/contrib/sessions/tests.py

     
    33>>> from django.contrib.sessions.backends.db import SessionStore as DatabaseSession
    44>>> from django.contrib.sessions.backends.cache import SessionStore as CacheSession
    55>>> from django.contrib.sessions.backends.file import SessionStore as FileSession
     6>>> from django.contrib.sessions.backends.base import SessionBase
    67
    78>>> db_session = DatabaseSession()
    89>>> db_session.modified
     
    5253>>> cache_session.delete(cache_session.session_key)
    5354>>> cache_session.exists(cache_session.session_key)
    5455False
     56
     57>>> s = SessionBase()
     58>>> s._session['some key'] = 'exists' # Pre-populate the session with some data
     59>>> s.accessed = False   # Reset to pretend this wasn't accessed previously
     60
     61>>> s.accessed, s.modified
     62(False, False)
     63
     64>>> s.pop('non existant key', 'does not exist')
     65'does not exist'
     66>>> s.accessed, s.modified
     67(True, False)
     68
     69>>> s.accessed = False  # Reset the accessed flag
     70
     71>>> s.pop('some key')
     72'exists'
     73>>> s.accessed, s.modified
     74(True, True)
     75
     76>>> s.pop('some key', 'does not exist')
     77'does not exist'
    5578"""
    5679
    5780if __name__ == '__main__':
  • django/contrib/sessions/backends/base.py

     
    4848        return self._session.get(key, default)
    4949
    5050    def pop(self, key, *args):
     51        self.modified = self.modified or key in self._session
    5152        return self._session.pop(key, *args)
    5253
    5354    def set_test_cookie(self):
Back to Top