36.8. ADDING TESTS
135import os.path
136from . import main
137self.tmpdir = tempfile.mkdtemp()
138
139dbpath = os.path.join( self.tmpdir, ’test.db’)
140uri = ’file://’ + dbpath
141settings = { ’zodbconn.uri’ : uri ,
142 |
’pyramid.includes’: [’pyramid_zodbconn’, ’pyramid_tm’] } |
143
144app = main({}, **settings)
145self.db = app.registry.zodb_database
146from webtest import TestApp
147self.testapp = TestApp(app)
148
149def tearDown(self):
150import shutil
151self.db.close()
152shutil.rmtree( self.tmpdir )
153
154def test_root(self):
155res = self.testapp.get(’/’, status=302)
156self.assertEqual(res.location, ’http://localhost/FrontPage’)
157
158def test_FrontPage(self):
159res = self.testapp.get(’/FrontPage’, status=200)
160self.assertTrue(’FrontPage’ in res.body)
161
162def test_unexisting_page(self):
163res = self.testapp.get(’/SomePage’, status=404)
164self.assertTrue(’Not Found’ in res.body)
165
166def test_successful_log_in(self):
167res = self.testapp.get( self.viewer_login, status=302)
168self.assertEqual(res.location, ’http://localhost/FrontPage’)
169
170def test_failed_log_in(self):
171res = self.testapp.get( self.viewer_wrong_login, status=200)
172self.assertTrue(’login’ in res.body)
173
174def test_logout_link_present_when_logged_in(self):
175res = self.testapp.get( self.viewer_login, status=302)
176res = self.testapp.get(’/FrontPage’, status=200)
177self.assertTrue(’Logout’ in res.body)
178
179def test_logout_link_not_present_after_logged_out(self):
180res = self.testapp.get( self.viewer_login, status=302)