Skip to content

Commit

Permalink
[Communication]: Added unit tests to check if idempotence parameters …
Browse files Browse the repository at this point in the history
…are being set (#18739)

* Added unit tests to check if idempotence parameters are being set

* Refactored send message parameters unit tests
  • Loading branch information
lsundaralingam authored May 14, 2021
1 parent 5486fc9 commit 541adce
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
28 changes: 26 additions & 2 deletions sdk/communication/azure-communication-sms/tests/test_sms_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 541adce

Please sign in to comment.