Changeset 5277

Show
Ignore:
Timestamp:
08/27/08 23:00:40 (3 months ago)
Author:
kskuhlman
Message:

Adding DBTest support for SQLAlchemy. Closes #1764.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.1/turbogears/testutil.py

    r5276 r5277  
    289289 
    290290 
    291 class DBTest(unittest.TestCase): 
     291class AbstractDBTest(unittest.TestCase): 
    292292    """A database enabled unit testing class. 
    293293 
     
    298298    model = None 
    299299 
     300    def setUp(self): 
     301        raise NotImplementedError() 
     302 
     303    def tearDown(self): 
     304        raise NotImplementedError() 
     305 
     306class DBTestSO(AbstractDBTest): 
    300307    def _get_soClasses(self): 
    301308        try: 
     
    323330                item.dropTable(ifExists=True, cascade=True) 
    324331 
     332class DBTestSA(AbstractDBTest): 
     333    def setUp(self): 
     334        database.get_engine() 
     335        database.metadata.create_all() 
     336 
     337    def tearDown(self): 
     338        database.metadata.drop_all() 
     339 
     340 
     341#Determine which class to use for "DBTest".  Setup & teardown should behave  
     342#simularly regardless of which ORM you choose. 
     343if config.get("sqlobject.dburi"): 
     344    DBTest = DBTestSO 
     345elif config.get("sqlalchemy.dburi"): 
     346    DBTest = DBTestSA 
     347else: 
     348    raise Exception("Unable to find sqlalchemy or sqlobject dburi") 
     349 
     350 
    325351def unmount(): 
    326352    """Remove an application from the object traversal tree."""