Field-level

  1. Determine the type of check (see Repository structure).

  2. Find a check under the corresponding contracting_process/field_level sub-directory to copy as a starting point.

  3. Update the _definitions() function to assign the check to fields in the contracting_process/field_level/definitions.py file.

    Note

    Coverage checks are performed for all fields listed in definitions.

Each check is a function, named calculate by convention, that:

  1. Accepts two arguments (e.g. {"email": "invalid"} and email), named item and key by convention

  2. Creates an empty result dict

  3. Determines whether the check passes

  4. If it passes, sets result["result"] = True

  5. If it fails, sets result["result"] = False as well as the value and reason keys

  6. Returns the result dict

Note

The field_coverage_check and field_quality_check functions handle most of this logic, such that you only need to implement whether the check passes.

An empty result dict looks like:

    return {
        "name": name,
        "result": None,
        "value": None,
        "reason": None,
        "version": version,
    }

Example

from pelican.util.checks import field_coverage_check

name = "exists"


def test(item, key):
    return key in item, "not set"


calculate = field_coverage_check(name, test)

Storage

The results for each item are stored in a single row in the field_level_check table. A stored result value looks like (only one entry in the checks array is shown):

{
    "meta": {
        "ocid": "ocds-lcuori-0rw29R-003-2011-1",
        "item_id": 8477481
    },
    "checks": {
        "id": [
            {
                "path": "id",
                "quality": {
                    "check_results": [],
                    "overall_result": null
                },
                "coverage": {
                    "check_results": [
                        {
                            "name": "exists",
                            "result": true,
                            "value": null,
                            "reason": null,
                            "version": 1.0
                        },
                        {
                            "name": "non_empty",
                            "result": true,
                            "value": null,
                            "reason": null,
                            "version": 1.0
                        }
                    ],
                    "overall_result": true
                }
            }
        ]
    }
}