def prepare_body(response): # content_type must be set to access response.text if not response.content_type: raise ResponseValidationError( 'Response validation error: Content-Type must be set') if 'application/json' in response.content_type: return simplejson.loads(response.text) else: return response.text
def _validate_response(response, schema_data, schema_resolver): """ Validates a response and raises a ResponseValidationError on failure. :param response: the response object to validate :type response: Pyramid response object passed into a view :param schema_data: our mapping from request data to schemas (see load_schema) :type schema_data: dict :param resolver: the request object to validate :type resolver: Pyramid request object passed into a view """ try: validate_outgoing_response(response, schema_data, schema_resolver) except jsonschema.exceptions.ValidationError as exc: # This will alter our stack trace slightly, but Pyramid knows how # to render it and the real value is in the message anyway. raise ResponseValidationError(str(exc))