def test_throws_exception_when_message_type_header_is_not_data():
    client_message = mock_client_message(mex_headers=build_mex_headers(
        message_type="REPORT"))

    message = MeshMessage(client_message)

    with pytest.raises(UnexpectedMessageType):
        message.validate()
def test_throws_exception_when_status_success_header_is_not_success():
    client_message = mock_client_message(mex_headers=build_mex_headers(
        status_success="ERROR"))

    message = MeshMessage(client_message)

    with pytest.raises(UnsuccessfulStatus):
        message.validate()
def test_throws_exception_when_status_event_header_is_not_transfer():
    client_message = mock_client_message(mex_headers=build_mex_headers(
        status_event="COLLECT"))

    message = MeshMessage(client_message)

    with pytest.raises(UnexpectedStatusEvent):
        message.validate()
def test_ignores_case_in_message_type_header(message_type_value):
    client_message = mock_client_message(mex_headers=build_mex_headers(
        message_type=message_type_value))
    try:
        message = MeshMessage(client_message)
        message.validate()
    except UnexpectedMessageType:
        pytest.fail(
            "UnexpectedMessageType was raised when it shouldn't have been")
def test_ignores_case_in_success_event_type_header(status_event_value):
    client_message = mock_client_message(mex_headers=build_mex_headers(
        status_event=status_event_value))
    try:
        message = MeshMessage(client_message)
        message.validate()
    except UnexpectedStatusEvent:
        pytest.fail(
            "UnexpectedStatusEvent was raised when it shouldn't have been")
def test_exception_raised_for_missing_validation_headers(missing_header_name):
    mex_headers = build_mex_headers()
    del mex_headers[missing_header_name]

    client_message = mock_client_message(mex_headers=mex_headers)

    message = MeshMessage(client_message)

    with pytest.raises(MissingMeshHeader) as exception_info:
        message.validate()

    exception = exception_info.value
    assert exception.header_name == missing_header_name
def test_exception_records_header_when_message_type_header_is_not_data():
    message_type_header_value = "REPORT"
    client_message = mock_client_message(mex_headers=build_mex_headers(
        message_type=message_type_header_value))

    message = MeshMessage(client_message)

    with pytest.raises(UnexpectedMessageType) as exception_info:
        message.validate()

    exception = exception_info.value
    assert exception.header_value == message_type_header_value
    assert exception.header_name == "messagetype"
    assert exception.expected_header_value == MESH_MESSAGE_TYPE_DATA
def test_exception_records_header_when_status_success_header_is_not_success():
    status_success_header_value = "ERROR"
    client_message = mock_client_message(mex_headers=build_mex_headers(
        status_success=status_success_header_value), )

    message = MeshMessage(client_message)

    with pytest.raises(UnsuccessfulStatus) as exception_info:
        message.validate()

    exception = exception_info.value
    assert exception.header_value == status_success_header_value
    assert exception.header_name == "statussuccess"
    assert exception.expected_header_value == MESH_STATUS_SUCCESS
def test_exception_records_header_when_status_event_header_is_not_transfer():
    status_event_header_value = "COLLECT"
    client_message = mock_client_message(mex_headers=build_mex_headers(
        status_event=status_event_header_value))

    message = MeshMessage(client_message)

    with pytest.raises(UnexpectedStatusEvent) as exception_info:
        message.validate()

    exception = exception_info.value
    assert exception.header_value == status_event_header_value
    assert exception.header_name == "statusevent"
    assert exception.expected_header_value == MESH_STATUS_EVENT_TRANSFER