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
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
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)
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