Merge pull request #2662 from alphagov/utils-bump

Utils bump
This commit is contained in:
Leo Hemsted
2019-11-19 10:55:07 +00:00
committed by Rebecca Law
11 changed files with 150 additions and 41 deletions

View File

@@ -7,6 +7,7 @@ from jsonschema import (Draft7Validator, ValidationError, FormatChecker)
from notifications_utils.recipients import (validate_phone_number, validate_email_address, InvalidPhoneError,
InvalidEmailError)
from app.v2.errors import BadRequestError
format_checker = FormatChecker()
@@ -56,6 +57,9 @@ def validate_schema_date_with_hour(instance):
def validate(json_to_validate, schema):
if json_to_validate is None:
raise BadRequestError(message="Request body is empty.",
status_code=400)
validator = Draft7Validator(schema, format_checker=format_checker)
errors = list(validator.iter_errors(json_to_validate))
if errors.__len__() > 0: