From cb0491cbff583e32c28780429a33d78adac349bf Mon Sep 17 00:00:00 2001 From: Leo Hemsted Date: Tue, 30 Aug 2016 19:07:46 +0100 Subject: [PATCH] add test for GET /notification simple schema with oneOf [email, sms]. also fixed error where ref'd schemas weren't being picked up --- .../GET_notification_return_email.json | 6 +- .../GET_notification_return_sms.json | 6 +- .../GET_notifications_return.json | 26 +++ tests/app/public_contracts/definitions.json | 2 +- .../public_contracts/email_notification.json | 208 +++++++++--------- .../public_contracts/sms_notification.json | 204 +++++++++-------- .../public_contracts/test_GET_notification.py | 7 + 7 files changed, 246 insertions(+), 213 deletions(-) create mode 100644 tests/app/public_contracts/GET_notifications_return.json diff --git a/tests/app/public_contracts/GET_notification_return_email.json b/tests/app/public_contracts/GET_notification_return_email.json index 949033e6b..e6fb6b19f 100644 --- a/tests/app/public_contracts/GET_notification_return_email.json +++ b/tests/app/public_contracts/GET_notification_return_email.json @@ -8,8 +8,10 @@ "properties": { "notification": {"$ref": "email_notification.json"} }, - "additionalProperties": false + "additionalProperties": false, + "required": ["notification"] } }, - "additionalProperties": false + "additionalProperties": false, + "required": ["data"] } diff --git a/tests/app/public_contracts/GET_notification_return_sms.json b/tests/app/public_contracts/GET_notification_return_sms.json index 356428fde..2127ffd46 100644 --- a/tests/app/public_contracts/GET_notification_return_sms.json +++ b/tests/app/public_contracts/GET_notification_return_sms.json @@ -8,8 +8,10 @@ "properties": { "notification": {"$ref": "sms_notification.json"} }, - "additionalProperties": false + "additionalProperties": false, + "required": ["notification"] } }, - "additionalProperties": false + "additionalProperties": false, + "required": ["data"] } diff --git a/tests/app/public_contracts/GET_notifications_return.json b/tests/app/public_contracts/GET_notifications_return.json new file mode 100644 index 000000000..7939dd8f1 --- /dev/null +++ b/tests/app/public_contracts/GET_notifications_return.json @@ -0,0 +1,26 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "description": "GET notification return schema - for sms notifications", + "type" : "object", + "properties": { + "notifications": { + "type": "array", + "items": { + "oneOf": [ + {"$ref": "sms_notification.json"}, + {"$ref": "email_notification.json"} + ] + } + }, + "links": { + "type": "object", + "additionalProperties": false + }, + "page_size": {"type": "number"}, + "total": {"type": "number"} + }, + "additionalProperties": false, + "required": [ + "notifications", "links", "page_size", "total" + ] +} diff --git a/tests/app/public_contracts/definitions.json b/tests/app/public_contracts/definitions.json index d8a2ea3ef..5b12591dc 100644 --- a/tests/app/public_contracts/definitions.json +++ b/tests/app/public_contracts/definitions.json @@ -8,5 +8,5 @@ "datetime": { "type": "string", "format": "date-time" - }, + } } diff --git a/tests/app/public_contracts/email_notification.json b/tests/app/public_contracts/email_notification.json index 6de386eea..013fb49ff 100644 --- a/tests/app/public_contracts/email_notification.json +++ b/tests/app/public_contracts/email_notification.json @@ -1,108 +1,106 @@ { - "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"} + "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"] }, - "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" - ] - } + "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" + ] } diff --git a/tests/app/public_contracts/sms_notification.json b/tests/app/public_contracts/sms_notification.json index 816a2056a..d81def6ea 100644 --- a/tests/app/public_contracts/sms_notification.json +++ b/tests/app/public_contracts/sms_notification.json @@ -1,106 +1,104 @@ { - "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"} + "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"] }, - "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" - ] - } + "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": "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" + ] } diff --git a/tests/app/public_contracts/test_GET_notification.py b/tests/app/public_contracts/test_GET_notification.py index a9cb0fce4..d7a03b77a 100644 --- a/tests/app/public_contracts/test_GET_notification.py +++ b/tests/app/public_contracts/test_GET_notification.py @@ -27,3 +27,10 @@ def test_get_email_contract(client, sample_email_notification): response = client.get('/notifications/{}'.format(sample_email_notification.id), headers=[auth_header]) validate(response.get_data(as_text=True), './GET_notification_return_email.json') + + +def test_get_notifications_contract(client, sample_notification, sample_email_notification): + auth_header = create_authorization_header(service_id=sample_notification.service_id) + response = client.get('/notifications', headers=[auth_header]) + + validate(response.get_data(as_text=True), './GET_notifications_return.json')