Update notification schemas with optional schedule_for element

This commit is contained in:
Rebecca Law
2017-05-15 15:02:38 +01:00
parent 75a4dad8c1
commit 38e5b31e9a
3 changed files with 60 additions and 8 deletions

View File

@@ -1,4 +1,5 @@
import json
from datetime import datetime
from jsonschema import (Draft4Validator, ValidationError, FormatChecker)
from notifications_utils.recipients import (validate_phone_number, validate_email_address, InvalidPhoneError,
@@ -20,6 +21,16 @@ def validate(json_to_validate, schema):
validate_email_address(instance)
return True
@format_checker.checks('datetime', raises=ValidationError)
def validate_schema_datetime(instance):
if isinstance(instance, str):
try:
datetime.strptime(instance, "%Y-%m-%d %H:%M:%S")
except ValueError as e:
raise ValidationError("datetime format is invalid. Use the format: "
"YYYY-MM-DD HH:MM:SS, for example 2017-05-30 13:00:00")
return True
validator = Draft4Validator(schema, format_checker=format_checker)
errors = list(validator.iter_errors(json_to_validate))
if errors.__len__() > 0:

View File

@@ -39,7 +39,8 @@ get_notification_response = {
"subject": {"type": ["string", "null"]},
"created_at": {"type": "string"},
"sent_at": {"type": ["string", "null"]},
"completed_at": {"type": ["string", "null"]}
"completed_at": {"type": ["string", "null"]},
"scheduled_for": {"type": ["string", "null"]}
},
"required": [
# technically, all keys are required since we always have all of them
@@ -111,7 +112,8 @@ post_sms_request = {
"reference": {"type": "string"},
"phone_number": {"type": "string", "format": "phone_number"},
"template_id": uuid,
"personalisation": personalisation
"personalisation": personalisation,
"scheduled_for": {"type": "string", "format": "datetime"}
},
"required": ["phone_number", "template_id"]
}
@@ -138,7 +140,8 @@ post_sms_response = {
"reference": {"type": ["string", "null"]},
"content": sms_content,
"uri": {"type": "string", "format": "uri"},
"template": template
"template": template,
"scheduled_for": {"type": "string"}
},
"required": ["id", "content", "uri", "template"]
}
@@ -153,7 +156,8 @@ post_email_request = {
"reference": {"type": "string"},
"email_address": {"type": "string", "format": "email_address"},
"template_id": uuid,
"personalisation": personalisation
"personalisation": personalisation,
"scheduled_for": {"type": "string", "format": "datetime"}
},
"required": ["email_address", "template_id"]
}
@@ -181,7 +185,8 @@ post_email_response = {
"reference": {"type": ["string", "null"]},
"content": email_content,
"uri": {"type": "string", "format": "uri"},
"template": template
"template": template,
"scheduled_for": {"type": "string"}
},
"required": ["id", "content", "uri", "template"]
}