예제 #1
0
def test_update_metric_serialization():
    """Test the serialization for 'update_metric' speech-act works."""
    msg = PrometheusMessage(
        message_id=2,
        dialogue_reference=(str(0), ""),
        target=1,
        performative=PrometheusMessage.Performative.UPDATE_METRIC,
        title="some_title",
        callable="some_update_function",
        value=1.0,
        labels={"label_key": "label_value"},
    )
    msg.to = "receiver"
    envelope = Envelope(to=msg.to, sender="sender", message=msg,)
    envelope_bytes = envelope.encode()

    actual_envelope = Envelope.decode(envelope_bytes)
    expected_envelope = envelope
    assert expected_envelope.to == actual_envelope.to
    assert expected_envelope.sender == actual_envelope.sender
    assert (
        expected_envelope.protocol_specification_id
        == actual_envelope.protocol_specification_id
    )
    assert expected_envelope.message != actual_envelope.message

    actual_msg = PrometheusMessage.serializer.decode(actual_envelope.message)
    actual_msg.to = actual_envelope.to
    actual_msg.sender = actual_envelope.sender
    expected_msg = msg
    assert expected_msg == actual_msg
예제 #2
0
def test_response_serialization():
    """Test the serialization for 'response' speech-act works."""
    msg = PrometheusMessage(
        message_id=1,
        dialogue_reference=(str(0), ""),
        target=0,
        performative=PrometheusMessage.Performative.RESPONSE,
        code=0,
        message="some_message",
    )
    msg.to = "receiver"
    envelope = Envelope(to=msg.to, sender="sender", message=msg,)
    envelope_bytes = envelope.encode()

    actual_envelope = Envelope.decode(envelope_bytes)
    expected_envelope = envelope
    assert expected_envelope.to == actual_envelope.to
    assert expected_envelope.sender == actual_envelope.sender
    assert (
        expected_envelope.protocol_specification_id
        == actual_envelope.protocol_specification_id
    )
    assert expected_envelope.message != actual_envelope.message

    actual_msg = PrometheusMessage.serializer.decode(actual_envelope.message)
    actual_msg.to = actual_envelope.to
    actual_msg.sender = actual_envelope.sender
    expected_msg = msg
    assert expected_msg == actual_msg