예제 #1
0
async def test_send_with_invalid_policy_async(invalid_policy):
    client = EventHubProducerClient.from_connection_string(invalid_policy)
    async with client:
        with pytest.raises(ConnectError):
            batch = EventDataBatch()
            batch.add(EventData("test data"))
            await client.send_batch(batch)
예제 #2
0
async def test_non_existing_entity_sender_async(connection_str):
    client = EventHubProducerClient.from_connection_string(
        connection_str, eventhub_name="nemo")
    async with client:
        with pytest.raises(ConnectError):
            batch = EventDataBatch()
            batch.add(EventData("test data"))
            await client.send_batch(batch)
def test_event_data_batch():
    batch = EventDataBatch(max_size_in_bytes=100, partition_key="par")
    batch.add(EventData("A"))
    assert str(batch) == "EventDataBatch(max_size_in_bytes=100, partition_id=None, partition_key='par', event_count=1)"
    assert repr(batch) == "EventDataBatch(max_size_in_bytes=100, partition_id=None, partition_key='par', event_count=1)"
    assert batch.size_in_bytes == 97 and len(batch) == 1
    with pytest.raises(ValueError):
        batch.add(EventData("A"))
def test_send_batch_with_invalid_key(invalid_key):
    client = EventHubProducerClient.from_connection_string(invalid_key)
    try:
        with pytest.raises(ConnectError):
            batch = EventDataBatch()
            batch.add(EventData("test data"))
            client.send_batch(batch)
    finally:
        client.close()
def test_send_batch_with_invalid_key(live_eventhub):
    conn_str = live_eventhub["connection_str"].format(
        live_eventhub['hostname'], live_eventhub['key_name'], 'invalid',
        live_eventhub['event_hub'])
    client = EventHubProducerClient.from_connection_string(conn_str)
    with pytest.raises(ConnectError):
        batch = EventDataBatch()
        batch.add(EventData("test data"))
        client.send_batch(batch)
    client.close()
def test_send_batch_with_invalid_hostname(invalid_hostname):
    if sys.platform.startswith('darwin'):
        pytest.skip(
            "Skipping on OSX - it keeps reporting 'Unable to set external certificates' "
            "and blocking other tests")
    client = EventHubProducerClient.from_connection_string(invalid_hostname)
    with client:
        with pytest.raises(ConnectError):
            batch = EventDataBatch()
            batch.add(EventData("test data"))
            client.send_batch(batch)
예제 #7
0
def test_event_data_batch():
    batch = EventDataBatch(max_size_in_bytes=110, partition_key="par")
    batch.add(EventData("A"))
    assert str(
        batch
    ) == "EventDataBatch(max_size_in_bytes=110, partition_id=None, partition_key='par', event_count=1)"
    assert repr(
        batch
    ) == "EventDataBatch(max_size_in_bytes=110, partition_id=None, partition_key='par', event_count=1)"

    # In uamqp v1.2.8, the encoding size of a message has changed. delivery_count in message header is now set to 0
    # instead of None according to the C spec.
    # This uamqp change is transparent to EH users so it's not considered as a breaking change. However, it's breaking
    # the unit test here. The solution is to add backward compatibility in test.
    if version.parse(uamqp.__version__) >= version.parse("1.2.8"):
        assert batch.size_in_bytes == 101 and len(batch) == 1
    else:
        assert batch.size_in_bytes == 93 and len(batch) == 1
    with pytest.raises(ValueError):
        batch.add(EventData("A"))
def test_event_data_batch():
    batch = EventDataBatch(max_size_in_bytes=100, partition_key="par")
    batch.add(EventData("A"))
    assert batch.size_in_bytes == 89 and len(batch) == 1
    with pytest.raises(ValueError):
        batch.add(EventData("A"))