Mercurial > p > roundup > code
diff test/session_common.py @ 6802:044dcf3608a2
update session db tests
session_common.py:
testList had no asserts. While adding them I found out the memory
and anydbm backends return byte strings while the rdbms backend
return strings. So added a call to s2b defined in each db test file
to covert. rdbms i a no-op and memory/anydbm call
roundup.anypy.strings::s2b().
also add some data to other tests and verify it.
other files:
define s2b appropriately.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Mon, 25 Jul 2022 15:02:30 -0400 |
| parents | 95a366d46065 |
| children | bdd28b244839 |
line wrap: on
line diff
--- a/test/session_common.py Mon Jul 25 14:28:31 2022 -0400 +++ b/test/session_common.py Mon Jul 25 15:02:30 2022 -0400 @@ -1,4 +1,4 @@ -import os, shutil, unittest +import os, shutil, time, unittest from .db_test_base import config @@ -20,14 +20,23 @@ 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.list() + 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!') + self.sessions.set('random_key', text='hello, world!', otherval='bar') self.assertEqual(self.sessions.getall('random_key'), - {'text': 'hello, world!'}) + {'text': 'hello, world!', 'otherval': 'bar'}) def testDestroy(self): self.sessions.set('random_key', text='hello, world!') @@ -37,9 +46,11 @@ self.assertRaises(KeyError, self.sessions.getall, 'random_key') def testSetSession(self): - self.sessions.set('random_key', text='hello, world!') + 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!')
