From ccf1455a8d1ac5d0476b6a1724776d5b23a1d7f9 Mon Sep 17 00:00:00 2001
From: Barry Warsaw <barry@python.org>
Date: Wed, 11 Apr 2001 22:03:57 +0000
Subject: [PATCH] Base class for all storage tests.  StorageTestBase inherits
 from unittest.TestCase.  It also provides the setUp(), _close(), and
 tearDown() methods, as well as the _dostore() convenience method.

---
 src/ZODB/tests/StorageTestBase.py | 55 +++++++++++++++++++++++++++++++
 1 file changed, 55 insertions(+)
 create mode 100644 src/ZODB/tests/StorageTestBase.py

diff --git a/src/ZODB/tests/StorageTestBase.py b/src/ZODB/tests/StorageTestBase.py
new file mode 100644
index 00000000..ac863090
--- /dev/null
+++ b/src/ZODB/tests/StorageTestBase.py
@@ -0,0 +1,55 @@
+# This class must be one of the mixin base class for your storage test.  It
+# provides basic setUp() and tearDown() semantics (which you can override),
+# and it also provides a helper method _dostore() which performs a complete
+# store transaction for a single object revision.
+
+import pickle
+import unittest
+from ZODB.Transaction import Transaction
+
+ZERO = '\0'*8
+
+
+
+class StorageTestBase(unittest.TestCase):
+    def setUp(self):
+        # You need to override this with a setUp that creates self._storage
+        self._transaction = Transaction()
+
+    def _close(self):
+        # You should override this if closing your storage requires additional
+        # shutdown operations.
+        self._transaction.abort()
+        self._storage.close()
+
+    def tearDown(self):
+        self._close()
+
+    def _dostore(self, oid=None, revid=None, data=None, version=None):
+        # Do a complete storage transaction.  The defaults are:
+        # - oid=None, ask the storage for a new oid
+        # - revid=None, use a revid of ZERO
+        # - data=None, pickle up some arbitrary data (the integer 7)
+        # - version=None, use the empty string version
+        #
+        # Returns the object's new revision id
+        if oid is None:
+            oid = self._storage.new_oid()
+        if revid is None:
+            revid = ZERO
+        if data is None:
+            data = pickle.dumps(7)
+        else:
+            data = pickle.dumps(data)
+        if version is None:
+            version = ''
+        # Begin the transaction
+        self._storage.tpc_begin(self._transaction)
+        # Store an object
+        newrevid = self._storage.store(oid, revid, data, version,
+                                       self._transaction)
+        # Finish the transaction
+        self._storage.tpc_vote(self._transaction)
+        self._storage.tpc_finish(self._transaction)
+        return newrevid
+        
-- 
2.30.9