moved unittests for (formerly) internal pages to the appropriate plugins

added "do_unittests.sh" - this script should be used to run all unittests before commit
fixed nasty "cannot-switch-languages"-bug
fixed language data loading for plugins
This commit is contained in:
lars 2006-11-02 13:55:31 +00:00
parent e42902f641
commit ada7458306
8 changed files with 91 additions and 34 deletions

View file

@ -85,6 +85,7 @@ class CryptoBoxContainer:
def getCapacity(self):
"""return the current capacity state of the volume
the volume may not be mounted
the result is a tuple of values in megabyte:
(size, available, used)
"""
@ -93,6 +94,16 @@ class CryptoBoxContainer:
int(info.f_bsize*info.f_blocks/1024/1024),
int(info.f_bsize*info.f_bavail/1024/1024),
int(info.f_bsize*(info.f_blocks-info.f_bavail)/1024/1024))
def getSize(self):
"""return the size of the block device (_not_ of the filesystem)
the result is a value in megabyte
an error is indicated by "-1"
"""
import CryptoBoxTools
return CryptoBoxTools.getBlockDeviceSize(self.device)
def resetObject(self):

View file

@ -88,13 +88,17 @@ class CryptoBoxPlugin:
## maybe we have to load a translation afterwards
if lang != "en":
langFiles.append(os.path.join(langdir, lang + ".hdf"))
file_found = False
lang_hdf = neo_util.HDF()
for langFile in langFiles:
if os.access(langFile, os.R_OK):
lang_hdf = neo_util.HDF()
lang_hdf.readFile(langFile)
return lang_hdf
self.cbox.log.debug("Couldn't find a valid plugin language file (%s)" % str(langFiles))
return None
file_found = True
if file_found:
return lang_hdf
else:
self.cbox.log.debug("Couldn't find a valid plugin language file (%s)" % str(langFiles))
return None
def loadDataSet(self, hdf):

View file

@ -157,3 +157,30 @@ def isPartOfBlockDevice(parent, subdevice):
pass
return False
def getBlockDeviceSize(device):
if not device: return -1
try:
rdev = os.stat(device).st_rdev
except OSError:
return -1
minor = os.minor(rdev)
major = os.major(rdev)
for f in file("/proc/partitions"):
try:
elements = f.split()
if len(elements) != 4: continue
if (int(elements[0]) == major) and (int(elements[1]) == minor):
return int(elements[2])/1024
except ValueError:
pass
return -1
def getBlockDeviceSizeHumanly(device):
size = getBlockDeviceSize(device)
if size > 5120:
return "%sGB" % size/1024
else:
return "%sMB" % size

View file

@ -1,5 +1,6 @@
import os
import CryptoBoxContainer
import CryptoBoxTools
## useful constant for some functions
CONT_TYPES = CryptoBoxContainer.CryptoBoxContainer.Types
@ -33,6 +34,7 @@ class WebInterfaceDataset(dict):
self["Data.CurrentDisk.encryption"] = isEncrypted
self["Data.CurrentDisk.plaintext"] = isPlain
self["Data.CurrentDisk.active"] = isMounted
self["Data.CurrentDisk.size"] = CryptoBoxTools.getBlockDeviceSizeHumanly(container.getDevice())
if isMounted:
(size, avail, used) = container.getCapacity()
percent = used / size
@ -56,6 +58,7 @@ class WebInterfaceDataset(dict):
self["Data.Disks.%d.encryption" % avail_counter] = isEncrypted
self["Data.Disks.%d.plaintext" % avail_counter] = isPlain
self["Data.Disks.%d.active" % avail_counter] = isMounted
self["Data.Disks.%d.size" % avail_counter] = CryptoBoxTools.getBlockDeviceSizeHumanly(container.getDevice())
if isMounted: active_counter += 1
avail_counter += 1
self["Data.activeDisksCount"] = active_counter
@ -75,7 +78,6 @@ class WebInterfaceDataset(dict):
self["Data.Version"] = self.cbox.VERSION
for lang in self.cbox.getAvailableLanguages():
self["Data.Languages." + lang] = self.__getLanguageName(lang)
## TODO: open issues: Data.Config.AdminPasswordIsSet
def __getLanguageName(self, lang):

View file

@ -12,6 +12,7 @@ class WebInterfacePlugins:
def __init__(self, log, plugins, handler_func):
for plugin in plugins.getPlugins():
if not plugin: continue
if not plugin.isEnabled(): continue
plname = plugin.getName()
log.info("Plugin '%s' loaded" % plname)
## this should be the "easiest" way to expose all plugins as URLs
@ -114,18 +115,21 @@ class WebInterfaceSites:
def index(self, weblang=""):
self.__resetDataset()
self.__setWebLang(weblang)
## do not forget the language!
param_dict = {"weblang":weblang}
## render "disks" plugin by default
return self.return_plugin_action(self.pluginList.getPlugin("disks"))()
return self.return_plugin_action(self.pluginList.getPlugin("disks"))(**param_dict)
def return_plugin_action(self, plugin):
def handler(self, **args):
self.__resetDataset()
args_orig = dict(args)
try:
self.__setWebLang(args["weblang"])
del args["weblang"]
except KeyError:
pass
self.__setWebLang("")
## check the device argument of volume plugins
if "volume" in plugin.pluginCapabilities:
try:
@ -155,7 +159,9 @@ class WebInterfaceSites:
and "plugin" in nextTemplate.keys() \
and "values" in nextTemplate.keys() \
and self.pluginList.getPlugin(nextTemplate["plugin"]):
valueDict = nextTemplate["values"]
valueDict = dict(nextTemplate["values"])
## force the current weblang attribute - otherwise it gets lost
valueDict["weblang"] = self.dataset["Settings.Language"]
new_plugin = self.pluginList.getPlugin(nextTemplate["plugin"])
return self.return_plugin_action(new_plugin)(**valueDict)
## save the currently active plugin name

View file

@ -73,6 +73,7 @@ Language = de
cryptsetup = /sbin/cryptsetup
mkfs-data = /sbin/mkfs.ext3
blkid = /sbin/blkid
blockdev = /sbin/blockdev
mount = /bin/mount
umount = /bin/umount
super = /usr/bin/super

View file

@ -0,0 +1,22 @@
#!/bin/sh
#
# run this script _before_ you do a commit and fix errors before uploading
#
# check if /dev/loop1 is available - otherwise some tests will fail!
if /sbin/losetup /dev/loop1 &>/dev/null
then true
else echo "misconfiguration detected: sorry - you need /dev/loop1 for the tests" >&2
echo "just do the following:" >&2
echo " dd if=/dev/zero of=test.img bs=1M count=1 seek=100" >&2
echo " sudo /sbin/losetup /dev/loop1 test.img" >&2
echo "then you can run the tests again ..." >&2
echo >&2
exit 1
fi
# do the tests
for a in unittests.*.py
do testoob -v "$a"
done

View file

@ -21,33 +21,17 @@ class WebServer(WebInterfaceTestClass.WebInterfaceTestClass):
class BuiltinPages(WebInterfaceTestClass.WebInterfaceTestClass):
def test_help_pages(self):
'''help pages should be available in different languages'''
## check english help pages
self.cmd.go(self.URL + "doc?weblang=en")
self.cmd.find("Table of Contents")
self.cmd.find("Getting started")
self.cmd.go(self.URL + "doc?weblang=de")
self.cmd.find("Table of Contents")
self.cmd.find("Wie geht es los")
self.cmd.go(self.URL + "doc?weblang=si")
self.assertRaises(TwillAssertionError, self.cmd.notfind, "Table of Contents")
#TODO: add a slovene text here, as soon as the help is translated
def test_goto_status(self):
'''display all active devices'''
self.cmd.go(self.URL + "status")
self.cmd.find("Status")
def test_goto_system(self):
self.cmd.go(self.URL + "system")
self.cmd.find("System")
def test_goto_index(self):
'''display all devices'''
self.cmd.go(self.URL + "?weblang=en")
self.cmd.find("The CryptoBox")
self.cmd.go(self.URL + "?weblang=de")
self.cmd.find("Die CryptoBox")
self.cmd.go(self.URL + "?weblang=si")
self.cmd.find("Privatnost v vsako vas")
self.cmd.go(self.URL + "?weblang=fr")
self.cmd.find("La CryptoBox")
if __name__ == "__main__":