def test_unicode_value(self): logger = logging.getLogger(__name__) db = self.request.site.db # create session and and store a unicode value session = Session(self.request) token = session.token logger.debug('created session %r', token) self.assertNotEqual(token, 'Session error') session.content = 'こんにちは' session.save(db) try: cmd = 'select * from sessions where id=%s' q = db(cmd, token) self.assertEqual(len(list(q)), 1) # Create new session object session2 = Session(self.request) # Load previously created session self.request.session_token = token session2.load(db, token) self.assertEqual(session2.content, 'こんにちは') finally: session.destroy() logger.debug('attempting to destroy session %r', token) cmd = 'select * from sessions where id=%s' q = db(cmd, token) self.assertEqual(len(list(q)), 0)
def test_session(self): db = self.request.site.db session = Session(self.request) #Create new session # id = session.new(db) id = session._token logger.debug('created session %r', id) # logger.debug('session._token is %r', session._token) self.assert_(id != 'Session error') session.MyName = 'Test' session.Message = 'This is a test session' session.Number = 123 session.save(db) try: cmd = 'select * from sessions where id=%s' q = db(cmd, id) self.assertEqual(len(list(q)), 1) # Create new session object session2 = Session(self.request) # Load previously created session self.request.session_token = id session2.load(db, id) self.assertEqual(session2.Number, 123) self.assertEqual(session2.MyName, 'Test') self.assertEqual(session2.Message, 'This is a test session') finally: session.destroy() logger.debug('attempting to destroy session %r', id) cmd = 'select * from sessions where id=%s' q = db(cmd, id) self.assertEqual(len(list(q)), 0)
def test_session(self): logger = logging.getLogger(__name__) db = self.request.site.db # create session and and store some values session = Session(self.request) token = session.token logger.debug('created session %r', token) self.assertNotEqual(token, 'Session error') session.MyName = 'Test' session.Message = 'This is a test session' session.Number = 123 session.save(db) try: cmd = 'select * from sessions where id=%s' q = db(cmd, token) self.assertEqual(len(list(q)), 1) # Create new session object session2 = Session(self.request) # Load previously created session self.request.session_token = token session2.load(db, token) self.assertEqual(session2.Number, 123) self.assertEqual(session2.MyName, 'Test') self.assertEqual(session2.Message, 'This is a test session') finally: session.destroy() logger.debug('attempting to destroy session %r', token) cmd = 'select * from sessions where id=%s' q = db(cmd, token) self.assertEqual(len(list(q)), 0)