Update of /cvsroot/sqlobject/SQLObject/tests
In directory sc8-pr-cvs1:/tmp/cvs-serv12426/tests
Modified Files:
SQLObjectTest.py test.py
Log Message:
Support for reading a class from a table definition (for MySQL)
Index: SQLObjectTest.py
===================================================================
RCS file: /cvsroot/sqlobject/SQLObject/tests/SQLObjectTest.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** SQLObjectTest.py 31 Mar 2003 02:00:58 -0000 1.2
--- SQLObjectTest.py 31 Mar 2003 05:51:28 -0000 1.3
***************
*** 15,28 ****
def setUp(self):
unittest.TestCase.setUp(self)
#__connection__.debug = self.debugSQL
! for c in self.classes:
if hasattr(c, 'drop'):
__connection__.query(c.drop)
! else:
c.dropTable(ifExists=True)
if hasattr(c, 'create'):
__connection__.query(c.create)
! else:
c.createTable(ifExists=True)
#__connection__.debug = 0
--- 15,31 ----
def setUp(self):
+ if self.debugSQL:
+ print
+ print '#' * 70
unittest.TestCase.setUp(self)
#__connection__.debug = self.debugSQL
! for c in self.classes + [self]:
if hasattr(c, 'drop'):
__connection__.query(c.drop)
! elif hasattr(c, 'dropTable'):
c.dropTable(ifExists=True)
if hasattr(c, 'create'):
__connection__.query(c.create)
! elif hasattr(c, 'createTable'):
c.createTable(ifExists=True)
#__connection__.debug = 0
Index: test.py
===================================================================
RCS file: /cvsroot/sqlobject/SQLObject/tests/test.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** test.py 31 Mar 2003 02:00:58 -0000 1.2
--- test.py 31 Mar 2003 05:51:28 -0000 1.3
***************
*** 1,4 ****
--- 1,5 ----
from SQLObjectTest import *
from SQLObject import *
+ from mx import DateTime
########################################
***************
*** 119,122 ****
--- 120,124 ----
self.assertEqual([p.name for p in Person.select('all')],
['bob', 'jake', 'jane', 'robert', 'tim'])
+ Person.delColumn(nickname, changeSchema=True)
def testDynamicJoin(self):
***************
*** 132,136 ****
--- 134,172 ----
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)
+
+ ########################################
+ ## Auto class generation
+ ########################################
+
+ class AutoTest(SQLObjectTest):
+
+ create = """
+ CREATE TABLE IF NOT EXISTS auto_test (
+ id INT AUTO_INCREMENT PRIMARY KEY,
+ first_name VARCHAR(100),
+ last_name VARCHAR(200) NOT NULL,
+ age INT,
+ created DATETIME NOT NULL,
+ happy char(1) DEFAULT 'Y' NOT NULL
+ )
+ """
+
+ drop = """
+ DROP TABLE IF EXISTS auto_test
+ """
+
+ def testClassCreate(self):
+ class AutoTest(SQLObject):
+ _fromDatabase = True
+ AutoTest.new(firstName='john',
+ lastName='doe',
+ age=10,
+ created=DateTime.now())
+ AutoTest.new(firstName='jane',
+ lastName='doe',
+ happy='N')
########################################
|