From: Rob van der Linde Date: Sun, 24 Sep 2023 23:51:19 +0000 (+1300) Subject: netcmd: tests: avoid the need to create a random command in GetSamDB X-Git-Tag: tevent-0.16.0~326 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7f4db71025e5e473ccbc0d03255932ce2dd4b7f9;p=thirdparty%2Fsamba.git netcmd: tests: avoid the need to create a random command in GetSamDB Also the code that looks over kwargs is somewhat confusing and unnecessary. Signed-off-by: Rob van der Linde Reviewed-by: Douglas Bagnall Reviewed-by: Andrew Bartlett --- diff --git a/python/samba/tests/samba_tool/base.py b/python/samba/tests/samba_tool/base.py index 9df8ee1e660..3098817869c 100644 --- a/python/samba/tests/samba_tool/base.py +++ b/python/samba/tests/samba_tool/base.py @@ -28,6 +28,8 @@ from samba.auth import system_session from samba.samdb import SamDB from io import StringIO from samba.netcmd.main import cmd_sambatool +from optparse import OptionParser +import samba.getopt as options import samba.tests @@ -46,32 +48,19 @@ class SambaToolCmdTest(samba.tests.BlackboxTestCase): def getSamDB(*argv): """a convenience function to get a samdb instance so that we can query it""" - # We build a fake command to get the options created the same - # way the command classes do it. It would be better if the command - # classes had a way to more cleanly do this, but this lets us write - # tests for now - cmd = cmd_sambatool.subcommands["user"].subcommands["setexpiry"] - parser, optiongroups = cmd._create_parser("user") + parser = OptionParser() + sambaopts = options.SambaOptions(parser) + credopts = options.CredentialsOptions(parser) + parser.add_option("-H", "--URL", + help="LDB URL for database or target server", + type=str, metavar="URL", dest="H") opts, args = parser.parse_args(list(argv)) - # Filter out options from option groups - args = args[1:] - kwargs = dict(opts.__dict__) - for option_group in parser.option_groups: - for option in option_group.option_list: - if option.dest is not None: - del kwargs[option.dest] - kwargs.update(optiongroups) - - H = kwargs.get("H", None) - sambaopts = kwargs.get("sambaopts", None) - credopts = kwargs.get("credopts", None) lp = sambaopts.get_loadparm() creds = credopts.get_credentials(lp, fallback_machine=True) - samdb = SamDB(url=H, session_info=system_session(), - credentials=creds, lp=lp) - return samdb + return SamDB(url=opts.H, session_info=system_session(), + credentials=creds, lp=lp) def _run(self, *argv): """run a samba-tool command"""