Update of /cvsroot/sqlobject/SQLObject/tests
In directory sc8-pr-cvs1:/tmp/cvs-serv3612/tests
Modified Files:
SQLObjectTest.py test.py
Log Message:
* Extended the tests to work with Postgres, SQLite, DBM
* Some databases don't implement some features (SQLite doesn't support
dynamic columns, all but MySQL don't support auto-class creation),
at least for now.
* Make SERIAL work for columns under Postgres, as well as _idName
* Fixed LIMIT/OFFSET bugs in Postgres, SQLite
* tableExists in Postgres
Index: SQLObjectTest.py
===================================================================
RCS file: /cvsroot/sqlobject/SQLObject/tests/SQLObjectTest.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** SQLObjectTest.py 7 Apr 2003 01:13:56 -0000 1.4
--- SQLObjectTest.py 7 Apr 2003 19:48:42 -0000 1.5
***************
*** 2,12 ****
from SQLObject import *
! __connection__ = MySQLConnection(host='localhost',
! db='test',
! user='test',
! passwd='',
! debug=0)
! #__connection__ = DBMConnection('data')
class SQLObjectTest(unittest.TestCase):
--- 2,32 ----
from SQLObject import *
! True, False = 1==1, 0==1
! def mysqlConnection():
! SQLObjectTest.supportDynamic = True
! SQLObjectTest.supportAuto = True
! return MySQLConnection(host='localhost',
! db='test',
! user='test',
! passwd='',
! debug=0)
!
! def dbmConnection():
! SQLObjectTest.supportDynamic = True
! SQLObjectTest.supportAuto = False
! return DBMConnection('data')
!
! def postgresConnection():
! SQLObjectTest.supportDynamic = True
! SQLObjectTest.supportAuto = False
! return PostgresConnection(db='test')
!
! def sqliteConnection():
! SQLObjectTest.supportDynamic = False
! SQLObjectTest.supportAuto = False
! return SQLiteConnection('data/sqlite.data')
!
! supportedDatabases = ['mysql', 'postgres', 'sqlite', 'dbm']
class SQLObjectTest(unittest.TestCase):
***************
*** 22,25 ****
--- 42,47 ----
unittest.TestCase.setUp(self)
#__connection__.debug = self.debugSQL
+ for c in self.classes:
+ c._connection = __connection__
for c in self.classes + [self]:
if hasattr(c, 'drop'):
***************
*** 45,48 ****
__connection__.query(c.drop)
! __all__ = ['SQLObjectTest', '__connection__',]
--- 67,79 ----
__connection__.query(c.drop)
! def setDatabaseType(t):
! global __connection__
! conn = globals()[t + "Connection"]()
! __connection__ = conn
!
! def connection():
! return __connection__
!
! __all__ = ['SQLObjectTest', 'setDatabaseType', 'connection',
! 'supportedDatabases']
Index: test.py
===================================================================
RCS file: /cvsroot/sqlobject/SQLObject/tests/test.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** test.py 7 Apr 2003 01:13:57 -0000 1.5
--- test.py 7 Apr 2003 19:48:44 -0000 1.6
***************
*** 93,96 ****
--- 93,98 ----
def testDynamicColumn(self):
+ if not self.supportDynamic:
+ return
nickname = StringCol('nickname', length=10)
Person.addColumn(nickname, changeSchema=True)
***************
*** 101,104 ****
--- 103,108 ----
def testDynamicJoin(self):
+ if not self.supportDynamic:
+ return
col = KeyCol('personID', foreignKey='Person')
Phone.addColumn(col, changeSchema=True)
***************
*** 110,115 ****
else:
phone.person = Person.selectBy(name='bob')[0]
! self.assertEqual([p.phone for p in Person.selectBy(name='tim')[0].phones],
! ['555-555-5555', '555-394-2930'])
Phone.delColumn(col, changeSchema=True)
Person.delJoin(join)
--- 114,121 ----
else:
phone.person = Person.selectBy(name='bob')[0]
! l = [p.phone for p in Person.selectBy(name='tim')[0].phones]
! l.sort()
! self.assertEqual(l,
! ['555-394-2930', '555-555-5555'])
Phone.delColumn(col, changeSchema=True)
Person.delJoin(join)
***************
*** 122,126 ****
class AutoTest(SQLObjectTest):
! create = """
CREATE TABLE IF NOT EXISTS auto_test (
id INT AUTO_INCREMENT PRIMARY KEY,
--- 128,132 ----
class AutoTest(SQLObjectTest):
! mysqlCreate = """
CREATE TABLE IF NOT EXISTS auto_test (
id INT AUTO_INCREMENT PRIMARY KEY,
***************
*** 133,143 ****
"""
! drop = """
DROP TABLE IF EXISTS auto_test
"""
def testClassCreate(self):
class AutoTest(SQLObject):
_fromDatabase = True
AutoTest.new(firstName='john',
lastName='doe',
--- 139,167 ----
"""
! postgresCreate = """
! CREATE TABLE auto_test (
! id SERIAL,
! first_name VARCHAR(100),
! last_name VARCHAR(200) NOT NULL,
! age INT,
! created DATETIME NOT NULL,
! happy char(1) DEFAULT 'Y' NOT NULL
! )
! """
!
! mysqlDrop = """
DROP TABLE IF EXISTS auto_test
"""
+ postgresDrop = """
+ DROP TABLE auto_test
+ """
+
def testClassCreate(self):
+ if not self.supportAuto:
+ return
class AutoTest(SQLObject):
_fromDatabase = True
+ _connection = connection()
AutoTest.new(firstName='john',
lastName='doe',
***************
*** 200,205 ****
if __name__ == '__main__':
import unittest, sys
for arg in sys.argv[1:]:
if arg in ('-vv', '--extra-verbose'):
SQLObjectTest.debugSQL = 1
! unittest.main()
--- 224,246 ----
if __name__ == '__main__':
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)
! print 'Testing %s' % db
! try:
! unittest.main()
! except SystemExit:
! pass
|