mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 18:01:08 -05:00
Add 'v2' notification schema to contract tests
Converted python-based schema in "app/v2/notifications/notification_schema.py" into a pure json schema and tested it with the new "v2/" API route to confirm that it validates. Also refactored some common code in the public contract GET tests that returns notifications.
This commit is contained in:
@@ -0,0 +1,67 @@
|
|||||||
|
{
|
||||||
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||||
|
"description": "GET notification response schema",
|
||||||
|
"type": "object",
|
||||||
|
"title": "response v2/notification",
|
||||||
|
"oneOf": [
|
||||||
|
{"properties": {
|
||||||
|
"email_address": {"type": "string", "format": "email_address"},
|
||||||
|
"type": {"enum": ["email"]},
|
||||||
|
|
||||||
|
"phone_number": {"type": "null"},
|
||||||
|
"line_1": {"type": "null"},
|
||||||
|
"postcode": {"type": "null"}
|
||||||
|
}},
|
||||||
|
{"properties": {
|
||||||
|
"phone_number": {"type": "string", "format": "phone_number"},
|
||||||
|
"type": {"enum": ["sms"]},
|
||||||
|
|
||||||
|
"email_address": {"type": "null"},
|
||||||
|
"line_1": {"type": "null"},
|
||||||
|
"postcode": {"type": "null"}
|
||||||
|
}},
|
||||||
|
{"properties": {
|
||||||
|
"line_1": {"type": "string", "minLength": 1},
|
||||||
|
"postcode": {"type": "string", "minLength": 1},
|
||||||
|
"type": {"enum": ["letter"]},
|
||||||
|
|
||||||
|
"email_address": {"type": "null"},
|
||||||
|
"phone_number": {"type": "null"}
|
||||||
|
}}
|
||||||
|
],
|
||||||
|
"properties": {
|
||||||
|
"id": {"$ref": "definitions.json#/uuid"},
|
||||||
|
"reference": {"type": ["string", "null"]},
|
||||||
|
"email_address": {"type": ["string", "null"]},
|
||||||
|
"phone_number": {"type": ["string", "null"]},
|
||||||
|
"line_1": {"type": ["string", "null"]},
|
||||||
|
"line_2": {"type": ["string", "null"]},
|
||||||
|
"line_3": {"type": ["string", "null"]},
|
||||||
|
"line_4": {"type": ["string", "null"]},
|
||||||
|
"line_5": {"type": ["string", "null"]},
|
||||||
|
"line_6": {"type": ["string", "null"]},
|
||||||
|
"postcode": {"type": ["string", "null"]},
|
||||||
|
"cost": {"type": "number"},
|
||||||
|
"type": {"enum": ["sms", "letter", "email"]},
|
||||||
|
"status": {"type": "string"},
|
||||||
|
"template": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"id": {"$ref": "definitions.json#/uuid"},
|
||||||
|
"uri": {"type": "string"},
|
||||||
|
"version": {"type": "number"}
|
||||||
|
},
|
||||||
|
"additionalProperties": false,
|
||||||
|
"required": ["id", "uri", "version"]
|
||||||
|
},
|
||||||
|
"created_at": {"type": "string"},
|
||||||
|
"sent_at": {"type": ["string", "null"]},
|
||||||
|
"completed_at": {"type": ["string", "null"]}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"id", "reference", "email_address", "phone_number",
|
||||||
|
"line_1", "line_2", "line_3", "line_4", "line_5", "line_6", "postcode",
|
||||||
|
"cost", "type", "status", "template",
|
||||||
|
"created_at", "sent_at", "completed_at"
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -1,59 +1,45 @@
|
|||||||
from . import validate
|
from . import validate
|
||||||
from app.models import ApiKey, KEY_TYPE_NORMAL
|
from app.models import ApiKey, KEY_TYPE_NORMAL
|
||||||
from app.dao.notifications_dao import dao_update_notification
|
|
||||||
from app.dao.api_key_dao import save_model_api_key
|
from app.dao.api_key_dao import save_model_api_key
|
||||||
from tests import create_authorization_header
|
from tests import create_authorization_header
|
||||||
|
|
||||||
|
|
||||||
def test_get_api_sms_contract(client, sample_notification):
|
def _get(client, notification, url):
|
||||||
api_key = ApiKey(service=sample_notification.service,
|
save_model_api_key(ApiKey(
|
||||||
name='api_key',
|
service=notification.service,
|
||||||
created_by=sample_notification.service.created_by,
|
name='api_key',
|
||||||
key_type=KEY_TYPE_NORMAL)
|
created_by=notification.service.created_by,
|
||||||
save_model_api_key(api_key)
|
key_type=KEY_TYPE_NORMAL
|
||||||
sample_notification.job = None
|
))
|
||||||
sample_notification.api_key = api_key
|
auth_header = create_authorization_header(service_id=notification.service_id)
|
||||||
sample_notification.key_type = KEY_TYPE_NORMAL
|
return client.get(url, headers=[auth_header])
|
||||||
dao_update_notification(sample_notification)
|
|
||||||
auth_header = create_authorization_header(service_id=sample_notification.service_id)
|
|
||||||
response = client.get('/notifications/{}'.format(sample_notification.id), headers=[auth_header])
|
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_v2_notification(client, sample_notification):
|
||||||
|
response = _get(client, sample_notification, '/v2/notifications/{}'.format(sample_notification.id))
|
||||||
|
validate(response.get_data(as_text=True), 'GET_notification_return_email_v2.json')
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_api_sms_contract(client, sample_notification):
|
||||||
|
response = _get(client, sample_notification, '/notifications/{}'.format(sample_notification.id))
|
||||||
validate(response.get_data(as_text=True), 'GET_notification_return_sms.json')
|
validate(response.get_data(as_text=True), 'GET_notification_return_sms.json')
|
||||||
|
|
||||||
|
|
||||||
def test_get_api_email_contract(client, sample_email_notification):
|
def test_get_api_email_contract(client, sample_email_notification):
|
||||||
api_key = ApiKey(service=sample_email_notification.service,
|
response = _get(client, sample_email_notification, '/notifications/{}'.format(sample_email_notification.id))
|
||||||
name='api_key',
|
|
||||||
created_by=sample_email_notification.service.created_by,
|
|
||||||
key_type=KEY_TYPE_NORMAL)
|
|
||||||
save_model_api_key(api_key)
|
|
||||||
sample_email_notification.job = None
|
|
||||||
sample_email_notification.api_key = api_key
|
|
||||||
sample_email_notification.key_type = KEY_TYPE_NORMAL
|
|
||||||
dao_update_notification(sample_email_notification)
|
|
||||||
|
|
||||||
auth_header = create_authorization_header(service_id=sample_email_notification.service_id)
|
|
||||||
response = client.get('/notifications/{}'.format(sample_email_notification.id), headers=[auth_header])
|
|
||||||
|
|
||||||
validate(response.get_data(as_text=True), 'GET_notification_return_email.json')
|
validate(response.get_data(as_text=True), 'GET_notification_return_email.json')
|
||||||
|
|
||||||
|
|
||||||
def test_get_job_sms_contract(client, sample_notification):
|
def test_get_job_sms_contract(client, sample_notification):
|
||||||
auth_header = create_authorization_header(service_id=sample_notification.service_id)
|
response = _get(client, sample_notification, '/notifications/{}'.format(sample_notification.id))
|
||||||
response = client.get('/notifications/{}'.format(sample_notification.id), headers=[auth_header])
|
|
||||||
|
|
||||||
validate(response.get_data(as_text=True), 'GET_notification_return_sms.json')
|
validate(response.get_data(as_text=True), 'GET_notification_return_sms.json')
|
||||||
|
|
||||||
|
|
||||||
def test_get_job_email_contract(client, sample_email_notification):
|
def test_get_job_email_contract(client, sample_email_notification):
|
||||||
auth_header = create_authorization_header(service_id=sample_email_notification.service_id)
|
response = _get(client, sample_email_notification, '/notifications/{}'.format(sample_email_notification.id))
|
||||||
response = client.get('/notifications/{}'.format(sample_email_notification.id), headers=[auth_header])
|
|
||||||
|
|
||||||
validate(response.get_data(as_text=True), 'GET_notification_return_email.json')
|
validate(response.get_data(as_text=True), 'GET_notification_return_email.json')
|
||||||
|
|
||||||
|
|
||||||
def test_get_notifications_contract(client, sample_notification, sample_email_notification):
|
def test_get_notifications_contract(client, sample_notification, sample_email_notification):
|
||||||
auth_header = create_authorization_header(service_id=sample_notification.service_id)
|
response = _get(client, sample_notification, '/notifications')
|
||||||
response = client.get('/notifications', headers=[auth_header])
|
|
||||||
|
|
||||||
validate(response.get_data(as_text=True), 'GET_notifications_return.json')
|
validate(response.get_data(as_text=True), 'GET_notifications_return.json')
|
||||||
|
|||||||
Reference in New Issue
Block a user