diff --git a/pythonrewrite/plugins/date/date.py b/pythonrewrite/plugins/date/date.py index f726d9c..c23aef4 100644 --- a/pythonrewrite/plugins/date/date.py +++ b/pythonrewrite/plugins/date/date.py @@ -35,7 +35,8 @@ class date(CryptoBoxPlugin.CryptoBoxPlugin): def getStatus(self): - return str(self.__getCurrentDate()) + now = self.__getCurrentDate() + return "%d/%d/%d/%d/%d/%d" % (now.year, now.month, now.day, now.hour, now.minute, now.second) def __prepareFormData(self): diff --git a/pythonrewrite/plugins/date/form_date.cs b/pythonrewrite/plugins/date/form_date.cs index ff33a18..97fdb10 100644 --- a/pythonrewrite/plugins/date/form_date.cs +++ b/pythonrewrite/plugins/date/form_date.cs @@ -2,7 +2,7 @@

- +


diff --git a/pythonrewrite/plugins/format_fs/volume_format_luks.cs b/pythonrewrite/plugins/format_fs/volume_format_luks.cs index d2ecc75..69fd554 100644 --- a/pythonrewrite/plugins/format_fs/volume_format_luks.cs +++ b/pythonrewrite/plugins/format_fs/volume_format_luks.cs @@ -10,7 +10,7 @@ - +

@@ -19,8 +19,8 @@ var:html_escape(Lang.Plugins.format_fs.Text.Yes) ?>

-

-

+

+

diff --git a/pythonrewrite/plugins/logs/unittests.py b/pythonrewrite/plugins/logs/unittests.py new file mode 100644 index 0000000..95bc49a --- /dev/null +++ b/pythonrewrite/plugins/logs/unittests.py @@ -0,0 +1,21 @@ +import WebInterfaceTestClass + +class unittests(WebInterfaceTestClass.WebInterfaceTestClass): + + def test_read_logs(self): + log_url = self.URL + "plugins/logs" + self.register_auth(log_url) + self.cmd.go(log_url) + self.cmd.find('class="console"') + + def test_write_logs(self): + ## we have to assume two things: + ## 1) log level is at least "error" + ## 2) the log message does not get lost in a possible stream of log messages + log_text = "unittest - just a marker - please ignore" + self.cbox.log.error(log_text) + log_url = self.URL + "plugins/logs" + self.register_auth(log_url) + self.cmd.go(log_url) + self.cmd.find(log_text) + diff --git a/pythonrewrite/plugins/network/form_network.cs b/pythonrewrite/plugins/network/form_network.cs index d2946e7..7373404 100644 --- a/pythonrewrite/plugins/network/form_network.cs +++ b/pythonrewrite/plugins/network/form_network.cs @@ -6,7 +6,7 @@

- +

255): @@ -39,6 +43,7 @@ class network(CryptoBoxPlugin.CryptoBoxPlugin): self.__prepareFormData() return "form_network" else: + self.cbox.log.debug("network plugin: show form") ## just show the form self.__prepareFormData() return "form_network" @@ -48,11 +53,11 @@ class network(CryptoBoxPlugin.CryptoBoxPlugin): return "%d.%d.%d.%d" % self.__getCurrentIP() - def __getRedirectDestionation(self, ip): + def __getRedirectDestination(self, ip): import cherrypy req = cherrypy.request - dest = ip base_parts = req.base.split(":") + dest = "%s:%s" % (base_parts[0], ip) if len(base_parts) == 3: dest += ":%s" % base_parts[2] return dest @@ -97,6 +102,7 @@ class network(CryptoBoxPlugin.CryptoBoxPlugin): time.sleep(CHANGE_IP_DELAY) proc = subprocess.Popen( shell = False, + stderr = subprocess.PIPE, args = [ self.cbox.prefs["Programs"]["super"], self.cbox.prefs["Programs"]["CryptoBoxRootActions"], @@ -104,6 +110,9 @@ class network(CryptoBoxPlugin.CryptoBoxPlugin): os.path.join(self.pluginDir, "root_action.py"), ip]) proc.communicate() + if proc.returncode != 0: + self.cbox.log.warn("failed to change IP address: %s" % ip) + self.cbox.log.warn("error output: %s" % str(proc.stderr.read())) return thread = threading.Thread() thread.run = delayedIPchange @@ -112,3 +121,5 @@ class network(CryptoBoxPlugin.CryptoBoxPlugin): # TODO: how could we guess, if it failed? return True + + diff --git a/pythonrewrite/plugins/network/unittests.py b/pythonrewrite/plugins/network/unittests.py new file mode 100644 index 0000000..8224b16 --- /dev/null +++ b/pythonrewrite/plugins/network/unittests.py @@ -0,0 +1,45 @@ +import WebInterfaceTestClass +from network import CHANGE_IP_DELAY + + +class unittests(WebInterfaceTestClass.WebInterfaceTestClass): + + def atest_ip_change(self): + '''change of network address''' + ## the time module is necessary for the CHANGE_IP_DELAY + import time + self.register_auth(self.URL + "plugins/network") + self.cmd.go(self.URL + "plugins/network") + ## extract the current IP from the network plugin output + def getCurrentIP(): + self.cmd.go(self.URL + "plugins/network") + self.cmd.show() + self.cmd.find(u'Data.Status.Plugins.network=([0-9\.]*)$', "m") + return self.locals["__match__"] + origIPtext = getCurrentIP() + origIPocts = origIPtext.split(".") + ## check, if the original IP is valid (contains four octets) + self.assertEquals(4, len(origIPocts)) + self.cmd.echo(origIPocts) + wrongIP = "192.168.123.321" + def setIP((ip1, ip2, ip3, ip4)): + self.cmd.go(self.URL + "plugins/network") + self.cmd.formvalue("set_ip", "ip1", str(ip1)) + self.cmd.formvalue("set_ip", "ip2", str(ip2)) + self.cmd.formvalue("set_ip", "ip3", str(ip3)) + self.cmd.formvalue("set_ip", "ip4", str(ip4)) + self.cmd.submit() + ## sleep a little bit longer than the delay necessary for ip-change + time.sleep(CHANGE_IP_DELAY + 0.2) + setIP([1,-2,0,1]) + self.assertEquals(origIPtext, getCurrentIP()) + setIP([1,0,0,256]) + self.assertEquals(origIPtext, getCurrentIP()) + setIP([1,"foo",0,1]) + self.assertEquals(origIPtext, getCurrentIP()) + setIP([10,12,0,2]) + self.assertEquals("10.12.0.2", getCurrentIP()) + setIP(origIPocts) + self.assertEquals(origIPtext, getCurrentIP()) + + diff --git a/pythonrewrite/plugins/partition/select_device.cs b/pythonrewrite/plugins/partition/select_device.cs index 9d26d1b..93803cf 100644 --- a/pythonrewrite/plugins/partition/select_device.cs +++ b/pythonrewrite/plugins/partition/select_device.cs @@ -6,7 +6,7 @@ 0 ?> - +


@@ -32,7 +32,7 @@ 0 ?> - + @@ -55,7 +55,7 @@

- + diff --git a/pythonrewrite/plugins/plugin-interface.txt b/pythonrewrite/plugins/plugin-interface.txt index 7431b0e..e40fc8f 100644 --- a/pythonrewrite/plugins/plugin-interface.txt +++ b/pythonrewrite/plugins/plugin-interface.txt @@ -34,6 +34,8 @@ Python code interface: - the class variable "enabled" is boolean and detemines the default availability of the plugin - volume plugins contain the attribute "device" (you may trust this value - a volume plugin will never get called with an invalid device) + - the python module which contains the plugin's class should also contain a class called + 'unittests' - it should inherit WebInterfaceTestClass.WebInterfaceTestClass Language file structure: diff --git a/pythonrewrite/plugins/plugin_manager/plugin_list.cs b/pythonrewrite/plugins/plugin_manager/plugin_list.cs index c384da1..04c3732 100644 --- a/pythonrewrite/plugins/plugin_manager/plugin_list.cs +++ b/pythonrewrite/plugins/plugin_manager/plugin_list.cs @@ -16,7 +16,7 @@

- +

diff --git a/pythonrewrite/plugins/shutdown/form_shutdown.cs b/pythonrewrite/plugins/shutdown/form_shutdown.cs index 23065c5..d45c015 100644 --- a/pythonrewrite/plugins/shutdown/form_shutdown.cs +++ b/pythonrewrite/plugins/shutdown/form_shutdown.cs @@ -10,14 +10,14 @@
- + - + diff --git a/pythonrewrite/plugins/shutdown/unittests.py b/pythonrewrite/plugins/shutdown/unittests.py new file mode 100644 index 0000000..58634c7 --- /dev/null +++ b/pythonrewrite/plugins/shutdown/unittests.py @@ -0,0 +1,11 @@ +import WebInterfaceTestClass + +class unittests(WebInterfaceTestClass.WebInterfaceTestClass): + + def test_read_form(self): + url = self.URL + "plugins/shutdown" + self.register_auth(url) + self.cmd.go(url) + self.cmd.find('

- + @@ -38,7 +38,7 @@

- +

@@ -66,7 +66,7 @@

- + - +
- + diff --git a/pythonrewrite/plugins/volume_mount/volume_umount.cs b/pythonrewrite/plugins/volume_mount/volume_umount.cs index 8019291..e09533b 100644 --- a/pythonrewrite/plugins/volume_mount/volume_umount.cs +++ b/pythonrewrite/plugins/volume_mount/volume_umount.cs @@ -1,6 +1,6 @@

- +

diff --git a/pythonrewrite/plugins/volume_props/volume_properties.cs b/pythonrewrite/plugins/volume_props/volume_properties.cs index 9ae88b4..2c16063 100644 --- a/pythonrewrite/plugins/volume_props/volume_properties.cs +++ b/pythonrewrite/plugins/volume_props/volume_properties.cs @@ -17,7 +17,7 @@

@@ -33,7 +33,7 @@