From b92e5d4c5cdb971fecead6c0e94865eba391682c Mon Sep 17 00:00:00 2001 From: Rikki Guy Date: Tue, 6 Aug 2024 15:21:33 +0100 Subject: [PATCH] tests: Sort aggregate org-ids to be deterministic Non-deterministic ordering of aggregate org-ids caused tests to intermittantly fail. --- datastore/data_quality/quality_data.py | 10 +++++----- datastore/tests/test_quality_data.py | 4 +++- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/datastore/data_quality/quality_data.py b/datastore/data_quality/quality_data.py index 23abc2f..93ffaf7 100644 --- a/datastore/data_quality/quality_data.py +++ b/datastore/data_quality/quality_data.py @@ -106,16 +106,19 @@ def create(grants): ], } + # Sort recipient / funder org-id lists to be deterministic for tests aggregates = { "count": cove_results["grants_aggregates"]["count"], "recipient_organisations": list( - cove_results["grants_aggregates"]["distinct_recipient_org_identifier"] + sorted( + cove_results["grants_aggregates"]["distinct_recipient_org_identifier"] + ) ), "recipient_individuals": cove_results["grants_aggregates"][ "recipient_individuals_count" ], "funders": list( - cove_results["grants_aggregates"]["distinct_funding_org_identifier"] + sorted(cove_results["grants_aggregates"]["distinct_funding_org_identifier"]) ), "max_award_date": cove_results["grants_aggregates"]["max_award_date"], "min_award_date": cove_results["grants_aggregates"]["min_award_date"], @@ -432,7 +435,6 @@ def get_pc_publishers_publishing_in_last(self, delta): ) def get_pc_publishers_with_recipient_ext_org(self): - ret = {} total_publishers = self.get_total_publishers() @@ -468,7 +470,6 @@ def get_pc_publishers_with_recipient_ext_org(self): return ret def get_total_grants_awarded_in_last_ten_years(self): - this_year_int = datetime.now().year award_years = {} @@ -485,7 +486,6 @@ def get_total_grants_awarded_in_last_ten_years(self): return award_years def get_pc_publishers_with_grants_awarded_in_last_ten_years(self): - this_year_int = datetime.now().year award_years = {} diff --git a/datastore/tests/test_quality_data.py b/datastore/tests/test_quality_data.py index 9de10a7..082a774 100644 --- a/datastore/tests/test_quality_data.py +++ b/datastore/tests/test_quality_data.py @@ -32,7 +32,9 @@ def test_create_sourcefile_publisher_quality_data(self): expected_sourcefile_aggregate = { "count": 5, - "recipient_organisations": ["360G-example-a", "360G-example-nonprimary"], + "recipient_organisations": sorted( + ["360G-example-a", "360G-example-nonprimary"] + ), "recipient_individuals": 0, "funders": ["GB-example-b"], "max_award_date": "2019-10-03",