From de9b3b61906ae4f1862ccce81577b323fadbb27d Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 12 Oct 2011 23:27:57 +0200 Subject: samba-tools/testparm: Add really basic unit test, demonstrating how to write unit tests for samba-tool in Python. Autobuild-User: Jelmer Vernooij Autobuild-Date: Thu Oct 13 01:56:20 CEST 2011 on sn-devel-104 --- source4/scripting/python/samba/tests/netcmd.py | 29 ++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'source4/scripting/python') diff --git a/source4/scripting/python/samba/tests/netcmd.py b/source4/scripting/python/samba/tests/netcmd.py index 7b53d53c3c..4f06124482 100644 --- a/source4/scripting/python/samba/tests/netcmd.py +++ b/source4/scripting/python/samba/tests/netcmd.py @@ -19,10 +19,39 @@ """Tests for samba.netcmd.""" +from cStringIO import StringIO from samba.netcmd import Command +from samba.netcmd.testparm import cmd_testparm import samba.tests +class NetCmdTestCase(samba.tests.TestCase): + + def run_netcmd(self, cmd_klass, args, retcode=0): + cmd = cmd_klass() + cmd.outf = StringIO() + cmd.errf = StringIO() + try: + retval = cmd._run(cmd_klass.__name__, *args) + except Exception, e: + cmd.show_command_error(e) + retval = 1 + self.assertEquals(retcode, retval) + return cmd.outf.getvalue(), cmd.errf.getvalue() + + +class TestParmTests(NetCmdTestCase): + + def test_no_client_ip(self): + out, err = self.run_netcmd(cmd_testparm, ["--client-name=foo"], + retcode=-1) + self.assertEquals("", out) + self.assertEquals( + "ERROR: Both a DNS name and an IP address are " + "required for the host access check\n", err) + + class CommandTests(samba.tests.TestCase): + def test_description(self): class cmd_foo(Command): """Mydescription""" -- cgit