async def sms_token_credential_auth_async(self): # To use Azure Active Directory Authentication (DefaultAzureCredential) make sure to have # AZURE_TENANT_ID, AZURE_CLIENT_ID and AZURE_CLIENT_SECRET as env variables. endpoint, _ = parse_connection_str(self.connection_string) sms_client = SmsClient(endpoint, DefaultAzureCredential()) async with sms_client: try: # calling send() with sms values sms_responses = await sms_client.send( from_=self.phone_number, to=self.phone_number, message="Hello World via SMS") sms_response = sms_responses[0] if (sms_response.successful): print( "Message with message id {} was successful sent to {}". format(sms_response.message_id, sms_response.to)) else: print( "Message failed to send to {} with the status code {} and error: {}" .format(sms_response.to, sms_response.http_status_code, sms_response.error_message)) except Exception: print(Exception) pass
def setUp(self): super(CommunicationTestCase, self).setUp() if self.is_playback(): self.connection_str = "endpoint=https://sanitized/;accesskey=fake===" else: self.connection_str = os.getenv('AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING') endpoint, _ = parse_connection_str(self.connection_str) self._resource_name = endpoint.split(".")[0] self.scrubber.register_name_pair(self._resource_name, "sanitized")
def test_send_sms_from_managed_identity(self): endpoint, access_key = parse_connection_str(self.connection_str) from devtools_testutils import is_live if not is_live(): credential = FakeTokenCredential() else: credential = DefaultAzureCredential() sms_client = SmsClient(endpoint, credential) # calling send() with sms values sms_responses = sms_client.send(from_=self.phone_number, to=[self.phone_number], message="Hello World via SMS") assert len(sms_responses) == 1 self.verify_successful_sms_response(sms_responses[0])
async def test_send_sms_async_from_managed_identity(self): endpoint, access_key = parse_connection_str(self.connection_str) from devtools_testutils import is_live if not is_live(): credential = FakeTokenCredential() else: credential = DefaultAzureCredential() sms_client = SmsClient(endpoint, credential) print(sms_client) async with sms_client: # calling send() with sms values sms_response = await sms_client.send( from_phone_number=PhoneNumber(self.phone_number), to_phone_numbers=[PhoneNumber(self.phone_number)], message="Hello World via SMS", send_sms_options=SendSmsOptions(enable_delivery_report=True) ) # optional property assert sms_response.message_id is not None
async def test_send_sms_async_from_managed_identity(self): endpoint, access_key = parse_connection_str(self.connection_str) from devtools_testutils import is_live if not is_live(): credential = FakeTokenCredential() else: credential = DefaultAzureCredential() sms_client = SmsClient(endpoint, credential) async with sms_client: # calling send() with sms values sms_responses = await sms_client.send( from_=self.phone_number, to=[self.phone_number], message="Hello World via SMS", enable_delivery_report=True, # optional property tag="custom-tag") # optional property assert len(sms_responses) is 1 for sms_response in sms_responses: self.verify_sms_response(sms_response)