[Zope-CVS] CVS: Products/Ape/lib/apelib/tests - testzope2sql.py:1.8
Shane Hathaway
shane at zope.com
Thu Mar 11 00:58:41 EST 2004
Update of /cvs-repository/Products/Ape/lib/apelib/tests
In directory cvs.zope.org:/tmp/cvs-serv13608/tests
Modified Files:
testzope2sql.py
Log Message:
Ape's sql package now uses a smarter connection class and no query generator.
The query generator could not adapt very well to the different
approaches databases take. It separated the SQL generation too far from
the execution, forcing every database to fit a common pattern. This
means that PostgreSQL support was easy, while MySQL was harder, and
other databases might have been worse.
Now, the connection class implements a fairly simple interface for
talking to the database. The connection is now free to use multiple
statements or shortcuts. Also, the DB-API module registry is no longer
needed.
=== Products/Ape/lib/apelib/tests/testzope2sql.py 1.7 => 1.8 ===
--- Products/Ape/lib/apelib/tests/testzope2sql.py:1.7 Mon Feb 2 10:07:22 2004
+++ Products/Ape/lib/apelib/tests/testzope2sql.py Thu Mar 11 00:58:40 2004
@@ -19,7 +19,7 @@
import unittest
import sys
-from apelib.sql.dbapi import DBAPIConnector
+import apelib.sql.dbapi
from apelib.zodb3.db import ApeDB
from apelib.zodb3.storage import ApeStorage
from apelib.zodb3.resource import StaticResource
@@ -32,39 +32,43 @@
class Zope2SQLTests (Zope2TestBase):
dbapi_module = None # Name of the Database API module (required)
- dbapi_params = () # Positional args for connect()
- dbapi_kwparams = {} # Keyword args for connect()
+ class_name = None
+ connect_args = '' # Python expression for connect()
- def getConnector(self):
- return DBAPIConnector(self.dbapi_module, self.dbapi_params,
- self.dbapi_kwparams, prefix='test_temp')
+ def getConnection(self):
+ c = getattr(apelib.sql.dbapi, self.class_name)
+ return c(self.dbapi_module, self.connect_args, prefix="test_temp_")
def setUp(self):
global conf
if conf is None:
conf = loadConf('sql')
- conn = self.getConnector()
+ conn = self.getConnection()
self.conf = conf
resource = StaticResource(self.conf)
self.conns = {'db': conn}
storage = ApeStorage(resource, self.conns, clear_all=1)
self.storage = storage
self.db = ApeDB(storage, resource)
- c = self.db.open()
try:
- if not c.root().has_key('Application'):
- from OFS.Application import Application
- c.root()['Application'] = Application()
- get_transaction().commit()
- finally:
- c.close()
+ c = self.db.open()
+ try:
+ if not c.root().has_key('Application'):
+ from OFS.Application import Application
+ c.root()['Application'] = Application()
+ get_transaction().commit()
+ finally:
+ get_transaction().abort()
+ c.close()
+ except:
+ self.db.close()
+ raise
def clear(self):
self.storage.initDatabases(clear_all=1)
- for conn in self.conns.values():
- conn.db.commit()
def tearDown(self):
+ get_transaction().abort()
self.clear()
self.db.close()
@@ -75,12 +79,14 @@
class PsycopgTests (Zope2SQLTests, unittest.TestCase):
dbapi_module = 'psycopg'
- dbapi_params = ('',)
+ class_name = 'PostgreSQLConnection'
+ connect_args = '""'
class MySQLTests (Zope2SQLTests, unittest.TestCase):
dbapi_module = 'MySQLdb'
- dbapi_kwparams = {'db': 'ape'}
+ class_name = 'MySQLConnection'
+ connect_args = 'db="ape"'
def test_suite():
@@ -97,11 +103,11 @@
% (repr(mname), k))
else:
case = v('testConnect')
- connector = case.getConnector()
+ conn = case.getConnection()
try:
- connector.connect()
- connector.close()
- except connector.error:
+ conn.connect()
+ conn.close()
+ except conn.module.Error:
sys.stderr.write('Warning: could not open a '
'connection using %s. Skipping %s.\n'
% (repr(mname), k))
@@ -112,4 +118,3 @@
if __name__ == '__main__':
unittest.main(defaultTest='test_suite')
-
More information about the Zope-CVS
mailing list