From 008f0fe67f25c33abf018d41a7e2ce8a073db97e Mon Sep 17 00:00:00 2001 From: Libba Lawrence Date: Thu, 23 May 2024 15:02:17 -0700 Subject: [PATCH 1/9] test --- .../azure-eventgrid/tests/conftest.py | 2 +- .../tests/eventgrid_preparer.py | 19 ++++++------ .../azure-eventgrid/tests/test_cncf_events.py | 1 - .../tests/test_cncf_events_async.py | 3 +- .../tests/test_eg_publisher_client.py | 28 ++++++++--------- .../tests/test_eg_publisher_client_async.py | 30 +++++++++---------- .../azure-eventgrid/tests/test_exceptions.py | 20 ++----------- .../tests/test_exceptions_async.py | 18 +++-------- 8 files changed, 48 insertions(+), 73 deletions(-) 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..63907377d488 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.oop("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..c4b4f3ee9e28 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.oop("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) @@ -318,7 +320,6 @@ def test_send_NONE_credential_async(self, eventgrid_topic_endpoint): with pytest.raises(ValueError, match="Parameter 'self._credential' must not be None."): client = EventGridPublisherClient(eventgrid_topic_endpoint, None) - @pytest.mark.live_test_only @EventGridPreparer() @recorded_by_proxy_async @pytest.mark.asyncio @@ -334,12 +335,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 +347,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..960734c4898e 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,6 +27,7 @@ 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): diff --git a/sdk/eventgrid/azure-eventgrid/tests/test_exceptions_async.py b/sdk/eventgrid/azure-eventgrid/tests/test_exceptions_async.py index 339ed7bda1f0..ff8f34623ca4 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,6 +29,7 @@ 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 From 6777c9b89eb3a5cf2675c54fc29097fab8d45580 Mon Sep 17 00:00:00 2001 From: Libba Lawrence Date: Thu, 23 May 2024 15:04:08 -0700 Subject: [PATCH 2/9] typo --- sdk/eventgrid/azure-eventgrid/tests/test_eg_publisher_client.py | 2 +- .../azure-eventgrid/tests/test_eg_publisher_client_async.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 63907377d488..ac3cdd25a8a8 100644 --- a/sdk/eventgrid/azure-eventgrid/tests/test_eg_publisher_client.py +++ b/sdk/eventgrid/azure-eventgrid/tests/test_eg_publisher_client.py @@ -273,7 +273,7 @@ def test_send_cloud_event_dict(self, eventgrid_cloud_event_topic_endpoint): @EventGridPreparer() def test_send_signature_credential(self, **kwargs): eventgrid_topic_endpoint = kwargs.pop("eventgrid_topic_endpoint") - eventgrid_topic_key = kwargs.oop("eventgrid_topic_key") + 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) 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 c4b4f3ee9e28..f7b57eb4f560 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 @@ -247,7 +247,7 @@ def callback(request): @pytest.mark.asyncio async def test_send_signature_credential(self, **kwargs): eventgrid_topic_endpoint = kwargs.pop("eventgrid_topic_endpoint") - eventgrid_topic_key = kwargs.oop("eventgrid_topic_key") + 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) From 93086f4a27a7f763460ccf0b072d3098f51182e9 Mon Sep 17 00:00:00 2001 From: Libba Lawrence Date: Thu, 23 May 2024 15:10:10 -0700 Subject: [PATCH 3/9] update recordings --- sdk/eventgrid/azure-eventgrid/assets.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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" } From b5bec11813806bb18dbc4b665f80ad0e906c6109 Mon Sep 17 00:00:00 2001 From: Libba Lawrence Date: Thu, 23 May 2024 16:05:24 -0700 Subject: [PATCH 4/9] mark live --- .../azure-eventgrid/tests/test_eg_publisher_client_async.py | 1 + 1 file changed, 1 insertion(+) 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 f7b57eb4f560..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 @@ -320,6 +320,7 @@ def test_send_NONE_credential_async(self, eventgrid_topic_endpoint): with pytest.raises(ValueError, match="Parameter 'self._credential' must not be None."): client = EventGridPublisherClient(eventgrid_topic_endpoint, None) + @pytest.mark.live_test_only @EventGridPreparer() @recorded_by_proxy_async @pytest.mark.asyncio From 2fbe6fb4c39410793cf7d977b6f12d1203f38036 Mon Sep 17 00:00:00 2001 From: Libba Lawrence Date: Fri, 24 May 2024 08:47:16 -0700 Subject: [PATCH 5/9] kwarg fix --- .../azure-eventgrid/tests/test_eg_publisher_client.py | 4 +--- .../azure-eventgrid/tests/test_eg_publisher_client_async.py | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) 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 ac3cdd25a8a8..213883b6a660 100644 --- a/sdk/eventgrid/azure-eventgrid/tests/test_eg_publisher_client.py +++ b/sdk/eventgrid/azure-eventgrid/tests/test_eg_publisher_client.py @@ -271,9 +271,7 @@ def test_send_cloud_event_dict(self, eventgrid_cloud_event_topic_endpoint): @pytest.mark.live_test_only @EventGridPreparer() - def test_send_signature_credential(self, **kwargs): - eventgrid_topic_endpoint = kwargs.pop("eventgrid_topic_endpoint") - eventgrid_topic_key = kwargs.pop("eventgrid_topic_key") + def test_send_signature_credential(self, *, eventgrid_topic_endpoint, eventgrid_topic_key, **kwargs): 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) 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 e4cbddb43008..13c2a2889abd 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 @@ -245,9 +245,7 @@ def callback(request): @pytest.mark.live_test_only @EventGridPreparer() @pytest.mark.asyncio - async def test_send_signature_credential(self, **kwargs): - eventgrid_topic_endpoint = kwargs.pop("eventgrid_topic_endpoint") - eventgrid_topic_key = kwargs.pop("eventgrid_topic_key") + async def test_send_signature_credential(self, *, eventgrid_topic_endpoint, eventgrid_topic_key, **kwargs): 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) From 7044424c17a421465a4ff47c709ecabc10140b31 Mon Sep 17 00:00:00 2001 From: Libba Lawrence Date: Fri, 24 May 2024 08:58:17 -0700 Subject: [PATCH 6/9] updates --- sdk/eventgrid/azure-eventgrid/tests/eventgrid_preparer.py | 2 +- sdk/eventgrid/azure-eventgrid/tests/test_exceptions.py | 6 ++---- .../azure-eventgrid/tests/test_exceptions_async.py | 6 ++---- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/sdk/eventgrid/azure-eventgrid/tests/eventgrid_preparer.py b/sdk/eventgrid/azure-eventgrid/tests/eventgrid_preparer.py index b9a1e245af64..05be8c83b5b1 100644 --- a/sdk/eventgrid/azure-eventgrid/tests/eventgrid_preparer.py +++ b/sdk/eventgrid/azure-eventgrid/tests/eventgrid_preparer.py @@ -4,7 +4,7 @@ from azure.mgmt.eventgrid.models import Topic, InputSchema, JsonInputSchemaMapping, JsonField, JsonFieldWithDefault EVENTGRID_TOPIC_PARAM = 'eventgrid_topic' -EVENTGRID_TOPIC_LOCATION = 'westus' +EVENTGRID_TOPIC_LOCATION = 'eastus' CLOUD_EVENT_SCHEMA = InputSchema.cloud_event_schema_v1_0 CUSTOM_EVENT_SCHEMA = InputSchema.custom_event_schema ID_JSON_FIELD = JsonField(source_field='customId') diff --git a/sdk/eventgrid/azure-eventgrid/tests/test_exceptions.py b/sdk/eventgrid/azure-eventgrid/tests/test_exceptions.py index 960734c4898e..e3942f6ec9cf 100644 --- a/sdk/eventgrid/azure-eventgrid/tests/test_exceptions.py +++ b/sdk/eventgrid/azure-eventgrid/tests/test_exceptions.py @@ -29,8 +29,7 @@ def create_eg_publisher_client(self, endpoint): @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, *, eventgrid_topic_endpoint, **kwargs): akc_credential = AzureKeyCredential("bad credential") client = EventGridPublisherClient(eventgrid_topic_endpoint, akc_credential) eg_event = EventGridEvent( @@ -42,10 +41,9 @@ def test_raise_on_auth_error(self, eventgrid_topic_endpoint): with pytest.raises(ClientAuthenticationError, match="The request authorization key is not authorized for*"): client.send(eg_event) - @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, *, eventgrid_topic_key, **kwargs): 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 ff8f34623ca4..de0e5e9a8b9e 100644 --- a/sdk/eventgrid/azure-eventgrid/tests/test_exceptions_async.py +++ b/sdk/eventgrid/azure-eventgrid/tests/test_exceptions_async.py @@ -31,9 +31,8 @@ def create_eg_publisher_client(self, endpoint): @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, *, eventgrid_topic_endpoint, **kwargs): akc_credential = AzureKeyCredential("bad credential") client = EventGridPublisherClient(eventgrid_topic_endpoint, akc_credential) eg_event = EventGridEvent( @@ -45,11 +44,10 @@ async def test_raise_on_auth_error(self, eventgrid_topic_endpoint): with pytest.raises(ClientAuthenticationError, match="The request authorization key is not authorized for*"): await client.send(eg_event) - @pytest.mark.skip("Fix during MQ - skip to unblock pipeline") @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, *, eventgrid_topic_key, **kwargs): akc_credential = AzureKeyCredential(eventgrid_topic_key) client = EventGridPublisherClient("https://bad-resource.westus-1.eventgrid.azure.net/api/events", akc_credential) eg_event = EventGridEvent( From d100bb22b0038aa3eb20b379416673512d462b21 Mon Sep 17 00:00:00 2001 From: Libba Lawrence Date: Fri, 24 May 2024 09:20:05 -0700 Subject: [PATCH 7/9] revert --- sdk/eventgrid/azure-eventgrid/tests/eventgrid_preparer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/eventgrid/azure-eventgrid/tests/eventgrid_preparer.py b/sdk/eventgrid/azure-eventgrid/tests/eventgrid_preparer.py index 05be8c83b5b1..b9a1e245af64 100644 --- a/sdk/eventgrid/azure-eventgrid/tests/eventgrid_preparer.py +++ b/sdk/eventgrid/azure-eventgrid/tests/eventgrid_preparer.py @@ -4,7 +4,7 @@ from azure.mgmt.eventgrid.models import Topic, InputSchema, JsonInputSchemaMapping, JsonField, JsonFieldWithDefault EVENTGRID_TOPIC_PARAM = 'eventgrid_topic' -EVENTGRID_TOPIC_LOCATION = 'eastus' +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') From cc184a891d9034bc93bdbe12eb2661aac1627def Mon Sep 17 00:00:00 2001 From: Libba Lawrence Date: Fri, 24 May 2024 09:35:25 -0700 Subject: [PATCH 8/9] kwargs --- .../azure-eventgrid/tests/test_eg_publisher_client.py | 4 +++- .../azure-eventgrid/tests/test_eg_publisher_client_async.py | 4 +++- sdk/eventgrid/azure-eventgrid/tests/test_exceptions.py | 6 ++++-- .../azure-eventgrid/tests/test_exceptions_async.py | 6 ++++-- 4 files changed, 14 insertions(+), 6 deletions(-) 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 213883b6a660..ac3cdd25a8a8 100644 --- a/sdk/eventgrid/azure-eventgrid/tests/test_eg_publisher_client.py +++ b/sdk/eventgrid/azure-eventgrid/tests/test_eg_publisher_client.py @@ -271,7 +271,9 @@ def test_send_cloud_event_dict(self, eventgrid_cloud_event_topic_endpoint): @pytest.mark.live_test_only @EventGridPreparer() - def test_send_signature_credential(self, *, eventgrid_topic_endpoint, eventgrid_topic_key, **kwargs): + 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) 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 13c2a2889abd..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 @@ -245,7 +245,9 @@ def callback(request): @pytest.mark.live_test_only @EventGridPreparer() @pytest.mark.asyncio - async def test_send_signature_credential(self, *, eventgrid_topic_endpoint, eventgrid_topic_key, **kwargs): + 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) diff --git a/sdk/eventgrid/azure-eventgrid/tests/test_exceptions.py b/sdk/eventgrid/azure-eventgrid/tests/test_exceptions.py index e3942f6ec9cf..11841b2bdb1b 100644 --- a/sdk/eventgrid/azure-eventgrid/tests/test_exceptions.py +++ b/sdk/eventgrid/azure-eventgrid/tests/test_exceptions.py @@ -29,7 +29,8 @@ def create_eg_publisher_client(self, endpoint): @pytest.mark.live_test_only @EventGridPreparer() - def test_raise_on_auth_error(self, *, eventgrid_topic_endpoint, **kwargs): + 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( @@ -43,7 +44,8 @@ def test_raise_on_auth_error(self, *, eventgrid_topic_endpoint, **kwargs): @pytest.mark.live_test_only @EventGridPreparer() - def test_raise_on_bad_resource(self, *, eventgrid_topic_key, **kwargs): + 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 de0e5e9a8b9e..0f08877a39e1 100644 --- a/sdk/eventgrid/azure-eventgrid/tests/test_exceptions_async.py +++ b/sdk/eventgrid/azure-eventgrid/tests/test_exceptions_async.py @@ -32,7 +32,8 @@ def create_eg_publisher_client(self, endpoint): @pytest.mark.live_test_only @EventGridPreparer() @pytest.mark.asyncio - async def test_raise_on_auth_error(self, *, eventgrid_topic_endpoint, **kwargs): + 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( @@ -47,7 +48,8 @@ async def test_raise_on_auth_error(self, *, eventgrid_topic_endpoint, **kwargs): @pytest.mark.live_test_only @EventGridPreparer() @pytest.mark.asyncio - async def test_raise_on_bad_resource(self, *, eventgrid_topic_key, **kwargs): + 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( From 0ba53f993e18fdf03ea9c6568002bc8e35a093e7 Mon Sep 17 00:00:00 2001 From: Libba Lawrence Date: Fri, 24 May 2024 09:50:35 -0700 Subject: [PATCH 9/9] continue skip --- sdk/eventgrid/azure-eventgrid/tests/test_exceptions.py | 1 + sdk/eventgrid/azure-eventgrid/tests/test_exceptions_async.py | 1 + 2 files changed, 2 insertions(+) diff --git a/sdk/eventgrid/azure-eventgrid/tests/test_exceptions.py b/sdk/eventgrid/azure-eventgrid/tests/test_exceptions.py index 11841b2bdb1b..20ccd66d2d56 100644 --- a/sdk/eventgrid/azure-eventgrid/tests/test_exceptions.py +++ b/sdk/eventgrid/azure-eventgrid/tests/test_exceptions.py @@ -42,6 +42,7 @@ def test_raise_on_auth_error(self, **kwargs): with pytest.raises(ClientAuthenticationError, match="The request authorization key is not authorized for*"): client.send(eg_event) + @pytest.mark.skip("Fix during MQ - skip to unblock pipeline") @pytest.mark.live_test_only @EventGridPreparer() def test_raise_on_bad_resource(self, **kwargs): diff --git a/sdk/eventgrid/azure-eventgrid/tests/test_exceptions_async.py b/sdk/eventgrid/azure-eventgrid/tests/test_exceptions_async.py index 0f08877a39e1..9d6ee172d99d 100644 --- a/sdk/eventgrid/azure-eventgrid/tests/test_exceptions_async.py +++ b/sdk/eventgrid/azure-eventgrid/tests/test_exceptions_async.py @@ -45,6 +45,7 @@ async def test_raise_on_auth_error(self, **kwargs): with pytest.raises(ClientAuthenticationError, match="The request authorization key is not authorized for*"): await client.send(eg_event) + @pytest.mark.skip("Fix during MQ - skip to unblock pipeline") @pytest.mark.live_test_only @EventGridPreparer() @pytest.mark.asyncio