Skip to content

Commit

Permalink
test: that we get the number of bins we expect from a public config file
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlougheed committed Nov 15, 2022
1 parent 3852bf7 commit 1b1f15b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
20 changes: 17 additions & 3 deletions chord_metadata_service/restapi/tests/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,16 @@
}
}

VALID_INDIVIDUALS = [VALID_INDIVIDUAL_1, VALID_INDIVIDUAL_2, VALID_INDIVIDUAL_3, VALID_INDIVIDUAL_4,
VALID_INDIVIDUAL_5, VALID_INDIVIDUAL_6, VALID_INDIVIDUAL_7, VALID_INDIVIDUAL_8]
VALID_INDIVIDUALS = [
VALID_INDIVIDUAL_1,
VALID_INDIVIDUAL_2,
VALID_INDIVIDUAL_3,
VALID_INDIVIDUAL_4,
VALID_INDIVIDUAL_5,
VALID_INDIVIDUAL_6,
VALID_INDIVIDUAL_7,
VALID_INDIVIDUAL_8,
]


extra_properties_with_list = {
Expand Down Expand Up @@ -260,7 +268,13 @@
"charts": [
{"field": "date_of_consent", "chart_type": "bar"},
{"field": "smoking", "chart_type": "bar"},
{"field": "baseline_creatinine", "chart_type": "bar"}
{"field": "baseline_creatinine", "chart_type": "bar"},
]
},
{
"section_title": "Third Section",
"charts": [
{"field": "lab_test_result_value", "chart_type": "bar"},
]
}
],
Expand Down
15 changes: 15 additions & 0 deletions chord_metadata_service/restapi/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,21 @@ def test_overview(self):
self.assertIsInstance(response_obj, dict)
self.assertEqual(response_obj["counts"]["individuals"], db_count)

@override_settings(CONFIG_PUBLIC=CONFIG_PUBLIC_TEST)
def test_overview_bins(self):
# test that there is the correct number of data entries for number
# histograms, vs. number of bins
response = self.client.get('/api/public_overview')
response_obj = response.json()
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertIsInstance(response_obj, dict)
self.assertEqual(
# 1 more bin than intervals expected: e.g. for config.bins = [2, 3, 4],
# we expect data entries for ≤2, [2 3), [3 4), ≥4
len(response_obj["fields"]["lab_test_result_value"]["config"]["bins"]) + 1,
len(response_obj["fields"]["lab_test_result_value"]["data"]),
)

@override_settings(CONFIG_PUBLIC={})
def test_overview_no_config(self):
response = self.client.get('/api/public_overview')
Expand Down

0 comments on commit 1b1f15b

Please sign in to comment.