[Zope-Checkins] CVS: Packages/ZODB/tests - testZODB.py:1.15.8.4

Tim Peters tim.one at comcast.net
Wed Aug 25 15:17:30 EDT 2004


Update of /cvs-repository/Packages/ZODB/tests
In directory cvs.zope.org:/tmp/cvs-serv23647/lib/python/ZODB/tests

Modified Files:
      Tag: Zope-2_7-branch
	testZODB.py 
Log Message:
Transaction.begin() should imply abort().

But didn't, if the only changes pending were in subtransactions.  Now it
does, + new checkTxnBeginImpliesAbort test to ensure it stays fixed.


=== Packages/ZODB/tests/testZODB.py 1.15.8.3 => 1.15.8.4 ===
--- Packages/ZODB/tests/testZODB.py:1.15.8.3	Fri May 21 12:14:05 2004
+++ Packages/ZODB/tests/testZODB.py	Wed Aug 25 15:17:30 2004
@@ -329,5 +329,40 @@
         self.obj = DecoyIndependent()
         self.readConflict()
 
+    def checkTxnBeginImpliesAbort(self):
+        # begin() should do an abort() first, if needed.
+        cn = self._db.open()
+        rt = cn.root()
+        rt['a'] = 1
+
+        get_transaction().begin()  # should abort adding 'a' to the root
+        rt = cn.root()
+        self.assertRaises(KeyError, rt.__getitem__, 'a')
+
+        # A longstanding bug:  this didn't work if changes were only in
+        # subtransactions.
+        get_transaction().begin()
+        rt = cn.root()
+        rt['a'] = 2
+        get_transaction().commit(1)
+
+        get_transaction().begin()
+        rt = cn.root()
+        self.assertRaises(KeyError, rt.__getitem__, 'a')
+
+        # One more time, mixing "top level" and subtransaction changes.
+        get_transaction().begin()
+        rt = cn.root()
+        rt['a'] = 3
+        get_transaction().commit(1)
+        rt['b'] = 4
+
+        get_transaction().begin()
+        rt = cn.root()
+        self.assertRaises(KeyError, rt.__getitem__, 'a')
+        self.assertRaises(KeyError, rt.__getitem__, 'b')
+
+        cn.close()
+
 def test_suite():
     return unittest.makeSuite(ZODBTests, 'check')



More information about the Zope-Checkins mailing list