Mercurial > p > roundup > code
view test/session_common.py @ 6803:db437dd13ed5
set method doesn't include user set timestamp if update
set() is supposed to update the record with the key if it already
exists.
It does update the value marshalled data blob. However it doesn't
update the timestamp column for rdbms tables if provided.
This change updates the x_time column with the provided __timestamp or
preserves the original timestamp.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Mon, 25 Jul 2022 15:07:32 -0400 |
| parents | 044dcf3608a2 |
| children | bdd28b244839 |
line wrap: on
line source
import os, shutil, time, unittest from .db_test_base import config class SessionTest(object): def setUp(self): # remove previous test, ignore errors if os.path.exists(config.DATABASE): shutil.rmtree(config.DATABASE) os.makedirs(config.DATABASE + '/files') self.db = self.module.Database(config, 'admin') self.sessions = self.db.getSessionManager() self.otks = self.db.getOTKManager() def tearDown(self): if hasattr(self, 'db'): self.db.close() if os.path.exists(config.DATABASE): shutil.rmtree(config.DATABASE) def testList(self): '''Under dbm/memory sessions store, keys are returned as byte strings. self.s2b converts string to byte under those backends but is a no-op for rdbms based backends. Unknown why keys can be strings not bytes for get/set and work correctly. ''' self.sessions.list() self.sessions.set('random_key', text='hello, world!') self.sessions.set('random_key2', text='hello, world!') self.assertEqual(self.sessions.list().sort(), [self.s2b('random_key'), self.s2b('random_key2')].sort()) def testGetAll(self): self.sessions.set('random_key', text='hello, world!', otherval='bar') self.assertEqual(self.sessions.getall('random_key'), {'text': 'hello, world!', 'otherval': 'bar'}) def testDestroy(self): self.sessions.set('random_key', text='hello, world!') self.assertEqual(self.sessions.getall('random_key'), {'text': 'hello, world!'}) self.sessions.destroy('random_key') self.assertRaises(KeyError, self.sessions.getall, 'random_key') def testSetSession(self): self.sessions.set('random_key', text='hello, world!', otherval='bar') self.assertEqual(self.sessions.get('random_key', 'text'), 'hello, world!') self.assertEqual(self.sessions.get('random_key', 'otherval'), 'bar') def testUpdateSession(self): self.sessions.set('random_key', text='hello, world!') self.assertEqual(self.sessions.get('random_key', 'text'), 'hello, world!') self.sessions.set('random_key', text='nope') self.assertEqual(self.sessions.get('random_key', 'text'), 'nope')
