Update of /cvsroot/sqlobject/SQLObject/tests
In directory sc8-pr-cvs1:/tmp/cvs-serv26904/tests
Modified Files:
SQLObjectTest.py test.py
Log Message:
Lots of transaction fixes.
Index: SQLObjectTest.py
===================================================================
RCS file: /cvsroot/sqlobject/SQLObject/tests/SQLObjectTest.py,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** SQLObjectTest.py 6 Sep 2003 07:12:02 -0000 1.12
--- SQLObjectTest.py 7 Sep 2003 00:49:03 -0000 1.13
***************
*** 50,56 ****
SQLObjectTest.supportAuto = False
SQLObjectTest.supportRestrictedEnum = False
! return FirebirdConnection('localhost', 'data/firebird.gdb')
! supportedDatabases = ['mysql', 'postgres', 'sqlite', 'firebird', 'dbm']
class SQLObjectTest(unittest.TestCase):
--- 50,73 ----
SQLObjectTest.supportAuto = False
SQLObjectTest.supportRestrictedEnum = False
! return FirebirdConnection('localhost', '/usr/home/ianb/w/SQLObject/data/firebird.gdb',
! user='sysdba', passwd='masterkey')
! _supportedDatabases = {
! 'mysql': 'MySQLdb',
! 'postgres': 'psycopg',
! 'sqlite': 'sqlite',
! 'firebird': 'kinterbasdb',
! 'dbm': 'anydbm'}
!
! def supportedDatabases():
! result = []
! for name, module in _supportedDatabases.items():
! try:
! exec 'import %s' % module
! except ImportError:
! pass
! else:
! result.append(name)
! return result
class SQLObjectTest(unittest.TestCase):
***************
*** 58,62 ****
classes = []
! debugSQL = 0
databaseName = None
--- 75,81 ----
classes = []
! debugSQL = False
! debugOutput = False
! debugInserts = False
databaseName = None
***************
*** 67,71 ****
print '#' * 70
unittest.TestCase.setUp(self)
! #__connection__.debug = self.debugSQL
for c in self.classes:
c._connection = __connection__
--- 86,93 ----
print '#' * 70
unittest.TestCase.setUp(self)
! if self.debugInserts:
! __connection__.debug = True
! __connection__.debugOuput = self.debugOutput
!
for c in self.classes:
c._connection = __connection__
***************
*** 88,94 ****
elif hasattr(c, 'createTable'):
c.createTable(ifNotExists=True)
- #__connection__.debug = self.debugSQL
self.inserts()
__connection__.debug = self.debugSQL
def inserts(self):
--- 110,116 ----
elif hasattr(c, 'createTable'):
c.createTable(ifNotExists=True)
self.inserts()
__connection__.debug = self.debugSQL
+ __connection__.debugOutput = self.debugOutput
def inserts(self):
Index: test.py
===================================================================
RCS file: /cvsroot/sqlobject/SQLObject/tests/test.py,v
retrieving revision 1.21
retrieving revision 1.22
diff -C2 -d -r1.21 -r1.22
*** test.py 17 Jul 2003 01:20:18 -0000 1.21
--- test.py 7 Sep 2003 00:49:03 -0000 1.22
***************
*** 1,2 ****
--- 1,10 ----
+ """
+ Main (um, only) unit testing for SQLObject.
+
+ Use -vv to see SQL queries, -vvv to also see output from queries,
+ and together with --inserts to see the SQL from the standard
+ insert statements (which are often boring).
+ """
+
from SQLObjectTest import *
from SQLObject import *
***************
*** 213,230 ****
########################################
class TransactionTest(SQLObjectTest):
! classes = [Names]
def inserts(self):
! Names.new(fname='bob', lname='jones')
def testTransaction(self):
if not self.supportTransactions: return
! trans = Names._connection.transaction()
! Names.new(fname='joe', lname='jones', connection=trans)
! trans.rollback()
! self.assertEqual([n.fname for n in Names.select()],
! ['bob'])
--- 221,255 ----
########################################
+ class TestSOTrans(SQLObject):
+ _cacheValues = False
+ name = StringCol(length=10, alternateID=True)
+ _defaultOrderBy = 'name'
+
class TransactionTest(SQLObjectTest):
! classes = [TestSOTrans]
def inserts(self):
! TestSOTrans.new(name='bob')
! TestSOTrans.new(name='tim')
def testTransaction(self):
if not self.supportTransactions: return
! trans = TestSOTrans._connection.transaction()
! try:
! TestSOTrans._connection.autoCommit = 'exception'
! TestSOTrans.new(name='joe', connection=trans)
! trans.rollback()
! self.assertEqual([n.name for n in TestSOTrans.select(connection=trans)],
! ['bob', 'tim'])
! b = TestSOTrans.byName('bob', connection=trans)
! b.name = 'robert'
! trans.commit()
! self.assertEqual(b.name, 'robert')
! b.name = 'bob'
! trans.rollback()
! self.assertEqual(b.name, 'robert')
! finally:
! TestSOTrans._connection.autoCommit = True
***************
*** 564,580 ****
import unittest, sys
dbs = []
for arg in sys.argv[1:]:
if arg.startswith('-d'):
dbs.append(arg[2:])
if arg.startswith('--database='):
dbs.append(arg[11:])
if arg in ('-vv', '--extra-verbose'):
! SQLObjectTest.debugSQL = 1
! sys.argv = [a for a in sys.argv
! if not a.startswith('-d') and not a.startswith('--database=')]
if not dbs:
dbs = ['mysql']
if dbs == ['all']:
! dbs = supportedDatabases
for db in dbs:
setDatabaseType(db)
--- 589,616 ----
import unittest, sys
dbs = []
+ newArgs = []
for arg in sys.argv[1:]:
if arg.startswith('-d'):
dbs.append(arg[2:])
+ continue
if arg.startswith('--database='):
dbs.append(arg[11:])
+ continue
if arg in ('-vv', '--extra-verbose'):
! SQLObjectTest.debugSQL = True
! if arg in ('-vvv', '--super-verbose'):
! SQLObjectTest.debugSQL = True
! SQLObjectTest.debugOutput = True
! newArgs.append('-vv')
! continue
! if arg in ('--inserts',):
! SQLObjectTest.debugInserts = True
! continue
! newArgs.append(arg)
! sys.argv = [sys.argv[0]] + newArgs
if not dbs:
dbs = ['mysql']
if dbs == ['all']:
! dbs = supportedDatabases()
for db in dbs:
setDatabaseType(db)
|