コード例 #1
0
def test_terminal_whoami_ls(terminal_connection):
    terminal = terminal_connection
    cmd = Whoami(connection=terminal)
    ret = cmd()
    user1 = ret['USER']
    cmd = Ls(connection=terminal)
    cmd()
    cmd = Whoami(connection=terminal)
    ret = cmd()
    user2 = ret['USER']
    assert user1 == user2
    assert getpass.getuser() == user2
コード例 #2
0
def test_two_commands_uptime_whoami(
        buffer_connection, command_output_and_expected_result_uptime_whoami):
    from moler.cmd.unix.uptime import Uptime
    from moler.cmd.unix.whoami import Whoami
    command_output, expected_result = command_output_and_expected_result_uptime_whoami
    uptime_cmd = Uptime(connection=buffer_connection.moler_connection)
    whoami_cmd = Whoami(connection=buffer_connection.moler_connection)
    uptime_cmd.start(timeout=2)
    time.sleep(0.005)
    whoami_cmd.start(timeout=2)
    time.sleep(0.05)
    assert CommandScheduler.is_waiting_for_execution(
        connection_observer=whoami_cmd) is True
    buffer_connection.moler_connection.data_received(
        command_output[0].encode("utf-8"), datetime.datetime.now())
    time.sleep(0.2)
    buffer_connection.moler_connection.data_received(
        command_output[1].encode("utf-8"), datetime.datetime.now())
    assert EventAwaiter.wait_for_all(timeout=2,
                                     events=[uptime_cmd, whoami_cmd]) is True
    ret_uptime = uptime_cmd.result()
    ret_whoami = whoami_cmd.result()
    assert ret_uptime == expected_result[0]
    assert ret_whoami == expected_result[1]
    assert CommandScheduler.is_waiting_for_execution(
        connection_observer=whoami_cmd) is False
コード例 #3
0
def test_terminal_cmd_whoami(terminal_connection):
    terminal = terminal_connection
    cmd = Whoami(connection=terminal)
    ret = cmd()
    assert 'USER' in ret
    assert ret['USER'] is not None
    assert getpass.getuser() == ret['USER']
コード例 #4
0
ファイル: test_cmd_whoami.py プロジェクト: wangliyao518/moler
def test_calling_whoami_returns_result(buffer_connection):
    from moler.cmd.unix.whoami import Whoami
    command_output, expected_result = command_output_and_expected_result()
    buffer_connection.remote_inject_response([command_output])
    whoami_cmd = Whoami(connection=buffer_connection.moler_connection)
    result = whoami_cmd()
    assert result == expected_result
コード例 #5
0
def test_terminal_timeout_next_command(terminal_connection):
    terminal = terminal_connection
    max_nr = 5
    for i in range(1, max_nr):
        cmd = Ping(connection=terminal, destination="127.0.0.1")
        with pytest.raises(CommandTimeout):
            cmd(timeout=0.3)
        cmd = Whoami(connection=terminal)
        ret = cmd()
        user = ret['USER']
        assert getpass.getuser() == user
コード例 #6
0
def test_terminal_cmd_whoami(terminal_connection):
    terminal = terminal_connection
    terminal.debug_hex_on_non_printable_chars = True
    terminal.debug_hex_on_all_chars = True
    cmd = Whoami(connection=terminal)
    ret = cmd()
    terminal.debug_hex_on_non_printable_chars = False
    terminal.debug_hex_on_all_chars = False
    assert 'USER' in ret
    assert ret['USER'] is not None
    assert getpass.getuser() == ret['USER']
コード例 #7
0
ファイル: test_cmd_sudo.py プロジェクト: nokia/moler
def test_failing_with_wrong_password(buffer_connection,
                                     command_output_password_fails):
    command_output = command_output_password_fails
    buffer_connection.remote_inject_response([command_output])
    cmd = Whoami(connection=buffer_connection.moler_connection)
    cmd_sudo = Sudo(connection=buffer_connection.moler_connection,
                    cmd_object=cmd,
                    password="******")
    with pytest.raises(CommandFailure):
        cmd_sudo(timeout=0.2)
    assert cmd_sudo._command_output_started is False
コード例 #8
0
def test_terminal_cmd_whoami_during_ping(terminal_connection):
    terminal = terminal_connection
    cmd_whoami = Whoami(connection=terminal)
    cmd_ping = Ping(connection=terminal, destination="127.0.0.1", options='-c 3')
    cmd_ping.start(timeout=3)
    cmd_whoami.start(timeout=5)
    ret_whoami = cmd_whoami.await_done(timeout=5)
    assert 'USER' in ret_whoami
    assert ret_whoami['USER'] is not None
    assert getpass.getuser() == ret_whoami['USER']
    ret_ping = cmd_ping.result()
    assert 'packets_transmitted' in ret_ping
    assert 3 == int(ret_ping['packets_transmitted'])
    assert 'packet_loss' in ret_ping
    assert 0 == int(ret_ping['packet_loss'])