Skip to content

Commit

Permalink
tests: Sort aggregate org-ids to be deterministic
Browse files Browse the repository at this point in the history
Non-deterministic ordering of aggregate org-ids caused tests to
intermittantly fail.
  • Loading branch information
R2ZER0 committed Sep 30, 2024
1 parent 1c787ea commit b92e5d4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 5 additions & 5 deletions datastore/data_quality/quality_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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 = {}

Expand All @@ -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 = {}

Expand Down
4 changes: 3 additions & 1 deletion datastore/tests/test_quality_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit b92e5d4

Please sign in to comment.