1 # Unix SMB/CIFS implementation.
2 # Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2009-2011
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 """Tests for samba.netcmd."""
20 from cStringIO
import StringIO
21 from samba
.netcmd
import Command
22 from samba
.netcmd
.testparm
import cmd_testparm
23 from samba
.netcmd
.main
import cmd_sambatool
26 class NetCmdTestCase(samba
.tests
.TestCase
):
28 def run_netcmd(self
, cmd_klass
, args
, retcode
=0):
29 cmd
= cmd_klass(outf
=StringIO(), errf
=StringIO())
31 retval
= cmd
._run
(cmd_klass
.__name
__, *args
)
33 cmd
.show_command_error(e
)
35 self
.assertEquals(retcode
, retval
)
36 return cmd
.outf
.getvalue(), cmd
.errf
.getvalue()
38 def iter_all_subcommands(self
):
40 todo
.extend(cmd_sambatool
.subcommands
.items())
42 (path
, cmd
) = todo
.pop()
44 subcmds
= getattr(cmd
, "subcommands", {})
45 todo
.extend([(path
+ " " + k
, v
) for (k
, v
) in
49 class TestParmTests(NetCmdTestCase
):
51 def test_no_client_ip(self
):
52 out
, err
= self
.run_netcmd(cmd_testparm
, ["--client-name=foo"],
54 self
.assertEquals("", out
)
56 "ERROR: Both a DNS name and an IP address are "
57 "required for the host access check\n", err
)
60 class CommandTests(NetCmdTestCase
):
62 def test_description(self
):
63 class cmd_foo(Command
):
65 self
.assertEquals("Mydescription", cmd_foo().short_description
)
68 class cmd_foo(Command
):
70 self
.assertEquals("foo", cmd_foo().name
)
72 def test_synopsis_everywhere(self
):
74 for path
, cmd
in self
.iter_all_subcommands():
75 if cmd
.synopsis
is None:
78 self
.fail("The following commands do not have a synopsis set: %r" %
81 def test_short_description_everywhere(self
):
83 for path
, cmd
in self
.iter_all_subcommands():
84 if cmd
.short_description
is None:
89 "The following commands do not have a short description set: %r" %