diff --git a/chord_metadata_service/discovery/tests/constants.py b/chord_metadata_service/discovery/tests/constants.py index de236dccc..1595e04a5 100644 --- a/chord_metadata_service/discovery/tests/constants.py +++ b/chord_metadata_service/discovery/tests/constants.py @@ -23,7 +23,7 @@ "search": [ { "section_title": "First Section", - "fields": ["sex", "age", "tissues"] + "fields": ["sex", "age", "tissues", "extraction_protocol"] } ], "fields": { @@ -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, diff --git a/chord_metadata_service/patients/tests/test_api.py b/chord_metadata_service/patients/tests/test_api.py index 8c7c7e8ee..001e6862b 100644 --- a/chord_metadata_service/patients/tests/test_api.py +++ b/chord_metadata_service/patients/tests/test_api.py @@ -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 @@ -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) @@ -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) @@ -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')