[Zodb-checkins] CVS: ZODB3/ZODB/tests - TransactionalUndoVersionStorage.py:1.8.8.1

Jeremy Hylton jeremy@zope.com
Wed, 13 Nov 2002 17:34:05 -0500


Update of /cvs-repository/ZODB3/ZODB/tests
In directory cvs.zope.org:/tmp/cvs-serv16887

Modified Files:
      Tag: ZODB3-3_1-branch
	TransactionalUndoVersionStorage.py 
Log Message:
Refactor UndoInVersion to make it easier to read.


=== ZODB3/ZODB/tests/TransactionalUndoVersionStorage.py 1.8 => 1.8.8.1 ===
--- ZODB3/ZODB/tests/TransactionalUndoVersionStorage.py:1.8	Wed Aug 14 18:07:09 2002
+++ ZODB3/ZODB/tests/TransactionalUndoVersionStorage.py	Wed Nov 13 17:34:04 2002
@@ -29,7 +29,23 @@
                 pass # not expected
         return self._dostore(*args, **kwargs)
 
+    def _undo(self, tid, oid):
+        t = Transaction()
+        self._storage.tpc_begin(t)
+        oids = self._storage.transactionalUndo(tid, t)
+        self._storage.tpc_vote(t)
+        self._storage.tpc_finish(t)
+        self.assertEqual(len(oids), 1)
+        self.assertEqual(oids[0], oid)
+
     def checkUndoInVersion(self):
+
+        def check_objects(nonversiondata, versiondata):
+            data, revid = self._storage.load(oid, version)
+            self.assertEqual(zodb_unpickle(data), MinPO(versiondata))
+            data, revid = self._storage.load(oid, '')
+            self.assertEqual(zodb_unpickle(data), MinPO(nonversiondata))
+        
         oid = self._storage.new_oid()
         version = 'one'
         revid_a = self._dostore(oid, data=MinPO(91))
@@ -37,21 +53,17 @@
                                 version=version)
         revid_c = self._dostore(oid, revid=revid_b, data=MinPO(93),
                                 version=version)
-        info=self._storage.undoInfo()
-        tid=info[0]['id']
-        t = Transaction()
-        self._storage.tpc_begin(t)
-        oids = self._storage.transactionalUndo(tid, t)
-        self._storage.tpc_vote(t)
-        self._storage.tpc_finish(t)
-        assert len(oids) == 1
-        assert oids[0] == oid
+        
+        info = self._storage.undoInfo()
+        self._undo(info[0]['id'], oid)
+        
         data, revid = self._storage.load(oid, '')
         assert revid == revid_a
         assert zodb_unpickle(data) == MinPO(91)
         data, revid = self._storage.load(oid, version)
         assert revid > revid_b and revid > revid_c
         assert zodb_unpickle(data) == MinPO(92)
+        
         # Now commit the version...
         t = Transaction()
         self._storage.tpc_begin(t)
@@ -61,28 +73,14 @@
         assert len(oids) == 1
         assert oids[0] == oid
 
-        #JF# No, because we fall back to non-version data.
-        #JF# self.assertRaises(POSException.VersionError,
-        #JF#                   self._storage.load,
-        #JF#                   oid, version)
-        data, revid = self._storage.load(oid, version)
-        assert zodb_unpickle(data) == MinPO(92)
-        data, revid = self._storage.load(oid, '')
-        assert zodb_unpickle(data) == MinPO(92)
+        check_objects(92, 92)
+        
         # ...and undo the commit
-        info=self._storage.undoInfo()
-        tid=info[0]['id']
-        t = Transaction()
-        self._storage.tpc_begin(t)
-        oids = self._storage.transactionalUndo(tid, t)
-        self._storage.tpc_vote(t)
-        self._storage.tpc_finish(t)
-        assert len(oids) == 1
-        assert oids[0] == oid
-        data, revid = self._storage.load(oid, version)
-        assert zodb_unpickle(data) == MinPO(92)
-        data, revid = self._storage.load(oid, '')
-        assert zodb_unpickle(data) == MinPO(91)
+        info = self._storage.undoInfo()
+        self._undo(info[0]['id'], oid)
+
+        check_objects(91, 92)
+        
         # Now abort the version
         t = Transaction()
         self._storage.tpc_begin(t)
@@ -91,31 +89,15 @@
         self._storage.tpc_finish(t)
         assert len(oids) == 1
         assert oids[0] == oid
-        # The object should not exist in the version now, but it should exist
-        # in the non-version
-        #JF# No, because we fall back
-        #JF# self.assertRaises(POSException.VersionError,
-        #JF#                   self._storage.load,
-        #JF#                   oid, version)
-        data, revid = self._storage.load(oid, version)
-        assert zodb_unpickle(data) == MinPO(91)
-        data, revid = self._storage.load(oid, '')
-        assert zodb_unpickle(data) == MinPO(91)
+
+        check_objects(91, 91)
+        
         # Now undo the abort
         info=self._storage.undoInfo()
-        tid=info[0]['id']
-        t = Transaction()
-        self._storage.tpc_begin(t)
-        oids = self._storage.transactionalUndo(tid, t)
-        self._storage.tpc_vote(t)
-        self._storage.tpc_finish(t)
-        assert len(oids) == 1
-        assert oids[0] == oid
+        self._undo(info[0]['id'], oid)
+        
         # And the object should be back in versions 'one' and ''
-        data, revid = self._storage.load(oid, version)
-        assert zodb_unpickle(data) == MinPO(92)
-        data, revid = self._storage.load(oid, '')
-        assert zodb_unpickle(data) == MinPO(91)
+        check_objects(91, 92)
 
     def checkUndoCommitVersion(self):
         def load_value(oid, version=''):