def validate_message()

in atomresponder/message_schema.py [0:0]


def validate_message(raw_message: dict) -> dict:
    """
    validates parsed data as a Media Atom message.
    :param raw_message: the parsed data to check, as a dictionary
    :return: a dictionary of validated data. If the data does not validate, then either a jsonschema.ValidationError or
    a ValueError is raised with a descriptive string.
    """
    if "type" not in raw_message:
        raise ValueError("Message was missing the \"type\" field")

    schema = None

    if raw_message["type"]==MESSAGE_TYPE_ASSIGNED_PROJECT:
        schema = AtomAssignedProjectMessageSchema
    elif raw_message["type"]==MESSAGE_TYPE_PAC_FILE:
        schema = PacFileMessageSchema
    elif raw_message["type"]==MESSAGE_TYPE_VIDEO_UPLOAD:
        schema = VideoUploadMessageSchema
    elif raw_message["type"]==MESSAGE_TYPE_RESYNC:
        schema = VideoUploadResyncMessageSchema
    else:
        raise ValueError("Message had an invalid \"type\" field: \"{}\".".format(raw_message["type"]))

    jsonschema.validate(raw_message, schema)    #raises ValidationError if it fails
    return raw_message