Add endpoint to get inbound by id

This commit is contained in:
Imdad Ahad
2017-06-06 17:12:21 +01:00
parent 23a501af16
commit ee488d416a
2 changed files with 48 additions and 1 deletions

View File

@@ -1,11 +1,19 @@
import uuid
from flask import (
Blueprint,
jsonify,
request
)
from werkzeug.exceptions import abort
from notifications_utils.recipients import validate_and_format_phone_number
from app.dao.inbound_sms_dao import dao_get_inbound_sms_for_service, dao_count_inbound_sms_for_service
from app.dao.inbound_sms_dao import (
dao_get_inbound_sms_for_service,
dao_count_inbound_sms_for_service,
dao_get_inbound_sms_by_id
)
from app.errors import register_errors
inbound_sms = Blueprint(
@@ -40,3 +48,16 @@ def get_inbound_sms_summary_for_service(service_id):
count=count,
most_recent=most_recent[0].created_at.isoformat() if most_recent else None
)
@inbound_sms.route('/<inbound_sms_id>', methods=['GET'])
def get_inbound_by_id(service_id, inbound_sms_id):
# TODO: Add JSON Schema here
try:
validated_uuid = uuid.UUID(inbound_sms_id)
except (ValueError, AttributeError):
abort(400)
inbound_sms = dao_get_inbound_sms_by_id(validated_uuid)
return jsonify(inbound_sms.serialize()), 200

View File

@@ -112,3 +112,29 @@ def test_get_inbound_sms_summary_with_no_inbound(admin_request, sample_service):
'count': 0,
'most_recent': None
}
def test_get_inbound_sms_by_id_returns_200(admin_request, sample_service):
inbound = create_inbound_sms(sample_service, user_number='447700900001')
response = admin_request.get(
'inbound_sms.get_inbound_by_id',
endpoint_kwargs={
'service_id': sample_service.id,
'inbound_sms_id': inbound.id
}
)
assert response['user_number'] == '447700900001'
assert response['service_id'] == str(sample_service.id)
def test_get_inbound_sms_by_id_invalid_id_returns_400(admin_request, sample_service):
assert admin_request.get(
'inbound_sms.get_inbound_by_id',
endpoint_kwargs={
'service_id': sample_service.id,
'inbound_sms_id': 'dsadsda'
},
expected_status=400
)