Ticket #1764: r1764.ken.patch
| File r1764.ken.patch, 2.3 kB (added by kskuhlman, 2 years ago) |
|---|
-
setup.py
old new 33 33 ] 34 34 35 35 sqlobject = [ 36 "SQLObject >= 0. 7.1",36 "SQLObject >= 0.8.0", 37 37 ] 38 38 39 39 exp = ["TGFastData"] -
turbogears/testutil.py
old new 275 275 return output, response 276 276 277 277 278 class DBTest(unittest.TestCase): 278 class AbstractDBTest(unittest.TestCase): 279 """A database enabled unit testing class. 279 280 281 Creates and destroys your database before and after each unit test. You must set the 282 model attribute in order for this class to function correctly. 283 """ 280 284 model = None 281 285 286 def setUp(self): 287 raise NotImplementedError() 288 289 def tearDown(self): 290 raise NotImplementedError() 291 292 class DBTestSO(AbstractDBTest): 282 293 def _get_soClasses(self): 283 294 try: 284 295 return [self.model.__dict__[x] for x in self.model.soClasses] … … 289 300 if not self.model: 290 301 self.model = get_model() 291 302 if not self.model: 292 raise "Unable to run database tests without a model" 293 303 raise Exception("Unable to run database tests without a model") 294 304 for item in self._get_soClasses(): 295 305 if isinstance(item, types.TypeType) and issubclass(item, 296 306 sqlobject.SQLObject) and item != sqlobject.SQLObject \ … … 305 315 and item != InheritableSQLObject: 306 316 item.dropTable(ifExists=True, cascade=True) 307 317 318 class DBTestSA(AbstractDBTest): 319 def setUp(self): 320 database.get_engine() 321 database.metadata.create_all() 322 323 def tearDown(self): 324 database.metadata.drop_all() 325 326 327 #Determine which class to use for "DBTest". Setup & teardown should behave 328 #simularly regardless of which ORM you choose. 329 if config.get("sqlobject.dburi"): 330 DBTest = DBTestSO 331 elif config.get("sqlalchemy.dburi"): 332 DBTest = DBTestSA 333 else: 334 raise Exception("Unable to find sqlalchemy or sqlobject dburi") 335 336 308 337 def unmount(): 309 338 """Remove an application from the object traversal tree.""" 310 339 # There's no clean way to remove a subtree under CP2, so the only use case