mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-30 06:21:50 -05:00
Improvements to the tests.
Update AuthError with a to_dict_v2 method.
This commit is contained in:
@@ -12,8 +12,15 @@ from app.dao.services_dao import dao_fetch_service_by_id
|
||||
class AuthError(Exception):
|
||||
def __init__(self, message, code):
|
||||
self.message = {"token": [message]}
|
||||
self.short_message = message
|
||||
self.code = code
|
||||
|
||||
def to_dict_v2(self):
|
||||
return {'code': self.code,
|
||||
'message': self.short_message,
|
||||
'fields': self.message,
|
||||
'link': 'link to docs'}
|
||||
|
||||
|
||||
def get_auth_token(req):
|
||||
auth_header = req.headers.get('Authorization', None)
|
||||
|
||||
@@ -51,10 +51,7 @@ def register_errors(blueprint):
|
||||
|
||||
@blueprint.errorhandler(AuthError)
|
||||
def auth_error(error):
|
||||
return jsonify(status_code=error.code,
|
||||
message=error.message,
|
||||
code=error.code,
|
||||
link='link to docs'), error.code
|
||||
return jsonify(error.to_dict_v2()), error.code
|
||||
|
||||
@blueprint.errorhandler(Exception)
|
||||
def internal_server_error(error):
|
||||
|
||||
@@ -56,12 +56,13 @@ post_sms_response = {
|
||||
}
|
||||
|
||||
|
||||
def create_post_sms_response_from_notification(notification, content):
|
||||
def create_post_sms_response_from_notification(notification, body, from_number, url_root):
|
||||
return {"id": notification.id,
|
||||
"reference": None, # not yet implemented
|
||||
"content": content,
|
||||
"uri": "v2/notifications/{}".format(notification.id),
|
||||
"content": {'body': body,
|
||||
'from_number': from_number},
|
||||
"uri": "{}/v2/notifications/{}".format(url_root, str(notification.id)),
|
||||
"template": {"id": notification.template_id,
|
||||
"version": notification.template_version,
|
||||
"uri": "v2/templates/{}".format(notification.template_id)}
|
||||
"uri": "{}/v2/templates/{}".format(url_root, str(notification.template_id))}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from flask import request, jsonify
|
||||
from flask import request, jsonify, current_app
|
||||
from sqlalchemy.orm.exc import NoResultFound
|
||||
|
||||
from app import api_user
|
||||
@@ -38,7 +38,8 @@ def post_sms_notification():
|
||||
api_key_id=api_user.id,
|
||||
key_type=api_user.key_type)
|
||||
send_notification_to_queue(notification, service.research_mode)
|
||||
resp = create_post_sms_response_from_notification(notification, content)
|
||||
|
||||
resp = create_post_sms_response_from_notification(notification, content, service.sms_sender, request.url_root)
|
||||
return jsonify(resp), 201
|
||||
|
||||
|
||||
@@ -67,4 +68,4 @@ def __validate_template(form, service):
|
||||
check_template_is_active(template)
|
||||
template_with_content = create_content_for_notification(template, form.get('personalisation', {}))
|
||||
check_sms_content_char_count(template_with_content.replaced_content_count)
|
||||
return template, template_with_content.replaced_content_count
|
||||
return template, template_with_content.content
|
||||
|
||||
Reference in New Issue
Block a user