twill unittests are finally working
This commit is contained in:
parent
88fc900cc5
commit
5af79f90b6
3 changed files with 102 additions and 189 deletions
|
@ -1,55 +0,0 @@
|
|||
import twill
|
||||
import cherrypy
|
||||
import CryptoBoxWebserverSites
|
||||
|
||||
|
||||
class TestIt:
|
||||
'''this will be the testclass of the webserver, using "twill"
|
||||
|
||||
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):
|
||||
cherrypy.config.update({
|
||||
'server.logToScreen' : True,
|
||||
'autoreload.on': False,
|
||||
'server.threadPool': 1,
|
||||
'server.environment': 'production',
|
||||
})
|
||||
cherrypy.root = CryptoBoxWebserverSites.CryptoBoxWebserverSites()
|
||||
|
||||
from cherrypy._cpwsgi import wsgiApp
|
||||
twill.add_wsgi_intercept('localhost', 8081, lambda: wsgiApp)
|
||||
|
||||
#output = open("foolog","w")
|
||||
#twill.set_output(output)
|
||||
|
||||
|
||||
def tearDown(self):
|
||||
# remove intercept.
|
||||
twill.remove_wsgi_intercept('localhost', 8081)
|
||||
|
||||
# shut down the cherrypy server.
|
||||
cherrypy.server.stop()
|
||||
|
||||
#output.close()
|
||||
|
||||
def test_01(self):
|
||||
twill.commands.go("http://localhost:8081/")
|
||||
twill.commands.show()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
t = TestIt()
|
||||
t.setUp()
|
||||
t.test_01()
|
||||
t.tearDown()
|
||||
|
||||
|
|
@ -1,116 +0,0 @@
|
|||
#!/usr/bin/env python2.4
|
||||
|
||||
"""
|
||||
BEWARE: this script may overwrite the data of one of your loop devices. You
|
||||
should restrict the AllowedDevices directive in cryptobox.conf to exclude
|
||||
your precious black devices from being used by this script.
|
||||
|
||||
the following script runs a number of tests for different parts
|
||||
"""
|
||||
|
||||
from CryptoBox import CryptoBoxProps
|
||||
from CryptoBoxContainer import CryptoBoxContainer
|
||||
import sys
|
||||
|
||||
|
||||
def main():
|
||||
cb = CryptoBoxProps()
|
||||
|
||||
print "Confguration:"
|
||||
print "\tConfig file:\t\t%s" % (cb.cbxPrefs.filename, )
|
||||
print "\tAllowed devices:\t%s" % (cb.cbxPrefs["Main"]["AllowedDevices"], )
|
||||
|
||||
"""for e in cb.getContainerList(filterType=CryptoBoxContainer.Types["luks"]):"""
|
||||
for e in cb.getContainerList():
|
||||
print "\t\t%d\t\t%s - %s - %d" % (cb.getContainerList().index(e), e.getDevice(), e.getName(), e.getType())
|
||||
|
||||
if not cb.getContainerList():
|
||||
print "no loop devices found for testing"
|
||||
sys.exit(1)
|
||||
|
||||
if len(cb.getContainerList()) > 1:
|
||||
print "I found more than one available loop device - I will stop now to avoid risking data loss."
|
||||
print "Please change the 'AllowedDevices' setting in 'cryptobox.conf' to reduce the number of allowed devices to only one."
|
||||
sys.exit(1)
|
||||
|
||||
testElement = cb.getContainerList()[0]
|
||||
print "\nRunning some tests now ..."
|
||||
if not plain_tests(testElement):
|
||||
print "some previous tests failed - we should stop now"
|
||||
sys.exit(1)
|
||||
luks_tests(testElement)
|
||||
|
||||
|
||||
" ***************** some functions ******************** "
|
||||
|
||||
def luks_tests(e):
|
||||
# umount if necessary
|
||||
try:
|
||||
e.umount()
|
||||
except "MountError":
|
||||
pass
|
||||
|
||||
e.create(e.Types["luks"], "alt")
|
||||
print "\tluks create:\tok"
|
||||
|
||||
e.changePassword("alt","neu")
|
||||
print "\tluks changepw:\tok"
|
||||
|
||||
e.setName("lalla")
|
||||
print "\tluks setName:\tok"
|
||||
|
||||
try:
|
||||
e.mount("neu")
|
||||
except "MountError":
|
||||
pass
|
||||
if e.isMounted(): print "\tluks mount:\tok"
|
||||
else: print "\tluks mount:\tfailed"
|
||||
|
||||
print "\tCapacity (size, free, used) [MB]:\t%s" % (e.getCapacity(), )
|
||||
|
||||
try:
|
||||
e.umount()
|
||||
except "MountError":
|
||||
pass
|
||||
if e.isMounted(): print "\tluks umount:\tfailed"
|
||||
else: print "\tluks umount:\tok"
|
||||
|
||||
if e.isMounted(): return False
|
||||
else: return True
|
||||
|
||||
|
||||
def plain_tests(e):
|
||||
# umount if necessary
|
||||
try:
|
||||
e.umount()
|
||||
except "MountError":
|
||||
pass
|
||||
|
||||
e.create(e.Types["plain"])
|
||||
print "\tplain create:\tok"
|
||||
|
||||
e.setName("plain-lili")
|
||||
print "\tplain setName:\tok"
|
||||
|
||||
try:
|
||||
e.mount()
|
||||
except "MountError":
|
||||
pass
|
||||
if e.isMounted(): print "\tplain mount:\tok"
|
||||
else: print "\tplain mount:\tfailed"
|
||||
|
||||
print "\tCapacity (size, free, used) [MB]:\t%s" % (e.getCapacity(), )
|
||||
|
||||
try:
|
||||
e.umount()
|
||||
except "MountError":
|
||||
pass
|
||||
if e.isMounted(): print "\tplain umount:\tfailed"
|
||||
else: print "\tplain umount:\tok"
|
||||
|
||||
if e.isMounted(): return False
|
||||
else: return True
|
||||
|
||||
# ************ main ****************
|
||||
|
||||
main()
|
|
@ -1,25 +1,109 @@
|
|||
#!/usr/bin/env python2.4
|
||||
|
||||
import unittest
|
||||
import cherrypy, os
|
||||
import CryptoBox
|
||||
import CryptoBoxWebserver
|
||||
import twill
|
||||
import cherrypy
|
||||
import WebInterfaceSites
|
||||
from twill import get_browser
|
||||
|
||||
class TestCryptoBoxWebserver(unittest.TestCase):
|
||||
cbw = CryptoBoxWebserver.CryptoBoxWebserver()
|
||||
cherrypy.config.configMap.update(
|
||||
{
|
||||
"/cryptobox.css": {
|
||||
"staticFilter.on" : True,
|
||||
"staticFilter.file": os.path.abspath("../www-data/cryptobox.css" )
|
||||
}
|
||||
## this makes assertRaises shorter
|
||||
from twill.errors import *
|
||||
from mechanize import BrowserStateError, LinkNotFoundError
|
||||
|
||||
## we do the following, for easy surfing
|
||||
## e.g. use: cbx.go(your_url)
|
||||
## commands api: http://twill.idyll.org/commands.html
|
||||
cbx = twill.commands
|
||||
CBXHOST="localhost"
|
||||
CBXPORT=8080
|
||||
CBX="http://"+CBXHOST+":"+str(CBXPORT)
|
||||
|
||||
class WebserverTests(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',
|
||||
})
|
||||
cbw.start()
|
||||
cherrypy.root = WebInterfaceSites.WebInterfaceSites()
|
||||
cherrypy.server.start(initOnly=True, serverClass=None)
|
||||
|
||||
def testConfigFile(self):
|
||||
'''testConfigFile TODO'''
|
||||
self.assertTrue(1)
|
||||
from cherrypy._cpwsgi import wsgiApp
|
||||
twill.add_wsgi_intercept(CBXHOST, CBXPORT, lambda: wsgiApp)
|
||||
|
||||
# grab the output of twill commands
|
||||
self.output = open("/tmp/twill.log","a")
|
||||
twill.set_output(self.output)
|
||||
|
||||
|
||||
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()
|
||||
|
||||
|
||||
########################################
|
||||
######## the tests start here ##########
|
||||
|
||||
def test_is_server_running(self):
|
||||
'''the server should run under given name and port'''
|
||||
cbx.go(CBX)
|
||||
# wrong port should fail
|
||||
self.assertRaises(BrowserStateError, cbx.go, "http://"+CBXHOST+":"+str(CBXPORT+1))
|
||||
# wrong hostname too
|
||||
self.assertRaises(BrowserStateError, cbx.go, "http://localhorst:"+str(CBXPORT))
|
||||
|
||||
def test_helppages(self):
|
||||
'''helpsites should be availbale in different languages'''
|
||||
cbx.go(CBX)
|
||||
cbx.go("doc")
|
||||
cbx.find("Table of Contents")
|
||||
|
||||
cbx.go("doc?weblang=en")
|
||||
cbx.find("Table of Contents")
|
||||
cbx.find("Getting started")
|
||||
self.assertRaises(TwillAssertionError, cbx.notfind, "Table of Contents")
|
||||
|
||||
cbx.go("doc?weblang=de")
|
||||
cbx.find("Table of Contents")
|
||||
cbx.find("Wie geht es los")
|
||||
|
||||
cbx.go("doc?weblang=si")
|
||||
#TODO: if weblang=si no help is displayed at all
|
||||
self.assertRaises(TwillAssertionError, cbx.notfind, "Table of Contents")
|
||||
|
||||
def test_goto_status(self):
|
||||
cbx.go(CBX)
|
||||
cbx.go("status")
|
||||
cbx.find("Status")
|
||||
|
||||
def test_goto_system(self):
|
||||
cbx.go(CBX)
|
||||
cbx.go("system")
|
||||
cbx.find("System")
|
||||
cbx.notfind("Sstem")
|
||||
self.assertRaises(TwillAssertionError, cbx.find, "Sstem")
|
||||
self.assertRaises(TwillAssertionError, cbx.notfind, "System")
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
|
|
Loading…
Reference in a new issue