def check_fields()

in src/es_pii_tool/helpers/utils.py [0:0]


def check_fields(result: t.Dict, job_config: t.Dict) -> bool:
    """Check document fields in result to ensure success

    :param result: The search result object
    :param job_config: The configuration settings for this job

    :type result: dict
    :type job_config: dict

    :returns: Success (``True``) or Failure (``False``)
    :rtype: bool
    """
    complete = True
    hit = result['hits']['hits'][0]['_source']
    for field in job_config['fields']:
        success = False
        if len(field.split('.')) > 1:
            success = check_dotted_fields(result, field, job_config['message'])

        elif field in hit:
            if hit[field] == job_config['message']:
                success = True

        else:
            logger.warning("Field %s not present in document", field)
            # Don't need to report the expected fail 2x, so we break the loop here
            break

        if success:
            logger.info("Field %s is redacted correctly", field)
        else:
            # A single failure is enough to make it a complete failure.
            complete = False
            logger.error("Field %s is not redacted correctly", field)
    return complete