Changeset 5276
- Timestamp:
- 08/27/08 22:49:10 (4 months ago)
- Files:
-
- branches/1.1/turbogears/identity/tests/test_identity.py (modified) (2 diffs)
- branches/1.1/turbogears/qstemplates/quickstart/+package+/tests/test_controllers.py_tmpl (modified) (2 diffs)
- branches/1.1/turbogears/qstemplates/quickstart/+package+/tests/test_model.py_tmpl (modified) (1 diff)
- branches/1.1/turbogears/qstemplates/quickstart/setup.py_tmpl (modified) (1 diff)
- branches/1.1/turbogears/tests/test_controllers.py (modified) (3 diffs)
- branches/1.1/turbogears/tests/test_paginate.py (modified) (3 diffs)
- branches/1.1/turbogears/tests/test_view.py (modified) (1 diff)
- branches/1.1/turbogears/testutil.py (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.1/turbogears/identity/tests/test_identity.py
r5274 r5276 156 156 157 157 158 class TestIdentity(testutil.TG WebTest):158 class TestIdentity(testutil.TGTest): 159 159 160 160 def setUp(self): … … 170 170 config.configure_loggers(test_config) 171 171 config.update(test_config['global']) 172 testutil.mount(IdentityRoot())173 testutil.TG WebTest.setUp(self)172 self.root = IdentityRoot 173 testutil.TGTest.setUp(self) 174 174 self.init_model() 175 175 176 176 def tearDown(self): 177 testutil.TG WebTest.tearDown(self)177 testutil.TGTest.tearDown(self) 178 178 config.update(self._original_config) 179 179 branches/1.1/turbogears/qstemplates/quickstart/+package+/tests/test_controllers.py_tmpl
r4695 r5276 5 5 import cherrypy 6 6 7 testutil.mount(root = Root()) 7 class TestPages(testutil.TGTest): 8 8 9 class TestPages(unittest.TestCase): 10 11 def setUp(self): 12 testutil.start_server() 13 14 def tearDown(self): 15 """Tests for apps using identity need to stop CP/TG after each test to 16 stop the VisitManager thread. 17 See http://trac.turbogears.org/turbogears/ticket/1217 for details. 18 """ 19 testutil.stop_server() 9 root = Root 20 10 21 11 def test_method(self): 22 12 "the index method should return a string called now" 23 13 import types 24 response = testutil.go("/")14 response = self.app.get("/") 25 15 assert type(response.raw["now"]) == types.StringType 26 16 27 17 def test_indextitle(self): 28 18 "The indexpage should have the right title" 29 response = testutil.go("/")19 response = self.app.get("/") 30 20 assert "<title>welcome to turbogears</title>" in response.body.lower() 31 21 … … 33 23 def test_logintitle(self): 34 24 "login page should have the right title" 35 response = testutil.go("/login")36 assert "<title> login</title>" in response.body.lower()25 response = self.app.get("/login") 26 assert "<title>Login</title>" in response, response 37 27 #end if branches/1.1/turbogears/qstemplates/quickstart/+package+/tests/test_model.py_tmpl
r4245 r5276 18 18 """ 19 19 20 from turbogears import testutil, database20 from turbogears.testutil import DBTest 21 21 22 22 # from ${package}.model import YourModelClass, User 23 23 24 # class TestUser(testutil.DBTest): 25 # def get_model(self): 26 # return User 24 # class TestUser(DBTest): 25 # model = User 27 26 # 28 27 # def test_creation(self): branches/1.1/turbogears/qstemplates/quickstart/setup.py_tmpl
r4201 r5276 28 28 install_requires=[ 29 29 "TurboGears >= ${turbogearsversion}", 30 "WebTest", 30 31 #if $sqlobject == 'True' 31 32 "$sqlobjectversion" branches/1.1/turbogears/tests/test_controllers.py
r5241 r5276 243 243 244 244 245 class TestRoot(testutil.TG WebTest):245 class TestRoot(testutil.TGTest): 246 246 247 247 def setUp(self): 248 248 testutil.mount(MyRoot(), '/') 249 249 testutil.mount(SubApp(), '/subthing') 250 self.app = testutil.make_app() 250 251 super(TestRoot, self).setUp() 251 252 … … 566 567 567 568 568 class TestURLs(testutil.TG WebTest):569 class TestURLs(testutil.TGTest): 569 570 570 571 def setUp(self): … … 572 573 testutil.mount(SubApp(), '/subthing') 573 574 testutil.mount(SubApp(), '/subthing/subsubthing') 575 self.app = testutil.make_app() 574 576 super(TestURLs, self).setUp() 575 577 branches/1.1/turbogears/tests/test_paginate.py
r5241 r5276 187 187 188 188 189 class TestSpy(testutil.TGWebTest): 189 class TestPagination(testutil.TGTest): 190 """Base class for all Paginate TestCases""" 191 192 def setUp(self): 193 self.root = self.MyRoot 194 super(TestPagination, self).setUp() 195 196 def request(self, url, status=200): 197 response = self.app.get(url, status=status) 198 self.body = response.body 199 if "fail: " in self.body: 200 print self.body 201 assert False, "Spy alert! Check body output for details..." 202 203 204 class TestSpy(TestPagination): 190 205 """Never trust a spy""" 191 206 … … 219 234 spy = Spy(foobar=10) 220 235 return dict(data=data, spy=spy) 221 222 223 def setUp(self):224 super(TestSpy, self).setUp(self.MyRoot)225 226 236 227 237 def test_spy(self): … … 250 260 Spy.assert_ok(response.body, 'var_name', 'data') 251 261 Spy.assert_ok(response.body, 'var_name', "'data'", raw=True) 252 253 254 class TestPagination(testutil.TGWebTest):255 """Base class for all Paginate TestCases"""256 257 def setUp(self):258 super(TestPagination, self).setUp(self.MyRoot)259 260 def request(self, url, status=200):261 response = self.app.get(url, status=status)262 self.body = response.body263 if "fail: " in self.body:264 print self.body265 assert False, "Spy alert! Check body output for details..."266 262 267 263 branches/1.1/turbogears/tests/test_view.py
r4921 r5276 4 4 import unittest 5 5 6 class TestView(testutil.TGWebTest): 6 class TestView(unittest.TestCase): 7 8 def setUp(self): 9 # The server needs to be started so that the template engines get loaded. 10 testutil.start_server() 7 11 8 12 def test_cycle(self): branches/1.1/turbogears/testutil.py
r5275 r5276 160 160 161 161 162 class TG WebTest(unittest.TestCase):162 class TGTest(unittest.TestCase): 163 163 """A WebTest enabled unit testing class. 164 164 165 This allows testers to subclass us and use self.app to make WebTest calls. 166 167 """ 168 169 def setUp(self, controller=None): 170 """Set up the WebTest by starting the server." 165 To use, subclass & set root to your controller object, or set app to a 166 webtest.TestApp instance. 167 168 In your tests, use self.app to make WebTest calls. 169 """ 170 171 root = None 172 app = None 173 174 def setUp(self): 175 """Set up the WebTest by starting the server. 171 176 172 177 You should override this and make sure you have properly … … 174 179 or simply pass a root controller to super. 175 180 Otherwise the Cherrypy filters for TurboGears will not be used. 176 177 181 """ 178 self.app = make_app(controller) 182 assert self.root or self.app, "Either self.root or self.app must be set" 183 if not self.app: 184 self.app = make_app(self.root) 179 185 start_server() 180 186 … … 182 188 """Tear down the WebTest by stopping the server.""" 183 189 stop_server(tg_only = True) 184 del self.app185 190 186 191 def login_user(self, user): … … 285 290 286 291 class DBTest(unittest.TestCase): 287 292 """A database enabled unit testing class. 293 294 Creates and destroys your database before and after each unit test. 295 You must set the model attribute in order for this class to 296 function correctly. 297 """ 288 298 model = None 289 299 … … 298 308 self.model = get_model() 299 309 if not self.model: 300 raise "Unable to run database tests without a model" 301 310 raise Exception("Unable to run database tests without a model") 302 311 for item in self._get_soClasses(): 303 312 if isinstance(item, types.TypeType) and issubclass(item,