mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 23:55:58 -05:00
add public contract tests
use jsonschema to test the GET /notification/{} endpoint to highlight any key name/format/type changes
This commit is contained in:
@@ -625,44 +625,6 @@ def test_get_notifications_for_service_returns_merged_template_content(notify_ap
|
||||
}
|
||||
|
||||
|
||||
def test_get_notification_public_api_format_is_not_changed(notify_api, sample_notification):
|
||||
with notify_api.test_request_context(), notify_api.test_client() as client:
|
||||
auth_header = create_authorization_header(service_id=sample_notification.service_id)
|
||||
|
||||
response = client.get(
|
||||
'/notifications/{}'.format(sample_notification.id),
|
||||
headers=[auth_header])
|
||||
|
||||
assert response.status_code == 200
|
||||
notification = json.loads(response.get_data(as_text=True))['data']['notification']
|
||||
# you should never remove things from this list!
|
||||
assert set(notification.keys()) == {
|
||||
# straight from db
|
||||
'id',
|
||||
'to',
|
||||
'job_row_number',
|
||||
'template_version',
|
||||
'billable_units',
|
||||
'notification_type',
|
||||
'created_at',
|
||||
'sent_at',
|
||||
'sent_by',
|
||||
'updated_at',
|
||||
'status',
|
||||
'reference',
|
||||
|
||||
# relationships
|
||||
'template',
|
||||
'service',
|
||||
'job',
|
||||
'api_key',
|
||||
|
||||
# other
|
||||
'body',
|
||||
'content_char_count'
|
||||
}
|
||||
|
||||
|
||||
def test_get_notification_selects_correct_template_for_personalisation(notify_api,
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
|
||||
128
tests/app/public_contracts/GET_notification_return_email.json
Normal file
128
tests/app/public_contracts/GET_notification_return_email.json
Normal file
@@ -0,0 +1,128 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"description": "GET notification return schema - for SMS notifications",
|
||||
"type" : "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"notification": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {"$ref": "#/definitions/uuid"},
|
||||
"to": {"type": "string", "format": "email"},
|
||||
"job_row_number": {"oneOf":[
|
||||
{"type": "number"},
|
||||
{"type": "null"}
|
||||
]},
|
||||
"template_version": {"type": "number"},
|
||||
"billable_units": {"type": "number"},
|
||||
"notification_type": {
|
||||
"type": "string",
|
||||
"enum": ["email"]
|
||||
},
|
||||
"created_at": {"$ref": "#/definitions/datetime"},
|
||||
"sent_at": {"oneOf":[
|
||||
{"$ref": "#/definitions/datetime"},
|
||||
{"type": "null"}
|
||||
]},
|
||||
"sent_by": {"oneOf":[
|
||||
{"type": "string"},
|
||||
{"type": "null"}
|
||||
]},
|
||||
"updated_at": {"oneOf":[
|
||||
{"$ref": "#/definitions/datetime"},
|
||||
{"type": "null"}
|
||||
]},
|
||||
"status": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"created",
|
||||
"sending",
|
||||
"delivered",
|
||||
"pending",
|
||||
"failed",
|
||||
"technical-failure",
|
||||
"temporary-failure",
|
||||
"permanent-failure"
|
||||
]
|
||||
},
|
||||
"reference": {"oneOf":[
|
||||
{"type": "string"},
|
||||
{"type": "null"}
|
||||
]},
|
||||
"template": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {"$ref": "#/definitions/uuid"},
|
||||
"name": {"type": "string"},
|
||||
"template_type": {
|
||||
"type": "string",
|
||||
"enum": ["email"]
|
||||
},
|
||||
"version": {"type": "number"}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"required": ["id", "name", "template_type", "version"]
|
||||
},
|
||||
"service": {"$ref": "#/definitions/uuid"},
|
||||
"job": {
|
||||
"oneOf": [
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {"$ref": "#/definitions/uuid"},
|
||||
"original_file_name": {"type": "string"}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"required": ["id", "original_file_name"]
|
||||
},
|
||||
{"type": "null"}
|
||||
]
|
||||
},
|
||||
"api_key": {"oneOf":[
|
||||
{"$ref": "#/definitions/uuid"},
|
||||
{"type": "null"}
|
||||
]},
|
||||
"body": {"type": "string"},
|
||||
"content_char_count": {"type": "null"},
|
||||
"subject": {"type": "string"}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"required": [
|
||||
"id",
|
||||
"to",
|
||||
"job_row_number",
|
||||
"template_version",
|
||||
"billable_units",
|
||||
"notification_type",
|
||||
"created_at",
|
||||
"sent_at",
|
||||
"sent_by",
|
||||
"updated_at",
|
||||
"status",
|
||||
"reference",
|
||||
"template",
|
||||
"service",
|
||||
"job",
|
||||
"api_key",
|
||||
"body",
|
||||
"content_char_count"
|
||||
]
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"definitions": {
|
||||
"uuid": {
|
||||
"type": "string",
|
||||
"pattern": "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$"
|
||||
},
|
||||
"datetime": {
|
||||
"type": "string",
|
||||
"format": "date-time"
|
||||
}
|
||||
}
|
||||
}
|
||||
127
tests/app/public_contracts/GET_notification_return_sms.json
Normal file
127
tests/app/public_contracts/GET_notification_return_sms.json
Normal file
@@ -0,0 +1,127 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"description": "GET notification return schema - for SMS notifications",
|
||||
"type" : "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"notification": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {"$ref": "#/definitions/uuid"},
|
||||
"to": {"type": "string"},
|
||||
"job_row_number": {"oneOf":[
|
||||
{"type": "number"},
|
||||
{"type": "null"}
|
||||
]},
|
||||
"template_version": {"type": "number"},
|
||||
"billable_units": {"type": "number"},
|
||||
"notification_type": {
|
||||
"type": "string",
|
||||
"enum": ["sms"]
|
||||
},
|
||||
"created_at": {"$ref": "#/definitions/datetime"},
|
||||
"sent_at": {"oneOf":[
|
||||
{"$ref": "#/definitions/datetime"},
|
||||
{"type": "null"}
|
||||
]},
|
||||
"sent_by": {"oneOf":[
|
||||
{"type": "string"},
|
||||
{"type": "null"}
|
||||
]},
|
||||
"updated_at": {"oneOf":[
|
||||
{"$ref": "#/definitions/datetime"},
|
||||
{"type": "null"}
|
||||
]},
|
||||
"status": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"created",
|
||||
"sending",
|
||||
"delivered",
|
||||
"pending",
|
||||
"failed",
|
||||
"technical-failure",
|
||||
"temporary-failure",
|
||||
"permanent-failure"
|
||||
]
|
||||
},
|
||||
"reference": {"oneOf":[
|
||||
{"type": "string"},
|
||||
{"type": "null"}
|
||||
]},
|
||||
"template": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {"$ref": "#/definitions/uuid"},
|
||||
"name": {"type": "string"},
|
||||
"template_type": {
|
||||
"type": "string",
|
||||
"enum": ["sms"]
|
||||
},
|
||||
"version": {"type": "number"}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"required": ["id", "name", "template_type", "version"]
|
||||
},
|
||||
"service": {"$ref": "#/definitions/uuid"},
|
||||
"job": {
|
||||
"oneOf": [
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {"$ref": "#/definitions/uuid"},
|
||||
"original_file_name": {"type": "string"}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"required": ["id", "original_file_name"]
|
||||
},
|
||||
{"type": "null"}
|
||||
]
|
||||
},
|
||||
"api_key": {"oneOf":[
|
||||
{"$ref": "#/definitions/uuid"},
|
||||
{"type": "null"}
|
||||
]},
|
||||
"body": {"type": "string"},
|
||||
"content_char_count": {"type": "number"}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"required": [
|
||||
"id",
|
||||
"to",
|
||||
"job_row_number",
|
||||
"template_version",
|
||||
"billable_units",
|
||||
"notification_type",
|
||||
"created_at",
|
||||
"sent_at",
|
||||
"sent_by",
|
||||
"updated_at",
|
||||
"status",
|
||||
"reference",
|
||||
"template",
|
||||
"service",
|
||||
"job",
|
||||
"api_key",
|
||||
"body",
|
||||
"content_char_count"
|
||||
]
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"definitions": {
|
||||
"uuid": {
|
||||
"type": "string",
|
||||
"pattern": "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$"
|
||||
},
|
||||
"datetime": {
|
||||
"type": "string",
|
||||
"format": "date-time"
|
||||
}
|
||||
}
|
||||
}
|
||||
0
tests/app/public_contracts/__init__.py
Normal file
0
tests/app/public_contracts/__init__.py
Normal file
30
tests/app/public_contracts/test_GET_notification.py
Normal file
30
tests/app/public_contracts/test_GET_notification.py
Normal file
@@ -0,0 +1,30 @@
|
||||
import os
|
||||
|
||||
from flask import json
|
||||
import jsonschema
|
||||
|
||||
from tests import create_authorization_header
|
||||
|
||||
|
||||
def test_get_sms_contract(client, sample_notification):
|
||||
auth_header = create_authorization_header(service_id=sample_notification.service_id)
|
||||
response = client.get('/notifications/{}'.format(sample_notification.id), headers=[auth_header])
|
||||
|
||||
with open(os.path.join(os.path.dirname(__file__), './GET_notification_return_sms.json')) as schema:
|
||||
jsonschema.validate(
|
||||
json.loads(response.get_data(as_text=True)),
|
||||
json.load(schema),
|
||||
format_checker=jsonschema.FormatChecker()
|
||||
)
|
||||
|
||||
|
||||
def test_get_email_contract(client, 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])
|
||||
|
||||
with open(os.path.join(os.path.dirname(__file__), './GET_notification_return_email.json')) as schema:
|
||||
jsonschema.validate(
|
||||
json.loads(response.get_data(as_text=True)),
|
||||
json.load(schema),
|
||||
format_checker=jsonschema.FormatChecker()
|
||||
)
|
||||
Reference in New Issue
Block a user