From 3eefe276d3fafd91c6a86977c501086d6eff26dd Mon Sep 17 00:00:00 2001 From: Hannes Schmidt Date: Thu, 12 Sep 2024 19:33:00 -0700 Subject: [PATCH] [3/3] [r a] Support for HCA data_use_restriction (#6131) Refactor test --- test/service/test_response.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/test/service/test_response.py b/test/service/test_response.py index fcd6131d0..4fe0c20c0 100644 --- a/test/service/test_response.py +++ b/test/service/test_response.py @@ -3510,24 +3510,26 @@ def test_projects_response(self): self.assertEqual({None: 2, 'Lung': 1, 'Retina': 1, 'Blood': 1}, terms) def test_data_use_restriction(self): + field, value = 'dataUseRestriction', 'NRES' params = { 'catalog': self.catalog, - 'sort': 'dataUseRestriction', - 'filters': json.dumps({'dataUseRestriction': {'is': ['NRES']}}) + 'sort': field, + 'filters': json.dumps({field: {'is': [value]}}) } - for entity_type in ('bundles', 'files', 'projects', 'samples'): + plugin = self.index_service.metadata_plugin(self.catalog) + for entity_type in plugin.exposed_indices: url = self.base_url.set(path=('index', entity_type), args=params) response = requests.get(url) response.raise_for_status() response = response.json() facets = response['termFacets'] - terms = {term['term'] for term in facets['dataUseRestriction']['terms']} - self.assertEqual({None, 'NRES'}, terms) + terms = {term['term'] for term in facets[field]['terms']} + self.assertEqual({None, value}, terms) hits = response['hits'] self.assertGreater(len(hits), 0) + expected = value if entity_type == 'projects' else [value] for hit in hits: - expected = 'NRES' if entity_type == 'projects' else ['NRES'] - self.assertEqual(expected, one(hit['projects'])['dataUseRestriction']) + self.assertEqual(expected, one(hit['projects'])[field]) class TestUnpopulatedIndexResponse(IndexResponseTestCase):