Commit cda3f6d8 authored by Chris McDonough's avatar Chris McDonough

Add a test for redo of an object's creation.

parent 8e553cc4
...@@ -23,6 +23,7 @@ from ZODB.Blobs.Blob import Blob ...@@ -23,6 +23,7 @@ from ZODB.Blobs.Blob import Blob
from ZODB.DB import DB from ZODB.DB import DB
import transaction import transaction
from ZODB.Blobs.Blob import Blob from ZODB.Blobs.Blob import Blob
from ZODB import utils
class BlobUndoTests(unittest.TestCase): class BlobUndoTests(unittest.TestCase):
...@@ -44,17 +45,20 @@ class BlobUndoTests(unittest.TestCase): ...@@ -44,17 +45,20 @@ class BlobUndoTests(unittest.TestCase):
connection = database.open() connection = database.open()
root = connection.root() root = connection.root()
transaction.begin() transaction.begin()
blob = Blob() root['blob'] = Blob()
blob.open('w').write('this is state 1')
root['blob'] = blob
transaction.commit() transaction.commit()
serial = base64.encodestring(blob_storage._tid) serial = base64.encodestring(blob_storage._tid)
# undo the creation of the previously added blob
transaction.begin() transaction.begin()
blob_storage.undo(serial, blob_storage._transaction) database.undo(serial, blob_storage._transaction)
transaction.commit() transaction.commit()
connection.close()
connection = database.open()
root = connection.root()
# the blob footprint object should exist no longer
self.assertRaises(KeyError, root.__getitem__, 'blob') self.assertRaises(KeyError, root.__getitem__, 'blob')
def testUndo(self): def testUndo(self):
...@@ -90,6 +94,79 @@ class BlobUndoTests(unittest.TestCase): ...@@ -90,6 +94,79 @@ class BlobUndoTests(unittest.TestCase):
self.assertEqual(blob.open('r').read(), 'this is state 1') self.assertEqual(blob.open('r').read(), 'this is state 1')
transaction.abort() transaction.abort()
def testRedo(self):
base_storage = FileStorage(self.storagefile)
blob_storage = BlobStorage(self.blob_dir, base_storage)
database = DB(blob_storage)
connection = database.open()
root = connection.root()
blob = Blob()
transaction.begin()
blob.open('w').write('this is state 1')
root['blob'] = blob
transaction.commit()
transaction.begin()
blob = root['blob']
blob.open('w').write('this is state 2')
transaction.commit()
serial = base64.encodestring(blob_storage._tid)
transaction.begin()
database.undo(serial)
transaction.commit()
transaction.begin()
blob = root['blob']
self.assertEqual(blob.open('r').read(), 'this is state 1')
transaction.abort()
serial = base64.encodestring(blob_storage._tid)
transaction.begin()
database.undo(serial)
transaction.commit()
transaction.begin()
blob = root['blob']
self.assertEqual(blob.open('r').read(), 'this is state 2')
transaction.abort()
def testRedoOfCreation(self):
base_storage = FileStorage(self.storagefile)
blob_storage = BlobStorage(self.blob_dir, base_storage)
database = DB(blob_storage)
connection = database.open()
root = connection.root()
blob = Blob()
transaction.begin()
blob.open('w').write('this is state 1')
root['blob'] = blob
transaction.commit()
serial = base64.encodestring(blob_storage._tid)
transaction.begin()
database.undo(serial)
transaction.commit()
self.assertRaises(KeyError, root.__getitem__, 'blob')
serial = base64.encodestring(blob_storage._tid)
transaction.begin()
database.undo(serial)
transaction.commit()
transaction.begin()
blob = root['blob']
self.assertEqual(blob.open('r').read(), 'this is state 1')
transaction.abort()
def test_suite(): def test_suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(BlobUndoTests)) suite.addTest(unittest.makeSuite(BlobUndoTests))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment