mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-30 14:31:57 -05:00
- is_default is required on the add_service_email_reply_to_request schema
- Added check that the service exists for the POST reply-to methods. - Added tests
This commit is contained in:
@@ -75,10 +75,10 @@ def _get_existing_default(service_id):
|
||||
if len(old_default) == 1:
|
||||
return old_default[0]
|
||||
else:
|
||||
# is this check necessary
|
||||
raise InvalidRequest(
|
||||
raise Exception(
|
||||
"There should only be one default reply to email for each service. Service {} has {}".format(
|
||||
service_id, len(old_default)))
|
||||
return None
|
||||
|
||||
|
||||
def _reset_old_default_to_false(old_default):
|
||||
|
||||
@@ -533,6 +533,8 @@ def get_email_reply_to_addresses(service_id):
|
||||
|
||||
@service_blueprint.route('/<uuid:service_id>/email-reply-to', methods=['POST'])
|
||||
def add_service_reply_to_email_address(service_id):
|
||||
# validate the service exists, throws ResultNotFound exception.
|
||||
dao_fetch_service_by_id(service_id)
|
||||
form = validate(request.get_json(), add_service_email_reply_to_request)
|
||||
new_reply_to = add_reply_to_email_address_for_service(service_id=service_id,
|
||||
email_address=form['email_address'],
|
||||
@@ -540,11 +542,13 @@ def add_service_reply_to_email_address(service_id):
|
||||
return jsonify(data=new_reply_to.serialize()), 201
|
||||
|
||||
|
||||
@service_blueprint.route('/<uuid:service_id>/email-reply-to/<uuid:id>', methods=['POST'])
|
||||
def update_service_reply_to_email_address(service_id, id):
|
||||
@service_blueprint.route('/<uuid:service_id>/email-reply-to/<uuid:reply_to_email_id>', methods=['POST'])
|
||||
def update_service_reply_to_email_address(service_id, reply_to_email_id):
|
||||
# validate the service exists, throws ResultNotFound exception.
|
||||
dao_fetch_service_by_id(service_id)
|
||||
form = validate(request.get_json(), add_service_email_reply_to_request)
|
||||
new_reply_to = update_reply_to_email_address(service_id=service_id,
|
||||
reply_to_id=id,
|
||||
reply_to_id=reply_to_email_id,
|
||||
email_address=form['email_address'],
|
||||
is_default=form.get('is_default', True))
|
||||
return jsonify(data=new_reply_to.serialize()), 200
|
||||
|
||||
@@ -7,5 +7,5 @@ add_service_email_reply_to_request = {
|
||||
"email_address": {"type": "string", "format": "email_address"},
|
||||
"is_default": {"type": "boolean"}
|
||||
},
|
||||
"required": ["email_address"]
|
||||
"required": ["email_address", "is_default"]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user