cryptonas/src/cryptobox/web/testclass.py
lars 108acd0e8a 'log' plugin: show warning if no log file is used
moved log file reading from cryptobox/core/main to 'log' plugin
added unittests for volume_mount, volume_format_fs and volume_rename
replace "get help" links with a "help mode" displaying information for every form
added first drafts of help texts for volume_mount, volume_format and partition
replaced the word 'container' with 'volume' in english texts
2006-12-12 13:34:05 +00:00

144 lines
4.2 KiB
Python

#
# 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
"""
__revision__ = "$Id"
import unittest
import twill
import cherrypy
import cryptobox.web.sites
import os
## commands api: http://twill.idyll.org/commands.html
CBXHOST = "localhost"
CBXPORT = 8081
CBX_URL = "http://%s:%d/" % (CBXHOST, CBXPORT)
LOG_FILE = "/tmp/cryptobox-twill.log"
WEBLOG_FILE = "/tmp/cryptobox-cherrypy.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': 'development',
'server.log_tracebacks': True,
'server.log_file': WEBLOG_FILE,
})
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
self.blockdevice, self.device = self.__find_test_device()
## umount the device (just to be sure)
url = self.url + "volume_mount?weblang=en&device=%2Fdev%2F" + self.device
self.register_auth(url)
self.cmd.go(url + "&action=umount")
def tearDown(self):
'''clean up the room when leaving'''
## remove intercept.
twill.remove_wsgi_intercept(CBXHOST, CBXPORT)
## stop the cryptobox
cherrypy.root.cleanup()
## 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 __find_test_device(self):
"""Search for a valid test device - the data will get lost ...
"""
for dev in ["ubdb", "loop", "ubda", "udbc", "ubdd"]:
if os.path.exists("/dev/%s1" % dev) \
and not self.__is_config_partition("/dev/%s1" % dev):
return (dev, dev + "1")
if os.path.exists("/dev/%s2" % dev) \
and not self.__is_config_partition("/dev/%s2" % dev):
return (dev, dev + "2")
else:
raise Exception, "no valid device for testing found"
def __is_config_partition(self, device):
"""Check if the device is a configuration partition.
"""
import subprocess
proc = subprocess.Popen(
shell = False,
stdout = subprocess.PIPE,
stderr = subprocess.PIPE,
args = [ '/sbin/e2label',
device ])
(stdout, stderr) = proc.communicate()
return stdout.strip() == "cbox_config"
def register_auth(self, url, user="admin", password="admin"):
self.cmd.add_auth("CryptoBox", url, user, password)