diff --git a/tests/app/public_contracts/schemas/GET_notification_return_email_v2.json b/tests/app/public_contracts/schemas/GET_notification_return_email_v2.json new file mode 100644 index 000000000..a6287c9ce --- /dev/null +++ b/tests/app/public_contracts/schemas/GET_notification_return_email_v2.json @@ -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" + ] +} \ No newline at end of file diff --git a/tests/app/public_contracts/test_GET_notification.py b/tests/app/public_contracts/test_GET_notification.py index fdc13e078..ae2a37371 100644 --- a/tests/app/public_contracts/test_GET_notification.py +++ b/tests/app/public_contracts/test_GET_notification.py @@ -1,59 +1,45 @@ from . import validate 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 tests import create_authorization_header -def test_get_api_sms_contract(client, sample_notification): - api_key = ApiKey(service=sample_notification.service, - name='api_key', - created_by=sample_notification.service.created_by, - key_type=KEY_TYPE_NORMAL) - save_model_api_key(api_key) - sample_notification.job = None - sample_notification.api_key = api_key - sample_notification.key_type = KEY_TYPE_NORMAL - 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 _get(client, notification, url): + save_model_api_key(ApiKey( + service=notification.service, + name='api_key', + created_by=notification.service.created_by, + key_type=KEY_TYPE_NORMAL + )) + auth_header = create_authorization_header(service_id=notification.service_id) + return client.get(url, 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') def test_get_api_email_contract(client, sample_email_notification): - api_key = ApiKey(service=sample_email_notification.service, - 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]) - + response = _get(client, sample_email_notification, '/notifications/{}'.format(sample_email_notification.id)) validate(response.get_data(as_text=True), 'GET_notification_return_email.json') def test_get_job_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]) - + response = _get(client, sample_notification, '/notifications/{}'.format(sample_notification.id)) validate(response.get_data(as_text=True), 'GET_notification_return_sms.json') def test_get_job_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]) - + response = _get(client, sample_email_notification, '/notifications/{}'.format(sample_email_notification.id)) 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]) - + response = _get(client, sample_notification, '/notifications') validate(response.get_data(as_text=True), 'GET_notifications_return.json')