mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 09:51:11 -05:00
separate definitions into separate files to allow reuse
see https://github.com/Julian/jsonschema/issues/98 took boring generic things (eg uuid) into definitions.json, and also separated email and sms notification objects into respective files
This commit is contained in:
@@ -1,128 +1,15 @@
|
|||||||
{
|
{
|
||||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||||
"description": "GET notification return schema - for SMS notifications",
|
"description": "GET notification return schema - for email notifications",
|
||||||
"type" : "object",
|
"type" : "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"data": {
|
"data": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"notification": {
|
"notification": {"$ref": "email_notification.json"}
|
||||||
"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
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"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"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,127 +1,15 @@
|
|||||||
{
|
{
|
||||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||||
"description": "GET notification return schema - for SMS notifications",
|
"description": "GET notification return schema - for sms notifications",
|
||||||
"type" : "object",
|
"type" : "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"data": {
|
"data": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"notification": {
|
"notification": {"$ref": "sms_notification.json"}
|
||||||
"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
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"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"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
12
tests/app/public_contracts/definitions.json
Normal file
12
tests/app/public_contracts/definitions.json
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||||
|
"description": "Common definitions - usage example: {'$ref': 'definitions.json#/uuid'} (swap quotes for double quotes)",
|
||||||
|
"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"
|
||||||
|
},
|
||||||
|
}
|
||||||
108
tests/app/public_contracts/email_notification.json
Normal file
108
tests/app/public_contracts/email_notification.json
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
{
|
||||||
|
"email_notification": {
|
||||||
|
"description": "Single email notification schema - as returned by GET /notification and GET /notification/{}",
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"id": {"$ref": "definitions.json#/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.json#/datetime"},
|
||||||
|
"sent_at": {"oneOf":[
|
||||||
|
{"$ref": "definitions.json#/datetime"},
|
||||||
|
{"type": "null"}
|
||||||
|
]},
|
||||||
|
"sent_by": {"oneOf":[
|
||||||
|
{"type": "string"},
|
||||||
|
{"type": "null"}
|
||||||
|
]},
|
||||||
|
"updated_at": {"oneOf":[
|
||||||
|
{"$ref": "definitions.json#/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.json#/uuid"},
|
||||||
|
"name": {"type": "string"},
|
||||||
|
"template_type": {
|
||||||
|
"type": "string",
|
||||||
|
"enum": ["email"]
|
||||||
|
},
|
||||||
|
"version": {"type": "number"}
|
||||||
|
},
|
||||||
|
"additionalProperties": false,
|
||||||
|
"required": ["id", "name", "template_type", "version"]
|
||||||
|
},
|
||||||
|
"service": {"$ref": "definitions.json#/uuid"},
|
||||||
|
"job": {
|
||||||
|
"oneOf": [
|
||||||
|
{
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"id": {"$ref": "definitions.json#/uuid"},
|
||||||
|
"original_file_name": {"type": "string"}
|
||||||
|
},
|
||||||
|
"additionalProperties": false,
|
||||||
|
"required": ["id", "original_file_name"]
|
||||||
|
},
|
||||||
|
{"type": "null"}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"api_key": {"oneOf":[
|
||||||
|
{"$ref": "definitions.json#/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",
|
||||||
|
"subject"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
106
tests/app/public_contracts/sms_notification.json
Normal file
106
tests/app/public_contracts/sms_notification.json
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
{
|
||||||
|
"sms_notification": {
|
||||||
|
"description": "Single sms notification schema - as returned by GET /notification and GET /notification/{}",
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"id": {"$ref": "definitions.json#/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.json#/datetime"},
|
||||||
|
"sent_at": {"oneOf":[
|
||||||
|
{"$ref": "definitions.json#/datetime"},
|
||||||
|
{"type": "null"}
|
||||||
|
]},
|
||||||
|
"sent_by": {"oneOf":[
|
||||||
|
{"type": "string"},
|
||||||
|
{"type": "null"}
|
||||||
|
]},
|
||||||
|
"updated_at": {"oneOf":[
|
||||||
|
{"$ref": "definitions.json#/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.json#/uuid"},
|
||||||
|
"name": {"type": "string"},
|
||||||
|
"template_type": {
|
||||||
|
"type": "string",
|
||||||
|
"enum": ["sms"]
|
||||||
|
},
|
||||||
|
"version": {"type": "number"}
|
||||||
|
},
|
||||||
|
"additionalProperties": false,
|
||||||
|
"required": ["id", "name", "template_type", "version"]
|
||||||
|
},
|
||||||
|
"service": {"$ref": "definitions.json#/uuid"},
|
||||||
|
"job": {
|
||||||
|
"oneOf": [
|
||||||
|
{
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"id": {"$ref": "definitions.json#/uuid"},
|
||||||
|
"original_file_name": {"type": "string"}
|
||||||
|
},
|
||||||
|
"additionalProperties": false,
|
||||||
|
"required": ["id", "original_file_name"]
|
||||||
|
},
|
||||||
|
{"type": "null"}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"api_key": {"oneOf":[
|
||||||
|
{"$ref": "definitions.json#/uuid"},
|
||||||
|
{"type": "null"}
|
||||||
|
]},
|
||||||
|
"body": {"type": "string"},
|
||||||
|
"content_char_count": {"type": "null"}
|
||||||
|
},
|
||||||
|
"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"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,26 +5,25 @@ import jsonschema
|
|||||||
|
|
||||||
from tests import create_authorization_header
|
from tests import create_authorization_header
|
||||||
|
|
||||||
|
def validate(json_string, schema_filename):
|
||||||
|
resolver = jsonschema.RefResolver('file://' + os.path.dirname(__file__) + '/', None)
|
||||||
|
with open(os.path.join(os.path.dirname(__file__), schema_filename)) as schema:
|
||||||
|
jsonschema.validate(
|
||||||
|
json.loads(json_string),
|
||||||
|
json.load(schema),
|
||||||
|
format_checker=jsonschema.FormatChecker(),
|
||||||
|
resolver=resolver
|
||||||
|
)
|
||||||
|
|
||||||
def test_get_sms_contract(client, sample_notification):
|
def test_get_sms_contract(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('/notifications/{}'.format(sample_notification.id), headers=[auth_header])
|
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:
|
validate(response.get_data(as_text=True), './GET_notification_return_sms.json')
|
||||||
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):
|
def test_get_email_contract(client, sample_email_notification):
|
||||||
auth_header = create_authorization_header(service_id=sample_email_notification.service_id)
|
auth_header = create_authorization_header(service_id=sample_email_notification.service_id)
|
||||||
response = client.get('/notifications/{}'.format(sample_email_notification.id), headers=[auth_header])
|
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:
|
validate(response.get_data(as_text=True), './GET_notification_return_email.json')
|
||||||
jsonschema.validate(
|
|
||||||
json.loads(response.get_data(as_text=True)),
|
|
||||||
json.load(schema),
|
|
||||||
format_checker=jsonschema.FormatChecker()
|
|
||||||
)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user