def test_no_autosave_saves_with_save(self): so = SessionObject({}, auto=False) so['foo'] = 'bar' so.save() so.persist() session = get_session(id=so.id) assert '_accessed_time' in session assert 'foo' in session
def test_no_autosave_saves_with_save(self): so = SessionObject({}, auto=False) so["foo"] = "bar" so.save() so.persist() session = get_session(id=so.id) assert "_accessed_time" in session assert "foo" in session
def test_accessed_time_off_saves_atime_when_saving(self): so = SessionObject({}, save_accessed_time=False) atime = so['_accessed_time'] so['foo'] = 'bar' so.save() so.persist() session = get_session(id=so.id, save_accessed_time=False) assert 'foo' in session assert '_accessed_time' in session self.assertEqual(session.last_accessed, atime)
def test_accessed_time_off_saves_atime_when_saving(self): so = SessionObject({}, save_accessed_time=False) atime = so["_accessed_time"] so["foo"] = "bar" so.save() so.persist() session = get_session(id=so.id, save_accessed_time=False) assert "foo" in session assert "_accessed_time" in session self.assertEqual(session.last_accessed, atime)
def _respond(cls, request): try: path_response = cls.__routes.match(request.path_info) if path_response[0] is None: raise exc.HTTPNotFound() endpoint = path_response[0] session = SessionObject( request.environ, **cls.__get_session_config()) try: method = endpoint(request.method) result = method( _Request( session=session, route_params=path_response[1], path_for=cls.__routes.path_for, raw=request ) ) except Exception as e: raise exc.HTTPServerError() response = webob.Response() if session.accessed(): if not session.dirty(): session.save() session.persist() cookie = session.__dict__['_headers']['cookie_out'] if \ session.__dict__['_headers']['set_cookie'] else None if cookie: response.headers.add('Set-Cookie', cookie) if cls.__config['show_x_powered_by']: response.headers.add( 'X-Powered-By', 'Lulu version %s' % _VERSION) if isinstance(result, basestring): response.text = result response.charset = 'utf8' elif type(result) is dict: response.content_type = result['content_type'] if \ 'content_type' in result.keys() else 'text/html' response.body = result['body'] return response except exc.HTTPError as e: return e
def test_no_autosave_saves_with_delete(self): req = {'cookie': {'beaker.session.id': 123}} so = SessionObject(req, auto=False) so['foo'] = 'bar' so.save() so.persist() session = get_session(id=so.id) assert 'foo' in session so2 = SessionObject(req, auto=False) so2.delete() so2.persist() session = get_session(id=so2.id) assert 'foo' not in session
def test_no_autosave_saves_with_delete(self): req = {"cookie": {"beaker.session.id": 123}} so = SessionObject(req, auto=False) so["foo"] = "bar" so.save() so.persist() session = get_session(id=so.id) assert "foo" in session so2 = SessionObject(req, auto=False) so2.delete() so2.persist() session = get_session(id=so2.id) assert "foo" not in session