Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_list_process_apps_empty():
lines = ''
itm = tm.InteractiveTomcatManager()
args = itm.parse_args(itm.list_parser, '')
apps = parse_apps(lines)
apps = itm._list_process_apps(apps, args)
assert isinstance(apps, list)
assert apps == []
def test_set_integer_valid():
itm = tm.InteractiveTomcatManager()
itm.timeout = 10
itm.onecmd_plus_hooks('set timeout=5')
assert itm.timeout == 5
assert itm.exit_code == itm.exit_codes.success
def get_itm(tms):
"""
Using this as a fixture with capsys breaks capsys. So we use a function.
"""
itm = tm.InteractiveTomcatManager()
args = 'connect {url} {user} {password}'.format(**tms)
itm.onecmd_plus_hooks(args)
return itm
def test_set_with_invalid_param():
itm = tm.InteractiveTomcatManager()
# this uuid won't be in itm.settable
invalid_setting = str(uuid.uuid1())
with pytest.raises(ValueError):
# pylint: disable=protected-access
itm._change_setting(invalid_setting, 'someval')
def test_list_parse_args(raw, state, sort):
itm = tm.InteractiveTomcatManager()
argv = '{} {} {}'.format(raw, state, sort)
itm.parse_args(itm.list_parser, argv)
assert itm.exit_code == itm.exit_codes.success
def get_itm(tms):
"""
Using this as a fixture with capsys breaks capsys. So we use a function.
"""
itm = tm.InteractiveTomcatManager()
args = 'connect {url} {user} {password}'.format(**tms)
itm.onecmd_plus_hooks(args)
return itm
def itm_with_config(mocker, configstring):
"""Return an InteractiveTomcatManager object with the config set from the passed string."""
itm = tm.InteractiveTomcatManager()
fd, fname = tempfile.mkstemp(prefix='', suffix='.ini')
os.close(fd)
with open(fname, 'w') as fobj:
fobj.write(configstring)
# itm aleady tried to load a config file, which it may or may not
# have found, depending on if you have one or not
# we are now going to patch up the config_file to point to
# a known file, and the reload the config from that
try:
config_file = mocker.patch('tomcatmanager.InteractiveTomcatManager.config_file',
new_callable=mock.PropertyMock)
config_file.return_value = fname
itm.load_config()
# this just verifies that our patch worked
assert itm.config_file == fname
def main(argv=None):
"""Entry point for 'tomcat-manager' command line program."""
parser = _build_parser()
args = parser.parse_args(argv)
if args.debug:
print("--argv=" + str(argv), file=sys.stderr)
print("--args=" + str(args), file=sys.stderr)
itm = tm.InteractiveTomcatManager()
# if we have command line switches, set those values
# these override any user settings loaded from a config file
if args.echo:
itm.echo = True
if args.quiet:
itm.quiet = True
if args.status_to_stdout:
itm.status_to_stdout = True
if args.debug:
itm.debug = True
if args.manager_url:
# try and connect
server_info = {'url': args.manager_url, 'user': '', 'password': ''}
server_info['user'] = (args.user or '')