def test_servicebus_received_message_repr_with_props():
    uamqp_received_message = uamqp.message.Message(
        body=b'data',
        annotations={
            _X_OPT_PARTITION_KEY: b'r_key',
            _X_OPT_VIA_PARTITION_KEY: b'r_via_key',
            _X_OPT_SCHEDULED_ENQUEUE_TIME: 123424566,
        },
        properties=uamqp.message.MessageProperties(
            message_id="id_message",
            absolute_expiry_time=100,
            content_type="content type",
            correlation_id="correlation",
            subject="github",
            group_id="id_session",
            reply_to="reply to",
            reply_to_group_id="reply to group"))
    received_message = ServiceBusReceivedMessage(
        message=uamqp_received_message,
        receiver=None,
    )
    assert "application_properties=None, session_id=id_session" in received_message.__repr__(
    )
    assert "content_type=content type, correlation_id=correlation, to=None, reply_to=reply to, reply_to_session_id=reply to group, subject=github" in received_message.__repr__(
    )
    assert "partition_key=r_key, scheduled_enqueue_time_utc" in received_message.__repr__(
    )
def test_servicebus_received_message_repr():
    uamqp_received_message = uamqp.message.Message(
        body=b'data',
        annotations={
            _X_OPT_PARTITION_KEY: b'r_key',
            _X_OPT_VIA_PARTITION_KEY: b'r_via_key',
            _X_OPT_SCHEDULED_ENQUEUE_TIME: 123424566,
        },
        properties=uamqp.message.MessageProperties()
    )
    received_message = ServiceBusReceivedMessage(uamqp_received_message, receiver=None)
    assert "application_properties=None, session_id=None" in received_message.__repr__()
    assert "content_type=None, correlation_id=None, to=None, reply_to=None, reply_to_session_id=None, subject=None,"
    assert "partition_key=r_key, scheduled_enqueue_time_utc" in received_message.__repr__()
def test_servicebus_received_state():
    uamqp_received_message = uamqp.message.Message(
        body=b'data',
        annotations={b"x-opt-message-state": 3},
        properties=uamqp.message.MessageProperties())
    received_message = ServiceBusReceivedMessage(uamqp_received_message,
                                                 receiver=None)
    assert received_message.state == 3

    uamqp_received_message = uamqp.message.Message(
        body=b'data',
        annotations={b"x-opt-message-state": 1},
        properties=uamqp.message.MessageProperties())
    received_message = ServiceBusReceivedMessage(uamqp_received_message,
                                                 receiver=None)
    assert received_message.state == ServiceBusMessageState.DEFERRED

    uamqp_received_message = uamqp.message.Message(
        body=b'data',
        annotations={},
        properties=uamqp.message.MessageProperties())
    received_message = ServiceBusReceivedMessage(uamqp_received_message,
                                                 receiver=None)
    assert received_message.state == ServiceBusMessageState.ACTIVE

    uamqp_received_message = uamqp.message.Message(
        body=b'data', properties=uamqp.message.MessageProperties())
    received_message = ServiceBusReceivedMessage(uamqp_received_message,
                                                 receiver=None)
    assert received_message.state == ServiceBusMessageState.ACTIVE

    uamqp_received_message = uamqp.message.Message(
        body=b'data',
        annotations={b"x-opt-message-state": 0},
        properties=uamqp.message.MessageProperties())
    received_message = ServiceBusReceivedMessage(uamqp_received_message,
                                                 receiver=None)
    assert received_message.state == ServiceBusMessageState.ACTIVE