mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-04 02:11:11 -05: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 flask import (jsonify, request, abort)
|
||||
from flask import (jsonify, request, abort, Blueprint)
|
||||
from sqlalchemy.exc import DataError
|
||||
from sqlalchemy.orm.exc import NoResultFound
|
||||
from app.dao.services_dao import get_model_services
|
||||
from app.aws_sqs import add_notification_to_queue
|
||||
from app.dao.users_dao import (
|
||||
get_model_users,
|
||||
save_model_user,
|
||||
@@ -16,8 +17,7 @@ from app.dao.users_dao import (
|
||||
from app.schemas import (
|
||||
user_schema, users_schema, service_schema, services_schema,
|
||||
request_verify_code_schema, user_schema_load_json)
|
||||
from app import notify_alpha_client
|
||||
from flask import Blueprint
|
||||
from app import (notify_alpha_client, api_user)
|
||||
|
||||
|
||||
user = Blueprint('user', __name__)
|
||||
@@ -137,16 +137,24 @@ def send_user_code(user_id):
|
||||
# notify_alpha_client
|
||||
if verify_code.get('code_type') == 'sms':
|
||||
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(
|
||||
mobile_number=mobile,
|
||||
message=secret_code)
|
||||
elif verify_code.get('code_type') == 'email':
|
||||
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(
|
||||
email,
|
||||
secret_code,
|
||||
'notify@digital.cabinet-office.gov.uk',
|
||||
'Verification code')
|
||||
notification['from_address'],
|
||||
notification['subject'])
|
||||
else:
|
||||
abort(500)
|
||||
return jsonify({}), 204
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import json
|
||||
import moto
|
||||
from datetime import (datetime, timedelta)
|
||||
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
|
||||
|
||||
|
||||
@moto.mock_sqs
|
||||
def test_user_verify_code_email(notify_api,
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
sqs_client_conn,
|
||||
sample_email_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']
|
||||
|
||||
|
||||
@moto.mock_sqs
|
||||
def test_send_user_code_for_sms(notify_api,
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
sample_sms_code,
|
||||
sqs_client_conn,
|
||||
mock_notify_client_send_sms,
|
||||
mock_secret_code):
|
||||
"""
|
||||
@@ -270,10 +275,12 @@ def test_send_user_code_for_sms(notify_api,
|
||||
message='11111')
|
||||
|
||||
|
||||
@moto.mock_sqs
|
||||
def test_send_user_code_for_sms_with_optional_to_field(notify_api,
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
sample_sms_code,
|
||||
sqs_client_conn,
|
||||
mock_notify_client_send_sms,
|
||||
mock_secret_code):
|
||||
"""
|
||||
@@ -296,10 +303,12 @@ def test_send_user_code_for_sms_with_optional_to_field(notify_api,
|
||||
message='11111')
|
||||
|
||||
|
||||
@moto.mock_sqs
|
||||
def test_send_user_code_for_email(notify_api,
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
sample_email_code,
|
||||
sqs_client_conn,
|
||||
mock_notify_client_send_email,
|
||||
mock_secret_code):
|
||||
"""
|
||||
@@ -323,10 +332,12 @@ def test_send_user_code_for_email(notify_api,
|
||||
'Verification code')
|
||||
|
||||
|
||||
@moto.mock_sqs
|
||||
def test_send_user_code_for_email_uses_optional_to_field(notify_api,
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
sample_email_code,
|
||||
sqs_client_conn,
|
||||
mock_notify_client_send_email,
|
||||
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):
|
||||
import json
|
||||
from app.schemas import request_verify_code_schema
|
||||
data = json.dumps({'code_type': 'sms', 'to': 'some@one.gov.uk'})
|
||||
code, error = request_verify_code_schema.loads(data)
|
||||
|
||||
Reference in New Issue
Block a user