mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-08 23:23:12 -04:00
Refactor to re-use existing contract-dependent method
This commit is contained in:
@@ -260,9 +260,10 @@ def send_notification(notification_type):
|
|||||||
status_code=400
|
status_code=400
|
||||||
)
|
)
|
||||||
|
|
||||||
|
notification_id = create_uuid()
|
||||||
|
notification.update({"template_version": template.version})
|
||||||
|
|
||||||
if not _simulated_recipient(notification['to'], notification_type):
|
if not _simulated_recipient(notification['to'], notification_type):
|
||||||
notification_id = create_uuid()
|
|
||||||
notification.update({"template_version": template.version})
|
|
||||||
persist_notification(
|
persist_notification(
|
||||||
service,
|
service,
|
||||||
notification_id,
|
notification_id,
|
||||||
@@ -273,16 +274,12 @@ def send_notification(notification_type):
|
|||||||
api_user.key_type
|
api_user.key_type
|
||||||
)
|
)
|
||||||
|
|
||||||
return jsonify(
|
return jsonify(
|
||||||
data=get_notification_return_data(
|
data=get_notification_return_data(
|
||||||
notification_id,
|
notification_id,
|
||||||
notification,
|
notification,
|
||||||
template_object)
|
template_object)
|
||||||
), 201
|
), 201
|
||||||
else:
|
|
||||||
return jsonify(
|
|
||||||
data=_get_simulated_recipient_response_data(template_object)
|
|
||||||
), 200
|
|
||||||
|
|
||||||
|
|
||||||
def get_notification_return_data(notification_id, notification, template):
|
def get_notification_return_data(notification_id, notification, template):
|
||||||
@@ -314,18 +311,6 @@ def _simulated_recipient(to_address, notification_type):
|
|||||||
else to_address in current_app.config['SIMULATED_EMAIL_ADDRESSES'])
|
else to_address in current_app.config['SIMULATED_EMAIL_ADDRESSES'])
|
||||||
|
|
||||||
|
|
||||||
def _get_simulated_recipient_response_data(template_object):
|
|
||||||
response_data = {
|
|
||||||
'body': template_object.replaced,
|
|
||||||
'template_version': template_object._template['version']
|
|
||||||
}
|
|
||||||
|
|
||||||
if template_object._template['template_type'] == 'email':
|
|
||||||
response_data.update({'subject': template_object.replaced_subject})
|
|
||||||
|
|
||||||
return response_data
|
|
||||||
|
|
||||||
|
|
||||||
def persist_notification(
|
def persist_notification(
|
||||||
service,
|
service,
|
||||||
notification_id,
|
notification_id,
|
||||||
|
|||||||
@@ -963,7 +963,7 @@ def test_should_not_send_email_if_simulated_email_address(client, to_email, samp
|
|||||||
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 == 200
|
assert response.status_code == 201
|
||||||
apply_async.assert_not_called()
|
apply_async.assert_not_called()
|
||||||
|
|
||||||
|
|
||||||
@@ -987,5 +987,5 @@ def test_should_not_send_sms_if_simulated_sms_number(client, to_sms, sample_temp
|
|||||||
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 == 200
|
assert response.status_code == 201
|
||||||
apply_async.assert_not_called()
|
apply_async.assert_not_called()
|
||||||
|
|||||||
Reference in New Issue
Block a user