Update the from number in the response of post notification.

This commit is contained in:
Rebecca Law
2017-11-10 14:17:29 +00:00
parent 24b7acf671
commit fe6bafcfb2
4 changed files with 5 additions and 4 deletions

View File

@@ -155,7 +155,7 @@ def check_service_sms_sender_id(service_id, sms_sender_id, notification_type):
message = 'sms_sender_id is not a valid option for {} notification'.format(notification_type) message = 'sms_sender_id is not a valid option for {} notification'.format(notification_type)
raise BadRequestError(message=message) raise BadRequestError(message=message)
try: try:
dao_get_service_sms_senders_by_id(service_id, sms_sender_id) return dao_get_service_sms_senders_by_id(service_id, sms_sender_id).sms_sender
except NoResultFound: except NoResultFound:
message = 'sms_sender_id {} does not exist in database for service id {}'\ message = 'sms_sender_id {} does not exist in database for service id {}'\
.format(sms_sender_id, service_id) .format(sms_sender_id, service_id)

View File

@@ -71,7 +71,7 @@ def post_notification(notification_type):
check_rate_limiting(authenticated_service, api_user) check_rate_limiting(authenticated_service, api_user)
check_service_email_reply_to_id(str(authenticated_service.id), service_email_reply_to_id, notification_type) check_service_email_reply_to_id(str(authenticated_service.id), service_email_reply_to_id, notification_type)
check_service_sms_sender_id(str(authenticated_service.id), service_sms_sender_id, notification_type) sms_sender = check_service_sms_sender_id(str(authenticated_service.id), service_sms_sender_id, notification_type)
template, template_with_content = validate_template( template, template_with_content = validate_template(
form['template_id'], form['template_id'],
@@ -98,7 +98,7 @@ def post_notification(notification_type):
if notification_type == SMS_TYPE: if notification_type == SMS_TYPE:
create_resp_partial = functools.partial( create_resp_partial = functools.partial(
create_post_sms_response_from_notification, create_post_sms_response_from_notification,
from_number=authenticated_service.get_default_sms_sender() from_number=sms_sender or authenticated_service.get_default_sms_sender()
) )
elif notification_type == EMAIL_TYPE: elif notification_type == EMAIL_TYPE:
create_resp_partial = functools.partial( create_resp_partial = functools.partial(

View File

@@ -374,7 +374,7 @@ def test_check_service_sms_sender_id_where_sms_sender_id_is_none(notification_ty
def test_check_service_sms_sender_id_where_sms_sender_id_is_found(sample_service): def test_check_service_sms_sender_id_where_sms_sender_id_is_found(sample_service):
sms_sender = create_service_sms_sender(service=sample_service, sms_sender='123456') sms_sender = create_service_sms_sender(service=sample_service, sms_sender='123456')
assert check_service_sms_sender_id(sample_service.id, sms_sender.id, SMS_TYPE) is None assert check_service_sms_sender_id(sample_service.id, sms_sender.id, SMS_TYPE) == '123456'
def test_check_service_sms_sender_id_where_service_id_is_not_found(sample_service, fake_uuid): def test_check_service_sms_sender_id_where_service_id_is_not_found(sample_service, fake_uuid):

View File

@@ -118,6 +118,7 @@ def test_post_sms_notification_returns_201_with_sms_sender_id(
notification_to_sms_sender = NotificationSmsSender.query.all() notification_to_sms_sender = NotificationSmsSender.query.all()
assert len(notification_to_sms_sender) == 1 assert len(notification_to_sms_sender) == 1
assert str(notification_to_sms_sender[0].notification_id) == resp_json['id'] assert str(notification_to_sms_sender[0].notification_id) == resp_json['id']
assert resp_json['content']['from_number'] == sms_sender.sms_sender
assert notification_to_sms_sender[0].service_sms_sender_id == sms_sender.id assert notification_to_sms_sender[0].service_sms_sender_id == sms_sender.id
mocked.assert_called_once_with([resp_json['id']], queue='send-sms-tasks') mocked.assert_called_once_with([resp_json['id']], queue='send-sms-tasks')