# # Copyright 2006 sense.lab e.V. # # This file is part of the CryptoBox. # # The CryptoBox is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # The CryptoBox is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with the CryptoBox; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # """ super class of all web interface unittests for the cryptobox just inherit this class and add some test functions """ import unittest import twill import cherrypy import cryptobox.web.sites import os ## we do the following, for easy surfing ## e.g. use: cbx.go(your_url) ## commands api: http://twill.idyll.org/commands.html CBXHOST="localhost" CBXPORT=8081 CBX_URL="http://%s:%d/" % (CBXHOST, CBXPORT) LOG_FILE="/tmp/twill.log" class WebInterfaceTestClass(unittest.TestCase): '''this class checks the webserver, using "twill" the tests in this class are from the browsers point of view, so not really unittests. fetch twill from: http://twill.idyll.org one way to manually run twill code is through the python interpreter commandline e.g.: import twill twill.shell.main() go http://localhost:8080 find "my very special html content" help ''' def setUp(self): '''configures the cherrypy server that it works nice with twill ''' cherrypy.config.update({ 'server.logToScreen' : False, 'autoreload.on': False, 'server.threadPool': 1, 'server.environment': 'production', }) cherrypy.root = cryptobox.web.sites.WebInterfaceSites("cryptobox-unittests.conf") cherrypy.server.start(initOnly=True, serverClass=None) from cherrypy._cpwsgi import wsgiApp twill.add_wsgi_intercept(CBXHOST, CBXPORT, lambda: wsgiApp) # grab the output of twill commands self.output = open(LOG_FILE,"a") twill.set_output(self.output) self.cmd = twill.commands self.URL = CBX_URL self.cbox = cherrypy.root.cbox self.globals, self.locals = twill.namespaces.get_twill_glocals() ## search for a usable block device ## use /dev/ubd? if possible - otherwise /dev/hd? ## so it will be possible to use these tests inside of an uml for d in ["ubdb", "loop", "ubda", "udbc", "ubdd", "hdb", "hda", "hdc", "hdd"]: if os.path.exists("/dev/%s1" % d): device = d break else: device = "hda" self.device = device def tearDown(self): '''clean up the room when leaving''' # remove intercept. twill.remove_wsgi_intercept(CBXHOST, CBXPORT) # shut down the cherrypy server. cherrypy.server.stop() self.output.close() def __get_soup(): browser = twill.commands.get_browser() soup = BeautifulSoup(browser.get_html()) return soup def register_auth(self, url, user="admin", password="admin"): self.cmd.add_auth("CryptoBox", url, user, password)