Skip to content

Commit

Permalink
test: nested search counts
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlougheed committed Oct 29, 2024
1 parent ca32349 commit 91ce645
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
12 changes: 11 additions & 1 deletion chord_metadata_service/discovery/tests/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"search": [
{
"section_title": "First Section",
"fields": ["sex", "age", "tissues"]
"fields": ["sex", "age", "tissues", "extraction_protocol"]
}
],
"fields": {
Expand Down Expand Up @@ -87,6 +87,16 @@
"units": "mm"
}
},
"extraction_protocol": {
"mapping": "experiment/extraction_protocol",
"mapping_for_search_filter": "individual/biosamples/experiment/extraction_protocol",
"title": "Experiment Extraction Protocol",
"description": "experiment extraction protocol",
"datatype": "string",
"config": {
"enum": ["NGS"]
},
},
},
"rules": {
"count_threshold": 5,
Expand Down
24 changes: 21 additions & 3 deletions chord_metadata_service/patients/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
CONFIG_PUBLIC_TEST_SEARCH_SEX_ONLY
)
from chord_metadata_service.discovery.types import DiscoveryConfig
from chord_metadata_service.experiments import models as ex_m
from chord_metadata_service.experiments.tests import constants as ex_c
from chord_metadata_service.patients.models import Individual
from chord_metadata_service.phenopackets import models as ph_m
from chord_metadata_service.phenopackets.tests import constants as ph_c
Expand Down Expand Up @@ -380,13 +382,13 @@ def setUp(self):
project=self.project_2,
)

individuals = [
self.individuals = [
c.generate_valid_individual(date_of_consent_range=(2020, 2023))
for _ in range(self.num_individuals)
]

individual_objs = [Individual.objects.create(**individual) for individual in individuals]
ph_m.Biosample.objects.create(**ph_c.valid_biosample_1(Individual.objects.all()[0]))
individual_objs = [Individual.objects.create(**individual) for individual in self.individuals]
biosample = ph_m.Biosample.objects.create(**ph_c.valid_biosample_1(Individual.objects.all()[0]))

for idx, individual in enumerate(individual_objs, 1):
self.meta_data = ph_m.MetaData.objects.create(**ph_c.VALID_META_DATA_1)
Expand All @@ -396,6 +398,13 @@ def setUp(self):
meta_data=self.meta_data,
dataset=self.dataset,
)
if idx == 1:
self.phenopacket.biosamples.add(biosample)
self.phenopacket.save()

instrument = ex_m.Instrument.objects.create(**ex_c.valid_instrument())
ex_m.Experiment.objects.create(**ex_c.valid_experiment(biosample, instrument, self.dataset, 1))
ex_m.Experiment.objects.create(**ex_c.valid_experiment(biosample, instrument, self.dataset, 2))

random.seed(self.random_seed)

Expand Down Expand Up @@ -694,6 +703,15 @@ def test_public_filtering_mapping_for_search_filter(self):
response_obj = response.json()
self.assertEqual(1, response_obj["count"])

@override_settings(CONFIG_PUBLIC=CONFIG_PUBLIC_TEST_NO_THRESHOLD)
def test_public_filtering_two_experiments(self):
response = self.dt_authz_counts_get(f"/api/public?sex={self.individuals[0]['sex']}&extraction_protocol=NGS")
self.assertEqual(response.status_code, status.HTTP_200_OK)
response_obj = response.json()
self.assertEqual(response_obj["count"], 1)
self.assertEqual(response_obj["biosamples"]["count"], 1)
self.assertEqual(response_obj["experiments"]["count"], 2)

@override_settings(CONFIG_PUBLIC=DISCOVERY_CONFIG_TEST)
def test_public_overview_sex(self):
response = self.dt_authz_counts_get('/api/public_search_fields')
Expand Down

0 comments on commit 91ce645

Please sign in to comment.