diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2011-10-12 23:27:57 +0200 |
---|---|---|
committer | Jelmer Vernooij <jelmer@samba.org> | 2011-10-13 01:56:20 +0200 |
commit | de9b3b61906ae4f1862ccce81577b323fadbb27d (patch) | |
tree | 07bce810019d88d1f8af0dd201c46c8f711c3b7c /source4/scripting/python | |
parent | 6f9a3177d49d49d9a631cb1f2219761a4721b387 (diff) | |
download | samba-de9b3b61906ae4f1862ccce81577b323fadbb27d.tar.gz samba-de9b3b61906ae4f1862ccce81577b323fadbb27d.tar.bz2 samba-de9b3b61906ae4f1862ccce81577b323fadbb27d.zip |
samba-tools/testparm: Add really basic unit test, demonstrating how to write unit tests for samba-tool in Python.
Autobuild-User: Jelmer Vernooij <jelmer@samba.org>
Autobuild-Date: Thu Oct 13 01:56:20 CEST 2011 on sn-devel-104
Diffstat (limited to 'source4/scripting/python')
-rw-r--r-- | source4/scripting/python/samba/tests/netcmd.py | 29 |
1 files changed, 29 insertions, 0 deletions
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""" |