Commits

Ben Bangert committed 7a0c71c

Fix bug in auto-save, add auto-save test

Comments (0)

Files changed (2)

         
         """
         if self.__dict__['_params'].get('auto'):
-            self._session.save()
+            self._session().save()
         else:
             if self.__dict__['_dirty']:
                 self._session().save()

tests/test_increment.py

     return ['The current value is: %d, session id is %s' % (session['value'],
                                                             session.id)]
 
+def simple_auto_app(environ, start_response):
+    """Like the simple_app, but assume that sessions auto-save"""
+    session = environ['beaker.session']
+    sess_id = environ.get('SESSION_ID')
+    if sess_id:
+        session = session.get_by_id(sess_id)
+    if not session:
+        start_response('200 OK', [('Content-type', 'text/plain')])
+        return ["No session id of %s found." % sess_id]
+    if not session.has_key('value'):
+        session['value'] = 0
+    session['value'] += 1
+    if environ['PATH_INFO'].startswith('/nosave'):
+        session.revert()
+    else:
+        session.save()
+    start_response('200 OK', [('Content-type', 'text/plain')])
+    return ['The current value is: %d, session id is %s' % (session['value'],
+                                                            session.id)]
+
+
 def test_increment():
     app = TestApp(SessionMiddleware(simple_app))
     res = app.get('/')
     res = app.get('/')
     assert 'current value is: 3' in res
 
+def test_increment_auto():
+    app = TestApp(SessionMiddleware(simple_auto_app, auto=True))
+    res = app.get('/')
+    assert 'current value is: 1' in res
+    res = app.get('/')
+    assert 'current value is: 2' in res
+    res = app.get('/')
+    assert 'current value is: 3' in res
+
+
 def test_different_sessions():
     app = TestApp(SessionMiddleware(simple_app))
     app2 = TestApp(SessionMiddleware(simple_app))