Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelwood committed Dec 12, 2024
1 parent 136eb6e commit 97e7767
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 0 deletions.
File renamed without changes.
57 changes: 57 additions & 0 deletions cove/cove_360/fixtures/multiple_funder_names_org_ids.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"grants": [
{
"id": "360G-sampletrust-105177/Z/14/Z",
"awardDate": "2024-12-30",
"amountAwarded": 10,
"url": "http://example.com",
"title": "test",
"currency": "GBP",
"description": "test",
"plannedDates": [
{
"duration": 30
}
],
"recipientOrganization": [
{
"id": "GB-323242-test",
"name": "Example Project Limited"
}
],
"fundingOrganization": [
{
"id": "GB-12345-test",
"name": "Example Funder Limited"
}
]
},
{
"id": "360G-sampletrust-123452",
"awardDate": "2024-12-30",
"amountAwarded": 10,
"url": "http://example.com",
"title": "test two",
"currency": "GBP",
"description": "test two",
"plannedDates": [
{
"duration": 30
}
],
"recipientOrganization": [
{
"id": "GB-323242-test",
"name": "Example Project Limited"
}
],
"fundingOrganization": [
{
"id": "GB-12345-test",
"name": "Example Funder"
}
]
}

]
}
Binary file added cove/cove_360/fixtures/org-id-strange-chars.ods
Binary file not shown.
9 changes: 9 additions & 0 deletions cove/cove_360/tests/test_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,15 @@ def test_oneof_validation(server_url, browser, httpserver):
"Sheet: grants Row: 3 Header: Beneficiary Location:Geographic Code",
"Sheet: grants Row: 4 Header: Beneficiary Location:Geographic Code",
], []),
("duration_usefulness.json", [
"1 grant does not contain plannedDates/0/duration or (plannedDates/startDate and plannedDates/endDate)",
], []),
("duration_usefulness.json", [
"1 grant does not contain plannedDates/0/duration or (plannedDates/startDate and plannedDates/endDate)",
], []),
("multiple_fundiner_names_org_ids.json", [
"added an additional name for an existing Funding Org"
], []),
])
def test_quality_checks(server_url, browser, httpserver, source_filename, expected_texts, unexpected_texts):
with open(os.path.join('cove_360', 'fixtures', source_filename), 'rb') as fp:
Expand Down
3 changes: 3 additions & 0 deletions lib360dataquality/additional_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ def __init__(self, **kw):
self.relevant_grant_type = TestRelevance.RECIPIENT_ANY

def process(self, grant, path_prefix):
# Each test must implement this function which is called on each grant after
# the class is initialised.
# Set self.count, self.failed, self.heading and self.message
pass

def produce_message(self):
Expand Down
49 changes: 49 additions & 0 deletions lib360dataquality/cove/threesixtygiving.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ def common_checks_360(
json_data,
cell_source_map,
TEST_CLASSES[test_class_type],
# Set ignore_errors to False for debugging checks otherwise all exceptions will pass
ignore_errors=True,
return_on_error=None,
aggregates=context["grants_aggregates"],
Expand Down Expand Up @@ -1764,9 +1765,56 @@ def process(self, grant, path_prefix):
self.message = self.check_text["message"][self.grants_percentage]


class MultiFundingOrgIdsForName(AdditionalTest):
"""Check for Funding org ids with multiple names."""

check_text = {
"heading": mark_safe("added an additional name for an existing Funding Org"),
"message": RangeDict(),
}
check_text["message"][(0, 100)] = mark_safe(
"Your data contains Funding Org names with differing org-ids. "
"Funding organisations typically only have one name and one org-id."
)

category = TestCategories.ORGANISATIONS

def __init__(self, **kw):
super().__init__(**kw)
# zxy-name: { names: [] }
self.funding_organisation_id_name = {}

def process(self, grant, path_prefix):
for num, organisation in enumerate(grant["fundingOrganization"]):
org_id = organisation["id"]
name = organisation["name"]

try:
names = self.funding_organisation_id_name[organisation["id"]]
except KeyError:
# initialise the data
names = [name]
self.funding_organisation_id_name[org_id] = names

if name not in names:
# We have a brand new name for this org id, suspicious.
names.append(name)
self.json_locations.append(
path_prefix + "/fundingOrganization/{}/name".format(num)
)
self.count = self.count + 1
self.failed = True

self.heading = self.format_heading_count(self.check_text["heading"])
self.message = mark_safe(self.check_text["message"][self.grants_percentage])




# Default tests run in CoVE, these are also the base list
# for the Quality Dashboard checks.
TEST_CLASSES = {
# Quality = Accuracy tests in cove
TestType.QUALITY_TEST_CLASS: [
ZeroAmountTest,
FundingOrgUnrecognisedPrefix,
Expand All @@ -1787,6 +1835,7 @@ def process(self, grant, path_prefix):
PostDatedAwardDates,
RecipientIndDEI,
GeoCodePostcode,
MultiFundingOrgIdsForName,
],
TestType.USEFULNESS_TEST_CLASS: [
RecipientOrg360GPrefix,
Expand Down

0 comments on commit 97e7767

Please sign in to comment.