Skip to content

Commit f98d6ad

Browse files
[ACS][CallAutomation] Live Test Updated V2 (Azure#38908)
* live test update v2 * fixing typing * fixing typing 2
1 parent ae4f530 commit f98d6ad

File tree

24 files changed

+42
-36
lines changed

24 files changed

+42
-36
lines changed

sdk/communication/azure-communication-callautomation/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/communication/azure-communication-callautomation",
5-
"Tag": "python/communication/azure-communication-callautomation_f861ccd219"
5+
"Tag": "python/communication/azure-communication-callautomation_bd0d24ba7b"
66
}

sdk/communication/azure-communication-callautomation/tests/callautomation_test_case.py

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
import requests
1515
from azure.servicebus import ServiceBusClient
16+
from azure.identity import AzureCliCredential
1617
from devtools_testutils import AzureRecordedTestCase, is_live
1718
from devtools_testutils.helpers import get_test_id
1819

@@ -26,33 +27,34 @@
2627
from azure.communication.identity import CommunicationIdentityClient
2728
from azure.communication.phonenumbers import PhoneNumbersClient
2829

29-
3030
class CallAutomationRecordedTestCase(AzureRecordedTestCase):
3131
@classmethod
3232
def setup_class(cls):
3333
if is_live():
3434
print("Live Test")
3535
cls.connection_str = os.environ.get('COMMUNICATION_LIVETEST_STATIC_CONNECTION_STRING')
36-
cls.servicebus_connection_str = os.environ.get('SERVICEBUS_STRING')
36+
cls.servicebus_str = os.environ.get('SERVICEBUS_STRING')
3737
cls.dispatcher_endpoint = os.environ.get('DISPATCHER_ENDPOINT')
3838
cls.file_source_url = os.environ.get('FILE_SOURCE_URL')
3939
cls.cognitive_service_endpoint = os.environ.get('COGNITIVE_SERVICE_ENDPOINT')
4040
cls.transport_url = os.environ.get('TRANSPORT_URL')
4141
else:
4242
print("Recorded Test")
4343
cls.connection_str = "endpoint=https://someEndpoint/;accesskey=someAccessKeyw=="
44-
cls.servicebus_connection_str = (
45-
"Endpoint=sb://someEndpoint/;SharedAccessKeyName=somekey;SharedAccessKey=someAccessKey="
46-
)
44+
cls.servicebus_str = "redacted.servicebus.windows.net"
4745
cls.dispatcher_endpoint = "https://REDACTED.azurewebsites.net"
4846
cls.file_source_url = "https://REDACTED/prompt.wav"
4947
cls.cognitive_service_endpoint = "https://sanitized/"
50-
cls.transport_url ="wss://REDACTED"
48+
cls.transport_url ="wss://sanitized/ws"
49+
5150

51+
cls.credential = AzureCliCredential()
5252
cls.dispatcher_callback = cls.dispatcher_endpoint + "/api/servicebuscallback/events"
5353
cls.identity_client = CommunicationIdentityClient.from_connection_string(cls.connection_str)
5454
cls.phonenumber_client = PhoneNumbersClient.from_connection_string(cls.connection_str)
55-
cls.service_bus_client = ServiceBusClient.from_connection_string(cls.servicebus_connection_str)
55+
cls.service_bus_client = ServiceBusClient(
56+
fully_qualified_namespace=cls.servicebus_str,
57+
credential=cls.credential)
5658

5759
cls.wait_for_event_flags = []
5860
cls.event_store: Dict[str, Dict[str, Any]] = {}
@@ -84,18 +86,14 @@ def _format_string(s) -> str:
8486
s2 = f"{s[36:44]}-{s[44:48]}-{s[48:52]}-{s[52:56]}-{s[56:]}"
8587
return f"{s1}_{s2}"
8688

87-
@staticmethod
88-
def _format_phonenumber_string(s) -> str:
89-
return s.replace(":+", "u002B")
90-
9189
@staticmethod
9290
def _parse_ids_from_identifier(identifier: CommunicationIdentifier) -> str:
9391
if identifier is None:
9492
raise ValueError("Identifier cannot be None")
9593
elif identifier.kind == CommunicationIdentifierKind.COMMUNICATION_USER:
9694
return CallAutomationRecordedTestCase._format_string("".join(filter(str.isalnum, identifier.raw_id)))
9795
elif identifier.kind == CommunicationIdentifierKind.PHONE_NUMBER:
98-
return CallAutomationRecordedTestCase._format_phonenumber_string(identifier.raw_id)
96+
return identifier.raw_id
9997
else:
10098
raise ValueError("Identifier type not supported")
10199

@@ -159,8 +157,10 @@ def _record_method_events(self) -> None:
159157
if is_live():
160158
file_path = self._get_test_event_file_name()
161159
try:
160+
keys_to_redact = ["incomingCallContext", "callerDisplayName"]
161+
redacted_dict = self.redact_by_key(self.event_to_save, keys_to_redact)
162162
with open(file_path, "w") as json_file:
163-
json.dump(self.event_to_save, json_file)
163+
json.dump(redacted_dict, json_file)
164164
except IOError as e:
165165
raise SystemExit(f"File write operation failed: {e}")
166166

@@ -394,4 +394,11 @@ def establish_callconnection_voip_connect_call(self, caller, target) -> tuple:
394394
call_connection_target = CallConnectionClient.from_connection_string(self.connection_str, answer_call_result.call_connection_id)
395395
self.open_call_connections[unique_id] = call_connection_caller
396396

397-
return unique_id, call_connection_caller, call_connection_target, call_automation_client_caller, callback_url
397+
return unique_id, call_connection_caller, call_connection_target, call_automation_client_caller, callback_url
398+
399+
def redact_by_key(self, data: Dict[str, Dict[str, any]], keys_to_redact: List[str]) -> Dict[str, Dict[str, any]]:
400+
for _, inner_dict in data.items():
401+
for key in keys_to_redact:
402+
if key in inner_dict:
403+
inner_dict[key] = "REDACTED"
404+
return data

sdk/communication/azure-communication-callautomation/tests/conftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def start_proxy(test_proxy):
3030
add_body_key_sanitizer(json_path="callbackUri", value="https://sanitized/")
3131
add_body_key_sanitizer(json_path="transportUrl", value="https://sanitized/")
3232
add_body_key_sanitizer(json_path="$..file.uri", value="https://REDACTED/prompt.wav")
33+
add_body_key_sanitizer(json_path="$..incomingCallContext", value="REDACTED")
3334
add_header_regex_sanitizer(key="Set-Cookie", value="sanitized")
3435
add_header_regex_sanitizer(key="Date", value="sanitized")
3536
add_header_regex_sanitizer(key="Cookie", value="sanitized")

sdk/communication/azure-communication-callautomation/tests/events/test_e2e_callautomation_client.pyTestCallAutomationClientAutomatedLiveTesttest_add_participant_then_cancel_request.event.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

sdk/communication/azure-communication-callautomation/tests/events/test_e2e_callautomation_client.pyTestCallAutomationClientAutomatedLiveTesttest_create_VOIP_call_and_answer_then_hangup.event.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

sdk/communication/azure-communication-callautomation/tests/events/test_e2e_callautomation_client.pyTestCallAutomationClientAutomatedLiveTesttest_create_VOIP_call_and_connect_call_then_hangup.event.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)