from cherrypy.test import test test.prefer_parent_path() import cherrypy def setup_server(): def check(username, password): # Dummy check_username_and_password function if username != 'test' or password != 'password': return u'Wrong login/password' class Test: _cp_config = {'tools.sessions.on': True, 'tools.session_auth.on': True, 'tools.session_auth.check_username_and_password': check, } def index(self): return "Hi %s, you are logged in" % cherrypy.request.login index.exposed = True cherrypy.tree.mount(Test()) cherrypy.config.update({'environment': 'test_suite'}) from cherrypy.test import helper class SessionAuthenticateTest(helper.CPWebCase): def testSessionAuthenticate(self): # request a page and check for login form self.getPage('/') self.assertInBody('