diff --git a/sdk/eventgrid/azure-eventgrid/CHANGELOG.md b/sdk/eventgrid/azure-eventgrid/CHANGELOG.md index f8922f12c804..3dfd9d3ff71d 100644 --- a/sdk/eventgrid/azure-eventgrid/CHANGELOG.md +++ b/sdk/eventgrid/azure-eventgrid/CHANGELOG.md @@ -8,7 +8,6 @@ - `decode_cloud_event` is renamed to `deserialize_cloud_events`. - `decode_eventgrid_event` is renamed to `deserialize_eventgrid_events`. - The system events now exist in the `azure.eventgrid.systemevents` namespace instead of `azure.eventgrid.models` namespace. - - The `send` method in the `EventGridPubliserClient` is now replaced by the `send_events`. - `topic_hostname` is renamed to `endpoint` in the `EventGridPublisherClient`. - `data` is now a required param for `CloudEvent`. - `azure.eventgrid.generate_shared_access_signature` method is now renamed to `generate_sas`. diff --git a/sdk/eventgrid/azure-eventgrid/README.md b/sdk/eventgrid/azure-eventgrid/README.md index b32151a17250..69cfb853a7f9 100644 --- a/sdk/eventgrid/azure-eventgrid/README.md +++ b/sdk/eventgrid/azure-eventgrid/README.md @@ -96,7 +96,7 @@ event = EventGridEvent( credential = AzureKeyCredential(key) client = EventGridPublisherClient(endpoint, credential) -client.send_events(event) +client.send(event) ``` ### Send a Cloud Event @@ -120,7 +120,7 @@ event = CloudEvent( credential = AzureKeyCredential(key) client = EventGridPublisherClient(endpoint, credential) -client.send_events(event) +client.send(event) ``` ### Consume an Event Grid Event diff --git a/sdk/eventgrid/azure-eventgrid/azure/eventgrid/_helpers.py b/sdk/eventgrid/azure-eventgrid/azure/eventgrid/_helpers.py index 6031491d89d0..4d77076183f4 100644 --- a/sdk/eventgrid/azure-eventgrid/azure/eventgrid/_helpers.py +++ b/sdk/eventgrid/azure-eventgrid/azure/eventgrid/_helpers.py @@ -93,6 +93,14 @@ def _is_cloud_event(event): except TypeError: return False +def _is_eventgrid_event(event): + # type: (Any) -> bool + required = ('subject', 'event_type', 'data', 'data_version', 'id', 'event_time') + try: + return all([prop in event for prop in required]) + except TypeError: + return False + def _eventgrid_data_typecheck(event): try: data = event.get('data') diff --git a/sdk/eventgrid/azure-eventgrid/azure/eventgrid/_publisher_client.py b/sdk/eventgrid/azure-eventgrid/azure/eventgrid/_publisher_client.py index 4b197d171bc7..06cda52dc996 100644 --- a/sdk/eventgrid/azure-eventgrid/azure/eventgrid/_publisher_client.py +++ b/sdk/eventgrid/azure-eventgrid/azure/eventgrid/_publisher_client.py @@ -27,12 +27,13 @@ _get_endpoint_only_fqdn, _get_authentication_policy, _is_cloud_event, + _is_eventgrid_event, _eventgrid_data_typecheck ) from ._generated._event_grid_publisher_client import EventGridPublisherClient as EventGridPublisherClientImpl from ._policies import CloudEventDistributedTracingPolicy from ._version import VERSION -from ._generated.models import CloudEvent as InternalCloudEvent, EventGridEvent as InternalEventGridEvent +from ._generated.models import CloudEvent as InternalCloudEvent if TYPE_CHECKING: # pylint: disable=unused-import,ungrouped-imports @@ -98,11 +99,14 @@ def _policies(credential, **kwargs): return policies @distributed_trace - def send_events(self, events, **kwargs): + def send(self, events, **kwargs): # type: (SendType, Any) -> None """Sends event data to topic hostname specified during client initialization. + Multiple events can be published at once by seding a list of events. It is very + inefficient to loop the send method for each event instead of just using a list + and we highly recommend against it. - :param events: A list or an instance of CloudEvent/EventGridEvent/CustomEvent to be sent. + :param events: A list of CloudEvent/EventGridEvent/CustomEvent to be sent. :type events: SendType :keyword str content_type: The type of content to be used to send the events. Has default value "application/json; charset=utf-8" for EventGridEvents, @@ -113,27 +117,24 @@ def send_events(self, events, **kwargs): if not isinstance(events, list): events = cast(ListEventType, [events]) - if all(isinstance(e, CloudEvent) for e in events) or all(_is_cloud_event(e) for e in events): + if isinstance(events[0], CloudEvent) or _is_cloud_event(events[0]): try: events = [cast(CloudEvent, e)._to_generated(**kwargs) for e in events] # pylint: disable=protected-access except AttributeError: pass # means it's a dictionary kwargs.setdefault("content_type", "application/cloudevents-batch+json; charset=utf-8") - self._client.publish_cloud_event_events( + return self._client.publish_cloud_event_events( self._endpoint, cast(List[InternalCloudEvent], events), **kwargs ) - elif all(isinstance(e, EventGridEvent) for e in events) or all(isinstance(e, dict) for e in events): - kwargs.setdefault("content_type", "application/json; charset=utf-8") + kwargs.setdefault("content_type", "application/json; charset=utf-8") + if isinstance(events[0], EventGridEvent) or _is_eventgrid_event(events[0]): for event in events: _eventgrid_data_typecheck(event) - self._client.publish_events(self._endpoint, cast(List[InternalEventGridEvent], events), **kwargs) - elif all(isinstance(e, CustomEvent) for e in events): - serialized_events = [dict(e) for e in events] # type: ignore - self._client.publish_custom_event_events(self._endpoint, cast(List, serialized_events), **kwargs) - else: - raise ValueError("Event schema is not correct.") + elif isinstance(events[0], CustomEvent): + events = [dict(e) for e in events] # type: ignore + return self._client.publish_custom_event_events(self._endpoint, cast(List, events), **kwargs) def close(self): # type: () -> None diff --git a/sdk/eventgrid/azure-eventgrid/azure/eventgrid/aio/_publisher_client_async.py b/sdk/eventgrid/azure-eventgrid/azure/eventgrid/aio/_publisher_client_async.py index a687c3916860..ac58142b78d2 100644 --- a/sdk/eventgrid/azure-eventgrid/azure/eventgrid/aio/_publisher_client_async.py +++ b/sdk/eventgrid/azure-eventgrid/azure/eventgrid/aio/_publisher_client_async.py @@ -28,10 +28,11 @@ _get_endpoint_only_fqdn, _get_authentication_policy, _is_cloud_event, + _is_eventgrid_event, _eventgrid_data_typecheck ) from .._generated.aio import EventGridPublisherClient as EventGridPublisherClientAsync -from .._generated.models import CloudEvent as InternalCloudEvent, EventGridEvent as InternalEventGridEvent +from .._generated.models import CloudEvent as InternalCloudEvent from .._version import VERSION SendType = Union[ @@ -98,13 +99,16 @@ def _policies( return policies @distributed_trace_async - async def send_events( + async def send( self, events: SendType, **kwargs: Any) -> None: """Sends event data to topic hostname specified during client initialization. + Multiple events can be published at once by seding a list of events. It is very + inefficient to loop the send method for each event instead of just using a list + and we highly recommend against it. - :param events: A list or an instance of CloudEvent/EventGridEvent/CustomEvent to be sent. + :param events: A list of CloudEvent/EventGridEvent/CustomEvent to be sent. :type events: SendType :keyword str content_type: The type of content to be used to send the events. Has default value "application/json; charset=utf-8" for EventGridEvents, @@ -115,37 +119,24 @@ async def send_events( if not isinstance(events, list): events = cast(ListEventType, [events]) - if all(isinstance(e, CloudEvent) for e in events) or all(_is_cloud_event(e) for e in events): + if isinstance(events[0], CloudEvent) or _is_cloud_event(events[0]): try: - events = [ - cast(CloudEvent, e)._to_generated(**kwargs) for e in events # pylint: disable=protected-access - ] + events = [cast(CloudEvent, e)._to_generated(**kwargs) for e in events] # pylint: disable=protected-access except AttributeError: pass # means it's a dictionary kwargs.setdefault("content_type", "application/cloudevents-batch+json; charset=utf-8") - await self._client.publish_cloud_event_events( + return await self._client.publish_cloud_event_events( self._endpoint, cast(List[InternalCloudEvent], events), **kwargs ) - elif all(isinstance(e, EventGridEvent) for e in events) or all(isinstance(e, dict) for e in events): - kwargs.setdefault("content_type", "application/json; charset=utf-8") + kwargs.setdefault("content_type", "application/json; charset=utf-8") + if isinstance(events[0], EventGridEvent) or _is_eventgrid_event(events[0]): for event in events: _eventgrid_data_typecheck(event) - await self._client.publish_events( - self._endpoint, - cast(List[InternalEventGridEvent], events), - **kwargs - ) - elif all(isinstance(e, CustomEvent) for e in events): - serialized_events = [dict(e) for e in events] # type: ignore - await self._client.publish_custom_event_events( - self._endpoint, - cast(List, serialized_events), - **kwargs - ) - else: - raise ValueError("Event schema is not correct.") + elif isinstance(events[0], CustomEvent): + events = [dict(e) for e in events] # type: ignore + return await self._client.publish_custom_event_events(self._endpoint, cast(List, events), **kwargs) async def __aenter__(self) -> "EventGridPublisherClient": await self._client.__aenter__() diff --git a/sdk/eventgrid/azure-eventgrid/migration_guide.md b/sdk/eventgrid/azure-eventgrid/migration_guide.md index 66a8d8154b19..7f6e285f5403 100644 --- a/sdk/eventgrid/azure-eventgrid/migration_guide.md +++ b/sdk/eventgrid/azure-eventgrid/migration_guide.md @@ -79,7 +79,7 @@ The `publish_events` API is replaced with `send` in v2.0. Additionally, `send` A | In v1.3 | Equivalent in v2.0 | Sample | |---|---|---| -|`EventGridClient(credentials).publish_events(topic_hostname, events)`|`EventGridPublisherClient(endpoint, credential).send_events(events)`|[Sample for client construction](https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs5_publish_events_using_cloud_events_1.0_schema.py)| +|`EventGridClient(credentials).publish_events(topic_hostname, events)`|`EventGridPublisherClient(endpoint, credential).send(events)`|[Sample for client construction](https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs5_publish_events_using_cloud_events_1.0_schema.py)| ### Consuming Events diff --git a/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs1_publish_custom_events_to_a_topic.py b/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs1_publish_custom_events_to_a_topic.py index c0e8994641f3..b91cb5a9f0cb 100644 --- a/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs1_publish_custom_events_to_a_topic.py +++ b/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs1_publish_custom_events_to_a_topic.py @@ -24,7 +24,7 @@ credential = AzureKeyCredential(topic_key) client = EventGridPublisherClient(endpoint, credential) -client.send_events([ +client.send([ EventGridEvent( event_type="Contoso.Items.ItemReceived", data={ diff --git a/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs1b_publish_custom_events_to_a_topic_with_signature.py b/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs1b_publish_custom_events_to_a_topic_with_signature.py index 84bd8d0ce325..dbee0f3ed381 100644 --- a/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs1b_publish_custom_events_to_a_topic_with_signature.py +++ b/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs1b_publish_custom_events_to_a_topic_with_signature.py @@ -27,7 +27,7 @@ credential = AzureSasCredential(signature) client = EventGridPublisherClient(endpoint, credential) -client.send_events([ +client.send([ EventGridEvent( event_type="Contoso.Items.ItemReceived", data={ diff --git a/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs2_publish_custom_events_to_a_domain_topic.py b/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs2_publish_custom_events_to_a_domain_topic.py index 9a7e600bcbbf..b97e03435278 100644 --- a/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs2_publish_custom_events_to_a_domain_topic.py +++ b/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs2_publish_custom_events_to_a_domain_topic.py @@ -24,7 +24,7 @@ credential = AzureKeyCredential(domain_key) client = EventGridPublisherClient(domain_hostname, credential) -client.send_events([ +client.send([ EventGridEvent( topic="MyCustomDomainTopic1", event_type="Contoso.Items.ItemReceived", diff --git a/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs5_publish_events_using_cloud_events_1.0_schema.py b/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs5_publish_events_using_cloud_events_1.0_schema.py index 026376e09e13..94649fe65502 100644 --- a/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs5_publish_events_using_cloud_events_1.0_schema.py +++ b/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs5_publish_events_using_cloud_events_1.0_schema.py @@ -24,7 +24,7 @@ credential = AzureKeyCredential(topic_key) client = EventGridPublisherClient(endpoint, credential) -client.send_events([ +client.send([ CloudEvent( type="Contoso.Items.ItemReceived", source="/contoso/items", diff --git a/sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_cloud_events_to_custom_topic_sample.py b/sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_cloud_events_to_custom_topic_sample.py index 9678194911fc..91ab801e9d5a 100644 --- a/sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_cloud_events_to_custom_topic_sample.py +++ b/sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_cloud_events_to_custom_topic_sample.py @@ -47,7 +47,7 @@ def publish_event(): event_list.append(event) # publish list of events - client.send_events(event_list) + client.send(event_list) print("Batch of size {} published".format(len(event_list))) time.sleep(randint(1, 5)) diff --git a/sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_cloud_events_to_domain_topic_sample.py b/sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_cloud_events_to_domain_topic_sample.py index a9040f7c5ba9..a83ec797d273 100644 --- a/sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_cloud_events_to_domain_topic_sample.py +++ b/sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_cloud_events_to_domain_topic_sample.py @@ -51,7 +51,7 @@ def publish_event(): event_list.append(event) # publish list of events - client.send_events(event_list) + client.send(event_list) print("Batch of size {} published".format(len(event_list))) time.sleep(randint(1, 5)) diff --git a/sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_custom_schema_events_to_topic_sample.py b/sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_custom_schema_events_to_topic_sample.py index 687f20352819..553060c28cb9 100644 --- a/sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_custom_schema_events_to_topic_sample.py +++ b/sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_custom_schema_events_to_topic_sample.py @@ -51,7 +51,7 @@ def publish_event(): event_list.append(event) # publish list of events - client.send_events(event_list) + client.send(event_list) print("Batch of size {} published".format(len(event_list))) time.sleep(randint(1, 5)) diff --git a/sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_event_grid_events_to_custom_topic_sample.py b/sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_event_grid_events_to_custom_topic_sample.py index b363c8b49db5..0fcca3d173b7 100644 --- a/sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_event_grid_events_to_custom_topic_sample.py +++ b/sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_event_grid_events_to_custom_topic_sample.py @@ -48,7 +48,7 @@ def publish_event(): event_list.append(event) # publish list of events - client.send_events(event_list) + client.send(event_list) print("Batch of size {} published".format(len(event_list))) time.sleep(randint(1, 5)) diff --git a/sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_with_shared_access_signature_sample.py b/sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_with_shared_access_signature_sample.py index dafddd78680f..f08a7d2345a4 100644 --- a/sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_with_shared_access_signature_sample.py +++ b/sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_with_shared_access_signature_sample.py @@ -51,7 +51,7 @@ def publish_event(): event_list.append(event) # publish list of events - client.send_events(event_list) + client.send(event_list) print("Batch of size {} published".format(len(event_list))) time.sleep(randint(1, 5)) diff --git a/sdk/eventgrid/azure-eventgrid/tests/test_eg_publisher_client.py b/sdk/eventgrid/azure-eventgrid/tests/test_eg_publisher_client.py index 490b94a57175..3f578a4889f3 100644 --- a/sdk/eventgrid/azure-eventgrid/tests/test_eg_publisher_client.py +++ b/sdk/eventgrid/azure-eventgrid/tests/test_eg_publisher_client.py @@ -8,7 +8,8 @@ import sys import os import pytest -from datetime import timedelta +import uuid +from datetime import datetime, timedelta from msrest.serialization import UTC import datetime as dt @@ -36,7 +37,7 @@ def test_send_event_grid_event_data_dict(self, resource_group, eventgrid_topic, event_type="Sample.EventGrid.Event", data_version="2.0" ) - client.send_events(eg_event) + client.send(eg_event) @CachedResourceGroupPreparer(name_prefix='eventgridtest') @CachedEventGridTopicPreparer(name_prefix='eventgridtest') @@ -55,7 +56,7 @@ def test_send_event_grid_event_data_as_list(self, resource_group, eventgrid_topi event_type="Sample.EventGrid.Event", data_version="2.0" ) - client.send_events([eg_event1, eg_event2]) + client.send([eg_event1, eg_event2]) @CachedResourceGroupPreparer(name_prefix='eventgridtest') @CachedEventGridTopicPreparer(name_prefix='eventgridtest') @@ -68,7 +69,7 @@ def test_send_event_grid_event_data_str(self, resource_group, eventgrid_topic, e event_type="Sample.EventGrid.Event", data_version="2.0" ) - client.send_events(eg_event) + client.send(eg_event) @CachedResourceGroupPreparer(name_prefix='eventgridtest') @CachedEventGridTopicPreparer(name_prefix='eventgridtest') @@ -82,7 +83,7 @@ def test_send_event_grid_event_data_bytes(self, resource_group, eventgrid_topic, data_version="2.0" ) with pytest.raises(TypeError, match="Data in EventGridEvent cannot be bytes*"): - client.send_events(eg_event) + client.send(eg_event) @CachedResourceGroupPreparer(name_prefix='eventgridtest') @CachedEventGridTopicPreparer(name_prefix='eventgridtest') @@ -93,10 +94,12 @@ def test_send_event_grid_event_dict_data_bytes(self, resource_group, eventgrid_t "subject":"sample", "data":b"eventgridevent", "event_type":"Sample.EventGrid.Event", - "data_version":"2.0" + "data_version":"2.0", + "id": uuid.uuid4(), + "event_time": datetime.now() } with pytest.raises(TypeError, match="Data in EventGridEvent cannot be bytes*"): - client.send_events(eg_event) + client.send(eg_event) @CachedResourceGroupPreparer(name_prefix='eventgridtest') @CachedEventGridTopicPreparer(name_prefix='cloudeventgridtest') @@ -108,7 +111,7 @@ def test_send_cloud_event_data_dict(self, resource_group, eventgrid_topic, event data = {"sample": "cloudevent"}, type="Sample.Cloud.Event" ) - client.send_events(cloud_event) + client.send(cloud_event) @CachedResourceGroupPreparer(name_prefix='eventgridtest') @@ -121,7 +124,7 @@ def test_send_cloud_event_data_none(self, resource_group, eventgrid_topic, event data = None, type="Sample.Cloud.Event" ) - client.send_events(cloud_event) + client.send(cloud_event) @CachedResourceGroupPreparer(name_prefix='eventgridtest') @CachedEventGridTopicPreparer(name_prefix='cloudeventgridtest') @@ -133,7 +136,7 @@ def test_send_cloud_event_data_str(self, resource_group, eventgrid_topic, eventg data = "cloudevent", type="Sample.Cloud.Event" ) - client.send_events(cloud_event) + client.send(cloud_event) @CachedResourceGroupPreparer(name_prefix='eventgridtest') @CachedEventGridTopicPreparer(name_prefix='cloudeventgridtest') @@ -145,7 +148,7 @@ def test_send_cloud_event_data_bytes(self, resource_group, eventgrid_topic, even data = b"cloudevent", type="Sample.Cloud.Event" ) - client.send_events(cloud_event) + client.send(cloud_event) @CachedResourceGroupPreparer(name_prefix='eventgridtest') @CachedEventGridTopicPreparer(name_prefix='cloudeventgridtest') @@ -157,7 +160,7 @@ def test_send_cloud_event_data_as_list(self, resource_group, eventgrid_topic, ev data = "cloudevent", type="Sample.Cloud.Event" ) - client.send_events([cloud_event]) + client.send([cloud_event]) @CachedResourceGroupPreparer(name_prefix='eventgridtest') @CachedEventGridTopicPreparer(name_prefix='cloudeventgridtest') @@ -173,7 +176,7 @@ def test_send_cloud_event_data_with_extensions(self, resource_group, eventgrid_t 'extension':'hello' } ) - client.send_events([cloud_event]) + client.send([cloud_event]) internal = cloud_event._to_generated().serialize() assert 'reason_code' in internal assert 'extension' in internal @@ -191,7 +194,7 @@ def test_send_cloud_event_dict(self, resource_group, eventgrid_topic, eventgrid_ "data": "cloudevent", "type": "Sample.Cloud.Event" } - client.send_events(cloud_event1) + client.send(cloud_event1) @CachedResourceGroupPreparer(name_prefix='eventgridtest') @CachedEventGridTopicPreparer(name_prefix='eventgridtest') @@ -206,7 +209,7 @@ def test_send_signature_credential(self, resource_group, eventgrid_topic, eventg event_type="Sample.EventGrid.Event", data_version="2.0" ) - client.send_events(eg_event) + client.send(eg_event) @CachedResourceGroupPreparer(name_prefix='eventgridtest') @CachedEventGridTopicPreparer(name_prefix='customeventgridtest') @@ -223,7 +226,7 @@ def test_send_custom_schema_event(self, resource_group, eventgrid_topic, eventgr "customData": "sample data" } ) - client.send_events(custom_event) + client.send(custom_event) @CachedResourceGroupPreparer(name_prefix='eventgridtest') @CachedEventGridTopicPreparer(name_prefix='customeventgridtest') @@ -250,7 +253,7 @@ def test_send_custom_schema_event_as_list(self, resource_group, eventgrid_topic, "customData": "sample data 2" } ) - client.send_events([custom_event1, custom_event2]) + client.send([custom_event1, custom_event2]) def test_send_throws_with_bad_credential(self): bad_credential = "I am a bad credential" diff --git a/sdk/eventgrid/azure-eventgrid/tests/test_eg_publisher_client_async.py b/sdk/eventgrid/azure-eventgrid/tests/test_eg_publisher_client_async.py index 322ca8d4cf0f..aca20a7c35e5 100644 --- a/sdk/eventgrid/azure-eventgrid/tests/test_eg_publisher_client_async.py +++ b/sdk/eventgrid/azure-eventgrid/tests/test_eg_publisher_client_async.py @@ -39,7 +39,7 @@ async def test_send_event_grid_event_data_dict(self, resource_group, eventgrid_t event_type="Sample.EventGrid.Event", data_version="2.0" ) - await client.send_events(eg_event) + await client.send(eg_event) @CachedResourceGroupPreparer(name_prefix='eventgridtest') @@ -60,7 +60,7 @@ async def test_send_event_grid_event_data_as_list(self, resource_group, eventgri event_type="Sample.EventGrid.Event", data_version="2.0" ) - await client.send_events([eg_event1, eg_event2]) + await client.send([eg_event1, eg_event2]) @CachedResourceGroupPreparer(name_prefix='eventgridtest') @@ -75,7 +75,7 @@ async def test_send_event_grid_event_data_str(self, resource_group, eventgrid_to event_type="Sample.EventGrid.Event", data_version="2.0" ) - await client.send_events(eg_event) + await client.send(eg_event) @CachedResourceGroupPreparer(name_prefix='eventgridtest') @CachedEventGridTopicPreparer(name_prefix='eventgridtest') @@ -90,7 +90,7 @@ async def test_send_event_grid_event_data_bytes(self, resource_group, eventgrid_ data_version="2.0" ) with pytest.raises(TypeError, match="Data in EventGridEvent cannot be bytes*"): - await client.send_events(eg_event) + await client.send(eg_event) @CachedResourceGroupPreparer(name_prefix='eventgridtest') @CachedEventGridTopicPreparer(name_prefix='eventgridtest') @@ -105,7 +105,7 @@ async def test_send_event_grid_event_dict_data_bytes(self, resource_group, event "data_version":"2.0" } with pytest.raises(TypeError, match="Data in EventGridEvent cannot be bytes*"): - await client.send_events(eg_event) + await client.send(eg_event) @CachedResourceGroupPreparer(name_prefix='eventgridtest') @CachedEventGridTopicPreparer(name_prefix='cloudeventgridtest') @@ -118,7 +118,7 @@ async def test_send_cloud_event_data_dict(self, resource_group, eventgrid_topic, data = {"sample": "cloudevent"}, type="Sample.Cloud.Event" ) - await client.send_events(cloud_event) + await client.send(cloud_event) @CachedResourceGroupPreparer(name_prefix='eventgridtest') @@ -132,7 +132,7 @@ async def test_send_cloud_event_data_str(self, resource_group, eventgrid_topic, data = "cloudevent", type="Sample.Cloud.Event" ) - await client.send_events(cloud_event) + await client.send(cloud_event) @CachedResourceGroupPreparer(name_prefix='eventgridtest') @CachedEventGridTopicPreparer(name_prefix='cloudeventgridtest') @@ -145,7 +145,7 @@ async def test_send_cloud_event_data_bytes(self, resource_group, eventgrid_topic data = b"cloudevent", type="Sample.Cloud.Event" ) - await client.send_events(cloud_event) + await client.send(cloud_event) @CachedResourceGroupPreparer(name_prefix='eventgridtest') @CachedEventGridTopicPreparer(name_prefix='cloudeventgridtest') @@ -158,7 +158,7 @@ async def test_send_cloud_event_data_as_list(self, resource_group, eventgrid_top data = "cloudevent", type="Sample.Cloud.Event" ) - await client.send_events([cloud_event]) + await client.send([cloud_event]) @CachedResourceGroupPreparer(name_prefix='eventgridtest') @@ -176,7 +176,7 @@ async def test_send_cloud_event_data_with_extensions(self, resource_group, event 'extension':'hello' } ) - await client.send_events([cloud_event]) + await client.send([cloud_event]) internal = cloud_event._to_generated().serialize() assert 'reason_code' in internal assert 'extension' in internal @@ -196,7 +196,7 @@ async def test_send_cloud_event_dict(self, resource_group, eventgrid_topic, even "data": "cloudevent", "type": "Sample.Cloud.Event" } - await client.send_events(cloud_event1) + await client.send(cloud_event1) @CachedResourceGroupPreparer(name_prefix='eventgridtest') @CachedEventGridTopicPreparer(name_prefix='cloudeventgridtest') @@ -209,7 +209,7 @@ async def test_send_cloud_event_data_none(self, resource_group, eventgrid_topic, data = None, type="Sample.Cloud.Event" ) - await client.send_events(cloud_event) + await client.send(cloud_event) @CachedResourceGroupPreparer(name_prefix='eventgridtest') @CachedEventGridTopicPreparer(name_prefix='eventgridtest') @@ -225,7 +225,7 @@ async def test_send_signature_credential(self, resource_group, eventgrid_topic, event_type="Sample.EventGrid.Event", data_version="2.0" ) - await client.send_events(eg_event) + await client.send(eg_event) @CachedResourceGroupPreparer(name_prefix='eventgridtest') @@ -244,7 +244,7 @@ async def test_send_custom_schema_event(self, resource_group, eventgrid_topic, e "customData": "sample data" } ) - await client.send_events(custom_event) + await client.send(custom_event) @CachedResourceGroupPreparer(name_prefix='eventgridtest') @@ -273,7 +273,7 @@ async def test_send_custom_schema_event_as_list(self, resource_group, eventgrid_ "customData": "sample data 2" } ) - await client.send_events([custom_event1, custom_event2]) + await client.send([custom_event1, custom_event2]) @CachedResourceGroupPreparer(name_prefix='eventgridtest') @CachedEventGridTopicPreparer(name_prefix='cloudeventgridtest') @@ -287,4 +287,4 @@ async def test_send_and_close_async_session(self, resource_group, eventgrid_topi data = "cloudevent", type="Sample.Cloud.Event" ) - await client.send_events(cloud_event) \ No newline at end of file + await client.send(cloud_event)