mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-04 18:31:13 -05:00
Merge pull request #785 from alphagov/check-notification_schema
Removed the oneOf validation in the get_notification_response schema.
This commit is contained in:
@@ -20,32 +20,6 @@ get_notification_response = {
|
|||||||
"description": "GET notification response schema",
|
"description": "GET notification response schema",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"title": "response v2/notification",
|
"title": "response v2/notification",
|
||||||
"oneOf": [
|
|
||||||
{"properties": {
|
|
||||||
"email_address": {"type": "string", "format": "email_address"},
|
|
||||||
"type": {"enum": ["email"]},
|
|
||||||
|
|
||||||
"phone_number": {"type": "null"},
|
|
||||||
"line_1": {"type": "null"},
|
|
||||||
"postcode": {"type": "null"}
|
|
||||||
}},
|
|
||||||
{"properties": {
|
|
||||||
"phone_number": {"type": "string", "format": "phone_number"},
|
|
||||||
"type": {"enum": ["sms"]},
|
|
||||||
|
|
||||||
"email_address": {"type": "null"},
|
|
||||||
"line_1": {"type": "null"},
|
|
||||||
"postcode": {"type": "null"}
|
|
||||||
}},
|
|
||||||
{"properties": {
|
|
||||||
"line_1": {"type": "string", "minLength": 1},
|
|
||||||
"postcode": {"type": "string", "minLength": 1},
|
|
||||||
"type": {"enum": ["letter"]},
|
|
||||||
|
|
||||||
"email_address": {"type": "null"},
|
|
||||||
"phone_number": {"type": "null"}
|
|
||||||
}}
|
|
||||||
],
|
|
||||||
"properties": {
|
"properties": {
|
||||||
"id": uuid,
|
"id": uuid,
|
||||||
"reference": {"type": ["string", "null"]},
|
"reference": {"type": ["string", "null"]},
|
||||||
@@ -213,17 +187,19 @@ post_email_response = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def create_post_sms_response_from_notification(notification, body, from_number, url_root):
|
def create_post_sms_response_from_notification(notification, body, from_number, url_root, service_id):
|
||||||
return {"id": notification.id,
|
return {"id": notification.id,
|
||||||
"reference": notification.client_reference,
|
"reference": notification.client_reference,
|
||||||
"content": {'body': body,
|
"content": {'body': body,
|
||||||
'from_number': from_number},
|
'from_number': from_number},
|
||||||
"uri": "{}v2/notifications/{}".format(url_root, str(notification.id)),
|
"uri": "{}v2/notifications/{}".format(url_root, str(notification.id)),
|
||||||
"template": __create_template_from_notification(notification=notification, url_root=url_root)
|
"template": __create_template_from_notification(notification=notification,
|
||||||
|
url_root=url_root,
|
||||||
|
service_id=service_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def create_post_email_response_from_notification(notification, content, subject, email_from, url_root):
|
def create_post_email_response_from_notification(notification, content, subject, email_from, url_root, service_id):
|
||||||
return {
|
return {
|
||||||
"id": notification.id,
|
"id": notification.id,
|
||||||
"reference": notification.client_reference,
|
"reference": notification.client_reference,
|
||||||
@@ -233,13 +209,15 @@ def create_post_email_response_from_notification(notification, content, subject,
|
|||||||
"subject": subject
|
"subject": subject
|
||||||
},
|
},
|
||||||
"uri": "{}v2/notifications/{}".format(url_root, str(notification.id)),
|
"uri": "{}v2/notifications/{}".format(url_root, str(notification.id)),
|
||||||
"template": __create_template_from_notification(notification=notification, url_root=url_root)
|
"template": __create_template_from_notification(notification=notification,
|
||||||
|
url_root=url_root,
|
||||||
|
service_id=service_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def __create_template_from_notification(notification, url_root):
|
def __create_template_from_notification(notification, url_root, service_id):
|
||||||
return {
|
return {
|
||||||
"id": notification.template_id,
|
"id": notification.template_id,
|
||||||
"version": notification.template_version,
|
"version": notification.template_version,
|
||||||
"uri": "{}v2/templates/{}".format(url_root, str(notification.template_id))
|
"uri": "{}services/{}/templates/{}".format(url_root, str(service_id), str(notification.template_id))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,10 +41,11 @@ def post_sms_notification():
|
|||||||
reference=form.get('reference'))
|
reference=form.get('reference'))
|
||||||
send_notification_to_queue(notification, service.research_mode)
|
send_notification_to_queue(notification, service.research_mode)
|
||||||
sms_sender = service.sms_sender if service.sms_sender else current_app.config.get('FROM_NUMBER')
|
sms_sender = service.sms_sender if service.sms_sender else current_app.config.get('FROM_NUMBER')
|
||||||
resp = create_post_sms_response_from_notification(notification,
|
resp = create_post_sms_response_from_notification(notification=notification,
|
||||||
str(template_with_content),
|
body=str(template_with_content),
|
||||||
sms_sender,
|
from_number=sms_sender,
|
||||||
request.url_root)
|
url_root=request.url_root,
|
||||||
|
service_id=service.id)
|
||||||
return jsonify(resp), 201
|
return jsonify(resp), 201
|
||||||
|
|
||||||
|
|
||||||
@@ -73,7 +74,8 @@ def post_email_notification():
|
|||||||
content=str(template_with_content),
|
content=str(template_with_content),
|
||||||
subject=template_with_content.subject,
|
subject=template_with_content.subject,
|
||||||
email_from=service.email_from,
|
email_from=service.email_from,
|
||||||
url_root=request.url_root)
|
url_root=request.url_root,
|
||||||
|
service_id=service.id)
|
||||||
return jsonify(resp), 201
|
return jsonify(resp), 201
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ from jsonschema import ValidationError
|
|||||||
|
|
||||||
from app.v2.notifications.notification_schemas import (
|
from app.v2.notifications.notification_schemas import (
|
||||||
get_notifications_request,
|
get_notifications_request,
|
||||||
|
get_notification_response,
|
||||||
post_sms_request as post_sms_request_schema,
|
post_sms_request as post_sms_request_schema,
|
||||||
post_sms_response as post_sms_response_schema,
|
post_sms_response as post_sms_response_schema,
|
||||||
post_email_request as post_email_request_schema,
|
post_email_request as post_email_request_schema,
|
||||||
@@ -309,3 +310,28 @@ def test_post_sms_response_schema_invalid_template_uri_raises_validation_error(r
|
|||||||
assert error['status_code'] == 400
|
assert error['status_code'] == 400
|
||||||
assert error['errors'] == [{'error': 'ValidationError',
|
assert error['errors'] == [{'error': 'ValidationError',
|
||||||
'message': "template invalid-uri is not a uri"}]
|
'message': "template invalid-uri is not a uri"}]
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_notifications_response_with_email_and_phone_number():
|
||||||
|
response = {"id": str(uuid.uuid4()),
|
||||||
|
"reference": "something",
|
||||||
|
"email_address": None,
|
||||||
|
"phone_number": "+447115411111",
|
||||||
|
"line_1": None,
|
||||||
|
"line_2": None,
|
||||||
|
"line_3": None,
|
||||||
|
"line_4": None,
|
||||||
|
"line_5": None,
|
||||||
|
"line_6": None,
|
||||||
|
"postcode": None,
|
||||||
|
"type": "email",
|
||||||
|
"status": "delivered",
|
||||||
|
"template": {"id": str(uuid.uuid4()), "version": 1, "uri": "http://template/id"},
|
||||||
|
"body": "some body",
|
||||||
|
"subject": "some subject",
|
||||||
|
"created_at": "2016-01-01",
|
||||||
|
"sent_at": "2016-01-01",
|
||||||
|
"completed_at": "2016-01-01"
|
||||||
|
}
|
||||||
|
|
||||||
|
assert validate(response, get_notification_response) == response
|
||||||
|
|||||||
@@ -37,7 +37,9 @@ def test_post_sms_notification_returns_201(notify_api, sample_template_with_plac
|
|||||||
assert 'v2/notifications/{}'.format(notification_id) in resp_json['uri']
|
assert 'v2/notifications/{}'.format(notification_id) in resp_json['uri']
|
||||||
assert resp_json['template']['id'] == str(sample_template_with_placeholders.id)
|
assert resp_json['template']['id'] == str(sample_template_with_placeholders.id)
|
||||||
assert resp_json['template']['version'] == sample_template_with_placeholders.version
|
assert resp_json['template']['version'] == sample_template_with_placeholders.version
|
||||||
assert 'v2/templates/{}'.format(sample_template_with_placeholders.id) in resp_json['template']['uri']
|
assert 'services/{}/templates/{}'.format(sample_template_with_placeholders.service_id,
|
||||||
|
sample_template_with_placeholders.id) \
|
||||||
|
in resp_json['template']['uri']
|
||||||
assert mocked.called
|
assert mocked.called
|
||||||
|
|
||||||
|
|
||||||
@@ -137,7 +139,9 @@ def test_post_email_notification_returns_201(client, sample_email_template_with_
|
|||||||
assert 'v2/notifications/{}'.format(notification.id) in resp_json['uri']
|
assert 'v2/notifications/{}'.format(notification.id) in resp_json['uri']
|
||||||
assert resp_json['template']['id'] == str(sample_email_template_with_placeholders.id)
|
assert resp_json['template']['id'] == str(sample_email_template_with_placeholders.id)
|
||||||
assert resp_json['template']['version'] == sample_email_template_with_placeholders.version
|
assert resp_json['template']['version'] == sample_email_template_with_placeholders.version
|
||||||
assert 'v2/templates/{}'.format(sample_email_template_with_placeholders.id) in resp_json['template']['uri']
|
assert 'services/{}/templates/{}'.format(str(sample_email_template_with_placeholders.service_id),
|
||||||
|
str(sample_email_template_with_placeholders.id)) \
|
||||||
|
in resp_json['template']['uri']
|
||||||
assert mocked.called
|
assert mocked.called
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user