diff --git a/sdk/eventgrid/azure-eventgrid/assets.json b/sdk/eventgrid/azure-eventgrid/assets.json index d7404dd2fdd0..7d595dc4f34e 100644 --- a/sdk/eventgrid/azure-eventgrid/assets.json +++ b/sdk/eventgrid/azure-eventgrid/assets.json @@ -2,5 +2,5 @@ "AssetsRepo": "Azure/azure-sdk-assets", "AssetsRepoPrefixPath": "python", "TagPrefix": "python/eventgrid/azure-eventgrid", - "Tag": "python/eventgrid/azure-eventgrid_f155c8ac2d" + "Tag": "python/eventgrid/azure-eventgrid_3ae14bceff" } diff --git a/sdk/eventgrid/azure-eventgrid/tests/conftest.py b/sdk/eventgrid/azure-eventgrid/tests/conftest.py index d95ebca3e613..dffb2825e3ba 100644 --- a/sdk/eventgrid/azure-eventgrid/tests/conftest.py +++ b/sdk/eventgrid/azure-eventgrid/tests/conftest.py @@ -51,7 +51,7 @@ def add_sanitizers(test_proxy): add_remove_header_sanitizer(headers="aeg-sas-key, aeg-sas-token, aeg-channel-name") add_general_regex_sanitizer( value="fakeresource", - regex="(?<=\\/\\/)[.*]+(?=\\.eastus-1\\.eventgrid\\.azure\\.net/api/events)", + regex="(?<=\\/\\/)[a-z-]+(?=\\.eastus-1\\.eventgrid\\.azure\\.net/api/events)" ) add_oauth_response_sanitizer() diff --git a/sdk/eventgrid/azure-eventgrid/tests/eventgrid_preparer.py b/sdk/eventgrid/azure-eventgrid/tests/eventgrid_preparer.py index 6b8fcb2b73fc..b92b99686ae8 100644 --- a/sdk/eventgrid/azure-eventgrid/tests/eventgrid_preparer.py +++ b/sdk/eventgrid/azure-eventgrid/tests/eventgrid_preparer.py @@ -1,5 +1,5 @@ import functools -from devtools_testutils import PowerShellPreparer, EnvironmentVariableLoader +from devtools_testutils import EnvironmentVariableLoader from azure.mgmt.eventgrid.models import ( Topic, @@ -9,8 +9,8 @@ JsonFieldWithDefault, ) -EVENTGRID_TOPIC_PARAM = "eventgrid_topic" -EVENTGRID_TOPIC_LOCATION = "eastus" +EVENTGRID_TOPIC_PARAM = 'eventgrid_topic' +EVENTGRID_TOPIC_LOCATION = 'westus' CLOUD_EVENT_SCHEMA = InputSchema.cloud_event_schema_v1_0 CUSTOM_EVENT_SCHEMA = InputSchema.custom_event_schema ID_JSON_FIELD = JsonField(source_field="customId") @@ -29,8 +29,7 @@ ) EventGridPreparer = functools.partial( - PowerShellPreparer, - "eventgrid", + EnvironmentVariableLoader, "eventgrid", eventgrid_topic_endpoint="https://fakeresource.eastus-1.eventgrid.azure.net/api/events", eventgrid_topic_key="fakekeyfakekeyfakekeyfakekeyfakekeyfakekeyA=", eventgrid_domain_endpoint="https://fakeresource.eastus-1.eventgrid.azure.net/api/events", diff --git a/sdk/eventgrid/azure-eventgrid/tests/test_cncf_events.py b/sdk/eventgrid/azure-eventgrid/tests/test_cncf_events.py index e7052226447d..06b2fc949305 100644 --- a/sdk/eventgrid/azure-eventgrid/tests/test_cncf_events.py +++ b/sdk/eventgrid/azure-eventgrid/tests/test_cncf_events.py @@ -1,7 +1,6 @@ import json from devtools_testutils import AzureRecordedTestCase, recorded_by_proxy -from azure.core.credentials import AzureKeyCredential, AzureSasCredential from azure.eventgrid import EventGridPublisherClient from cloudevents.http import CloudEvent @@ -18,7 +17,7 @@ def create_eg_publisher_client(self, endpoint): @EventGridPreparer() @recorded_by_proxy - def test_send_cncf_data_dict(self, eventgrid_cloud_event_topic_endpoint): + def test_send_cloud_event_data_dict(self, eventgrid_cloud_event_topic_endpoint): client = self.create_eg_publisher_client(eventgrid_cloud_event_topic_endpoint) attributes = { "type": "com.example.sampletype1", @@ -38,7 +37,7 @@ def callback(request): @EventGridPreparer() @recorded_by_proxy - def test_send_cncf_data_base64_using_data(self, eventgrid_cloud_event_topic_endpoint): + def test_send_cloud_event_data_base64_using_data(self, eventgrid_cloud_event_topic_endpoint): client = self.create_eg_publisher_client(eventgrid_cloud_event_topic_endpoint) attributes = { "type": "com.example.sampletype1", @@ -56,7 +55,7 @@ def callback(request): @EventGridPreparer() @recorded_by_proxy - def test_send_cncf_data_none(self, eventgrid_cloud_event_topic_endpoint): + def test_send_cloud_event_data_none(self, eventgrid_cloud_event_topic_endpoint): client = self.create_eg_publisher_client(eventgrid_cloud_event_topic_endpoint) attributes = { "type": "com.example.sampletype1", @@ -68,7 +67,7 @@ def test_send_cncf_data_none(self, eventgrid_cloud_event_topic_endpoint): @EventGridPreparer() @recorded_by_proxy - def test_send_cncf_data_str(self, eventgrid_cloud_event_topic_endpoint): + def test_send_cloud_event_data_str(self, eventgrid_cloud_event_topic_endpoint): client = self.create_eg_publisher_client(eventgrid_cloud_event_topic_endpoint) attributes = { "type": "com.example.sampletype1", @@ -86,7 +85,7 @@ def callback(request): @EventGridPreparer() @recorded_by_proxy - def test_send_cncf_data_as_list(self, eventgrid_cloud_event_topic_endpoint): + def test_send_cloud_event_data_as_list(self, eventgrid_cloud_event_topic_endpoint): client = self.create_eg_publisher_client(eventgrid_cloud_event_topic_endpoint) attributes = { "type": "com.example.sampletype1", @@ -98,7 +97,7 @@ def test_send_cncf_data_as_list(self, eventgrid_cloud_event_topic_endpoint): @EventGridPreparer() @recorded_by_proxy - def test_send_cncf_data_with_extensions(self, eventgrid_cloud_event_topic_endpoint): + def test_send_cloud_event_data_with_extensions(self, eventgrid_cloud_event_topic_endpoint): client = self.create_eg_publisher_client(eventgrid_cloud_event_topic_endpoint) attributes = { "type": "com.example.sampletype1", diff --git a/sdk/eventgrid/azure-eventgrid/tests/test_cncf_events_async.py b/sdk/eventgrid/azure-eventgrid/tests/test_cncf_events_async.py index 247317ce074c..a4c34a8cafd9 100644 --- a/sdk/eventgrid/azure-eventgrid/tests/test_cncf_events_async.py +++ b/sdk/eventgrid/azure-eventgrid/tests/test_cncf_events_async.py @@ -1,9 +1,8 @@ import json import pytest -from devtools_testutils import AzureRecordedTestCase, CachedResourceGroupPreparer +from devtools_testutils import AzureRecordedTestCase from devtools_testutils.aio import recorded_by_proxy_async -from azure.core.credentials import AzureKeyCredential, AzureSasCredential from azure.eventgrid.aio import EventGridPublisherClient from cloudevents.http import CloudEvent @@ -21,7 +20,7 @@ def create_eg_publisher_client(self, endpoint): @EventGridPreparer() @recorded_by_proxy_async @pytest.mark.asyncio - async def test_send_cncf_data_dict_async(self, eventgrid_cloud_event_topic_endpoint): + async def test_send_cloud_event_data_dict(self, eventgrid_cloud_event_topic_endpoint): client = self.create_eg_publisher_client(eventgrid_cloud_event_topic_endpoint) attributes = { "type": "com.example.sampletype1", @@ -42,7 +41,7 @@ def callback(request): @EventGridPreparer() @recorded_by_proxy_async @pytest.mark.asyncio - async def test_send_cncf_data_base64_using_data_async(self, eventgrid_cloud_event_topic_endpoint): + async def test_send_cloud_event_data_base64_using_data(self, eventgrid_cloud_event_topic_endpoint): client = self.create_eg_publisher_client(eventgrid_cloud_event_topic_endpoint) attributes = { "type": "com.example.sampletype1", @@ -61,7 +60,7 @@ def callback(request): @EventGridPreparer() @recorded_by_proxy_async @pytest.mark.asyncio - async def test_send_cncf_data_none_async(self, eventgrid_cloud_event_topic_endpoint): + async def test_send_cloud_event_data_none(self, eventgrid_cloud_event_topic_endpoint): client = self.create_eg_publisher_client(eventgrid_cloud_event_topic_endpoint) attributes = { "type": "com.example.sampletype1", @@ -74,7 +73,7 @@ async def test_send_cncf_data_none_async(self, eventgrid_cloud_event_topic_endpo @EventGridPreparer() @recorded_by_proxy_async @pytest.mark.asyncio - async def test_send_cncf_data_str_async(self, eventgrid_cloud_event_topic_endpoint): + async def test_send_cloud_event_data_str(self, eventgrid_cloud_event_topic_endpoint): client = self.create_eg_publisher_client(eventgrid_cloud_event_topic_endpoint) attributes = { "type": "com.example.sampletype1", @@ -93,7 +92,7 @@ def callback(request): @EventGridPreparer() @recorded_by_proxy_async @pytest.mark.asyncio - async def test_send_cncf_data_as_list_async(self, eventgrid_cloud_event_topic_endpoint): + async def test_send_cloud_event_data_as_list(self, eventgrid_cloud_event_topic_endpoint): client = self.create_eg_publisher_client(eventgrid_cloud_event_topic_endpoint) attributes = { "type": "com.example.sampletype1", @@ -106,7 +105,7 @@ async def test_send_cncf_data_as_list_async(self, eventgrid_cloud_event_topic_en @EventGridPreparer() @recorded_by_proxy_async @pytest.mark.asyncio - async def test_send_cncf_data_with_extensions_async(self, eventgrid_cloud_event_topic_endpoint): + async def test_send_cloud_event_data_with_extensions(self, eventgrid_cloud_event_topic_endpoint): client = self.create_eg_publisher_client(eventgrid_cloud_event_topic_endpoint) attributes = { "type": "com.example.sampletype1", 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 1c1f7c80b0d7..68b66ae5cd05 100644 --- a/sdk/eventgrid/azure-eventgrid/tests/test_eg_publisher_client.py +++ b/sdk/eventgrid/azure-eventgrid/tests/test_eg_publisher_client.py @@ -21,7 +21,7 @@ from devtools_testutils import AzureRecordedTestCase, recorded_by_proxy -from azure.core.credentials import AzureKeyCredential, AzureSasCredential +from azure.core.credentials import AzureSasCredential from azure.core.messaging import CloudEvent from azure.core.serialization import NULL from azure.eventgrid import EventGridPublisherClient, EventGridEvent, generate_sas @@ -54,10 +54,10 @@ def test_send_event_grid_event_data_dict(self, eventgrid_topic_endpoint): @EventGridPreparer() @recorded_by_proxy - def test_send_event_grid_event_fails_without_full_url(self, eventgrid_topic_key, eventgrid_topic_endpoint): - akc_credential = AzureKeyCredential(eventgrid_topic_key) + def test_send_event_grid_event_fails_without_full_url(self,eventgrid_topic_endpoint): + credential = self.get_credential(EventGridPublisherClient) parsed_url = urlparse(eventgrid_topic_endpoint) - client = EventGridPublisherClient(parsed_url.netloc, akc_credential) + client = EventGridPublisherClient(parsed_url.netloc, credential) eg_event = EventGridEvent( subject="sample", data={"sample": "eventgridevent"}, @@ -273,9 +273,11 @@ def test_send_cloud_event_dict(self, eventgrid_cloud_event_topic_endpoint): } client.send(cloud_event1) + @pytest.mark.live_test_only @EventGridPreparer() - @recorded_by_proxy - def test_send_signature_credential(self, eventgrid_topic_key, eventgrid_topic_endpoint): + def test_send_signature_credential(self, **kwargs): + eventgrid_topic_endpoint = kwargs.pop("eventgrid_topic_endpoint") + eventgrid_topic_key = kwargs.pop("eventgrid_topic_key") expiration_date_utc = dt.datetime.now(UTC()) + timedelta(hours=1) signature = generate_sas(eventgrid_topic_endpoint, eventgrid_topic_key, expiration_date_utc) credential = AzureSasCredential(signature) @@ -355,14 +357,8 @@ def test_send_token_credential(self, eventgrid_topic_endpoint): @pytest.mark.live_test_only @EventGridPreparer() @recorded_by_proxy - def test_send_partner_namespace( - self, - eventgrid_partner_namespace_topic_endpoint, - eventgrid_partner_namespace_topic_key, - eventgrid_partner_channel_name, - ): - credential = AzureKeyCredential(eventgrid_partner_namespace_topic_key) - client = EventGridPublisherClient(eventgrid_partner_namespace_topic_endpoint, credential) + def test_send_partner_namespace(self, eventgrid_partner_namespace_topic_endpoint, eventgrid_partner_channel_name): + client = self.create_eg_publisher_client(eventgrid_partner_namespace_topic_endpoint) cloud_event = CloudEvent( source="http://samplesource.dev", data="cloudevent", 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 3eee77aa3ce2..d7ab21ec1e11 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 @@ -18,7 +18,7 @@ from devtools_testutils import AzureRecordedTestCase from devtools_testutils.aio import recorded_by_proxy_async -from azure.core.credentials import AzureKeyCredential, AzureSasCredential +from azure.core.credentials import AzureSasCredential from azure.core.messaging import CloudEvent from azure.core.serialization import NULL from azure.eventgrid import EventGridEvent, generate_sas @@ -37,7 +37,7 @@ def create_eg_publisher_client(self, endpoint): @EventGridPreparer() @recorded_by_proxy_async @pytest.mark.asyncio - async def test_send_event_grid_event_data_dict_async(self, eventgrid_topic_endpoint): + async def test_send_event_grid_event_data_dict(self, eventgrid_topic_endpoint): client = self.create_eg_publisher_client(eventgrid_topic_endpoint) eg_event = EventGridEvent( subject="sample", @@ -50,7 +50,7 @@ async def test_send_event_grid_event_data_dict_async(self, eventgrid_topic_endpo @EventGridPreparer() @recorded_by_proxy_async @pytest.mark.asyncio - async def test_send_event_grid_event_data_as_list_async(self, eventgrid_topic_endpoint): + async def test_send_event_grid_event_data_as_list(self, eventgrid_topic_endpoint): client = self.create_eg_publisher_client(eventgrid_topic_endpoint) eg_event1 = EventGridEvent( subject="sample", @@ -69,12 +69,10 @@ async def test_send_event_grid_event_data_as_list_async(self, eventgrid_topic_en @EventGridPreparer() @recorded_by_proxy_async @pytest.mark.asyncio - async def test_send_event_grid_event_fails_without_full_url_async( - self, eventgrid_topic_key, eventgrid_topic_endpoint - ): - akc_credential = AzureKeyCredential(eventgrid_topic_key) + async def test_send_event_grid_event_fails_without_full_url(self, eventgrid_topic_endpoint): + credential = self.get_credential(EventGridPublisherClient, is_async=True) parsed_url = urlparse(eventgrid_topic_endpoint) - client = EventGridPublisherClient(parsed_url.netloc, akc_credential) + client = EventGridPublisherClient(parsed_url.netloc, credential) eg_event = EventGridEvent( subject="sample", data={"sample": "eventgridevent"}, @@ -87,7 +85,7 @@ async def test_send_event_grid_event_fails_without_full_url_async( @EventGridPreparer() @recorded_by_proxy_async @pytest.mark.asyncio - async def test_send_event_grid_event_data_str_async(self, eventgrid_topic_endpoint): + async def test_send_event_grid_event_data_str(self, eventgrid_topic_endpoint): client = self.create_eg_publisher_client(eventgrid_topic_endpoint) eg_event = EventGridEvent( subject="sample", @@ -100,7 +98,7 @@ async def test_send_event_grid_event_data_str_async(self, eventgrid_topic_endpoi @EventGridPreparer() @recorded_by_proxy_async @pytest.mark.asyncio - async def test_send_event_grid_event_data_bytes_async(self, eventgrid_topic_endpoint): + async def test_send_event_grid_event_data_bytes(self, eventgrid_topic_endpoint): client = self.create_eg_publisher_client(eventgrid_topic_endpoint) eg_event = EventGridEvent( subject="sample", @@ -114,7 +112,7 @@ async def test_send_event_grid_event_data_bytes_async(self, eventgrid_topic_endp @EventGridPreparer() @recorded_by_proxy_async @pytest.mark.asyncio - async def test_send_event_grid_event_dict_data_bytes_async(self, eventgrid_topic_endpoint): + async def test_send_event_grid_event_dict_data_bytes(self, eventgrid_topic_endpoint): client = self.create_eg_publisher_client(eventgrid_topic_endpoint) eg_event = { "subject": "sample", @@ -130,7 +128,7 @@ async def test_send_event_grid_event_dict_data_bytes_async(self, eventgrid_topic @EventGridPreparer() @recorded_by_proxy_async @pytest.mark.asyncio - async def test_send_cloud_event_data_dict_async(self, eventgrid_cloud_event_topic_endpoint): + async def test_send_cloud_event_data_dict(self, eventgrid_cloud_event_topic_endpoint): client = self.create_eg_publisher_client(eventgrid_cloud_event_topic_endpoint) cloud_event = CloudEvent( source="http://samplesource.dev", data={"sample": "cloudevent"}, type="Sample.Cloud.Event" @@ -148,7 +146,7 @@ async def test_send_cloud_event_data_str(self, eventgrid_cloud_event_topic_endpo @EventGridPreparer() @recorded_by_proxy_async @pytest.mark.asyncio - async def test_send_cloud_event_data_str_async(self, eventgrid_cloud_event_topic_endpoint): + async def test_send_cloud_event_data_str(self, eventgrid_cloud_event_topic_endpoint): client = self.create_eg_publisher_client(eventgrid_cloud_event_topic_endpoint) cloud_event = CloudEvent( source="http://samplesource.dev", @@ -160,7 +158,7 @@ async def test_send_cloud_event_data_str_async(self, eventgrid_cloud_event_topic @EventGridPreparer() @recorded_by_proxy_async @pytest.mark.asyncio - async def test_send_cloud_event_data_bytes_async(self, eventgrid_cloud_event_topic_endpoint): + async def test_send_cloud_event_data_bytes(self, eventgrid_cloud_event_topic_endpoint): client = self.create_eg_publisher_client(eventgrid_cloud_event_topic_endpoint) cloud_event = CloudEvent( source="http://samplesource.dev", @@ -172,7 +170,7 @@ async def test_send_cloud_event_data_bytes_async(self, eventgrid_cloud_event_top @EventGridPreparer() @recorded_by_proxy_async @pytest.mark.asyncio - async def test_send_cloud_event_data_as_list_async(self, eventgrid_cloud_event_topic_endpoint): + async def test_send_cloud_event_data_as_list(self, eventgrid_cloud_event_topic_endpoint): client = self.create_eg_publisher_client(eventgrid_cloud_event_topic_endpoint) cloud_event = CloudEvent( source="http://samplesource.dev", @@ -184,7 +182,7 @@ async def test_send_cloud_event_data_as_list_async(self, eventgrid_cloud_event_t @EventGridPreparer() @recorded_by_proxy_async @pytest.mark.asyncio - async def test_send_cloud_event_data_with_extensions_async(self, eventgrid_cloud_event_topic_endpoint): + async def test_send_cloud_event_data_with_extensions(self, eventgrid_cloud_event_topic_endpoint): client = self.create_eg_publisher_client(eventgrid_cloud_event_topic_endpoint) cloud_event = CloudEvent( source="http://samplesource.dev", @@ -201,7 +199,7 @@ async def test_send_cloud_event_data_with_extensions_async(self, eventgrid_cloud @EventGridPreparer() @recorded_by_proxy_async @pytest.mark.asyncio - async def test_send_cloud_event_dict_async(self, eventgrid_cloud_event_topic_endpoint): + async def test_send_cloud_event_dict(self, eventgrid_cloud_event_topic_endpoint): client = self.create_eg_publisher_client(eventgrid_cloud_event_topic_endpoint) cloud_event1 = { "id": "1234", @@ -215,7 +213,7 @@ async def test_send_cloud_event_dict_async(self, eventgrid_cloud_event_topic_end @EventGridPreparer() @recorded_by_proxy_async @pytest.mark.asyncio - async def test_send_cloud_event_data_none_async(self, eventgrid_cloud_event_topic_endpoint): + async def test_send_cloud_event_data_none(self, eventgrid_cloud_event_topic_endpoint): client = self.create_eg_publisher_client(eventgrid_cloud_event_topic_endpoint) cloud_event = CloudEvent(source="http://samplesource.dev", data=None, type="Sample.Cloud.Event") await client.send(cloud_event) @@ -224,7 +222,7 @@ async def test_send_cloud_event_data_none_async(self, eventgrid_cloud_event_topi @EventGridPreparer() @recorded_by_proxy_async @pytest.mark.asyncio - async def test_send_cloud_event_data_NULL_async(self, eventgrid_cloud_event_topic_endpoint): + async def test_send_cloud_event_data_NULL(self, eventgrid_cloud_event_topic_endpoint): client = self.create_eg_publisher_client(eventgrid_cloud_event_topic_endpoint) cloud_event = CloudEvent(source="http://samplesource.dev", data=NULL, type="Sample.Cloud.Event") @@ -234,10 +232,12 @@ def callback(request): await client.send(cloud_event, raw_request_hook=callback) + @pytest.mark.live_test_only @EventGridPreparer() - @recorded_by_proxy_async @pytest.mark.asyncio - async def test_send_signature_credential_async(self, eventgrid_topic_key, eventgrid_topic_endpoint): + async def test_send_signature_credential(self, **kwargs): + eventgrid_topic_endpoint = kwargs.pop("eventgrid_topic_endpoint") + eventgrid_topic_key = kwargs.pop("eventgrid_topic_key") expiration_date_utc = dt.datetime.now(UTC()) + timedelta(hours=1) signature = generate_sas(eventgrid_topic_endpoint, eventgrid_topic_key, expiration_date_utc) credential = AzureSasCredential(signature) @@ -253,7 +253,7 @@ async def test_send_signature_credential_async(self, eventgrid_topic_key, eventg @EventGridPreparer() @recorded_by_proxy_async @pytest.mark.asyncio - async def test_send_custom_schema_event_async(self, eventgrid_custom_event_topic_endpoint): + async def test_send_custom_schema_event(self, eventgrid_custom_event_topic_endpoint): client = self.create_eg_publisher_client(eventgrid_custom_event_topic_endpoint) custom_event = { "customSubject": "sample", @@ -268,7 +268,7 @@ async def test_send_custom_schema_event_async(self, eventgrid_custom_event_topic @EventGridPreparer() @recorded_by_proxy_async @pytest.mark.asyncio - async def test_send_custom_schema_event_as_list_async(self, eventgrid_custom_event_topic_endpoint): + async def test_send_custom_schema_event_as_list(self, eventgrid_custom_event_topic_endpoint): client = self.create_eg_publisher_client(eventgrid_custom_event_topic_endpoint) custom_event1 = { "customSubject": "sample", @@ -291,7 +291,7 @@ async def test_send_custom_schema_event_as_list_async(self, eventgrid_custom_eve @EventGridPreparer() @recorded_by_proxy_async @pytest.mark.asyncio - async def test_send_and_close_async_session_async(self, eventgrid_cloud_event_topic_endpoint): + async def test_send_and_close_async_session(self, eventgrid_cloud_event_topic_endpoint): client = self.create_eg_publisher_client(eventgrid_cloud_event_topic_endpoint) async with client: # this throws if client can't close cloud_event = CloudEvent( @@ -304,7 +304,7 @@ async def test_send_and_close_async_session_async(self, eventgrid_cloud_event_to @pytest.mark.skip() @EventGridPreparer() @recorded_by_proxy_async - def test_send_NONE_credential_async(self, eventgrid_topic_endpoint): + def test_send_NONE_credential(self, eventgrid_topic_endpoint): with pytest.raises(ValueError, match="Parameter 'self._credential' must not be None."): client = EventGridPublisherClient(eventgrid_topic_endpoint, None) @@ -312,7 +312,7 @@ def test_send_NONE_credential_async(self, eventgrid_topic_endpoint): @EventGridPreparer() @recorded_by_proxy_async @pytest.mark.asyncio - async def test_send_token_credential_async(self, eventgrid_topic_endpoint): + async def test_send_token_credential(self, eventgrid_topic_endpoint): credential = self.get_credential(EventGridPublisherClient) client = EventGridPublisherClient(eventgrid_topic_endpoint, credential) eg_event = EventGridEvent( @@ -326,14 +326,9 @@ async def test_send_token_credential_async(self, eventgrid_topic_endpoint): @pytest.mark.live_test_only @EventGridPreparer() @recorded_by_proxy_async - async def test_send_partner_namespace_async( - self, - eventgrid_partner_namespace_topic_endpoint, - eventgrid_partner_namespace_topic_key, - eventgrid_partner_channel_name, - ): - credential = AzureKeyCredential(eventgrid_partner_namespace_topic_key) - client = EventGridPublisherClient(eventgrid_partner_namespace_topic_endpoint, credential) + @pytest.mark.asyncio + async def test_send_partner_namespace(self, eventgrid_partner_namespace_topic_endpoint, eventgrid_partner_channel_name): + client = self.create_eg_publisher_client(eventgrid_partner_namespace_topic_endpoint) cloud_event = CloudEvent( source="http://samplesource.dev", data="cloudevent", diff --git a/sdk/eventgrid/azure-eventgrid/tests/test_exceptions.py b/sdk/eventgrid/azure-eventgrid/tests/test_exceptions.py index a19b3dd8e1a1..b634cdfc48bd 100644 --- a/sdk/eventgrid/azure-eventgrid/tests/test_exceptions.py +++ b/sdk/eventgrid/azure-eventgrid/tests/test_exceptions.py @@ -4,31 +4,18 @@ # license information. # -------------------------------------------------------------------------- -import logging -import sys import os import json import pytest -import uuid -from datetime import datetime, timedelta from azure.core.exceptions import ( HttpResponseError, ClientAuthenticationError, - ServiceRequestError, ) -from msrest.serialization import UTC -import datetime as dt - -try: - from urllib.parse import urlparse -except ImportError: - from urlparse import urlparse from devtools_testutils import AzureMgmtRecordedTestCase, recorded_by_proxy from azure.core.credentials import AzureKeyCredential from azure.eventgrid import EventGridPublisherClient, EventGridEvent -from azure.core.messaging import CloudEvent from eventgrid_preparer import ( EventGridPreparer, @@ -41,9 +28,10 @@ def create_eg_publisher_client(self, endpoint): client = self.create_client_from_credential(EventGridPublisherClient, credential=credential, endpoint=endpoint) return client + @pytest.mark.live_test_only @EventGridPreparer() - @recorded_by_proxy - def test_raise_on_auth_error(self, eventgrid_topic_endpoint): + def test_raise_on_auth_error(self, **kwargs): + eventgrid_topic_endpoint = kwargs.pop("eventgrid_topic_endpoint") akc_credential = AzureKeyCredential("bad credential") client = EventGridPublisherClient(eventgrid_topic_endpoint, akc_credential) eg_event = EventGridEvent( @@ -60,18 +48,17 @@ def test_raise_on_auth_error(self, eventgrid_topic_endpoint): @pytest.mark.skip("Fix during MQ - skip to unblock pipeline") @pytest.mark.live_test_only - def test_raise_on_bad_resource(self): - credential = AzureKeyCredential(os.environ["EVENTGRID_TOPIC_KEY"]) - client = EventGridPublisherClient( - "https://bad-resource.eastus-1.eventgrid.azure.net/api/events", - credential, - ) - eg_event = CloudEvent( - subject="sample", - data={"sample": "eventgridevent"}, - source="source", - type="Sample.Cloud.Event", - ) + @EventGridPreparer() + def test_raise_on_bad_resource(self, **kwargs): + eventgrid_topic_key = kwargs.pop("eventgrid_topic_key") + akc_credential = AzureKeyCredential(eventgrid_topic_key) + client = EventGridPublisherClient("https://bad-resource.westus-1.eventgrid.azure.net/api/events", akc_credential) + eg_event = EventGridEvent( + subject="sample", + data={"sample": "eventgridevent"}, + event_type="Sample.EventGrid.Event", + data_version="2.0" + ) with pytest.raises(HttpResponseError): client.send(eg_event) diff --git a/sdk/eventgrid/azure-eventgrid/tests/test_exceptions_async.py b/sdk/eventgrid/azure-eventgrid/tests/test_exceptions_async.py index 461c17453482..635ae83dd9b3 100644 --- a/sdk/eventgrid/azure-eventgrid/tests/test_exceptions_async.py +++ b/sdk/eventgrid/azure-eventgrid/tests/test_exceptions_async.py @@ -4,35 +4,20 @@ # license information. # -------------------------------------------------------------------------- -import logging -import sys import os import json import pytest -import uuid -from datetime import datetime, timedelta -from azure.core.exceptions import ( - HttpResponseError, - ClientAuthenticationError, - ServiceRequestError, -) +from azure.core.exceptions import HttpResponseError, ClientAuthenticationError from msrest.serialization import UTC import datetime as dt -try: - from urllib.parse import urlparse -except ImportError: - from urlparse import urlparse from devtools_testutils import AzureRecordedTestCase from devtools_testutils.aio import recorded_by_proxy_async -from azure.core.credentials import AzureKeyCredential, AzureSasCredential -from azure.core.messaging import CloudEvent -from azure.core.serialization import NULL -from azure.eventgrid import EventGridEvent, generate_sas +from azure.core.credentials import AzureKeyCredential +from azure.eventgrid import EventGridEvent from azure.eventgrid.aio import EventGridPublisherClient -from azure.eventgrid._legacy._helpers import _cloud_event_to_generated from eventgrid_preparer import ( EventGridPreparer, @@ -45,10 +30,11 @@ def create_eg_publisher_client(self, endpoint): client = self.create_client_from_credential(EventGridPublisherClient, credential=credential, endpoint=endpoint) return client + @pytest.mark.live_test_only @EventGridPreparer() - @recorded_by_proxy_async @pytest.mark.asyncio - async def test_raise_on_auth_error(self, eventgrid_topic_endpoint): + async def test_raise_on_auth_error(self, **kwargs): + eventgrid_topic_endpoint = kwargs.pop("eventgrid_topic_endpoint") akc_credential = AzureKeyCredential("bad credential") client = EventGridPublisherClient(eventgrid_topic_endpoint, akc_credential) eg_event = EventGridEvent( @@ -67,12 +53,10 @@ async def test_raise_on_auth_error(self, eventgrid_topic_endpoint): @pytest.mark.live_test_only @EventGridPreparer() @pytest.mark.asyncio - async def test_raise_on_bad_resource(self): - credential = AzureKeyCredential(os.environ["EVENTGRID_TOPIC_KEY"]) - client = EventGridPublisherClient( - "https://bad-resource.eastus-1.eventgrid.azure.net/api/events", - credential, - ) + async def test_raise_on_bad_resource(self, **kwargs): + eventgrid_topic_key = kwargs.pop("eventgrid_topic_key") + akc_credential = AzureKeyCredential(eventgrid_topic_key) + client = EventGridPublisherClient("https://bad-resource.westus-1.eventgrid.azure.net/api/events", akc_credential) eg_event = EventGridEvent( subject="sample", data={"sample": "eventgridevent"},