Beispiel #1
0
def test_main_version(capsys):
    with pytest.raises(SystemExit) as exit_e:
        main(['--version'])
    out, err = capsys.readouterr()
    out = out.splitlines()
    assert exit_e.value.code == 0
    assert out[0] == tm.VERSION_STRING
    assert not err
Beispiel #2
0
def test_main_help(capsys):
    with pytest.raises(SystemExit) as exit_e:
        main(['--help'])
    out, err = capsys.readouterr()
    out = out.splitlines()
    assert exit_e.value.code == 0
    assert 'usage' in out[0]
    assert not err
Beispiel #3
0
def test_main_version_with_others(tomcat_manager_server, capsys):
    cmdline = '-v -q -u {user} -p {password} {url} list'.format(**tomcat_manager_server)
    argv = cmdline.split(' ')
    with pytest.raises(SystemExit) as exit_e:
        main(argv)
    out, err = capsys.readouterr()
    out = out.splitlines()
    assert exit_e.value.code == 0
    assert out[0] == tm.VERSION_STRING
    assert not err
Beispiel #4
0
def test_main_timeout(tomcat_manager_server, capsys):
    cmdline = '-t 25 -u {user} -p {password} {url} settings timeout'.format(**tomcat_manager_server)
    argv = cmdline.split(' ')
    exit_code = main(argv)
    out, _ = capsys.readouterr()
    out = out.splitlines()
    assert exit_code == 0
    assert 'timeout=25' in out[0]
Beispiel #5
0
def test_main_quiet(tomcat_manager_server, capsys):
    cmdline = '-q -u {user} -p {password} {url} list'.format(**tomcat_manager_server)
    argv = cmdline.split(' ')
    exit_code = main(argv)
    out, err = capsys.readouterr()
    out = out.splitlines()
    assert exit_code == 0
    assert 'Path' in out[0]
    assert not err
Beispiel #6
0
def test_main_status_to_stdout(tomcat_manager_server, capsys):
    cmdline = '-s -u {user} -p {password} {url} list'.format(**tomcat_manager_server)
    argv = cmdline.split(' ')
    exit_code = main(argv)
    out, _ = capsys.readouterr()
    out = out.splitlines()
    assert exit_code == 0
    assert '--connected to' in out[0]
    assert 'Path' in out[1]
    assert 'Sessions' in out[1]
Beispiel #7
0
def test_main_user_password_url_command(tomcat_manager_server, capsys):
    cmdline = '-u {user} -p {password} {url} list'.format(**tomcat_manager_server)
    argv = cmdline.split(' ')
    exit_code = main(argv)
    out, err = capsys.readouterr()
    out = out.splitlines()
    err = err.splitlines()
    assert exit_code == 0
    assert 'Path' in out[0]
    assert 'Sessions' in out[0]
    assert '--connected to' in err[0]
Beispiel #8
0
def test_main_stdin(tomcat_manager_server, capsys):
    inio = io.StringIO('list\n')
    stdin = sys.stdin
    cmdline = '-u {user} -p {password} {url}'.format(**tomcat_manager_server)
    argv = cmdline.split(' ')
    try:
        sys.stdin = inio
        exit_code = main(argv)
    finally:
        sys.stdin = stdin

    out, err = capsys.readouterr()
    out = out.splitlines()
    err = err.splitlines()
    assert exit_code == 0
    assert 'Path' in out[0]
    assert 'Sessions' in out[0]
    assert '--connected to' in err[0]
Beispiel #9
0
def test_main_noargs(mocker):
    mock_cmdloop = mocker.patch('cmd2.Cmd.cmdloop')
    argv = []
    main(argv)
    assert mock_cmdloop.call_count == 1