def test_SendMessage_SimpleMessage_SocketCalled(self, mock_socket): rc_instance = remote_console.RemoteConsole() msg = bytearray(0) rc_instance._send_message(msg) assert mock_socket.sendall.called_once_with(msg)
def test_CreateMessage_SimpleNoopMessage_MessageCreated(self): rc_instance = remote_console.RemoteConsole() expected = bytearray(b'0foo\x00') actual = rc_instance._create_message( remote_console.CONSOLE_MESSAGE_MAP['NOOP'], 'foo') assert expected == actual
def test_Pump_CheckSendMessage_AssertSendMessageCalled(self): rc_instance = remote_console.RemoteConsole() rc_instance._send_message = mock.MagicMock() rc_instance._handle_message = mock.MagicMock() rc_instance._handle_message.side_effect = Exception( ) # to force except path in pump() rc_instance.pump() rc_instance._send_message.assert_called_once()
def test_HandleMessage_AutoCompleteListDone_ReadySet(self): rc_instance = remote_console.RemoteConsole() rc_instance.on_display = mock.MagicMock() rc_instance.ready = mock.MagicMock() msg = '70' # socket.recv returns string, not byte array. 7 is AUTOCOMPLETELISTDONE rc_instance._handle_message(msg) rc_instance.on_display.assert_not_called() rc_instance.ready.set.assert_called_once()
def test_HandleMessage_AutoCompleteList_NoOp(self): rc_instance = remote_console.RemoteConsole() rc_instance.on_display = mock.MagicMock() rc_instance.ready = mock.MagicMock() msg = b'60' # in python3 socket.recv returns byte array. 6 is AUTOCOMPLETELIST rc_instance._handle_message(msg) rc_instance.on_display.assert_not_called() rc_instance.ready.set.assert_not_called()
def test_HandleMessage_LogMessage_HandlerSet(self): rc_instance = remote_console.RemoteConsole() rc_instance.on_display = mock.MagicMock() rc_instance.ready = mock.MagicMock() mock_evt_handler = mock.MagicMock() msg = '2foo warning0' # socket.recv returns string, not byte array. 2 is LOGMESSAGED rc_instance.handlers['foo warning'] = mock_evt_handler rc_instance._handle_message(msg) rc_instance.on_display.assert_called_once_with('foo warning') mock_evt_handler.set.assert_called_once() assert 'foo warning' not in rc_instance.handlers.keys() rc_instance.ready.set.assert_not_called()
def test_SendCommand_CheckMessageCreated_AssertCreateMessageCalled( self, mock_create_message): rc_instance = remote_console.RemoteConsole() rc_instance.send_command("testCommand") mock_create_message.assert_called_once()
def test_ExpectLogLine_CheckIfEventLogged_DoesNotReturnFalse(self): rc_instance = remote_console.RemoteConsole() result = rc_instance.expect_log_line("test") assert result
def test_Stop_SocketCommand_SocketCalledForShutdownAndClose( self, mock_socket): rc_instance = remote_console.RemoteConsole() rc_instance.stop() mock_socket.assert_called_once()
def test_Start_SocketConnection_SocketCalledOnce(self, mock_socket): rc_instance = remote_console.RemoteConsole() rc_instance.start() mock_socket.assert_called_once()
def test_Start_CheckDefaultConnection_ConnectionTrue(self): rc_instance = remote_console.RemoteConsole() rc_instance.start() assert rc_instance.connected