Changeset 2640

Show
Ignore:
Timestamp:
01/10/2007 10:05:39 AM (2 years ago)
Author:
paul
Message:

Added flags at the top of the unit tests to easily set which database backends
to test against.

Fixed a problem in my branch's dCursorMixin.isChanged(allRows=False) that
wasn't taking into account new records. I found this thanks to the unit testing.

Files:

Legend:

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

    r2637 r2640  
    22import dabo 
    33from dabo.lib import getRandomUUID 
     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. 
     8test_sqlite = True 
     9test_mysql = True 
     10 
     11if test_sqlite: 
     12    sqlite_unittest = unittest.TestCase 
     13else: 
     14    sqlite_unittest = object 
     15 
     16if test_mysql: 
     17    mysql_unittest = unittest.TestCase 
     18else: 
     19    mysql_unittest = object 
    420 
    521 
     
    177193 
    178194 
    179 class Test_dBizobj_sqlite(Test_dBizobj, unittest.TestCase): 
     195class Test_dBizobj_sqlite(Test_dBizobj, sqlite_unittest): 
    180196    def setUp(self): 
    181197        con = dabo.db.dConnection(DbType="SQLite", Database=":memory:") 
     
    194210 
    195211 
    196 class Test_dBizobj_mysql(Test_dBizobj): 
     212class Test_dBizobj_mysql(Test_dBizobj, mysql_unittest): 
    197213    def setUp(self): 
    198214        con = dabo.db.dConnection(DbType="MySQL", User="dabo_unittest",  
  • branches/paul_sandbox/dabo/db/dCursorMixin.py

    r2621 r2640  
    628628             
    629629            memento = self._mementos.get(rec[self.KeyField], None) 
    630             new_rec = self._newRecords.get(rec[self.KeyField], None
    631  
    632             return not (memento is None and new_rec is None
     630            new_rec = self._newRecords.has_key(rec[self.KeyField]
     631 
     632            return not (memento is None and not new_rec
    633633 
    634634 
  • branches/paul_sandbox/dabo/db/test/test_dCursorMixin.py

    r2634 r2640  
    22import dabo 
    33from dabo.lib import getRandomUUID 
     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. 
     8test_sqlite = True 
     9test_mysql = True 
     10 
     11if test_sqlite: 
     12    sqlite_unittest = unittest.TestCase 
     13else: 
     14    sqlite_unittest = object 
     15 
     16if test_mysql: 
     17    mysql_unittest = unittest.TestCase 
     18else: 
     19    mysql_unittest = object 
    420 
    521 
     
    164180        self.assertEqual(cur._mementos, {cur.Record.pk: {"cField": priorVal}}) 
    165181        self.assertEqual(cur.isChanged(), True) 
     182        self.assertEqual(cur.isChanged(allRows=False), True) 
    166183 
    167184        # Change it back: 
     
    169186        self.assertEqual(cur._mementos, {}) 
    170187        self.assertEqual(cur.isChanged(), False) 
     188        self.assertEqual(cur.isChanged(allRows=False), False) 
    171189 
    172190        # Make a change that is different and cancel: 
     
    175193        self.assertEqual(cur._mementos, {}) 
    176194        self.assertEqual(cur.isChanged(), False) 
     195        self.assertEqual(cur.isChanged(allRows=False), False) 
    177196 
    178197        # Add a record: 
     
    187206        self.assertEqual(cur._newRecords, {"-1-dabotmp": None}) 
    188207        self.assertEqual(cur.isChanged(), True) 
     208        self.assertEqual(cur.isChanged(allRows=False), True) 
    189209        self.assertEqual(cur.Record.pk, "-1-dabotmp") 
    190210        self.assertEqual(cur.Record.cField, "") 
     
    197217        self.assertEqual(cur._newRecords, {}) 
    198218        self.assertEqual(cur.isChanged(), False) 
     219        self.assertEqual(cur.isChanged(allRows=False), False) 
    199220        self.assertEqual(cur.Record.pk, 4) 
    200221 
     
    205226 
    206227 
    207 class Test_dCursorMixin_sqlite(Test_dCursorMixin, unittest.TestCase): 
     228class Test_dCursorMixin_sqlite(Test_dCursorMixin, sqlite_unittest): 
    208229    def setUp(self): 
    209230        con = dabo.db.dConnection(DbType="SQLite", Database=":memory:") 
     
    222243 
    223244 
    224 class Test_dCursorMixin_mysql(Test_dCursorMixin, unittest.TestCase): 
     245class Test_dCursorMixin_mysql(Test_dCursorMixin, mysql_unittest): 
    225246    def setUp(self): 
    226247        con = dabo.db.dConnection(DbType="MySQL", User="dabo_unittest",  
  • trunk/dabo/biz/test/test_dBizobj.py

    r2637 r2640  
    22import dabo 
    33from dabo.lib import getRandomUUID 
     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. 
     8test_sqlite = True 
     9test_mysql = True 
     10 
     11if test_sqlite: 
     12    sqlite_unittest = unittest.TestCase 
     13else: 
     14    sqlite_unittest = object 
     15 
     16if test_mysql: 
     17    mysql_unittest = unittest.TestCase 
     18else: 
     19    mysql_unittest = object 
    420 
    521 
     
    123139 
    124140 
    125 class Test_dBizobj_sqlite(Test_dBizobj, unittest.TestCase): 
     141class Test_dBizobj_sqlite(Test_dBizobj, sqlite_unittest): 
    126142    def setUp(self): 
    127143        con = dabo.db.dConnection(DbType="SQLite", Database=":memory:") 
     
    140156 
    141157 
    142 class Test_dBizobj_mysql(Test_dBizobj): 
     158class Test_dBizobj_mysql(Test_dBizobj, mysql_unittest): 
    143159    def setUp(self): 
    144160        con = dabo.db.dConnection(DbType="MySQL", User="dabo_unittest",  
  • trunk/dabo/db/test/test_dCursorMixin.py

    r2611 r2640  
    22import dabo 
    33 
     4 
     5# Testing anything other than sqlite requires network access. So set these 
     6# flags so that only the db's you want to test against are True. 
     7test_sqlite = True 
     8test_mysql = True 
     9 
     10if test_sqlite: 
     11    sqlite_unittest = unittest.TestCase 
     12else: 
     13    sqlite_unittest = object 
     14 
     15if test_mysql: 
     16    mysql_unittest = unittest.TestCase 
     17else: 
     18    mysql_unittest = object 
    419 
    520 
     
    2843 
    2944 
    30 class Test_dCursorMixin_sqlite(Test_dCursorMixin, unittest.TestCase): 
     45class Test_dCursorMixin_sqlite(Test_dCursorMixin, sqlite_unittest): 
    3146    def setUp(self): 
    3247        con = dabo.db.dConnection(DbType="SQLite", Database=":memory:") 
     
    4762        self.cur = None 
    4863 
     64class Test_dCursorMixin_mysql(Test_dCursorMixin, mysql_unittest): 
     65    def setUp(self): 
     66        con = dabo.db.dConnection(DbType="MySQL", User="dabo_unittest",  
     67                password="T30T35DB4K30Z45I67N60", Database="dabo_unittest", 
     68                Host="paulmcnett.com") 
     69        self.cur = con.getDaboCursor() 
     70        super(Test_dCursorMixin_mysql, self).setUp() 
     71 
     72    def tearDown(self): 
     73        self.cur.execute("drop table %s" % self.temp_table_name) 
     74        super(Test_dCursorMixin_mysql, self).tearDown() 
     75 
     76    def createSchema(self): 
     77        cur = self.cur 
     78        cur.execute(""" 
     79create table %s (pk INTEGER PRIMARY KEY AUTO_INCREMENT, cField CHAR (32), iField INT, nField DECIMAL (8,2)) 
     80""" % self.temp_table_name) 
     81        cur.execute("""      
     82insert into %s (cField, iField, nField) values ("Paul Keith McNett", 23, 23.23) 
     83""" % self.temp_table_name) 
     84        cur.execute("""      
     85insert into %s (cField, iField, nField) values ("Edward Leafe", 42, 42.42) 
     86""" % self.temp_table_name) 
     87        cur.execute("""      
     88insert into %s (cField, iField, nField) values ("Carl Karsten", 10223, 23032.76) 
     89""" % self.temp_table_name) 
     90 
     91 
    4992if __name__ == "__main__": 
    5093    unittest.main()