def test_compose_message():
    """
    Test correct message composing.
    """
    message = b'message'
    topic = b'test topic'

    # Basic composing
    for serializer in AgentAddressSerializer.SERIALIZER_SIMPLE:
        serializer = AgentAddressSerializer(serializer)
        assert compose_message(message, topic, serializer) == topic + message
    for serializer in AgentAddressSerializer.SERIALIZER_SEPARATOR:
        serializer = AgentAddressSerializer(serializer)
        assert (compose_message(message, topic, serializer) == topic +
                TOPIC_SEPARATOR + message)

    # Raise with wrong serializer
    with pytest.raises(Exception):
        compose_message(message, topic, 'foo')
def test_compose_message():
    """
    Test correct message composing.
    """
    message = b'message'
    topic = b'test topic'

    # Basic composing
    for serializer in AgentAddressSerializer.SERIALIZER_SIMPLE:
        serializer = AgentAddressSerializer(serializer)
        assert compose_message(message, topic, serializer) \
            == topic + message
    for serializer in AgentAddressSerializer.SERIALIZER_SEPARATOR:
        serializer = AgentAddressSerializer(serializer)
        assert compose_message(message, topic, serializer) \
            == topic + TOPIC_SEPARATOR + message

    # Raise with wrong serializer
    with pytest.raises(Exception):
        compose_message(message, topic, 'foo')