Exemple #1
0
def test_sftp_returns_proper_command_string_pathname(buffer_connection):
    sftp_cmd = Sftp(connection=buffer_connection.moler_connection,
                    host="myhost.com",
                    user="******",
                    password='******',
                    source_path="/home/fred/homework.txt")
    assert "sftp [email protected]:/home/fred/homework.txt" == sftp_cmd.command_string
Exemple #2
0
def test_sftp_raises_ssh_error(buffer_connection,
                               command_output_and_expected_result_ssh_error):
    command_output, expected_result = command_output_and_expected_result_ssh_error
    buffer_connection.remote_inject_response([command_output])
    sftp_cmd = Sftp(connection=buffer_connection.moler_connection,
                    host='192.168.0.103',
                    user='******',
                    password='******')
    with pytest.raises(CommandFailure):
        sftp_cmd()
Exemple #3
0
def test_sftp_raises_permission_denied_error(
        buffer_connection,
        command_output_and_expected_result_permission_denied):
    command_output, expected_result = command_output_and_expected_result_permission_denied
    buffer_connection.remote_inject_response([command_output])
    sftp_cmd = Sftp(connection=buffer_connection.moler_connection,
                    host='192.168.0.102',
                    user='******',
                    password='******',
                    command='get animals/pets/dog /root/dog')
    with pytest.raises(CommandFailure):
        sftp_cmd()
Exemple #4
0
def test_sftp_raises_file_error_nol_such_file(
        buffer_connection, command_output_and_expected_result_no_such_file):
    command_output, expected_result = command_output_and_expected_result_no_such_file
    buffer_connection.remote_inject_response([command_output])
    sftp_cmd = Sftp(connection=buffer_connection.moler_connection,
                    host='192.168.0.102',
                    user='******',
                    password='******',
                    source_path='dog',
                    destination_path='/home/xyz/Work/dog')
    with pytest.raises(CommandFailure):
        sftp_cmd()
Exemple #5
0
def test_sftp_raises_authentication_failure(
        buffer_connection,
        command_output_and_expected_result_authentication_failure):
    command_output, expected_result = command_output_and_expected_result_authentication_failure
    buffer_connection.remote_inject_response([command_output])
    sftp_cmd = Sftp(connection=buffer_connection.moler_connection,
                    host='192.168.0.102',
                    user='******',
                    password='******',
                    source_path='cat',
                    destination_path='/home/xyz/Docs/cat')
    with pytest.raises(CommandFailure):
        sftp_cmd()
Exemple #6
0
def test_sftp_returns_proper_result(buffer_connection,
                                    command_output_and_expected_result):
    command_output, expected_result = command_output_and_expected_result
    buffer_connection.remote_inject_response([command_output])
    sftp_cmd = Sftp(connection=buffer_connection.moler_connection,
                    host='192.168.0.102',
                    user='******',
                    password='******',
                    options='-4',
                    source_path='bear',
                    destination_path='/home/xyz/Docs/bear')
    result = sftp_cmd()
    assert result == expected_result
Exemple #7
0
def test_sftp_returns_result_of_fetching_file_with_progress_bar(
        buffer_connection, command_output_and_expected_result_progress_bar):

    sftp_cmd = Sftp(connection=buffer_connection.moler_connection,
                    host='192.168.0.102',
                    user='******',
                    password='******',
                    source_path="debian-9.5.0-i386-netinst.iso")
    assert "sftp [email protected]:debian-9.5.0-i386-netinst.iso" == sftp_cmd.command_string
    command_output, expected_result = command_output_and_expected_result_progress_bar
    sftp_cmd.start()
    time.sleep(0.1)
    for output in command_output:
        buffer_connection.moler_connection.data_received(
            output.encode("utf-8"), datetime.datetime.now())
    sftp_cmd.await_done()
    assert sftp_cmd.current_ret == expected_result
    assert sftp_cmd.done() is True
Exemple #8
0
def test_sftp_returns_result_pwd_in_prompt(
        buffer_connection, command_output_and_expected_result_pwd_in_prompt):

    sftp_cmd = Sftp(connection=buffer_connection.moler_connection,
                    host='192.168.0.102',
                    user='******',
                    password='******',
                    command='pwd')
    assert "sftp [email protected]" == sftp_cmd.command_string
    command_output, expected_result = command_output_and_expected_result_pwd_in_prompt
    sftp_cmd.start()
    time.sleep(0.1)
    for output in command_output:
        buffer_connection.moler_connection.data_received(
            output.encode("utf-8"), datetime.datetime.now())
    sftp_cmd.await_done()
    assert sftp_cmd.current_ret == expected_result
    assert sftp_cmd.done() is True
Exemple #9
0
def test_sftp_no_result(buffer_connection,
                        command_output_and_expected_result_no_result):

    sftp_cmd = Sftp(connection=buffer_connection.moler_connection,
                    host='192.168.0.102',
                    user='******',
                    password='******',
                    command="mkdir pet",
                    no_result=True)
    assert "sftp [email protected]" == sftp_cmd.command_string
    command_output, expected_result = command_output_and_expected_result_no_result
    sftp_cmd.start(timeout=1)
    time.sleep(0.1)
    for output in command_output:
        buffer_connection.moler_connection.data_received(
            output.encode("utf-8"))
    assert sftp_cmd.current_ret == expected_result
    sftp_cmd.await_done()
    assert sftp_cmd.done() is True
Exemple #10
0
def test_sftp_raise_not_confirmed_connection(
        buffer_connection, command_output_and_expected_result_not_confirmed):

    sftp_cmd = Sftp(connection=buffer_connection.moler_connection,
                    host='192.168.0.102',
                    user='******',
                    password='******',
                    confirm_connection=False,
                    command="mkdir",
                    no_result=True)
    assert "sftp [email protected]" == sftp_cmd.command_string
    sftp_cmd.start()
    command_output, expected_result = command_output_and_expected_result_not_confirmed
    time.sleep(0.2)
    for output in command_output:
        buffer_connection.moler_connection.data_received(
            output.encode("utf-8"), datetime.datetime.now())
    with pytest.raises(CommandFailure):
        sftp_cmd.await_done(timeout=2)
Exemple #11
0
def test_sftp_returns_proper_command_string_user(buffer_connection):
    sftp_cmd = Sftp(connection=buffer_connection.moler_connection,
                    host="myhost.com",
                    user="******",
                    password='******')
    assert "sftp [email protected]" == sftp_cmd.command_string
Exemple #12
0
def test_sftp_returns_proper_command_string_options(buffer_connection):
    sftp_cmd = Sftp(connection=buffer_connection.moler_connection,
                    host="myhost.com",
                    password='******',
                    options='-4')
    assert "sftp -4 myhost.com" == sftp_cmd.command_string