[Zope-CVS] CVS: Products/Ape/lib/apelib/tests -
testzope2fs.py:1.6.2.3
Shane Hathaway
shane at zope.com
Thu Feb 26 10:02:46 EST 2004
Update of /cvs-repository/Products/Ape/lib/apelib/tests
In directory cvs.zope.org:/tmp/cvs-serv28241/lib/apelib/tests
Modified Files:
Tag: ape-fs-oid-branch
testzope2fs.py
Log Message:
Fixed a small bug in opening existing databases.
Also added a test of opening existing databases.
=== Products/Ape/lib/apelib/tests/testzope2fs.py 1.6.2.2 => 1.6.2.3 ===
--- Products/Ape/lib/apelib/tests/testzope2fs.py:1.6.2.2 Wed Feb 25 22:08:56 2004
+++ Products/Ape/lib/apelib/tests/testzope2fs.py Thu Feb 26 10:02:46 2004
@@ -50,26 +50,12 @@
class Zope2FSTests (unittest.TestCase, Zope2TestBase):
- def _createConnections(self, path):
- conn = FSConnection(path)
- return {'fs': conn}
+ annotation_prefix = '.'
def setUp(self):
- global conf
- if conf is None:
- conf = loadConf('filesystem')
- if not os.path.exists(tmpdir):
- os.mkdir(tmpdir)
- self.path = tmpdir
+ self.db, self.conn = self.openDatabase()
self.conf = conf
- conns = self._createConnections(tmpdir)
- assert len(conns) == 1
- self.conn = conns['fs']
- resource = StaticResource(self.conf)
- storage = ApeStorage(resource, conns)
- self.storage = storage
- db = ApeDB(storage, resource, cache_size=0)
- self.db = db
+ self.path = tmpdir
c = self.db.open()
try:
if not c.root().has_key('Application'):
@@ -83,9 +69,23 @@
def tearDown(self):
get_transaction().abort()
- self.db.close()
+ if self.db is not None:
+ self.db.close()
rmtree(self.path)
+ def openDatabase(self):
+ global conf
+ if conf is None:
+ conf = loadConf('filesystem')
+ if not os.path.exists(tmpdir):
+ os.mkdir(tmpdir)
+ conn = FSConnection(tmpdir, annotation_prefix=self.annotation_prefix)
+ conns = {'fs': conn}
+ resource = StaticResource(conf)
+ storage = ApeStorage(resource, conns)
+ db = ApeDB(storage, resource, cache_size=0)
+ return db, conn
+
def clearCaches(self):
"""Clears caches after a filesystem write.
"""
@@ -657,11 +657,31 @@
conn2.close()
+ def testOpenExisting(self):
+ # Verifies that opening an existing database finds the same data.
+ conn = self.db.open()
+ try:
+ app = conn.root()['Application']
+ app.test_attribute = '123'
+ get_transaction().commit()
+ finally:
+ conn.close()
+
+ # Close the database and open a new one.
+ self.db.close()
+ self.db = None
+ self.db, self.conn = self.openDatabase()
+ conn = self.db.open()
+ try:
+ root = conn.root()
+ app = root['Application']
+ self.assertEqual(app.test_attribute, '123')
+ finally:
+ conn.close()
+
+
class Zope2FSUnderscoreTests (Zope2FSTests):
-
- def _createConnections(self, path):
- conn = FSConnection(path, annotation_prefix='_')
- return {'fs': conn}
+ annotation_prefix = '_'
if __name__ == '__main__':
More information about the Zope-CVS
mailing list