コード例 #1
0
ファイル: test_cmd_su.py プロジェクト: nokia/moler
def test_failing_calling_twice_the_same_command_object(buffer_connection, command_output_and_expected_result_pwd):
    from moler.cmd.unix.pwd import Pwd
    command_output, expected_result = command_output_and_expected_result_pwd
    buffer_connection.remote_inject_response([command_output])

    cmd_pwd = Pwd(connection=buffer_connection.moler_connection)
    cmd_su = Su(connection=buffer_connection.moler_connection, password="******", cmd_object=cmd_pwd)
    result = cmd_su()
    assert result == expected_result
    cmd_sudo = Su(connection=buffer_connection.moler_connection, password="******", cmd_object=cmd_pwd)
    with pytest.raises(CommandFailure):
        cmd_sudo()
コード例 #2
0
def test_su_catches_authentication_failure(buffer_connection):
    from moler.exceptions import CommandFailure
    command_output, expected_result = command_output_and_expected_result_auth()
    buffer_connection.remote_inject_response([command_output])
    su_cmd = Su(connection=buffer_connection.moler_connection)
    with pytest.raises(CommandFailure):
        su_cmd()
コード例 #3
0
ファイル: test_cmd_su.py プロジェクト: nokia/moler
def test_su_catches_authentication_failure(buffer_connection, command_output_and_expected_result_auth):
    from moler.exceptions import CommandFailure
    command_output, expected_result = command_output_and_expected_result_auth
    buffer_connection.remote_inject_response([command_output])
    su_cmd = Su(connection=buffer_connection.moler_connection, prompt=r"xyz@debian:", expected_prompt=r"root@debian")
    with pytest.raises(CommandFailure):
        su_cmd()
コード例 #4
0
def test_su_returns_proper_command_string(buffer_connection):
    telnet_cmd = Su(buffer_connection,
                    user='******',
                    options='-p',
                    password="******",
                    prompt=None,
                    newline_chars=None)
    assert "su -p xyz" == telnet_cmd.command_string
コード例 #5
0
ファイル: test_cmd_su.py プロジェクト: nokia/moler
def test_failing_with_both_parameters(buffer_connection):
    from moler.cmd.unix.cp import Cp
    cmd_cp = Cp(connection=buffer_connection.moler_connection, src="src", dst="dst")
    cmd_sudo = Su(connection=buffer_connection.moler_connection, cmd_class_name="moler.cmd.unix.cp.Cp",
                  cmd_object=cmd_cp, password="******")
    with pytest.raises(CommandFailure) as err:
        cmd_sudo(timeout=0.2)
    assert "Both 'cmd_object' and 'cmd_class_name' parameters were provided" in str(err.value)
コード例 #6
0
ファイル: test_cmd_su.py プロジェクト: nokia/moler
def test_su_catches_missing_binary_failure(buffer_connection):
    from moler.exceptions import CommandFailure

    buffer_connection.remote_inject_response(["xyz@debian:~/Moler$ su\n",
                                              "/system/bin/sh: su: not found\n",
                                              "xyz@debian:~/Moler$"])
    su_cmd = Su(connection=buffer_connection.moler_connection)
    with pytest.raises(CommandFailure) as err:
        su_cmd()
    assert "/system/bin/sh: su: not found" in str(err.value)
コード例 #7
0
ファイル: test_cmd_su.py プロジェクト: nokia/moler
def test_sudo_su_object(buffer_connection, command_output_and_expected_result_ls_l):
    from moler.cmd.unix.sudo import Sudo
    from moler.cmd.unix.ls import Ls
    command_output = command_output_and_expected_result_ls_l[0]
    expected_dict = command_output_and_expected_result_ls_l[1]
    buffer_connection.remote_inject_response([command_output])
    cmd_ls = Ls(connection=buffer_connection.moler_connection, options="-l")
    cmd_su = Su(connection=buffer_connection.moler_connection, cmd_object=cmd_ls)
    cmd_sudo = Sudo(connection=buffer_connection.moler_connection, cmd_object=cmd_su)
    ret = cmd_sudo()
    assert ret == expected_dict
コード例 #8
0
ファイル: test_cmd_su.py プロジェクト: nokia/moler
def test_sudo_su(buffer_connection):
    from moler.cmd.unix.sudo import Sudo
    command_output = """sudo su -c 'pwd'
/home/auto/inv
moler_bash#"""
    expected_dict = {'full_path': '/home/auto/inv', 'path_to_current': '/home/auto', 'current_path': 'inv'}
    buffer_connection.remote_inject_response([command_output])
    cmd_su = Su(connection=buffer_connection.moler_connection, prompt=r"moler_bash#",
                cmd_class_name='moler.cmd.unix.pwd.Pwd')
    cmd_sudo = Sudo(connection=buffer_connection.moler_connection, cmd_object=cmd_su)
    ret = cmd_sudo()
    assert ret == expected_dict
コード例 #9
0
ファイル: test_cmd_sudo.py プロジェクト: nokia/moler
def test_calling_by_command_object_su(buffer_connection):
    command_output = """sudo su
root@host#"""
    buffer_connection.remote_inject_response([command_output])

    cmd_su = Su(connection=buffer_connection.moler_connection,
                expected_prompt="root@host.*#")
    cmd_sudo = Sudo(connection=buffer_connection.moler_connection,
                    cmd_object=cmd_su,
                    expected_prompt="root@host.*#")
    assert "sudo su" == cmd_sudo.command_string
    cmd_sudo()
コード例 #10
0
ファイル: test_cmd_su.py プロジェクト: nokia/moler
def test_su_returns_proper_command_string_pwd(buffer_connection):
    cmd = Su(buffer_connection, cmd_class_name='moler.cmd.unix.pwd.Pwd')
    assert "su -c 'pwd'" == cmd.command_string