Ticket #1764: TurboGears-1.1-DBTest-SQLAlchemy.patch
| File TurboGears-1.1-DBTest-SQLAlchemy.patch, 2.2 kB (added by lmacken, 2 years ago) |
|---|
-
turbogears/testutil.py
old new 165 165 166 166 167 167 class DBTest(unittest.TestCase): 168 """A database enabled unit testing class. 168 169 170 Creates and destroys your database before and after each unit test, 171 based on the configuration defined in test.cfg. This class supports 172 both SQLAlchemy and SQLObject configurations. 173 174 """ 169 175 model = None 170 176 177 def setUp(self): 178 if config.get("sqlalchemy.dburi"): 179 self._sa_setUp() 180 elif config.get("sqlobject.dburi"): 181 self._so_setUp() 182 else: 183 raise Exception("Unable to find sqlalchemy or sqlobject dburi") 184 185 def tearDown(self): 186 if config.get("sqlalchemy.dburi"): 187 self._sa_tearDown() 188 elif config.get("sqlobject.dburi"): 189 self._so_tearDown() 190 191 ## SQLAlchemy specific methods 192 193 def _sa_setUp(self): 194 database.get_engine() 195 database.metadata.create_all() 196 197 def _sa_tearDown(self): 198 database.metadata.drop_all() 199 200 ## SQLObject specific methods 201 171 202 def _get_soClasses(self): 172 203 try: 173 204 return [self.model.__dict__[x] for x in self.model.soClasses] 174 205 except AttributeError: 175 206 return self.model.__dict__.values() 176 207 177 def setUp(self):208 def _so_setUp(self): 178 209 if not self.model: 179 210 self.model = get_model() 180 211 if not self.model: 181 raise "Unable to run database tests without a model" 182 212 raise Exception("Unable to run database tests without a model") 183 213 for item in self._get_soClasses(): 184 214 if isinstance(item, types.TypeType) and issubclass(item, 185 215 sqlobject.SQLObject) and item != sqlobject.SQLObject \ 186 216 and item != InheritableSQLObject: 187 217 item.createTable(ifNotExists=True) 188 218 189 def tearDown(self):219 def _so_tearDown(self): 190 220 database.rollback_all() 191 221 for item in reversed(self._get_soClasses()): 192 222 if isinstance(item, types.TypeType) and issubclass(item,