Ticket #1762: TurboGears-1.0-WebTest.patch
| File TurboGears-1.0-WebTest.patch, 2.6 kB (added by lmacken, 8 months ago) |
|---|
-
testutil.py
old new 23 23 from turbogears.identity import current_provider 24 24 from turbogears.util import get_model 25 25 26 from webtest import TestApp 27 26 28 cwd = os.getcwd() 27 29 28 30 # For clean tests, remove all compiled Kid templates … … 197 199 item.dropTable(ifExists=True) 198 200 199 201 202 class TGWebTest(unittest.TestCase): 203 """ A WebTest enabled unit testing class. 204 205 This allows testers to subclass us and use self.app to make WebTest calls. 206 """ 207 def setUp(self): 208 from cherrypy._cpwsgi import wsgiApp 209 start_cp() 210 startup.startTurboGears() 211 self.app = TestApp(wsgiApp) 212 213 def tearDown(self): 214 startup.stopTurboGears() 215 del self.app 216 217 def login_user(self, user): 218 """ Log a specified user object into the system """ 219 self.app.post(config.get('identity.failure_url'), { 220 'login' : 'Login', 221 'user_name' : user.user_name, 222 'password' : user.password 223 }) 224 225 226 class DBWebTest(TGWebTest, DBTest): 227 """ A database driven WebTest enabled unit testing class. 228 229 This class will automatically setup and tear down your database, along 230 with TurboGears and WebTest before and after each unit test. 231 """ 232 def setUp(self): 233 DBTest.setUp(self) 234 TGWebTest.setUp(self) 235 236 def tearDown(self): 237 TGWebTest.tearDown(self) 238 DBTest.tearDown(self) 239 240 200 241 def reset_cp(): 201 242 cherrypy.root = None 202 243 … … 305 346 306 347 __all__ = ["call", "create_request", "createRequest", "DBTest", 307 348 "attach_identity", "set_identity_user", 308 "capture_log", "print_log", "get_log", "sqlalchemy_cleanup"] 349 "capture_log", "print_log", "get_log", "sqlalchemy_cleanup", 350 "TGWebTest", "DBWebTest"] -
view/base.py
old new 126 126 format = config.get("%s.outputformat" % enginename, "html") 127 127 args, kw = adapt_call(engine.render, args= [], 128 128 kw = dict(info=info, format=format, fragment=fragment, template=template, mapping=mapping), start=1) 129 130 if hasattr(cherrypy.request, 'wsgi_environ'): 131 if 'paste.testing' in cherrypy.request.wsgi_environ: 132 cherrypy.request.wsgi_environ['paste.testing_variables']['namespace'] = info 133 129 134 return engine.render(**kw) 130 135 131 136 def transform(info, template):