samba-tools/testparm: Add really basic unit test, demonstrating how to write unit...
authorJelmer Vernooij <jelmer@samba.org>
Wed, 12 Oct 2011 21:27:57 +0000 (23:27 +0200)
committerJelmer Vernooij <jelmer@samba.org>
Wed, 12 Oct 2011 23:56:20 +0000 (01:56 +0200)
Autobuild-User: Jelmer Vernooij <jelmer@samba.org>
Autobuild-Date: Thu Oct 13 01:56:20 CEST 2011 on sn-devel-104

source4/scripting/python/samba/tests/netcmd.py

index 7b53d53c3caa373c0cfa441253fdf8e3c69ea205..4f06124482b56909a5cfea8f41804caf703d2afe 100644 (file)
 
 """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"""