mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 15:46:07 -05:00
Refactor:
* Filter inbound by service_id * Refactor to return 404 instead of 400 for consistency
This commit is contained in:
@@ -49,5 +49,8 @@ def delete_inbound_sms_created_more_than_a_week_ago():
|
|||||||
return deleted
|
return deleted
|
||||||
|
|
||||||
|
|
||||||
def dao_get_inbound_sms_by_id(inbound_id):
|
def dao_get_inbound_sms_by_id(service_id, inbound_id):
|
||||||
return InboundSms.query.filter_by(id=inbound_id).one()
|
return InboundSms.query.filter_by(
|
||||||
|
id=inbound_id,
|
||||||
|
service_id=service_id
|
||||||
|
).one()
|
||||||
|
|||||||
@@ -1,11 +1,8 @@
|
|||||||
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
|
||||||
|
|
||||||
@@ -19,7 +16,7 @@ from app.errors import register_errors
|
|||||||
inbound_sms = Blueprint(
|
inbound_sms = Blueprint(
|
||||||
'inbound_sms',
|
'inbound_sms',
|
||||||
__name__,
|
__name__,
|
||||||
url_prefix='/service/<service_id>/inbound-sms'
|
url_prefix='/service/<uuid:service_id>/inbound-sms'
|
||||||
)
|
)
|
||||||
|
|
||||||
register_errors(inbound_sms)
|
register_errors(inbound_sms)
|
||||||
@@ -50,14 +47,8 @@ def get_inbound_sms_summary_for_service(service_id):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@inbound_sms.route('/<inbound_sms_id>', methods=['GET'])
|
@inbound_sms.route('/<uuid:inbound_sms_id>', methods=['GET'])
|
||||||
def get_inbound_by_id(service_id, inbound_sms_id):
|
def get_inbound_by_id(service_id, inbound_sms_id):
|
||||||
# TODO: Add JSON Schema here
|
inbound_sms = dao_get_inbound_sms_by_id(service_id, inbound_sms_id)
|
||||||
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
|
return jsonify(inbound_sms.serialize()), 200
|
||||||
|
|||||||
@@ -92,6 +92,6 @@ def test_should_not_delete_inbound_sms_before_seven_days(sample_service):
|
|||||||
def test_get_inbound_sms_by_id_returns(sample_service):
|
def test_get_inbound_sms_by_id_returns(sample_service):
|
||||||
inbound = create_inbound_sms(sample_service)
|
inbound = create_inbound_sms(sample_service)
|
||||||
|
|
||||||
inbound_from_db = dao_get_inbound_sms_by_id(inbound.id)
|
inbound_from_db = dao_get_inbound_sms_by_id(sample_service.id, inbound.id)
|
||||||
|
|
||||||
assert inbound == inbound_from_db
|
assert inbound == inbound_from_db
|
||||||
|
|||||||
@@ -129,12 +129,23 @@ def test_get_inbound_sms_by_id_returns_200(admin_request, sample_service):
|
|||||||
assert response['service_id'] == str(sample_service.id)
|
assert response['service_id'] == str(sample_service.id)
|
||||||
|
|
||||||
|
|
||||||
def test_get_inbound_sms_by_id_invalid_id_returns_400(admin_request, sample_service):
|
def test_get_inbound_sms_by_id_invalid_id_returns_404(admin_request, sample_service):
|
||||||
assert admin_request.get(
|
assert admin_request.get(
|
||||||
'inbound_sms.get_inbound_by_id',
|
'inbound_sms.get_inbound_by_id',
|
||||||
endpoint_kwargs={
|
endpoint_kwargs={
|
||||||
'service_id': sample_service.id,
|
'service_id': sample_service.id,
|
||||||
'inbound_sms_id': 'dsadsda'
|
'inbound_sms_id': 'bar'
|
||||||
},
|
},
|
||||||
expected_status=400
|
expected_status=404
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_inbound_sms_by_id_with_invalid_service_id_returns_404(admin_request, sample_service):
|
||||||
|
assert admin_request.get(
|
||||||
|
'inbound_sms.get_inbound_by_id',
|
||||||
|
endpoint_kwargs={
|
||||||
|
'service_id': 'foo',
|
||||||
|
'inbound_sms_id': '2cfbd6a1-1575-4664-8969-f27be0ea40d9'
|
||||||
|
},
|
||||||
|
expected_status=404
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user