"""Tests for samba.netcmd."""
+import os
+import tempfile
+
from io import StringIO
from samba.netcmd import Command
from samba.netcmd.testparm import cmd_testparm
import samba.tests
-class NetCmdTestCase(samba.tests.TestCase):
+class NetCmdTestCase(samba.tests.TestCaseInTempDir):
def run_netcmd(self, cmd_klass, args, retcode=0):
cmd = cmd_klass(outf=StringIO(), errf=StringIO())
class TestParmTests(NetCmdTestCase):
+ def setUp(self):
+ super().setUp()
+
+ # Override these global parameters in case their default values are
+ # invalid.
+ contents = """[global]
+ netbios name = test
+ lock dir = /
+ pid directory = /
+[tmp]
+ path = /
+"""
+ self.smbconf = self.create_smbconf(contents)
+
+ def create_smbconf(self, contents):
+ smbconf = tempfile.NamedTemporaryFile(mode='w',
+ dir=self.tempdir,
+ delete=False)
+ self.addCleanup(os.remove, smbconf.name)
+
+ try:
+ smbconf.write(contents)
+ finally:
+ smbconf.close()
+
+ return smbconf
+
def test_no_client_ip(self):
out, err = self.run_netcmd(cmd_testparm, ["--client-name=foo"],
retcode=-1)
"ERROR: Both a DNS name and an IP address are "
"required for the host access check\n", err)
+ def test_section(self):
+ # We don't get an opportunity to verify the output, as the parameters
+ # are dumped directly to stdout, so just check the return code.
+ self.run_netcmd(cmd_testparm,
+ ["--configfile=%s" % self.smbconf.name,
+ "--section-name=tmp"],
+ retcode=None)
+
class CommandTests(NetCmdTestCase):