Skip to content

Commit 7181462

Browse files
authored
[EG] Update tests (#35833)
* [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
1 parent 6186af3 commit 7181462

File tree

9 files changed

+82
-123
lines changed

9 files changed

+82
-123
lines changed

sdk/eventgrid/azure-eventgrid/assets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"AssetsRepo": "Azure/azure-sdk-assets",
33
"AssetsRepoPrefixPath": "python",
44
"TagPrefix": "python/eventgrid/azure-eventgrid",
5-
"Tag": "python/eventgrid/azure-eventgrid_f155c8ac2d"
5+
"Tag": "python/eventgrid/azure-eventgrid_3ae14bceff"
66
}

sdk/eventgrid/azure-eventgrid/tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def add_sanitizers(test_proxy):
5151
add_remove_header_sanitizer(headers="aeg-sas-key, aeg-sas-token, aeg-channel-name")
5252
add_general_regex_sanitizer(
5353
value="fakeresource",
54-
regex="(?<=\\/\\/)[.*]+(?=\\.eastus-1\\.eventgrid\\.azure\\.net/api/events)",
54+
regex="(?<=\\/\\/)[a-z-]+(?=\\.eastus-1\\.eventgrid\\.azure\\.net/api/events)"
5555
)
5656

5757
add_oauth_response_sanitizer()

sdk/eventgrid/azure-eventgrid/tests/eventgrid_preparer.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import functools
2-
from devtools_testutils import PowerShellPreparer, EnvironmentVariableLoader
2+
from devtools_testutils import EnvironmentVariableLoader
33

44
from azure.mgmt.eventgrid.models import (
55
Topic,
@@ -9,8 +9,8 @@
99
JsonFieldWithDefault,
1010
)
1111

12-
EVENTGRID_TOPIC_PARAM = "eventgrid_topic"
13-
EVENTGRID_TOPIC_LOCATION = "eastus"
12+
EVENTGRID_TOPIC_PARAM = 'eventgrid_topic'
13+
EVENTGRID_TOPIC_LOCATION = 'westus'
1414
CLOUD_EVENT_SCHEMA = InputSchema.cloud_event_schema_v1_0
1515
CUSTOM_EVENT_SCHEMA = InputSchema.custom_event_schema
1616
ID_JSON_FIELD = JsonField(source_field="customId")
@@ -29,8 +29,7 @@
2929
)
3030

3131
EventGridPreparer = functools.partial(
32-
PowerShellPreparer,
33-
"eventgrid",
32+
EnvironmentVariableLoader, "eventgrid",
3433
eventgrid_topic_endpoint="https://fakeresource.eastus-1.eventgrid.azure.net/api/events",
3534
eventgrid_topic_key="fakekeyfakekeyfakekeyfakekeyfakekeyfakekeyA=",
3635
eventgrid_domain_endpoint="https://fakeresource.eastus-1.eventgrid.azure.net/api/events",

sdk/eventgrid/azure-eventgrid/tests/test_cncf_events.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import json
22
from devtools_testutils import AzureRecordedTestCase, recorded_by_proxy
33

4-
from azure.core.credentials import AzureKeyCredential, AzureSasCredential
54
from azure.eventgrid import EventGridPublisherClient
65
from cloudevents.http import CloudEvent
76

@@ -18,7 +17,7 @@ def create_eg_publisher_client(self, endpoint):
1817

1918
@EventGridPreparer()
2019
@recorded_by_proxy
21-
def test_send_cncf_data_dict(self, eventgrid_cloud_event_topic_endpoint):
20+
def test_send_cloud_event_data_dict(self, eventgrid_cloud_event_topic_endpoint):
2221
client = self.create_eg_publisher_client(eventgrid_cloud_event_topic_endpoint)
2322
attributes = {
2423
"type": "com.example.sampletype1",
@@ -38,7 +37,7 @@ def callback(request):
3837

3938
@EventGridPreparer()
4039
@recorded_by_proxy
41-
def test_send_cncf_data_base64_using_data(self, eventgrid_cloud_event_topic_endpoint):
40+
def test_send_cloud_event_data_base64_using_data(self, eventgrid_cloud_event_topic_endpoint):
4241
client = self.create_eg_publisher_client(eventgrid_cloud_event_topic_endpoint)
4342
attributes = {
4443
"type": "com.example.sampletype1",
@@ -56,7 +55,7 @@ def callback(request):
5655

5756
@EventGridPreparer()
5857
@recorded_by_proxy
59-
def test_send_cncf_data_none(self, eventgrid_cloud_event_topic_endpoint):
58+
def test_send_cloud_event_data_none(self, eventgrid_cloud_event_topic_endpoint):
6059
client = self.create_eg_publisher_client(eventgrid_cloud_event_topic_endpoint)
6160
attributes = {
6261
"type": "com.example.sampletype1",
@@ -68,7 +67,7 @@ def test_send_cncf_data_none(self, eventgrid_cloud_event_topic_endpoint):
6867

6968
@EventGridPreparer()
7069
@recorded_by_proxy
71-
def test_send_cncf_data_str(self, eventgrid_cloud_event_topic_endpoint):
70+
def test_send_cloud_event_data_str(self, eventgrid_cloud_event_topic_endpoint):
7271
client = self.create_eg_publisher_client(eventgrid_cloud_event_topic_endpoint)
7372
attributes = {
7473
"type": "com.example.sampletype1",
@@ -86,7 +85,7 @@ def callback(request):
8685

8786
@EventGridPreparer()
8887
@recorded_by_proxy
89-
def test_send_cncf_data_as_list(self, eventgrid_cloud_event_topic_endpoint):
88+
def test_send_cloud_event_data_as_list(self, eventgrid_cloud_event_topic_endpoint):
9089
client = self.create_eg_publisher_client(eventgrid_cloud_event_topic_endpoint)
9190
attributes = {
9291
"type": "com.example.sampletype1",
@@ -98,7 +97,7 @@ def test_send_cncf_data_as_list(self, eventgrid_cloud_event_topic_endpoint):
9897

9998
@EventGridPreparer()
10099
@recorded_by_proxy
101-
def test_send_cncf_data_with_extensions(self, eventgrid_cloud_event_topic_endpoint):
100+
def test_send_cloud_event_data_with_extensions(self, eventgrid_cloud_event_topic_endpoint):
102101
client = self.create_eg_publisher_client(eventgrid_cloud_event_topic_endpoint)
103102
attributes = {
104103
"type": "com.example.sampletype1",

sdk/eventgrid/azure-eventgrid/tests/test_cncf_events_async.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import json
22
import pytest
3-
from devtools_testutils import AzureRecordedTestCase, CachedResourceGroupPreparer
3+
from devtools_testutils import AzureRecordedTestCase
44
from devtools_testutils.aio import recorded_by_proxy_async
55

6-
from azure.core.credentials import AzureKeyCredential, AzureSasCredential
76
from azure.eventgrid.aio import EventGridPublisherClient
87
from cloudevents.http import CloudEvent
98

@@ -21,7 +20,7 @@ def create_eg_publisher_client(self, endpoint):
2120
@EventGridPreparer()
2221
@recorded_by_proxy_async
2322
@pytest.mark.asyncio
24-
async def test_send_cncf_data_dict_async(self, eventgrid_cloud_event_topic_endpoint):
23+
async def test_send_cloud_event_data_dict(self, eventgrid_cloud_event_topic_endpoint):
2524
client = self.create_eg_publisher_client(eventgrid_cloud_event_topic_endpoint)
2625
attributes = {
2726
"type": "com.example.sampletype1",
@@ -42,7 +41,7 @@ def callback(request):
4241
@EventGridPreparer()
4342
@recorded_by_proxy_async
4443
@pytest.mark.asyncio
45-
async def test_send_cncf_data_base64_using_data_async(self, eventgrid_cloud_event_topic_endpoint):
44+
async def test_send_cloud_event_data_base64_using_data(self, eventgrid_cloud_event_topic_endpoint):
4645
client = self.create_eg_publisher_client(eventgrid_cloud_event_topic_endpoint)
4746
attributes = {
4847
"type": "com.example.sampletype1",
@@ -61,7 +60,7 @@ def callback(request):
6160
@EventGridPreparer()
6261
@recorded_by_proxy_async
6362
@pytest.mark.asyncio
64-
async def test_send_cncf_data_none_async(self, eventgrid_cloud_event_topic_endpoint):
63+
async def test_send_cloud_event_data_none(self, eventgrid_cloud_event_topic_endpoint):
6564
client = self.create_eg_publisher_client(eventgrid_cloud_event_topic_endpoint)
6665
attributes = {
6766
"type": "com.example.sampletype1",
@@ -74,7 +73,7 @@ async def test_send_cncf_data_none_async(self, eventgrid_cloud_event_topic_endpo
7473
@EventGridPreparer()
7574
@recorded_by_proxy_async
7675
@pytest.mark.asyncio
77-
async def test_send_cncf_data_str_async(self, eventgrid_cloud_event_topic_endpoint):
76+
async def test_send_cloud_event_data_str(self, eventgrid_cloud_event_topic_endpoint):
7877
client = self.create_eg_publisher_client(eventgrid_cloud_event_topic_endpoint)
7978
attributes = {
8079
"type": "com.example.sampletype1",
@@ -93,7 +92,7 @@ def callback(request):
9392
@EventGridPreparer()
9493
@recorded_by_proxy_async
9594
@pytest.mark.asyncio
96-
async def test_send_cncf_data_as_list_async(self, eventgrid_cloud_event_topic_endpoint):
95+
async def test_send_cloud_event_data_as_list(self, eventgrid_cloud_event_topic_endpoint):
9796
client = self.create_eg_publisher_client(eventgrid_cloud_event_topic_endpoint)
9897
attributes = {
9998
"type": "com.example.sampletype1",
@@ -106,7 +105,7 @@ async def test_send_cncf_data_as_list_async(self, eventgrid_cloud_event_topic_en
106105
@EventGridPreparer()
107106
@recorded_by_proxy_async
108107
@pytest.mark.asyncio
109-
async def test_send_cncf_data_with_extensions_async(self, eventgrid_cloud_event_topic_endpoint):
108+
async def test_send_cloud_event_data_with_extensions(self, eventgrid_cloud_event_topic_endpoint):
110109
client = self.create_eg_publisher_client(eventgrid_cloud_event_topic_endpoint)
111110
attributes = {
112111
"type": "com.example.sampletype1",

sdk/eventgrid/azure-eventgrid/tests/test_eg_publisher_client.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
from devtools_testutils import AzureRecordedTestCase, recorded_by_proxy
2323

24-
from azure.core.credentials import AzureKeyCredential, AzureSasCredential
24+
from azure.core.credentials import AzureSasCredential
2525
from azure.core.messaging import CloudEvent
2626
from azure.core.serialization import NULL
2727
from azure.eventgrid import EventGridPublisherClient, EventGridEvent, generate_sas
@@ -54,10 +54,10 @@ def test_send_event_grid_event_data_dict(self, eventgrid_topic_endpoint):
5454

5555
@EventGridPreparer()
5656
@recorded_by_proxy
57-
def test_send_event_grid_event_fails_without_full_url(self, eventgrid_topic_key, eventgrid_topic_endpoint):
58-
akc_credential = AzureKeyCredential(eventgrid_topic_key)
57+
def test_send_event_grid_event_fails_without_full_url(self,eventgrid_topic_endpoint):
58+
credential = self.get_credential(EventGridPublisherClient)
5959
parsed_url = urlparse(eventgrid_topic_endpoint)
60-
client = EventGridPublisherClient(parsed_url.netloc, akc_credential)
60+
client = EventGridPublisherClient(parsed_url.netloc, credential)
6161
eg_event = EventGridEvent(
6262
subject="sample",
6363
data={"sample": "eventgridevent"},
@@ -273,9 +273,11 @@ def test_send_cloud_event_dict(self, eventgrid_cloud_event_topic_endpoint):
273273
}
274274
client.send(cloud_event1)
275275

276+
@pytest.mark.live_test_only
276277
@EventGridPreparer()
277-
@recorded_by_proxy
278-
def test_send_signature_credential(self, eventgrid_topic_key, eventgrid_topic_endpoint):
278+
def test_send_signature_credential(self, **kwargs):
279+
eventgrid_topic_endpoint = kwargs.pop("eventgrid_topic_endpoint")
280+
eventgrid_topic_key = kwargs.pop("eventgrid_topic_key")
279281
expiration_date_utc = dt.datetime.now(UTC()) + timedelta(hours=1)
280282
signature = generate_sas(eventgrid_topic_endpoint, eventgrid_topic_key, expiration_date_utc)
281283
credential = AzureSasCredential(signature)
@@ -355,14 +357,8 @@ def test_send_token_credential(self, eventgrid_topic_endpoint):
355357
@pytest.mark.live_test_only
356358
@EventGridPreparer()
357359
@recorded_by_proxy
358-
def test_send_partner_namespace(
359-
self,
360-
eventgrid_partner_namespace_topic_endpoint,
361-
eventgrid_partner_namespace_topic_key,
362-
eventgrid_partner_channel_name,
363-
):
364-
credential = AzureKeyCredential(eventgrid_partner_namespace_topic_key)
365-
client = EventGridPublisherClient(eventgrid_partner_namespace_topic_endpoint, credential)
360+
def test_send_partner_namespace(self, eventgrid_partner_namespace_topic_endpoint, eventgrid_partner_channel_name):
361+
client = self.create_eg_publisher_client(eventgrid_partner_namespace_topic_endpoint)
366362
cloud_event = CloudEvent(
367363
source="http://samplesource.dev",
368364
data="cloudevent",

0 commit comments

Comments
 (0)