mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-10 07:12:20 -05:00
Add endpoint to get inbound by id
This commit is contained in:
@@ -1,11 +1,19 @@
|
|||||||
|
import uuid
|
||||||
|
|
||||||
from flask import (
|
from flask import (
|
||||||
Blueprint,
|
Blueprint,
|
||||||
jsonify,
|
jsonify,
|
||||||
request
|
request
|
||||||
)
|
)
|
||||||
|
from werkzeug.exceptions import abort
|
||||||
|
|
||||||
from notifications_utils.recipients import validate_and_format_phone_number
|
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
|
from app.errors import register_errors
|
||||||
|
|
||||||
inbound_sms = Blueprint(
|
inbound_sms = Blueprint(
|
||||||
@@ -40,3 +48,16 @@ def get_inbound_sms_summary_for_service(service_id):
|
|||||||
count=count,
|
count=count,
|
||||||
most_recent=most_recent[0].created_at.isoformat() if most_recent else None
|
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
|
||||||
|
|||||||
@@ -112,3 +112,29 @@ def test_get_inbound_sms_summary_with_no_inbound(admin_request, sample_service):
|
|||||||
'count': 0,
|
'count': 0,
|
||||||
'most_recent': None
|
'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
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user