[Zodb-checkins] CVS: Zope3/src/zodb/storage/tests - test_demo.py:1.3

Barry Warsaw barry@wooz.org
Thu, 3 Apr 2003 16:46:30 -0500


Update of /cvs-repository/Zope3/src/zodb/storage/tests
In directory cvs.zope.org:/tmp/cvs-serv7999

Modified Files:
	test_demo.py 
Log Message:
Updated tests for the demo storage.  First, there's the basic storage
tests, which demo should easily pass since it's based on the memory
storage.

Second are the more interesting tests where state in the front storage
depends on state in the back storage.


=== Zope3/src/zodb/storage/tests/test_demo.py 1.2 => 1.3 ===
--- Zope3/src/zodb/storage/tests/test_demo.py:1.2	Thu Mar 13 17:09:45 2003
+++ Zope3/src/zodb/storage/tests/test_demo.py	Thu Apr  3 16:46:29 2003
@@ -11,48 +11,120 @@
 # FOR A PARTICULAR PURPOSE.
 #
 ##############################################################################
-import zodb.storage.file
-import zodb.storage.demo
+
 import os
 import tempfile
 import unittest
 
+from zodb.interfaces import ConflictError, VersionLockError
+from zodb.storage.base import ZERO
+from zodb.storage.file import FileStorage
+from zodb.storage.demo import DemoStorage
+
+from zodb.storage.tests.minpo import MinPO
+from zodb.storage.tests.base import zodb_unpickle
+
+# Demo storage can't possible pass the readonly or persistent tests
 from zodb.storage.tests import base, basic, conflict, corruption, history, \
-     iterator, mt, packable, persistent, readonly, recovery, revision, \
+     iterator, mt, packable, recovery, revision, \
      synchronization, undo, undoversion, version
 
-class DemoStorageTests(base.StorageTestBase,
-    basic.BasicStorage,
-##    undo.TransactionalUndoStorage,
-    revision.RevisionStorage,
-    version.VersionStorage,
-##    undoversion.TransactionalUndoVersionStorage,
-##    packable.PackableStorage,
-    synchronization.SynchronizedStorage,
-##    conflict.ConflictResolvingStorage,
-##    conflict.ConflictResolvingTransUndoStorage,
-##    iterator.IteratorStorage,
-##    iterator.ExtendedIteratorStorage,
-##    persistent.PersistentStorage,
-    mt.MTStorage,
-##    readonly.ReadOnlyStorage,
-                       ):
-                       
+class BasicDemoStorageTests(base.StorageTestBase,
+                            basic.BasicStorage,
+                            undo.TransactionalUndoStorage,
+                            revision.RevisionStorage,
+                            version.VersionStorage,
+                            undoversion.TransactionalUndoVersionStorage,
+                            packable.PackableStorage,
+                            synchronization.SynchronizedStorage,
+                            conflict.ConflictResolvingStorage,
+                            conflict.ConflictResolvingTransUndoStorage,
+                            iterator.IteratorStorage,
+                            iterator.ExtendedIteratorStorage,
+                            mt.MTStorage,
+                            ):
+
+    def setUp(self):
+        self._back = FileStorage(tempfile.mktemp())
+        self._storage = DemoStorage('demo', self._back)
+
+    def tearDown(self):
+        self._storage.close()
+        self._back.close()
+        self._back.cleanup()
+
+    # Individual tests that can't possible succeed
+    def testDatabaseVersionPersistent(self): pass
+
+    
+class InterestingDemoStorageTests(base.StorageTestBase):
     def setUp(self):
-        self._base = zodb.storage.file.FileStorage(tempfile.mktemp())
-        self._storage = zodb.storage.demo.DemoStorage(self._base)
+        self._backfile = tempfile.mktemp()
+        self._storage = FileStorage(self._backfile, create=True)
+
+    def flip(self):
+        self._storage.close()
+        self._back = FileStorage(self._backfile, read_only=True)
+        self._storage = DemoStorage('demo', self._back)
 
     def tearDown(self):
         self._storage.close()
-        self._base.close()
-        self._base.cleanup()
+        self._back.close()
+        self._back.cleanup()
 
-    def checkDatabaseVersionPersistent(self):
-        pass # XXX should this test be run?
+    def testFindRootInBack(self):
+        eq = self.assertEqual
+        self._initroot()
+        data0, revid0 = self._storage.load(ZERO)
+        self.flip()
+        data1, revid1 = self._storage.load(ZERO)
+        eq(data0, data1)
+        eq(revid0, revid1)
+
+    def testFindObjectInBack(self):
+        eq = self.assertEqual
+        oid = self._storage.newObjectId()
+        obj = MinPO(11)
+        self._dostore(oid=oid, data=obj)
+        self.flip()
+        data, revid = self._storage.load(oid)
+        eq(obj, zodb_unpickle(data))
+
+    def testStoreInBackStoreInFront(self):
+        eq = self.assertEqual
+        oid = self._storage.newObjectId()
+        revid1 = self._dostore(oid=oid, data=MinPO(7))
+        self.flip()
+        revid2 = self._dostore(oid=oid, data=MinPO(8), revid=revid1)
+        data, serial = self._storage.load(oid, '')
+        eq(serial, revid2)
+        eq(zodb_unpickle(data), MinPO(8))
+
+    def testStoreInBackConflictInFront(self):
+        raises = self.assertRaises
+        oid = self._storage.newObjectId()
+        revid1 = self._dostore(oid=oid, data=MinPO(7))
+        self.flip()
+        # Calculate a bogus revid
+        bogus = '\ff' + revid1[1:]
+        raises(ConflictError, self._dostore,
+               oid=oid, data=MinPO(8), revid=bogus)
+
+    def testStoreInBackVersionLockInFront(self):
+        raises = self.assertRaises
+        oid = self._storage.newObjectId()
+        revid1 = self._dostore(oid=oid, data=MinPO(7), version='backversion')
+        self.flip()
+        raises(VersionLockError, self._dostore,
+               oid=oid, data=MinPO(8), revid=revid1, version='frontversion')
 
-    def checkPackVersions(self):
-        pass # XXX this test should be run!
 
 def test_suite():
-    suite = unittest.makeSuite(DemoStorageTests, 'check')
+    suite = unittest.TestSuite()
+    suite.addTest(unittest.makeSuite(BasicDemoStorageTests))
+    suite.addTest(unittest.makeSuite(InterestingDemoStorageTests))
     return suite
+
+
+if __name__ == '__main__':
+    unittest.main(defaultTest='test_suite')