mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-09 17:45:41 -04:00
Update send user code to use optional to field 'to' send the sms message to.
This commit is contained in:
@@ -124,8 +124,9 @@ def send_user_code(user_id):
|
|||||||
# TODO this will need to fixed up when we stop using
|
# TODO this will need to fixed up when we stop using
|
||||||
# notify_alpha_client
|
# notify_alpha_client
|
||||||
if verify_code['code_type'] == 'sms':
|
if verify_code['code_type'] == 'sms':
|
||||||
|
mobile = user.mobile_number if 'to' not in verify_code else verify_code['to']
|
||||||
notify_alpha_client.send_sms(
|
notify_alpha_client.send_sms(
|
||||||
mobile_number=user.mobile_number,
|
mobile_number=mobile,
|
||||||
message=secret_code)
|
message=secret_code)
|
||||||
elif verify_code['code_type'] == 'email':
|
elif verify_code['code_type'] == 'email':
|
||||||
email = user.email_address if 'to' not in verify_code else verify_code['to']
|
email = user.email_address if 'to' not in verify_code else verify_code['to']
|
||||||
|
|||||||
@@ -231,6 +231,32 @@ def test_send_user_code_for_sms(notify_api,
|
|||||||
message='11111')
|
message='11111')
|
||||||
|
|
||||||
|
|
||||||
|
def test_send_user_code_for_sms_with_optional_to_field(notify_api,
|
||||||
|
notify_db,
|
||||||
|
notify_db_session,
|
||||||
|
sample_sms_code,
|
||||||
|
mock_notify_client_send_sms,
|
||||||
|
mock_secret_code):
|
||||||
|
"""
|
||||||
|
Tests POST endpoint '/<user_id>/code' successful sms with optional to field
|
||||||
|
"""
|
||||||
|
with notify_api.test_request_context():
|
||||||
|
with notify_api.test_client() as client:
|
||||||
|
data = json.dumps({'code_type': 'sms', 'to': '+441119876757'})
|
||||||
|
auth_header = create_authorization_header(
|
||||||
|
path=url_for('user.send_user_code', user_id=sample_sms_code.user.id),
|
||||||
|
method='POST',
|
||||||
|
request_body=data)
|
||||||
|
resp = client.post(
|
||||||
|
url_for('user.send_user_code', user_id=sample_sms_code.user.id),
|
||||||
|
data=data,
|
||||||
|
headers=[('Content-Type', 'application/json'), auth_header])
|
||||||
|
|
||||||
|
assert resp.status_code == 204
|
||||||
|
mock_notify_client_send_sms.assert_called_once_with(mobile_number='+441119876757',
|
||||||
|
message='11111')
|
||||||
|
|
||||||
|
|
||||||
def test_send_user_code_for_email(notify_api,
|
def test_send_user_code_for_email(notify_api,
|
||||||
notify_db,
|
notify_db,
|
||||||
notify_db_session,
|
notify_db_session,
|
||||||
|
|||||||
Reference in New Issue
Block a user