Skip to content

Commit

Permalink
feat: Determine field-level checks based on schema, #12
Browse files Browse the repository at this point in the history
The change to the fixture is due to the corrections in 2f0fd89
  • Loading branch information
jpmckinney committed Oct 29, 2021
1 parent 2f0fd89 commit 9451fbe
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 737 deletions.
691 changes: 90 additions & 601 deletions contracting_process/field_level/definitions.py

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/tasks/checks/field.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Backend

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

#. Accepts two arguments (e.g. ``{"email": "invalid"}`` and ``email``). named ``item`` and ``key`` by convention
#. Accepts two arguments (e.g. ``{"email": "invalid"}`` and ``email``), named ``item`` and ``key`` by convention
#. Creates an empty ``result`` dict
#. Determines whether the check passes
#. If it passes, sets ``result["result"] = True``
Expand All @@ -34,7 +34,7 @@ An empty ``result`` dict looks like:

.. literalinclude:: ../../../tools/checks.py
:language: python
:start-after: obj =
:start-after: _empty_field_result
:end-at: }

Example
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions requirements.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
cachetools
click
jsonref
phonenumbers
pika
psycopg2
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ click==7.1.2
# via -r requirements.in
idna==2.8
# via requests
jsonref==0.2
# via -r requirements.in
phonenumbers==8.10.17
# via -r requirements.in
pika==1.1.0
Expand Down
2 changes: 2 additions & 0 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ iniconfig==1.1.1
# via pytest
isort==5.8.0
# via -r requirements_dev.in
jsonref==0.2
# via -r requirements.txt
jsonschema==4.0.0
# via -r requirements_dev.in
mccabe==0.6.1
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def set_additional_properties_false(data):
for value in data.values():
set_additional_properties_false(value)

with open(os.path.join("tests", "fixtures", "release-schema.json")) as f:
with open(os.path.join("pelican", "static", "release-schema.json")) as f:
schema = json.load(f)

set_additional_properties_false(schema)
Expand Down
175 changes: 42 additions & 133 deletions tests/fixtures/field-result.json
Original file line number Diff line number Diff line change
Expand Up @@ -5132,9 +5132,9 @@
}
}
],
"tender.enquiryPeriod.durationInDays": [
"tender.enquiryPeriod.startDate": [
{
"path": "tender.enquiryPeriod.durationInDays",
"path": "tender.enquiryPeriod.startDate",
"coverage": {
"overall_result": true,
"check_results": [
Expand All @@ -5158,7 +5158,7 @@
"overall_result": true,
"check_results": [
{
"name": "number_checks",
"name": "date_time",
"result": true,
"value": null,
"reason": null,
Expand All @@ -5168,9 +5168,9 @@
}
}
],
"tender.enquiryPeriod.startDate": [
"tender.enquiryPeriod.endDate": [
{
"path": "tender.enquiryPeriod.startDate",
"path": "tender.enquiryPeriod.endDate",
"coverage": {
"overall_result": true,
"check_results": [
Expand Down Expand Up @@ -5204,9 +5204,30 @@
}
}
],
"tender.enquiryPeriod.endDate": [
"tender.enquiryPeriod.maxExtentDate": [
{
"path": "tender.enquiryPeriod.endDate",
"path": "tender.enquiryPeriod.maxExtentDate",
"coverage": {
"overall_result": false,
"check_results": [
{
"name": "exists",
"result": false,
"value": null,
"reason": "not set",
"version": 1.0
}
]
},
"quality": {
"overall_result": null,
"check_results": null
}
}
],
"tender.enquiryPeriod.durationInDays": [
{
"path": "tender.enquiryPeriod.durationInDays",
"coverage": {
"overall_result": true,
"check_results": [
Expand All @@ -5230,7 +5251,7 @@
"overall_result": true,
"check_results": [
{
"name": "date_time",
"name": "number_checks",
"result": true,
"value": null,
"reason": null,
Expand All @@ -5240,27 +5261,6 @@
}
}
],
"tender.enquiryPeriod.maxExtentDate": [
{
"path": "tender.enquiryPeriod.maxExtentDate",
"coverage": {
"overall_result": false,
"check_results": [
{
"name": "exists",
"result": false,
"value": null,
"reason": "not set",
"version": 1.0
}
]
},
"quality": {
"overall_result": null,
"check_results": null
}
}
],
"tender.hasEnquiries": [
{
"path": "tender.hasEnquiries",
Expand Down Expand Up @@ -10286,67 +10286,8 @@
]
},
"quality": {
"overall_result": false,
"check_results": [
{
"name": "document_description_length",
"result": false,
"value": {
"transactions": [
{
"id": "ocds-213czf-000-00001-1",
"source": "https://openspending.org/uk-barnet-spending/",
"date": "2010-08-01T00:00:00Z",
"value": {
"amount": 50000,
"currency": "GBP"
},
"payer": {
"id": "GB-LAC-E09000003",
"name": "London Borough of Barnet"
},
"payee": {
"id": "GB-COH-11111111",
"name": "AnyCorp Cycle Provision"
},
"uri": "https://openspending.org/uk-barnet-spending/transaction/asd9235qaghvs1059620ywhgai"
},
{
"id": "ocds-213czf-000-00001-2",
"source": "https://openspending.org/uk-barnet-spending/",
"date": "2010-10-01T00:00:00Z",
"value": {
"amount": 10000,
"currency": "GBP"
},
"payer": {
"id": "GB-LAC-E09000003",
"name": "London Borough of Barnet"
},
"payee": {
"id": "GB-COH-11111111",
"name": "AnyCorp Cycle Provision"
},
"uri": "https://openspending.org/uk-barnet-spending/transaction/asd9235qaghvs105962as0012"
}
],
"documents": [
{
"id": "9.0",
"documentType": "physicalProgressReport",
"title": "Progress report",
"description": "Physical progress report for cycle path construction",
"url": "http://example.com/reports/ocds-213czf-000-00001/cycle-path-01.pdf",
"datePublished": "2010-12-15T15:34:02Z",
"format": "application/pdf",
"language": "en"
}
]
},
"reason": "not a str",
"version": 1.0
}
]
"overall_result": null,
"check_results": null
}
}
],
Expand Down Expand Up @@ -11472,46 +11413,6 @@
}
}
],
"contracts.implementation.transactions.currency": [
{
"path": "contracts[0].implementation.transactions[0].currency",
"coverage": {
"overall_result": false,
"check_results": [
{
"name": "exists",
"result": false,
"value": null,
"reason": "not set",
"version": 1.0
}
]
},
"quality": {
"overall_result": null,
"check_results": null
}
},
{
"path": "contracts[0].implementation.transactions[1].currency",
"coverage": {
"overall_result": false,
"check_results": [
{
"name": "exists",
"result": false,
"value": null,
"reason": "not set",
"version": 1.0
}
]
},
"quality": {
"overall_result": null,
"check_results": null
}
}
],
"contracts.implementation.transactions.providerOrganization": [
{
"path": "contracts[0].implementation.transactions[0].providerOrganization",
Expand Down Expand Up @@ -12208,8 +12109,16 @@
]
},
"quality": {
"overall_result": null,
"check_results": null
"overall_result": true,
"check_results": [
{
"name": "language",
"result": true,
"value": null,
"reason": null,
"version": 1.0
}
]
}
}
],
Expand All @@ -12235,4 +12144,4 @@
}
]
}
}
}

0 comments on commit 9451fbe

Please sign in to comment.