def validate_field_block()

in vs-metadata/validate.py [0:0]


def validate_field_block(counter, field_node):
    """
    validates the contents of a single field block
    :param field_node:
    :return:
    """
    passing = True
    if not validate_node_single_nonempty(field_node, "name"):
        print("Field {0} in the doc has no name".format(counter))
        return False
    field_name = field_node.find("{0}name".format(xmlns)).text
    prefix = "Field {0} ({1})".format(counter, field_name)

    if not validate_node_single_nonempty(field_node,"schema"):
        print("{0} has no schema node".format(prefix))
        passing = False
    else:
        schema_node = field_node.find("{0}schema".format(xmlns))
        if not(schema_node.attrib.get("min")) or not(schema_node.attrib.get("max")) or not(schema_node.attrib.get("name")):
            print("{0} schema node is missing required arguments".format(prefix))
            passing = False
        if schema_node.attrib.get("name") != field_name:
            print("{0} schema node name is not the same as field name. Expected {1}, got {2}".format(prefix, field_name, schema_node.attrib.get("name")))
    if not validate_node_single_nonempty(field_node,"type"):
        print("{0} has no type node".format(prefix))
        passing = False

    originNodes = [x for x in field_node.findall("{0}origin".format(xmlns))]
    if len(originNodes)>0:
        print("{0} should not have an origin node".format(prefix))
        passing = False

    extradata = extract_extradata(field_node)

    if extradata:
        try:
            extradata_parsed = json.loads(extradata)
            readonly = extradata_parsed.get("readonly","")
            if not isinstance(readonly, bool):
                print("{0} Readonly should be a boolean".format(prefix))
                passing = False
            # if readonly!="true" and readonly!="false":
            #     print("{0} Readonly value was '{1}', not true or false".format(prefix, readonly))
            #     passing = False
            values = extradata_parsed.get("values",[])
            if not isinstance(values, list):
                print("{0} values key was a {1}, not a list".format(prefix, str(values.__class__)))
                passing = False
        except Exception as e:
            print("{0} extradata was not valid json: {1}".format(prefix, e))
            passing = False
        return passing
    else:
        print("{0} has no extradata present".format(prefix, counter, field_name))
        return False