Commits

Ben Bangert  committed f30754a

More unit tests to ensure auto-loading and revert work, and bug fixes

  • Participants
  • Parent commits 7a0c71c

Comments (0)

Files changed (2)

File beaker/session.py

         self.secret = secret
         self.secure = secure
         self.id = id
+        self.accessed_dict = {}
             
         if self.use_cookies:
             cookieheader = request.get('cookie', '')
         return session_data
     
     def _persist_session_dict(self, session_dict):
-        if not session_dict:
+        if not session_dict and 'session' in self.namespace:
             del self.namespace['session']
         else:
             self.namespace['session'] = session_dict

File tests/test_increment.py

     else:
         session.save()
     start_response('200 OK', [('Content-type', 'text/plain')])
-    return ['The current value is: %d, session id is %s' % (session['value'],
+    return ['The current value is: %d, session id is %s' % (session.get('value', 0),
                                                             session.id)]
 
 
     assert 'current value is: 2' in res2
     assert 'current value is: 4' in res
 
+def test_different_sessions_auto():
+    app = TestApp(SessionMiddleware(simple_auto_app, auto=True))
+    app2 = TestApp(SessionMiddleware(simple_auto_app, auto=True))
+    res = app.get('/')
+    assert 'current value is: 1' in res
+    res = app2.get('/')
+    assert 'current value is: 1' in res
+    res = app2.get('/')
+    res = app2.get('/')
+    res = app2.get('/')
+    res2 = app.get('/')
+    assert 'current value is: 2' in res2
+    assert 'current value is: 4' in res
+
 def test_nosave():
     app = TestApp(SessionMiddleware(simple_app))
     res = app.get('/nosave')
     assert [] == res.headers.getall('Set-Cookie')
     assert 'current value is: 2' in res
 
+def test_revert():
+    app = TestApp(SessionMiddleware(simple_auto_app, auto=True))
+    res = app.get('/nosave')
+    assert 'current value is: 0' in res
+    res = app.get('/nosave')
+    assert 'current value is: 0' in res
+    
+    res = app.get('/')
+    assert 'current value is: 1' in res
+    assert [] == res.headers.getall('Set-Cookie')
+    res = app.get('/')
+    assert [] == res.headers.getall('Set-Cookie')
+    assert 'current value is: 2' in res
+    
+    # Finally, ensure that reverting shows the proper one
+    res = app.get('/nosave')
+    assert [] == res.headers.getall('Set-Cookie')
+    assert 'current value is: 2' in res
+
 def test_load_session_by_id():
     options = {'session.data_dir':loc, 'session.secret':'blah'}
     app = TestApp(SessionMiddleware(simple_app, **options))