Files
notifications-api/tests/app/clients/test_aws_sns.py

37 lines
1.1 KiB
Python
Raw Normal View History

2022-06-17 11:16:23 -07:00
import pytest
2022-06-17 11:16:23 -07:00
from app import aws_sns_client
2022-06-17 11:16:23 -07:00
def test_send_sms_successful_returns_aws_sns_response(notify_api, mocker):
2023-08-29 14:54:30 -07:00
boto_mock = mocker.patch.object(aws_sns_client, "_client", create=True)
2022-06-17 11:16:23 -07:00
to = "6135555555"
2023-08-29 14:54:30 -07:00
content = reference = "foo"
2022-06-17 11:16:23 -07:00
with notify_api.app_context():
aws_sns_client.send_sms(to, content, reference)
boto_mock.publish.assert_called_once_with(
PhoneNumber="+16135555555",
Message=content,
2023-02-28 16:50:00 -05:00
MessageAttributes={
2023-08-29 14:54:30 -07:00
"AWS.SNS.SMS.SMSType": {
"DataType": "String",
"StringValue": "Transactional",
},
"AWS.MM.SMS.OriginationNumber": {
"DataType": "String",
"StringValue": "+18556438890",
},
},
2022-06-17 11:16:23 -07:00
)
2023-08-29 14:54:30 -07:00
def test_send_sms_returns_raises_error_if_there_is_no_valid_number_is_found(
notify_api, mocker
):
mocker.patch.object(aws_sns_client, "_client", create=True)
2022-06-17 11:16:23 -07:00
to = ""
2023-08-29 14:54:30 -07:00
content = reference = "foo"
2022-06-17 11:16:23 -07:00
with pytest.raises(ValueError) as excinfo:
aws_sns_client.send_sms(to, content, reference)
2023-08-29 14:54:30 -07:00
assert "No valid numbers found for SMS delivery" in str(excinfo.value)