diff --git a/app/schema_validation/__init__.py b/app/schema_validation/__init__.py index fe643ad61..bd94755d4 100644 --- a/app/schema_validation/__init__.py +++ b/app/schema_validation/__init__.py @@ -42,4 +42,27 @@ def build_error_message(errors): def __format_message(e): - return e.message.replace("'", "") if not e.cause else "{} {}".format(e.path[0], e.cause.message) + def get_path(e): + error_path = None + try: + error_path = e.path.popleft() + # no need to catch IndexError exception explicity as + # error_path is None if e.path has no items + finally: + return error_path + + def get_error_message(e): + error_message = None + try: + error_message = e.cause.message + except AttributeError: + error_message = e.message + finally: + return error_message.replace("'", '') + + path = get_path(e) + message = get_error_message(e) + if path: + return "{} {}".format(path, message) + else: + return "{}".format(message) diff --git a/app/v2/notifications/notification_schemas.py b/app/v2/notifications/notification_schemas.py index 3078a2fd8..beb12f779 100644 --- a/app/v2/notifications/notification_schemas.py +++ b/app/v2/notifications/notification_schemas.py @@ -10,7 +10,7 @@ template = { "properties": { "id": uuid, "version": {"type": "integer"}, - "uri": {"type": "string"} + "uri": {"type": "string", "format": "uri"} }, "required": ["id", "version", "uri"] } @@ -163,7 +163,7 @@ post_sms_response = { "id": uuid, "reference": {"type": ["string", "null"]}, "content": sms_content, - "uri": {"type": "string"}, + "uri": {"type": "string", "format": "uri"}, "template": template }, "required": ["id", "content", "uri", "template"] @@ -206,7 +206,7 @@ post_email_response = { "id": uuid, "reference": {"type": ["string", "null"]}, "content": email_content, - "uri": {"type": "string"}, + "uri": {"type": "string", "format": "uri"}, "template": template }, "required": ["id", "content", "uri", "template"] @@ -218,7 +218,7 @@ def create_post_sms_response_from_notification(notification, body, from_number, "reference": notification.client_reference, "content": {'body': body, 'from_number': from_number}, - "uri": "{}/v2/notifications/{}".format(url_root, str(notification.id)), + "uri": "{}v2/notifications/{}".format(url_root, str(notification.id)), "template": __create_template_from_notification(notification=notification, url_root=url_root) } @@ -232,7 +232,7 @@ def create_post_email_response_from_notification(notification, content, subject, "body": content, "subject": subject }, - "uri": "{}/v2/notifications/{}".format(url_root, str(notification.id)), + "uri": "{}v2/notifications/{}".format(url_root, str(notification.id)), "template": __create_template_from_notification(notification=notification, url_root=url_root) } @@ -241,5 +241,5 @@ def __create_template_from_notification(notification, url_root): return { "id": notification.template_id, "version": notification.template_version, - "uri": "{}/v2/templates/{}".format(url_root, str(notification.template_id)) + "uri": "{}v2/templates/{}".format(url_root, str(notification.template_id)) } diff --git a/tests/app/delivery/test_send_to_providers.py b/tests/app/delivery/test_send_to_providers.py index dfddbb49b..2f37d1eed 100644 --- a/tests/app/delivery/test_send_to_providers.py +++ b/tests/app/delivery/test_send_to_providers.py @@ -109,7 +109,6 @@ def test_should_send_personalised_template_to_correct_email_provider_and_persist assert '