Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion 360-ds
Submodule 360-ds deleted from bd34fe
28 changes: 27 additions & 1 deletion cove/cove_360/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from django.core.files.base import ContentFile
from django.core.files.uploadedfile import UploadedFile

from lib360dataquality.cove.threesixtygiving import get_grants_aggregates, run_extra_checks, extend_numbers, spreadsheet_style_errors_table, TEST_CLASSES, group_validation_errors
from lib360dataquality.cove.threesixtygiving import get_grants_aggregates, run_extra_checks, extend_numbers, spreadsheet_style_errors_table, validator, TEST_CLASSES, group_validation_errors
from lib360dataquality.additional_test import TestCategories, TestImportance

# Source is cove_360/fixtures/fundingproviders-grants_fixed_2_grants.json
Expand Down Expand Up @@ -990,6 +990,32 @@ def test_extend_numbers():
assert list(extend_numbers([4, 5, 7, 2001])) == [3, 4, 5, 6, 7, 8, 2000, 2001, 2002]


def test_unique_ids():
schema = {
"type": "object",
"properties": {
"grants": {
"type": "array",
"items": {"type": "object"},
"uniqueItems": True,
}
},
}
v = validator(schema)

errors = list(v.iter_errors({"grants": [{"id": "1"}, {"id": "2"}, {"id": "1"}]}))
assert [(e.message, e.error_id) for e in errors] == [("Non-unique id values", "uniqueItems_with_id")]

errors = list(v.iter_errors({"grants": [{"title": "a"}, {"title": "b"}]}))
assert errors == []

errors = list(v.iter_errors({"grants": [{"title": "a"}, {"title": "a"}]}))
assert [(e.message, e.error_id) for e in errors] == [("Array has non-unique elements", "uniqueItems_no_ids")]

errors = list(v.iter_errors({"grants": [{"id": "1"}, {"id": "2"}]}))
assert errors == []


def ex(value):
''' Shorthand for value metadata with type `example`.'''
return {'type': 'example', 'value': value}
Expand Down
5 changes: 5 additions & 0 deletions lib360dataquality/cove/threesixtygiving.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from decimal import Decimal
import logging

import jsonschema
import libcove.lib.common as libcove_common
import libcove.lib.tools as tools
import openpyxl
Expand Down Expand Up @@ -172,6 +173,10 @@ def oneOf_draft4(validator, oneOf, instance, schema):

validator.VALIDATORS["oneOf"] = oneOf_draft4

# Force jsonschema to use our validator
# https://github.com/python-jsonschema/jsonschema/issues/994
jsonschema.validators._META_SCHEMAS["https://json-schema.org/draft/2020-12/schema"] = validator


@tools.ignore_errors
def get_grants_aggregates(json_data):
Expand Down
4 changes: 2 additions & 2 deletions requirements_cove.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ jsonref==1.1.0
# via
# flattentool
# libcove
jsonschema==3.2.0
jsonschema==4.18
# via
# -r requirements_cove.in
# lib360dataquality
# libcove
libcove==0.31.0
libcove==0.32.1
# via
# -r requirements_cove.in
# lib360dataquality
Expand Down
4 changes: 2 additions & 2 deletions requirements_cove_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,12 @@ jsonref==1.1.0
# via
# flattentool
# libcove
jsonschema==3.2.0
jsonschema==4.18
# via
# -r requirements_cove.in
# lib360dataquality
# libcove
libcove==0.31.0
libcove==0.32.1
# via
# -r requirements_cove.in
# lib360dataquality
Expand Down
4 changes: 2 additions & 2 deletions requirements_cove_dokku.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ jsonref==1.1.0
# -r requirements_cove.txt
# flattentool
# libcove
jsonschema==3.2.0
jsonschema==4.18
# via
# -r requirements_cove.txt
# lib360dataquality
# libcove
libcove==0.31.0
libcove==0.32.1
# via
# -r requirements_cove.txt
# lib360dataquality
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
'python-dateutil',
'rangedict',
'ijson',
'jsonschema<4',
'jsonschema>=4.18',
'json-merge-patch',
],
extras_require={
Expand Down
Loading