Add V2 inbound_sms API

- had to update the serialization in the model so that the date time is appended with the UTC timezone
- test has been added to ensure that the schema will validate the response correctly
This commit is contained in:
Ken Tsang
2017-11-03 16:35:22 +00:00
parent 8b2c242355
commit 85b8e24e17
10 changed files with 315 additions and 4 deletions

View File

@@ -0,0 +1,6 @@
from flask import Blueprint
from app.v2.errors import register_errors
v2_inbound_sms_blueprint = Blueprint("v2_inbound_sms", __name__, url_prefix='/v2/inbound_sms')
register_errors(v2_inbound_sms_blueprint)

View File

@@ -0,0 +1,36 @@
import uuid
from flask import jsonify, request, url_for, current_app
from sqlalchemy.orm.exc import NoResultFound
from werkzeug.exceptions import abort
from notifications_utils.recipients import validate_and_format_phone_number
from notifications_utils.recipients import InvalidPhoneError
from app import authenticated_service
from app.dao import inbound_sms_dao
from app.v2.errors import BadRequestError
from app.v2.inbound_sms import v2_inbound_sms_blueprint
@v2_inbound_sms_blueprint.route("/<user_number>", methods=['GET'])
def get_inbound_sms_by_number(user_number):
try:
validate_and_format_phone_number(user_number)
except InvalidPhoneError as e:
raise BadRequestError(message=str(e))
inbound_sms = inbound_sms_dao.dao_get_inbound_sms_for_service(
authenticated_service.id, user_number=user_number
)
return jsonify(inbound_sms_list=[i.serialize() for i in inbound_sms]), 200
@v2_inbound_sms_blueprint.route("", methods=['GET'])
def get_all_inbound_sms():
all_inbound_sms = inbound_sms_dao.dao_get_inbound_sms_for_service(
authenticated_service.id
)
return jsonify(inbound_sms_list=[i.serialize() for i in all_inbound_sms]), 200

View File

@@ -0,0 +1,51 @@
from app.schema_validation.definitions import uuid
get_inbound_sms_single_response = {
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "GET inbound sms schema response",
"type": "object",
"title": "GET response v2/inbound_sms",
"properties": {
"provider_date": {
"format": "date-time",
"type": "string",
"description": "Date+time sent by provider"
},
"provider_reference": {"type": ["string", "null"]},
"user_number": {"type": "string"},
"created_at": {
"format": "date-time",
"type": "string",
"description": "Date+time created at"
},
"service_id": uuid,
"id": uuid,
"notify_number": {"type": "string"},
"content": {"type": "string"},
},
"required": [
"id", "provider_date", "provider_reference",
"user_number", "created_at", "service_id",
"notify_number", "content"
],
}
get_inbound_sms_response = {
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "GET list of inbound sms response schema",
"type": "object",
"properties": {
"inbound_sms_list": {
"type": "array",
"items": {
"type": "object",
"$ref": "#/definitions/inbound_sms"
}
},
},
"required": ["inbound_sms_list"],
"definitions": {
"inbound_sms": get_inbound_sms_single_response
}
}