Skip to content

Commit d54a7f5

Browse files
committed
Fix tests for memorydb and anydbm backends
The anydbm backend silently drops properties in the journal that are not in the database during serialisation. The memorydb backend (only used for testing) cannot deal with user changes (re-open of db under a different user).
1 parent 2746c2d commit d54a7f5

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

test/db_test_base.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,9 @@ def setUp(self):
164164

165165
def iterSetup(self, classname='issue'):
166166
cls = getattr(self.db, classname)
167-
def filt_iter(*args):
167+
def filt_iter(*args, **kw):
168168
""" for checking equivalence of filter and filter_iter """
169-
return list(cls.filter_iter(*args))
169+
return list(cls.filter_iter(*args, **kw))
170170
return self.assertEqual, cls.filter, filt_iter
171171

172172
def filteringSetupTransitiveSearch(self, classname='issue'):
@@ -1280,7 +1280,7 @@ def testJournalNonexistingProperty(self):
12801280
# non-existing classes and link/unlink events to non-existing
12811281
# properties in a class: These all may be the result of a schema
12821282
# change and should not lead to a traceback.
1283-
self.db.user.create(username="mary")
1283+
self.db.user.create(username="mary", roles="User")
12841284
id = self.db.issue.create(title="spam", status='1')
12851285
self.db.commit()
12861286
journal = self.db.getjournal('issue', id)
@@ -1300,16 +1300,24 @@ def testJournalNonexistingProperty(self):
13001300
self.db.commit()
13011301
result=self.db.issue.history(id)
13021302
result.sort()
1303-
self.assertEqual(len(result), 4)
1304-
self.assertEqual(result [1][4], jp1)
1305-
self.assertEqual(result [2][4], jp2)
1306-
self.assertEqual(result [3][4], jp3)
1303+
# anydbm drops unknown properties during serialisation
1304+
if self.db.dbtype == 'anydbm':
1305+
self.assertEqual(len(result), 3)
1306+
self.assertEqual(result [1][4], jp2)
1307+
self.assertEqual(result [2][4], jp3)
1308+
else:
1309+
self.assertEqual(len(result), 4)
1310+
self.assertEqual(result [1][4], jp1)
1311+
self.assertEqual(result [2][4], jp2)
1312+
self.assertEqual(result [3][4], jp3)
13071313
self.db.close()
13081314
# Verify that normal user doesn't see obsolete props/classes
1309-
self.open_database('mary')
1310-
setupSchema(self.db, 0, self.module)
1311-
result=self.db.issue.history(id)
1312-
self.assertEqual(len(result), 1)
1315+
# Backend memorydb cannot re-open db for different user
1316+
if self.db.dbtype != 'memorydb':
1317+
self.open_database('mary')
1318+
setupSchema(self.db, 0, self.module)
1319+
result=self.db.issue.history(id)
1320+
self.assertEqual(len(result), 1)
13131321

13141322
def testJournalPreCommit(self):
13151323
id = self.db.user.create(username="mary")

test/memorydb.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,9 @@ class Database(back_anydbm.Database):
182182
modified. Do some sort of conflict checking on the dirty stuff.
183183
- perhaps detect write collisions (related to above)?
184184
"""
185+
186+
dbtype = "memorydb"
187+
185188
def __init__(self, config, journaltag=None):
186189
self.config, self.journaltag = config, journaltag
187190
self.classes = {}

0 commit comments

Comments
 (0)