mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-30 06:21:50 -05:00
Create 'v2' get notification route
The new 'v2' API wants to return less data than the previous one, which was sending back tons of fields the clients never used. This new route returns only useful information, with the JSON response dict being built up in the model's `.serialize()` method. Note that writing the test for this was a bit painful because of having to treat loads of keys differently. Hopefully we think this is a good way to write this test, because if we don't, we should start thinking of a better way to check the values are what we expect.
This commit is contained in:
46
tests/app/v2/notifications/test_get_notifications.py
Normal file
46
tests/app/v2/notifications/test_get_notifications.py
Normal file
@@ -0,0 +1,46 @@
|
||||
import json
|
||||
|
||||
from app import DATETIME_FORMAT
|
||||
from tests import create_authorization_header
|
||||
|
||||
|
||||
def test_get_notification_by_id_returns_200(client, sample_notification):
|
||||
auth_header = create_authorization_header(service_id=sample_notification.service_id)
|
||||
|
||||
response = client.get(
|
||||
path='/v2/notifications/{}'.format(sample_notification.id),
|
||||
headers=[('Content-Type', 'application/json'), auth_header])
|
||||
|
||||
assert response.status_code == 200
|
||||
assert response.headers['Content-type'] == 'application/json'
|
||||
|
||||
json_response = json.loads(response.get_data(as_text=True))
|
||||
|
||||
expected_template_response = {
|
||||
'id': '{}'.format(sample_notification.serialize()['template']['id']),
|
||||
'version': sample_notification.serialize()['template']['version'],
|
||||
'uri': sample_notification.serialize()['template']['uri']
|
||||
}
|
||||
|
||||
expected_response = {
|
||||
'id': '{}'.format(sample_notification.id),
|
||||
'reference': None,
|
||||
'email_address': None,
|
||||
'phone_number': '{}'.format(sample_notification.to),
|
||||
'line_1': None,
|
||||
'line_2': None,
|
||||
'line_3': None,
|
||||
'line_4': None,
|
||||
'line_5': None,
|
||||
'line_6': None,
|
||||
'postcode': None,
|
||||
'cost': sample_notification.cost(),
|
||||
'type': '{}'.format(sample_notification.notification_type),
|
||||
'status': '{}'.format(sample_notification.status),
|
||||
'template': expected_template_response,
|
||||
'created_at': sample_notification.created_at.strftime(DATETIME_FORMAT),
|
||||
'sent_at': sample_notification.sent_at,
|
||||
'completed_at': sample_notification.completed_at()
|
||||
}
|
||||
|
||||
assert json_response == expected_response
|
||||
@@ -4,8 +4,9 @@ import pytest
|
||||
from flask import json
|
||||
from jsonschema import ValidationError
|
||||
|
||||
from app.v2.notifications.notification_schemas import post_sms_request, post_sms_response, post_email_request, \
|
||||
post_email_response
|
||||
from app.v2.notifications.notification_schemas import (
|
||||
post_sms_request, post_sms_response, post_email_request, post_email_response
|
||||
)
|
||||
from app.schema_validation import validate
|
||||
|
||||
valid_json = {"phone_number": "07515111111",
|
||||
|
||||
Reference in New Issue
Block a user