From 541adce75b63fa64173f312c8023b15c775c863f Mon Sep 17 00:00:00 2001 From: Lakshman Sundaralingam Date: Fri, 14 May 2021 11:02:45 -0700 Subject: [PATCH] [Communication]: Added unit tests to check if idempotence parameters are being set (#18739) * Added unit tests to check if idempotence parameters are being set * Refactored send message parameters unit tests --- .../tests/test_sms_client.py | 28 +++++++++++++++++-- .../tests/test_sms_client_async.py | 24 ++++++++++++++++ 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/sdk/communication/azure-communication-sms/tests/test_sms_client.py b/sdk/communication/azure-communication-sms/tests/test_sms_client.py index 9007beb05ccc..5048420de3ad 100644 --- a/sdk/communication/azure-communication-sms/tests/test_sms_client.py +++ b/sdk/communication/azure-communication-sms/tests/test_sms_client.py @@ -10,9 +10,9 @@ from unittest_helpers import mock_response try: - from unittest.mock import Mock + from unittest.mock import Mock, patch except ImportError: # python < 3.3 - from mock import Mock # type: ignore + from mock import Mock, patch # type: ignore class FakeTokenCredential(object): def __init__(self): @@ -61,3 +61,27 @@ def mock_send(*_, **__): self.assertEqual(202, sms_response.http_status_code) self.assertIsNotNone(sms_response.error_message) self.assertTrue(sms_response.successful) + + @patch( + "azure.communication.sms._generated.operations._sms_operations.SmsOperations.send" + ) + def test_send_message_parameters(self, mock_send): + phone_number = "+14255550123" + msg = "Hello World via SMS" + tag = "custom-tag" + + sms_client = SmsClient("https://endpoint", FakeTokenCredential()) + sms_client.send( + from_=phone_number, + to=[phone_number], + message=msg, + enable_delivery_report=True, + tag=tag) + + send_message_request = mock_send.call_args[0][0] + self.assertEqual(phone_number, send_message_request.from_property) + self.assertEqual(phone_number, send_message_request.sms_recipients[0].to) + self.assertIsNotNone(send_message_request.sms_recipients[0].repeatability_request_id) + self.assertIsNotNone(send_message_request.sms_recipients[0].repeatability_first_sent) + self.assertTrue(send_message_request.sms_send_options.enable_delivery_report) + self.assertEqual(tag, send_message_request.sms_send_options.tag) diff --git a/sdk/communication/azure-communication-sms/tests/test_sms_client_async.py b/sdk/communication/azure-communication-sms/tests/test_sms_client_async.py index f5b9e3025dcf..c13b480a4883 100644 --- a/sdk/communication/azure-communication-sms/tests/test_sms_client_async.py +++ b/sdk/communication/azure-communication-sms/tests/test_sms_client_async.py @@ -61,3 +61,27 @@ async def mock_send(*_, **__): self.assertEqual(202, sms_response.http_status_code) self.assertIsNotNone(sms_response.error_message) self.assertTrue(sms_response.successful) + + @patch( + "azure.communication.sms._generated.aio.operations._sms_operations.SmsOperations.send" + ) + async def test_send_message_parameters_async(self, mock_send): + phone_number = "+14255550123" + msg = "Hello World via SMS" + tag = "custom-tag" + + sms_client = SmsClient("https://endpoint", FakeTokenCredential()) + await sms_client.send( + from_=phone_number, + to=[phone_number], + message=msg, + enable_delivery_report=True, + tag=tag) + + send_message_request = mock_send.call_args[0][0] + self.assertEqual(phone_number, send_message_request.from_property) + self.assertEqual(phone_number, send_message_request.sms_recipients[0].to) + self.assertIsNotNone(send_message_request.sms_recipients[0].repeatability_request_id) + self.assertIsNotNone(send_message_request.sms_recipients[0].repeatability_first_sent) + self.assertTrue(send_message_request.sms_send_options.enable_delivery_report) + self.assertEqual(tag, send_message_request.sms_send_options.tag)