diff --git a/sdk/eventgrid/azure-eventgrid/assets.json b/sdk/eventgrid/azure-eventgrid/assets.json index 884eb4ab595a..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_d176c3a3b4" + "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 c26a3608ff0b..fa630f477a16 100644 --- a/sdk/eventgrid/azure-eventgrid/tests/conftest.py +++ b/sdk/eventgrid/azure-eventgrid/tests/conftest.py @@ -44,5 +44,5 @@ def add_aeg_sanitizer(test_proxy): add_remove_header_sanitizer(headers="aeg-sas-key, aeg-sas-token") add_general_regex_sanitizer( value="fakeresource", - regex="(?<=\\/\\/)[a-z-]+(?=\\.westus2-1\\.eventgrid\\.azure\\.net/api/events)" + regex="(?<=\\/\\/)[a-z-]+(?=\\.eastus-1\\.eventgrid\\.azure\\.net/api/events)" ) diff --git a/sdk/eventgrid/azure-eventgrid/tests/eventgrid_preparer.py b/sdk/eventgrid/azure-eventgrid/tests/eventgrid_preparer.py index 546442b29b5d..b9a1e245af64 100644 --- a/sdk/eventgrid/azure-eventgrid/tests/eventgrid_preparer.py +++ b/sdk/eventgrid/azure-eventgrid/tests/eventgrid_preparer.py @@ -1,10 +1,8 @@ import functools -from devtools_testutils import PowerShellPreparer +from devtools_testutils import EnvironmentVariableLoader from azure.mgmt.eventgrid.models import Topic, InputSchema, JsonInputSchemaMapping, JsonField, JsonFieldWithDefault -from devtools_testutils.resource_testcase import RESOURCE_GROUP_PARAM - EVENTGRID_TOPIC_PARAM = 'eventgrid_topic' EVENTGRID_TOPIC_LOCATION = 'westus' CLOUD_EVENT_SCHEMA = InputSchema.cloud_event_schema_v1_0 @@ -18,15 +16,18 @@ CUSTOM_JSON_INPUT_SCHEMA_MAPPING = JsonInputSchemaMapping(id=ID_JSON_FIELD, topic=TOPIC_JSON_FIELD, event_time=EVENT_TIME_JSON_FIELD, event_type=EVENT_TYPE_JSON_FIELD_WITH_DEFAULT, subject=SUBJECT_JSON_FIELD_WITH_DEFAULT, data_version=DATA_VERSION_JSON_FIELD_WITH_DEFAULT) EventGridPreparer = functools.partial( - PowerShellPreparer, "eventgrid", - eventgrid_topic_endpoint="https://fakeresource.westus2-1.eventgrid.azure.net/api/events", + EnvironmentVariableLoader, "eventgrid", + eventgrid_topic_endpoint="https://fakeresource.eastus-1.eventgrid.azure.net/api/events", eventgrid_topic_key="fakekeyfakekeyfakekeyfakekeyfakekeyfakekeyA=", - eventgrid_domain_endpoint="https://fakeresource.westus2-1.eventgrid.azure.net/api/events", + eventgrid_domain_endpoint="https://fakeresource.eastus-1.eventgrid.azure.net/api/events", eventgrid_domain_key="fakekeyfakekeyfakekeyfakekeyfakekeyfakekeyA=", - eventgrid_cloud_event_topic_endpoint="https://fakeresource.westus2-1.eventgrid.azure.net/api/events", + eventgrid_cloud_event_topic_endpoint="https://fakeresource.eastus-1.eventgrid.azure.net/api/events", eventgrid_cloud_event_topic_key="fakekeyfakekeyfakekeyfakekeyfakekeyfakekeyA=", - eventgrid_cloud_event_domain_endpoint="https://fakeresource.westus2-1.eventgrid.azure.net/api/events", + eventgrid_cloud_event_domain_endpoint="https://fakeresource.eastus-1.eventgrid.azure.net/api/events", eventgrid_cloud_event_domain_key="fakekeyfakekeyfakekeyfakekeyfakekeyfakekeyA=", - eventgrid_custom_event_topic_endpoint="https://fakeresource.westus2-1.eventgrid.azure.net/api/events", + eventgrid_custom_event_topic_endpoint="https://fakeresource.eastus-1.eventgrid.azure.net/api/events", eventgrid_custom_event_topic_key="fakekeyfakekeyfakekeyfakekeyfakekeyfakekeyA=", + eventgrid_partner_namespace_topic_endpoint="https://fakeresource.eastus-1.eventgrid.azure.net/api/events", + eventgrid_partner_namespace_topic_key="fakekeyfakekeyfakekeyfakekeyfakekeyfakekeyA=", + eventgrid_partner_channel_name="fake_channel_name" ) diff --git a/sdk/eventgrid/azure-eventgrid/tests/test_cncf_events.py b/sdk/eventgrid/azure-eventgrid/tests/test_cncf_events.py index 377838160d01..6cf34da3e4e1 100644 --- a/sdk/eventgrid/azure-eventgrid/tests/test_cncf_events.py +++ b/sdk/eventgrid/azure-eventgrid/tests/test_cncf_events.py @@ -2,7 +2,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 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 c9903da23b2f..febd44175a99 100644 --- a/sdk/eventgrid/azure-eventgrid/tests/test_cncf_events_async.py +++ b/sdk/eventgrid/azure-eventgrid/tests/test_cncf_events_async.py @@ -1,10 +1,9 @@ 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 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 77ab8fa7a039..ac3cdd25a8a8 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 @@ -51,10 +51,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"}, @@ -269,9 +269,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) @@ -346,12 +348,10 @@ def test_send_token_credential(self, eventgrid_topic_endpoint): client.send(eg_event) @pytest.mark.live_test_only - def test_send_partner_namespace(self): - eventgrid_partner_namespace_endpoint = os.environ['EVENTGRID_PARTNER_NAMESPACE_TOPIC_ENDPOINT'] - eventgrid_partner_namespace_key = os.environ['EVENTGRID_PARTNER_NAMESPACE_TOPIC_KEY'] - channel_name = os.environ['EVENTGRID_PARTNER_CHANNEL_NAME'] - credential = AzureKeyCredential(eventgrid_partner_namespace_key) - client = EventGridPublisherClient(eventgrid_partner_namespace_endpoint, credential) + @EventGridPreparer() + @recorded_by_proxy + 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", @@ -360,6 +360,6 @@ def test_send_partner_namespace(self): def callback(request): req = request.http_request.headers - assert req.get("aeg-channel-name") == channel_name + assert req.get("aeg-channel-name") == eventgrid_partner_channel_name - client.send(cloud_event, channel_name=channel_name, raw_request_hook=callback) + client.send(cloud_event, channel_name=eventgrid_partner_channel_name, raw_request_hook=callback) 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 ec225dfea98c..e4cbddb43008 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 @@ -72,10 +72,10 @@ async def test_send_event_grid_event_data_as_list(self, eventgrid_topic_endpoint @EventGridPreparer() @recorded_by_proxy_async @pytest.mark.asyncio - async def test_send_event_grid_event_fails_without_full_url(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"}, @@ -242,10 +242,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(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) @@ -334,12 +336,11 @@ async def test_send_token_credential(self, eventgrid_topic_endpoint): await client.send(eg_event) @pytest.mark.live_test_only - async def test_send_partner_namespace(self): - eventgrid_partner_namespace_endpoint = os.environ['EVENTGRID_PARTNER_NAMESPACE_TOPIC_ENDPOINT'] - eventgrid_partner_namespace_key = os.environ['EVENTGRID_PARTNER_NAMESPACE_TOPIC_KEY'] - channel_name = os.environ['EVENTGRID_PARTNER_CHANNEL_NAME'] - credential = AzureKeyCredential(eventgrid_partner_namespace_key) - client = EventGridPublisherClient(eventgrid_partner_namespace_endpoint, credential) + @EventGridPreparer() + @recorded_by_proxy_async + @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", @@ -347,6 +348,6 @@ async def test_send_partner_namespace(self): ) def callback(request): req = request.http_request.headers - assert req.get("aeg-channel-name") == channel_name + assert req.get("aeg-channel-name") == eventgrid_partner_channel_name - await client.send(cloud_event, channel_name=channel_name, raw_request_hook=callback) + await client.send(cloud_event, channel_name=eventgrid_partner_channel_name, raw_request_hook=callback) diff --git a/sdk/eventgrid/azure-eventgrid/tests/test_exceptions.py b/sdk/eventgrid/azure-eventgrid/tests/test_exceptions.py index d3bdf37efe72..20ccd66d2d56 100644 --- a/sdk/eventgrid/azure-eventgrid/tests/test_exceptions.py +++ b/sdk/eventgrid/azure-eventgrid/tests/test_exceptions.py @@ -4,33 +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, AzureSasCredential -from azure.core.messaging import CloudEvent -from azure.core.serialization import NULL -from azure.eventgrid import EventGridPublisherClient, EventGridEvent, generate_sas -from azure.eventgrid._helpers import _cloud_event_to_generated +from azure.core.credentials import AzureKeyCredential +from azure.eventgrid import EventGridPublisherClient, EventGridEvent from eventgrid_preparer import ( EventGridPreparer, @@ -42,9 +27,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( @@ -59,7 +45,8 @@ 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 @EventGridPreparer() - def test_raise_on_bad_resource(self, eventgrid_topic_key): + 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( diff --git a/sdk/eventgrid/azure-eventgrid/tests/test_exceptions_async.py b/sdk/eventgrid/azure-eventgrid/tests/test_exceptions_async.py index 339ed7bda1f0..9d6ee172d99d 100644 --- a/sdk/eventgrid/azure-eventgrid/tests/test_exceptions_async.py +++ b/sdk/eventgrid/azure-eventgrid/tests/test_exceptions_async.py @@ -4,31 +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._helpers import _cloud_event_to_generated from eventgrid_preparer import ( EventGridPreparer, @@ -40,10 +29,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( @@ -59,7 +49,8 @@ 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, eventgrid_topic_key): + 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(