Improvements to the tests.

Update AuthError with a to_dict_v2 method.
This commit is contained in:
Rebecca Law
2016-11-01 10:33:34 +00:00
parent a358f3cb3a
commit 482d10545b
8 changed files with 58 additions and 46 deletions

View File

@@ -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)

View File

@@ -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):

View File

@@ -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))}
}

View File

@@ -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