Return notification_id on create notification endpoints

- /notification/sms
 - /notification/email
 - /notificaiton/sms/service/<service_id>
Update message attribute on SQS to notification_id from message_id
This commit is contained in:
Rebecca Law
2016-02-10 11:15:41 +00:00
parent ea22e53453
commit a01828a6d0
3 changed files with 15 additions and 14 deletions

View File

@@ -10,11 +10,12 @@ def add_notification_to_queue(service_id, template_id, type_, notification):
).create_queue(QueueName="{}_{}".format( ).create_queue(QueueName="{}_{}".format(
current_app.config['NOTIFICATION_QUEUE_PREFIX'], current_app.config['NOTIFICATION_QUEUE_PREFIX'],
str(service_id))) str(service_id)))
message_id = str(uuid.uuid4()) notification_id = str(uuid.uuid4())
serializer = URLSafeSerializer(current_app.config.get('SECRET_KEY')) serializer = URLSafeSerializer(current_app.config.get('SECRET_KEY'))
encrypted = serializer.dumps(notification, current_app.config.get('DANGEROUS_SALT')) encrypted = serializer.dumps(notification, current_app.config.get('DANGEROUS_SALT'))
q.send_message(MessageBody=encrypted, q.send_message(MessageBody=encrypted,
MessageAttributes={'type': {'StringValue': type_, 'DataType': 'String'}, MessageAttributes={'type': {'StringValue': type_, 'DataType': 'String'},
'message_id': {'StringValue': message_id, 'DataType': 'String'}, 'notification_id': {'StringValue': notification_id, 'DataType': 'String'},
'service_id': {'StringValue': str(service_id), 'DataType': 'String'}, 'service_id': {'StringValue': str(service_id), 'DataType': 'String'},
'template_id': {'StringValue': str(template_id), 'DataType': 'String'}}) 'template_id': {'StringValue': str(template_id), 'DataType': 'String'}})
return notification_id

View File

@@ -29,9 +29,8 @@ def create_sms_notification():
if errors: if errors:
return jsonify(result="error", message=errors), 400 return jsonify(result="error", message=errors), 400
add_notification_to_queue(api_user['client'], notification['template'], 'sms', notification) notification_id = add_notification_to_queue(api_user['client'], notification['template'], 'sms', notification)
# TODO data to be returned return jsonify({'notification_id': notification_id}), 201
return jsonify({}), 204
@notifications.route('/email', methods=['POST']) @notifications.route('/email', methods=['POST'])
@@ -40,9 +39,8 @@ def create_email_notification():
notification, errors = email_notification_schema.load(resp_json) notification, errors = email_notification_schema.load(resp_json)
if errors: if errors:
return jsonify(result="error", message=errors), 400 return jsonify(result="error", message=errors), 400
add_notification_to_queue(api_user['client'], "admin", 'email', notification) notification_id = add_notification_to_queue(api_user['client'], "admin", 'email', notification)
# TODO data to be returned return jsonify({'notification_id': notification_id}), 201
return jsonify({}), 204
@notifications.route('/sms/service/<service_id>', methods=['POST']) @notifications.route('/sms/service/<service_id>', methods=['POST'])
@@ -66,6 +64,5 @@ def create_sms_for_service(service_id):
message = "Invalid template: id {} for service id: {}".format(template.id, service_id) message = "Invalid template: id {} for service id: {}".format(template.id, service_id)
return jsonify(result="error", message=message), 400 return jsonify(result="error", message=message), 400
add_notification_to_queue(service_id, template_id, 'sms', notification) notification_id = add_notification_to_queue(service_id, template_id, 'sms', notification)
# TODO data to be returned return jsonify({'notification_id': notification_id}), 201
return jsonify({}), 204

View File

@@ -199,7 +199,8 @@ def test_should_allow_valid_message(notify_api,
data=json.dumps(data), data=json.dumps(data),
headers=[('Content-Type', 'application/json'), auth_header]) headers=[('Content-Type', 'application/json'), auth_header])
assert response.status_code == 204 assert response.status_code == 201
assert json.loads(response.data)['notification_id'] is not None
@moto.mock_sqs @moto.mock_sqs
@@ -232,7 +233,8 @@ def test_send_email_valid_data(notify_api,
data=json.dumps(data), data=json.dumps(data),
headers=[('Content-Type', 'application/json'), auth_header]) headers=[('Content-Type', 'application/json'), auth_header])
assert response.status_code == 204 assert response.status_code == 201
assert json.loads(response.data)['notification_id'] is not None
@moto.mock_sqs @moto.mock_sqs
@@ -263,7 +265,8 @@ def test_valid_message_with_service_id(notify_api,
data=json.dumps(data), data=json.dumps(data),
headers=[('Content-Type', 'application/json'), auth_header]) headers=[('Content-Type', 'application/json'), auth_header])
assert response.status_code == 204 assert response.status_code == 201
assert json.loads(response.data)['notification_id'] is not None
@moto.mock_sqs @moto.mock_sqs