Пример #1
0
    def _run_expired_session_test_for_engine(self):
        # establish that get_session will return the same session
        # when that session key has not yet expired.
        session = get_session('session1')
        self.assertEqual(session.session_key, 'session1')
        session['touched'] = 'writesomething'
        session.save()
        session = get_session('session1')
        self.assertEqual(session.session_key, 'session1')
        session['touched'] = 'writesomethingelse'
        session.save()
        self.assertEqual(session.session_key, 'session1')

        # when the session expires immediately, the same session should
        # still be returned.
        # create a new session
        session = get_session('session2')
        self.assertEqual(session.session_key, 'session2')
        session['touched'] = 'writesomething'
        session.save()
        self.assertEqual(session.session_key, 'session2')

        # expire the session manually
        session.set_expiry(-100000)

        # get a session with the same id, even when it has expired.
        session = get_session('session2')
        self.assertEqual(session.session_key, 'session2')
        session['touched'] = 'writesomethingelse'
        session.save()
        self.assertEqual(session.session_key, 'session2')
Пример #2
0
def start_or_resume(session_id, session_type):
    if session_type == 'ANON':
        return get_session(session_id, raise_on_create=False)

    return get_session(session_id, raise_on_create=True)