Example #1
0
def test_read_generic(mock_socket):
    sut = DoIPClient(test_ip, test_logical_address)
    mock_socket.rx_queue.append(unknown_mercedes_message)
    result = sut.read_doip()
    assert type(result) == ReservedMessage
    assert result.payload_type == 0xf010
    assert result.payload == unknown_mercedes_message[8:]
Example #2
0
def test_activation_with_alive_check(mock_socket):
    sut = DoIPClient(test_ip, test_logical_address)
    mock_socket.rx_queue.append(alive_check_request)
    mock_socket.rx_queue.append(successful_activation_response)
    result = sut.request_activation(0)
    assert result.client_logical_address == 0x0e00
    assert mock_socket.tx_queue[-1] == alive_check_response
Example #3
0
def test_request_entity_status(mock_socket):
    sut = DoIPClient(test_ip, test_logical_address)
    mock_socket.rx_queue.append(entity_status_response)
    result = sut.request_entity_status()
    assert mock_socket.tx_queue[-1] == entity_status_request
    assert result.node_type == 1
    assert result.max_concurrent_sockets == 16
    assert result.currently_open_sockets == 1
Example #4
0
def test_send_diagnostic_negative(mock_socket):
    sut = DoIPClient(test_ip, test_logical_address)
    mock_socket.rx_queue.append(diagnostic_negative_response)
    with pytest.raises(
            IOError,
            match=r'Diagnostic request rejected with negative acknowledge code'
    ):
        result = sut.send_diagnostic(bytearray([0, 1, 2]))
    assert mock_socket.tx_queue[-1] == diagnostic_request
Example #5
0
def test_send_good_activation_request_with_vm(mock_socket):
    sut = DoIPClient(test_ip, test_logical_address)
    mock_socket.rx_queue.append(successful_activation_response_with_vm)
    result = sut.request_activation(0, 0x01020304)
    assert mock_socket.tx_queue[-1] == activation_request_with_vm
    assert result.client_logical_address == 0x0e00
    assert result.logical_address == 55
    assert result.response_code == 16
    assert result.vm_specific == 0x04030201
Example #6
0
def test_request_vehicle_identification_with_vin(mock_socket):
    sut = DoIPClient(test_ip, test_logical_address)
    mock_socket.rx_queue.append(vehicle_identification_response)
    result = sut.request_vehicle_identification(vin='1' * 17)
    assert mock_socket.tx_queue[-1] == vehicle_identification_request_with_vin
    assert result.vin == '1' * 17
    assert result.logical_address == 0x1234
    assert result.eid == b'1' * 6
    assert result.gid == b'2' * 6
    assert result.further_action_required == 0x00
    assert result.vin_sync_status == 0x00
Example #7
0
def test_send_generic(mock_socket):
    sut = DoIPClient(test_ip, test_logical_address)
    result = sut.send_doip(0xf010, unknown_mercedes_message[8:])
    assert mock_socket.tx_queue[-1] == unknown_mercedes_message
Example #8
0
def test_failed_activation_constructor(mock_socket):
    # Swap out the default good response with a bad one
    mock_socket.rx_queue[-1] = unsuccessful_activation_response
    with pytest.raises(ConnectionRefusedError,
                       match=r'Activation Request failed with code'):
        sut = DoIPClient(test_ip, test_logical_address)
Example #9
0
def test_request_diagnostic_power_mode(mock_socket):
    sut = DoIPClient(test_ip, test_logical_address)
    mock_socket.rx_queue.append(diagnostic_power_mode_response)
    result = sut.request_diagnostic_power_mode()
    assert mock_socket.tx_queue[-1] == diagnostic_power_mode_request
    assert result.diagnostic_power_mode == 0x01
Example #10
0
def test_receive_diagnostic(mock_socket):
    sut = DoIPClient(test_ip, test_logical_address)
    mock_socket.rx_queue.append(diagnostic_result)
    result = sut.receive_diagnostic()
    assert result == bytearray([0, 1, 2, 3])
Example #11
0
def test_send_diagnostic_postive(mock_socket):
    sut = DoIPClient(test_ip, test_logical_address)
    mock_socket.rx_queue.append(diagnostic_positive_response)
    assert None == sut.send_diagnostic(bytearray([0, 1, 2]))
    assert mock_socket.tx_queue[-1] == diagnostic_request
Example #12
0
def test_request_alive_check(mock_socket):
    sut = DoIPClient(test_ip, test_logical_address)
    mock_socket.rx_queue.append(alive_check_response)
    result = sut.request_alive_check()
    assert result.source_address == 0x0e00
    assert mock_socket.tx_queue[-1] == alive_check_request
Example #13
0
def test_activation_with_nack(mock_socket):
    sut = DoIPClient(test_ip, test_logical_address)
    mock_socket.rx_queue.append(nack_response)
    with pytest.raises(IOError,
                       match=r"DoIP Negative Acknowledge. NACK Code: "):
        result = sut.request_activation(0)