Skip to content

Commit

Permalink
[EG] Update tests (#35833)
Browse files Browse the repository at this point in the history
* [EG] Update tests (#35752)

* test

* typo

* update recordings

* mark live

* kwarg fix

* updates

* revert

* kwargs

* continue skip

* rename

* naming

* remove _async

* nit

* typo

* remove async
  • Loading branch information
l0lawrence authored May 31, 2024
1 parent 6186af3 commit 7181462
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 123 deletions.
2 changes: 1 addition & 1 deletion sdk/eventgrid/azure-eventgrid/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
2 changes: 1 addition & 1 deletion sdk/eventgrid/azure-eventgrid/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
9 changes: 4 additions & 5 deletions sdk/eventgrid/azure-eventgrid/tests/eventgrid_preparer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import functools
from devtools_testutils import PowerShellPreparer, EnvironmentVariableLoader
from devtools_testutils import EnvironmentVariableLoader

from azure.mgmt.eventgrid.models import (
Topic,
Expand All @@ -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")
Expand All @@ -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",
Expand Down
13 changes: 6 additions & 7 deletions sdk/eventgrid/azure-eventgrid/tests/test_cncf_events.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
15 changes: 7 additions & 8 deletions sdk/eventgrid/azure-eventgrid/tests/test_cncf_events_async.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
24 changes: 10 additions & 14 deletions sdk/eventgrid/azure-eventgrid/tests/test_eg_publisher_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"},
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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",
Expand Down
Loading

0 comments on commit 7181462

Please sign in to comment.