Changeset 2651

Show
Ignore:
Timestamp:
01/11/07 09:36:32 (2 years ago)
Author:
paul
Message:

Added the firebird test to dCursorMixin, although it still needs work. Thanks
Uwe Grauer for getting it going.

Removed all but sqlite from the test backends for the dBizobj test.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/paul_sandbox/dabo/biz/test/test_dBizobj.py

    r2649 r2651  
    33from dabo.lib import getRandomUUID 
    44 
    5  
    6 # Testing anything other than sqlite requires network access. So set these 
    7 # flags so that only the db's you want to test against are True. 
    8 test_sqlite = True 
    9 test_mysql = True 
    10  
    11 if test_sqlite: 
    12     sqlite_unittest = unittest.TestCase 
    13 else: 
    14     sqlite_unittest = object 
    15  
    16 if test_mysql: 
    17     mysql_unittest = unittest.TestCase 
    18 else: 
    19     mysql_unittest = object 
    20  
    21  
    22 class Test_dBizobj(object): 
     5## Only tests against sqlite, as we already test dCursorMixin against the 
     6## various backends.  
     7 
     8class Test_dBizobj(unittest.TestCase): 
    239    def setUp(self): 
    24         biz = self.biz 
     10        self.con = dabo.db.dConnection(DbType="SQLite", Database=":memory:") 
     11        biz = self.biz = dabo.biz.dBizobj(self.con) 
    2512        uniqueName = getRandomUUID().replace("-", "")[-20:] 
    2613        self.temp_table_name = "unittest%s" % uniqueName 
     
    3623 
    3724    def createSchema(self): 
    38         """Create the test schema. Override in subclasses.""" 
    39         pass 
     25        biz = self.biz 
     26        tableName = self.temp_table_name 
     27        childTableName = self.temp_child_table_name 
     28        biz._CurrentCursor.executescript(""" 
     29create table %(tableName)s (pk INTEGER PRIMARY KEY AUTOINCREMENT, cField CHAR, iField INT, nField DECIMAL (8,2)); 
     30insert into %(tableName)s (cField, iField, nField) values ("Paul Keith McNett", 23, 23.23); 
     31insert into %(tableName)s (cField, iField, nField) values ("Edward Leafe", 42, 42.42); 
     32insert into %(tableName)s (cField, iField, nField) values ("Carl Karsten", 10223, 23032.76); 
     33 
     34create table %(childTableName)s (pk INTEGER PRIMARY KEY AUTOINCREMENT, parent_fk INT, cInvNum CHAR); 
     35insert into %(childTableName)s (parent_fk, cInvNum) values (1, "IN00023"); 
     36insert into %(childTableName)s (parent_fk, cInvNum) values (1, "IN00455"); 
     37insert into %(childTableName)s (parent_fk, cInvNum) values (3, "IN00024"); 
     38""" % locals()) 
    4039 
    4140 
     
    296295         
    297296 
    298 class Test_dBizobj_sqlite(Test_dBizobj, sqlite_unittest): 
    299     def setUp(self): 
    300         self.con = dabo.db.dConnection(DbType="SQLite", Database=":memory:") 
    301         self.biz = dabo.biz.dBizobj(self.con) 
    302         super(Test_dBizobj_sqlite, self).setUp() 
    303  
    304     def createSchema(self): 
    305         biz = self.biz 
    306         tableName = self.temp_table_name 
    307         childTableName = self.temp_child_table_name 
    308         biz._CurrentCursor.executescript(""" 
    309 create table %(tableName)s (pk INTEGER PRIMARY KEY AUTOINCREMENT, cField CHAR, iField INT, nField DECIMAL (8,2)); 
    310 insert into %(tableName)s (cField, iField, nField) values ("Paul Keith McNett", 23, 23.23); 
    311 insert into %(tableName)s (cField, iField, nField) values ("Edward Leafe", 42, 42.42); 
    312 insert into %(tableName)s (cField, iField, nField) values ("Carl Karsten", 10223, 23032.76); 
    313  
    314 create table %(childTableName)s (pk INTEGER PRIMARY KEY AUTOINCREMENT, parent_fk INT, cInvNum CHAR); 
    315 insert into %(childTableName)s (parent_fk, cInvNum) values (1, "IN00023"); 
    316 insert into %(childTableName)s (parent_fk, cInvNum) values (1, "IN00455"); 
    317 insert into %(childTableName)s (parent_fk, cInvNum) values (3, "IN00024"); 
    318 """ % locals()) 
    319  
    320  
    321 class Test_dBizobj_mysql(Test_dBizobj, mysql_unittest): 
    322     def setUp(self): 
    323         self.con = dabo.db.dConnection(DbType="MySQL", User="dabo_unittest",  
    324                 password="T30T35DB4K30Z45I67N60", Database="dabo_unittest", 
    325                 Host="paulmcnett.com") 
    326         self.biz = dabo.biz.dBizobj(self.con) 
    327         super(Test_dBizobj_mysql, self).setUp() 
    328  
    329     def tearDown(self): 
    330         self.biz._CurrentCursor.execute("drop table %s" % self.temp_table_name) 
    331         super(Test_dBizobj_mysql, self).tearDown() 
    332  
    333     def createSchema(self): 
    334         biz = self.biz 
    335         cur = biz._CurrentCursor 
    336         tableName = self.temp_table_name 
    337         childTableName = self.temp_child_table_name 
    338         cur.execute(""" 
    339 create table %s (pk INTEGER PRIMARY KEY AUTO_INCREMENT, cField CHAR (32), iField INT, nField DECIMAL (8,2)) 
    340 """ % tableName) 
    341         cur.execute("""      
    342 insert into %s (cField, iField, nField) values ("Paul Keith McNett", 23, 23.23) 
    343 """ % tableName) 
    344         cur.execute("""      
    345 insert into %s (cField, iField, nField) values ("Edward Leafe", 42, 42.42) 
    346 """ % tableName) 
    347         cur.execute("""      
    348 insert into %s (cField, iField, nField) values ("Carl Karsten", 10223, 23032.76) 
    349 """ % tableName) 
    350  
    351         cur.execute(""" 
    352 create table %s (pk INTEGER PRIMARY KEY AUTO_INCREMENT, parent_fk INT, cInvNum CHAR (16)) 
    353 """ % childTableName) 
    354         cur.execute(""" 
    355 insert into %s (parent_fk, cInvNum) values (1, "IN00023") 
    356 """ % childTableName) 
    357         cur.execute(""" 
    358 insert into %s (parent_fk, cInvNum) values (1, "IN00455") 
    359 """ % childTableName) 
    360         cur.execute(""" 
    361 insert into %s (parent_fk, cInvNum) values (3, "IN00024") 
    362 """ % childTableName) 
    363  
    364  
    365297if __name__ == "__main__": 
    366298    unittest.main() 
  • branches/paul_sandbox/dabo/db/test/test_dCursorMixin.py

    r2643 r2651  
    55 
    66# Testing anything other than sqlite requires network access. So set these 
    7 # flags so that only the db's you want to test against are True. 
    8 test_sqlite = True 
    9 test_mysql = True 
    10  
    11 if test_sqlite: 
    12     sqlite_unittest = unittest.TestCase 
    13 else: 
    14     sqlite_unittest = object 
    15  
    16 if test_mysql: 
    17     mysql_unittest = unittest.TestCase 
    18 else: 
    19     mysql_unittest = object 
     7# flags so that only the db's you want to test against are True. DB's set as 
     8# False by default are probably not working as-is. 
     9db_tests = {"sqlite": True, 
     10            "mysql": True, 
     11            "firebird": False, 
     12            "postgresql": False, 
     13            "mssql": False, 
     14           } 
     15 
     16# Convert the flags into class references. Setting to object will keep the tests 
     17# for that backend from running. 
     18for k, v in db_tests.iteritems(): 
     19    if v: 
     20        db_tests[k] = unittest.TestCase 
     21    else: 
     22        db_tests[k] = object 
     23 
    2024 
    2125 
     
    236240 
    237241 
    238 class Test_dCursorMixin_sqlite(Test_dCursorMixin, sqlite_unittest): 
     242class Test_dCursorMixin_sqlite(Test_dCursorMixin, db_tests["sqlite"]): 
    239243    def setUp(self): 
    240244        con = dabo.db.dConnection(DbType="SQLite", Database=":memory:") 
     
    253257 
    254258 
    255 class Test_dCursorMixin_mysql(Test_dCursorMixin, mysql_unittest): 
     259class Test_dCursorMixin_mysql(Test_dCursorMixin, db_tests["mysql"]): 
    256260    def setUp(self): 
    257261        con = dabo.db.dConnection(DbType="MySQL", User="dabo_unittest",  
     
    281285 
    282286 
     287class Test_dCursorMixin_firebird(Test_dCursorMixin, db_tests["firebird"]): 
     288    ## NOTE: Firebird not set up completely yet. What is here is courtesy Uwe 
     289    ##       Grauer. We need insert statements, and we need a firebird server. 
     290    ##       I intend to set up a test server, but don't know when it will  
     291    ##       actually occur. 
     292    def setUp(self): 
     293        con = dabo.db.dConnection(DbType="Firebird", User="dabo_unittest",  
     294                password="T30T35DB4K30Z45I67N60", Database="dabo_unittest", 
     295                Host="paulmcnett.com") 
     296        self.cur = con.getDaboCursor() 
     297        super(Test_dCursorMixin_firebird, self).setUp() 
     298 
     299    def tearDown(self): 
     300        self.cur.execute("drop table %s" % self.temp_table_name) 
     301        super(Test_dCursorMixin_firebird, self).tearDown() 
     302 
     303    def createSchema(self): 
     304        cur = self.cur 
     305        cur.execute(""" 
     306create table %s (pk INTEGER NOT NULL, cField CHAR (32), iField INT, 
     307nField DECIMAL (8,2), PRIMARY KEY (pk)) 
     308""" % self.temp_table_name) 
     309                cur.execute(""" 
     310create generator gen_%s 
     311""" % self.temp_table_name) 
     312        cur.execute(""" 
     313create trigger set_%s_pk for %s active 
     314before insert position 0 
     315as 
     316begin 
     317    if (new.pk is null) then 
     318    new.pk = gen_id(gen_%s, 1); 
     319end 
     320""" % self.temp_table_name, self.temp_table_name, self.temp_table_name) 
     321 
     322 
    283323if __name__ == "__main__": 
    284324    unittest.main()