Changeset 2651
- Timestamp:
- 01/11/07 09:36:32 (2 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/paul_sandbox/dabo/biz/test/test_dBizobj.py
r2649 r2651 3 3 from dabo.lib import getRandomUUID 4 4 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 8 class Test_dBizobj(unittest.TestCase): 23 9 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) 25 12 uniqueName = getRandomUUID().replace("-", "")[-20:] 26 13 self.temp_table_name = "unittest%s" % uniqueName … … 36 23 37 24 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(""" 29 create table %(tableName)s (pk INTEGER PRIMARY KEY AUTOINCREMENT, cField CHAR, iField INT, nField DECIMAL (8,2)); 30 insert into %(tableName)s (cField, iField, nField) values ("Paul Keith McNett", 23, 23.23); 31 insert into %(tableName)s (cField, iField, nField) values ("Edward Leafe", 42, 42.42); 32 insert into %(tableName)s (cField, iField, nField) values ("Carl Karsten", 10223, 23032.76); 33 34 create table %(childTableName)s (pk INTEGER PRIMARY KEY AUTOINCREMENT, parent_fk INT, cInvNum CHAR); 35 insert into %(childTableName)s (parent_fk, cInvNum) values (1, "IN00023"); 36 insert into %(childTableName)s (parent_fk, cInvNum) values (1, "IN00455"); 37 insert into %(childTableName)s (parent_fk, cInvNum) values (3, "IN00024"); 38 """ % locals()) 40 39 41 40 … … 296 295 297 296 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.biz306 tableName = self.temp_table_name307 childTableName = self.temp_child_table_name308 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.biz335 cur = biz._CurrentCursor336 tableName = self.temp_table_name337 childTableName = self.temp_child_table_name338 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 365 297 if __name__ == "__main__": 366 298 unittest.main() branches/paul_sandbox/dabo/db/test/test_dCursorMixin.py
r2643 r2651 5 5 6 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 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. 9 db_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. 18 for k, v in db_tests.iteritems(): 19 if v: 20 db_tests[k] = unittest.TestCase 21 else: 22 db_tests[k] = object 23 20 24 21 25 … … 236 240 237 241 238 class Test_dCursorMixin_sqlite(Test_dCursorMixin, sqlite_unittest):242 class Test_dCursorMixin_sqlite(Test_dCursorMixin, db_tests["sqlite"]): 239 243 def setUp(self): 240 244 con = dabo.db.dConnection(DbType="SQLite", Database=":memory:") … … 253 257 254 258 255 class Test_dCursorMixin_mysql(Test_dCursorMixin, mysql_unittest):259 class Test_dCursorMixin_mysql(Test_dCursorMixin, db_tests["mysql"]): 256 260 def setUp(self): 257 261 con = dabo.db.dConnection(DbType="MySQL", User="dabo_unittest", … … 281 285 282 286 287 class 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(""" 306 create table %s (pk INTEGER NOT NULL, cField CHAR (32), iField INT, 307 nField DECIMAL (8,2), PRIMARY KEY (pk)) 308 """ % self.temp_table_name) 309 cur.execute(""" 310 create generator gen_%s 311 """ % self.temp_table_name) 312 cur.execute(""" 313 create trigger set_%s_pk for %s active 314 before insert position 0 315 as 316 begin 317 if (new.pk is null) then 318 new.pk = gen_id(gen_%s, 1); 319 end 320 """ % self.temp_table_name, self.temp_table_name, self.temp_table_name) 321 322 283 323 if __name__ == "__main__": 284 324 unittest.main()
