Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Communication]: Added unit tests to check if idempotence parameters are being set #18739

Merged
merged 2 commits into from
May 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)