mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-25 00:33:41 -04:00
Missed a couple of places where we should push to the queue.
This commit is contained in:
@@ -1,8 +1,9 @@
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from flask import (jsonify, request, abort)
|
from flask import (jsonify, request, abort, Blueprint)
|
||||||
from sqlalchemy.exc import DataError
|
from sqlalchemy.exc import DataError
|
||||||
from sqlalchemy.orm.exc import NoResultFound
|
from sqlalchemy.orm.exc import NoResultFound
|
||||||
from app.dao.services_dao import get_model_services
|
from app.dao.services_dao import get_model_services
|
||||||
|
from app.aws_sqs import add_notification_to_queue
|
||||||
from app.dao.users_dao import (
|
from app.dao.users_dao import (
|
||||||
get_model_users,
|
get_model_users,
|
||||||
save_model_user,
|
save_model_user,
|
||||||
@@ -16,8 +17,7 @@ from app.dao.users_dao import (
|
|||||||
from app.schemas import (
|
from app.schemas import (
|
||||||
user_schema, users_schema, service_schema, services_schema,
|
user_schema, users_schema, service_schema, services_schema,
|
||||||
request_verify_code_schema, user_schema_load_json)
|
request_verify_code_schema, user_schema_load_json)
|
||||||
from app import notify_alpha_client
|
from app import (notify_alpha_client, api_user)
|
||||||
from flask import Blueprint
|
|
||||||
|
|
||||||
|
|
||||||
user = Blueprint('user', __name__)
|
user = Blueprint('user', __name__)
|
||||||
@@ -137,16 +137,24 @@ def send_user_code(user_id):
|
|||||||
# notify_alpha_client
|
# notify_alpha_client
|
||||||
if verify_code.get('code_type') == 'sms':
|
if verify_code.get('code_type') == 'sms':
|
||||||
mobile = user.mobile_number if verify_code.get('to', None) is None else verify_code.get('to')
|
mobile = user.mobile_number if verify_code.get('to', None) is None else verify_code.get('to')
|
||||||
|
notification = {'to': mobile, 'content': secret_code}
|
||||||
|
add_notification_to_queue(api_user['client'], 'admin', 'sms', notification)
|
||||||
notify_alpha_client.send_sms(
|
notify_alpha_client.send_sms(
|
||||||
mobile_number=mobile,
|
mobile_number=mobile,
|
||||||
message=secret_code)
|
message=secret_code)
|
||||||
elif verify_code.get('code_type') == 'email':
|
elif verify_code.get('code_type') == 'email':
|
||||||
email = user.email_address if verify_code.get('to', None) is None else verify_code.get('to')
|
email = user.email_address if verify_code.get('to', None) is None else verify_code.get('to')
|
||||||
|
notification = {
|
||||||
|
'to_address': email,
|
||||||
|
'from_address': 'notify@digital.cabinet-office.gov.uk',
|
||||||
|
'subject': 'Verification code',
|
||||||
|
'body': secret_code}
|
||||||
|
add_notification_to_queue(api_user['client'], 'admin', 'sms', notification)
|
||||||
notify_alpha_client.send_email(
|
notify_alpha_client.send_email(
|
||||||
email,
|
email,
|
||||||
secret_code,
|
secret_code,
|
||||||
'notify@digital.cabinet-office.gov.uk',
|
notification['from_address'],
|
||||||
'Verification code')
|
notification['subject'])
|
||||||
else:
|
else:
|
||||||
abort(500)
|
abort(500)
|
||||||
return jsonify({}), 204
|
return jsonify({}), 204
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import json
|
import json
|
||||||
|
import moto
|
||||||
from datetime import (datetime, timedelta)
|
from datetime import (datetime, timedelta)
|
||||||
from flask import url_for
|
from flask import url_for
|
||||||
|
|
||||||
@@ -55,9 +56,11 @@ def test_user_verify_code_sms_missing_code(notify_api,
|
|||||||
assert not VerifyCode.query.first().code_used
|
assert not VerifyCode.query.first().code_used
|
||||||
|
|
||||||
|
|
||||||
|
@moto.mock_sqs
|
||||||
def test_user_verify_code_email(notify_api,
|
def test_user_verify_code_email(notify_api,
|
||||||
notify_db,
|
notify_db,
|
||||||
notify_db_session,
|
notify_db_session,
|
||||||
|
sqs_client_conn,
|
||||||
sample_email_code):
|
sample_email_code):
|
||||||
"""
|
"""
|
||||||
Tests POST endpoint '/<user_id>/verify/code'
|
Tests POST endpoint '/<user_id>/verify/code'
|
||||||
@@ -244,10 +247,12 @@ def test_user_verify_password_missing_password(notify_api,
|
|||||||
assert 'Required field missing data' in json_resp['message']['password']
|
assert 'Required field missing data' in json_resp['message']['password']
|
||||||
|
|
||||||
|
|
||||||
|
@moto.mock_sqs
|
||||||
def test_send_user_code_for_sms(notify_api,
|
def test_send_user_code_for_sms(notify_api,
|
||||||
notify_db,
|
notify_db,
|
||||||
notify_db_session,
|
notify_db_session,
|
||||||
sample_sms_code,
|
sample_sms_code,
|
||||||
|
sqs_client_conn,
|
||||||
mock_notify_client_send_sms,
|
mock_notify_client_send_sms,
|
||||||
mock_secret_code):
|
mock_secret_code):
|
||||||
"""
|
"""
|
||||||
@@ -270,10 +275,12 @@ def test_send_user_code_for_sms(notify_api,
|
|||||||
message='11111')
|
message='11111')
|
||||||
|
|
||||||
|
|
||||||
|
@moto.mock_sqs
|
||||||
def test_send_user_code_for_sms_with_optional_to_field(notify_api,
|
def test_send_user_code_for_sms_with_optional_to_field(notify_api,
|
||||||
notify_db,
|
notify_db,
|
||||||
notify_db_session,
|
notify_db_session,
|
||||||
sample_sms_code,
|
sample_sms_code,
|
||||||
|
sqs_client_conn,
|
||||||
mock_notify_client_send_sms,
|
mock_notify_client_send_sms,
|
||||||
mock_secret_code):
|
mock_secret_code):
|
||||||
"""
|
"""
|
||||||
@@ -296,10 +303,12 @@ def test_send_user_code_for_sms_with_optional_to_field(notify_api,
|
|||||||
message='11111')
|
message='11111')
|
||||||
|
|
||||||
|
|
||||||
|
@moto.mock_sqs
|
||||||
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,
|
||||||
sample_email_code,
|
sample_email_code,
|
||||||
|
sqs_client_conn,
|
||||||
mock_notify_client_send_email,
|
mock_notify_client_send_email,
|
||||||
mock_secret_code):
|
mock_secret_code):
|
||||||
"""
|
"""
|
||||||
@@ -323,10 +332,12 @@ def test_send_user_code_for_email(notify_api,
|
|||||||
'Verification code')
|
'Verification code')
|
||||||
|
|
||||||
|
|
||||||
|
@moto.mock_sqs
|
||||||
def test_send_user_code_for_email_uses_optional_to_field(notify_api,
|
def test_send_user_code_for_email_uses_optional_to_field(notify_api,
|
||||||
notify_db,
|
notify_db,
|
||||||
notify_db_session,
|
notify_db_session,
|
||||||
sample_email_code,
|
sample_email_code,
|
||||||
|
sqs_client_conn,
|
||||||
mock_notify_client_send_email,
|
mock_notify_client_send_email,
|
||||||
mock_secret_code):
|
mock_secret_code):
|
||||||
"""
|
"""
|
||||||
@@ -358,7 +369,6 @@ def test_request_verify_code_schema_invalid_code_type(notify_api, notify_db, not
|
|||||||
|
|
||||||
|
|
||||||
def test_request_verify_code_schema_with_to(notify_api, notify_db, notify_db_session, sample_user):
|
def test_request_verify_code_schema_with_to(notify_api, notify_db, notify_db_session, sample_user):
|
||||||
import json
|
|
||||||
from app.schemas import request_verify_code_schema
|
from app.schemas import request_verify_code_schema
|
||||||
data = json.dumps({'code_type': 'sms', 'to': 'some@one.gov.uk'})
|
data = json.dumps({'code_type': 'sms', 'to': 'some@one.gov.uk'})
|
||||||
code, error = request_verify_code_schema.loads(data)
|
code, error = request_verify_code_schema.loads(data)
|
||||||
|
|||||||
Reference in New Issue
Block a user