Skip to content

Commit 2bf2f52

Browse files
committed
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.
1 parent 7f5e3f7 commit 2bf2f52

File tree

4 files changed

+24
-7
lines changed

4 files changed

+24
-7
lines changed

test/session_common.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import os, shutil, unittest
1+
import os, shutil, time, unittest
22

33
from .db_test_base import config
44

@@ -20,14 +20,23 @@ def tearDown(self):
2020
shutil.rmtree(config.DATABASE)
2121

2222
def testList(self):
23+
'''Under dbm/memory sessions store, keys are returned as
24+
byte strings. self.s2b converts string to byte under those
25+
backends but is a no-op for rdbms based backends.
26+
27+
Unknown why keys can be strings not bytes for get/set
28+
and work correctly.
29+
'''
2330
self.sessions.list()
2431
self.sessions.set('random_key', text='hello, world!')
25-
self.sessions.list()
32+
self.sessions.set('random_key2', text='hello, world!')
33+
self.assertEqual(self.sessions.list().sort(),
34+
[self.s2b('random_key'), self.s2b('random_key2')].sort())
2635

2736
def testGetAll(self):
28-
self.sessions.set('random_key', text='hello, world!')
37+
self.sessions.set('random_key', text='hello, world!', otherval='bar')
2938
self.assertEqual(self.sessions.getall('random_key'),
30-
{'text': 'hello, world!'})
39+
{'text': 'hello, world!', 'otherval': 'bar'})
3140

3241
def testDestroy(self):
3342
self.sessions.set('random_key', text='hello, world!')
@@ -37,9 +46,11 @@ def testDestroy(self):
3746
self.assertRaises(KeyError, self.sessions.getall, 'random_key')
3847

3948
def testSetSession(self):
40-
self.sessions.set('random_key', text='hello, world!')
49+
self.sessions.set('random_key', text='hello, world!', otherval='bar')
4150
self.assertEqual(self.sessions.get('random_key', 'text'),
4251
'hello, world!')
52+
self.assertEqual(self.sessions.get('random_key', 'otherval'),
53+
'bar')
4354

4455
def testUpdateSession(self):
4556
self.sessions.set('random_key', text='hello, world!')

test/test_anydbm.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
from .db_test_base import HTMLItemTest, SpecialActionTest
2323
from .rest_common import TestCase as RestTestCase
2424

25+
from roundup.anypy import strings
26+
2527
class anydbmOpener:
2628
module = get_backend('anydbm')
2729

@@ -51,7 +53,7 @@ class anydbmHTMLItemTest(HTMLItemTest, unittest.TestCase):
5153

5254
from .session_common import SessionTest
5355
class anydbmSessionTest(anydbmOpener, SessionTest, unittest.TestCase):
54-
pass
56+
s2b = lambda x,y: strings.s2b(y)
5557

5658
class anydbmSpecialActionTestCase(anydbmOpener, SpecialActionTest,
5759
unittest.TestCase):

test/test_memorydb.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
from .db_test_base import DBTest, ROTest, SchemaTest, config, setupSchema
66
from roundup.test import memorydb
77

8+
from roundup.anypy import strings
9+
810
class memorydbOpener:
911
module = memorydb
1012

@@ -54,6 +56,8 @@ class memorydbSchemaTest(memorydbOpener, SchemaTest, unittest.TestCase):
5456

5557
from .session_common import SessionTest
5658
class memorydbSessionTest(memorydbOpener, SessionTest, unittest.TestCase):
59+
s2b = lambda x,y: strings.s2b(y)
60+
5761
def setUp(self):
5862
self.db = self.module.Database(config, 'admin')
5963
setupSchema(self.db, 1, self.module)

test/test_sqlite.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class sqliteSpecialActionTestCase(sqliteOpener, SpecialActionTest,
9898

9999
from .session_common import SessionTest
100100
class sqliteSessionTest(sqliteOpener, SessionTest, unittest.TestCase):
101-
pass
101+
s2b = lambda x,y : y
102102

103103
class sqliteRestTest (RestTestCase, unittest.TestCase):
104104
backend = 'sqlite'

0 commit comments

Comments
 (0)