mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 15:46:07 -05:00
Make get_notifications return single notification by reference
This commit is contained in:
@@ -18,12 +18,23 @@ def get_notification_by_id(id):
|
|||||||
@notification_blueprint.route("", methods=['GET'])
|
@notification_blueprint.route("", methods=['GET'])
|
||||||
def get_notifications():
|
def get_notifications():
|
||||||
_data = request.args.to_dict(flat=False)
|
_data = request.args.to_dict(flat=False)
|
||||||
|
|
||||||
|
# flat=False makes everything a list, but we only ever allow one value for "older_than"
|
||||||
if 'older_than' in _data:
|
if 'older_than' in _data:
|
||||||
# flat=False makes everything a list, but we only ever allow one value for "older_than"
|
|
||||||
_data['older_than'] = _data['older_than'][0]
|
_data['older_than'] = _data['older_than'][0]
|
||||||
|
|
||||||
|
# and client reference
|
||||||
|
if 'client_reference' in _data:
|
||||||
|
_data['client_reference'] = _data['client_reference'][0]
|
||||||
|
|
||||||
data = validate(_data, get_notifications_request)
|
data = validate(_data, get_notifications_request)
|
||||||
|
|
||||||
|
if data.get('client_reference'):
|
||||||
|
notification = notifications_dao.get_notification_by_reference(
|
||||||
|
str(api_user.service_id), data.get('client_reference'), key_type=None
|
||||||
|
)
|
||||||
|
return jsonify(notification.serialize()), 200
|
||||||
|
|
||||||
paginated_notifications = notifications_dao.get_notifications_for_service(
|
paginated_notifications = notifications_dao.get_notifications_for_service(
|
||||||
str(api_user.service_id),
|
str(api_user.service_id),
|
||||||
filter_dict=data,
|
filter_dict=data,
|
||||||
|
|||||||
@@ -78,6 +78,7 @@ get_notifications_request = {
|
|||||||
"description": "schema for query parameters allowed when getting list of notifications",
|
"description": "schema for query parameters allowed when getting list of notifications",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
"client_reference": {"type": "string"},
|
||||||
"status": {
|
"status": {
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"items": {
|
"items": {
|
||||||
|
|||||||
@@ -60,6 +60,40 @@ def test_get_notification_by_id_returns_200(
|
|||||||
assert json_response == expected_response
|
assert json_response == expected_response
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_notification_by_reference_returns_200(client, notify_db, notify_db_session):
|
||||||
|
sample_notification_with_reference = create_sample_notification(
|
||||||
|
notify_db, notify_db_session, client_reference='some-client-reference')
|
||||||
|
|
||||||
|
auth_header = create_authorization_header(service_id=sample_notification_with_reference.service_id)
|
||||||
|
response = client.get(
|
||||||
|
path='/v2/notifications?client_reference={}'.format(sample_notification_with_reference.client_reference),
|
||||||
|
headers=[('Content-Type', 'application/json'), auth_header])
|
||||||
|
|
||||||
|
assert response.status_code == 200
|
||||||
|
assert response.headers['Content-type'] == 'application/json'
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_notification_by_reference_nonexistent_reference_returns_400(client, sample_notification):
|
||||||
|
auth_header = create_authorization_header(service_id=sample_notification.service_id)
|
||||||
|
response = client.get(
|
||||||
|
path='/v2/notifications?client_reference={}'.format(sample_notification.client_reference),
|
||||||
|
headers=[('Content-Type', 'application/json'), auth_header])
|
||||||
|
|
||||||
|
assert response.status_code == 404
|
||||||
|
assert response.headers['Content-type'] == 'application/json'
|
||||||
|
|
||||||
|
json_response = json.loads(response.get_data(as_text=True))
|
||||||
|
assert json_response == {
|
||||||
|
"errors": [
|
||||||
|
{
|
||||||
|
"error": "NoResultFound",
|
||||||
|
"message": "No result found"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"status_code": 404
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def test_get_notification_by_id_nonexistent_id(client, sample_notification):
|
def test_get_notification_by_id_nonexistent_id(client, sample_notification):
|
||||||
auth_header = create_authorization_header(service_id=sample_notification.service_id)
|
auth_header = create_authorization_header(service_id=sample_notification.service_id)
|
||||||
response = client.get(
|
response = client.get(
|
||||||
|
|||||||
Reference in New Issue
Block a user