diff test/db_test_base.py @ 5317:c0cda00af479

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).
author Ralf Schlatterbeck <rsc@runtux.com>
date Thu, 19 Apr 2018 17:03:11 +0200
parents 5a014410f254
children 506c7ee9a385
line wrap: on
line diff
--- a/test/db_test_base.py	Thu Apr 19 15:14:07 2018 +0200
+++ b/test/db_test_base.py	Thu Apr 19 17:03:11 2018 +0200
@@ -164,9 +164,9 @@
 
     def iterSetup(self, classname='issue'):
         cls = getattr(self.db, classname)
-        def filt_iter(*args):
+        def filt_iter(*args, **kw):
             """ for checking equivalence of filter and filter_iter """
-            return list(cls.filter_iter(*args))
+            return list(cls.filter_iter(*args, **kw))
         return self.assertEqual, cls.filter, filt_iter
 
     def filteringSetupTransitiveSearch(self, classname='issue'):
@@ -1280,7 +1280,7 @@
         # non-existing classes and link/unlink events to non-existing
         # properties in a class: These all may be the result of a schema
         # change and should not lead to a traceback.
-        self.db.user.create(username="mary")
+        self.db.user.create(username="mary", roles="User")
         id = self.db.issue.create(title="spam", status='1')
         self.db.commit()
         journal = self.db.getjournal('issue', id)
@@ -1300,16 +1300,24 @@
         self.db.commit()
         result=self.db.issue.history(id)
         result.sort()
-        self.assertEqual(len(result), 4)
-        self.assertEqual(result [1][4], jp1)
-        self.assertEqual(result [2][4], jp2)
-        self.assertEqual(result [3][4], jp3)
+        # anydbm drops unknown properties during serialisation
+        if self.db.dbtype == 'anydbm':
+            self.assertEqual(len(result), 3)
+            self.assertEqual(result [1][4], jp2)
+            self.assertEqual(result [2][4], jp3)
+        else:
+            self.assertEqual(len(result), 4)
+            self.assertEqual(result [1][4], jp1)
+            self.assertEqual(result [2][4], jp2)
+            self.assertEqual(result [3][4], jp3)
         self.db.close()
         # Verify that normal user doesn't see obsolete props/classes
-        self.open_database('mary')
-        setupSchema(self.db, 0, self.module)
-        result=self.db.issue.history(id)
-        self.assertEqual(len(result), 1)
+        # Backend memorydb cannot re-open db for different user
+        if self.db.dbtype != 'memorydb':
+            self.open_database('mary')
+            setupSchema(self.db, 0, self.module)
+            result=self.db.issue.history(id)
+            self.assertEqual(len(result), 1)
 
     def testJournalPreCommit(self):
         id = self.db.user.create(username="mary")

Roundup Issue Tracker: http://roundup-tracker.org/