Skip to content

Commit

Permalink
[3/3] [r a] Support for HCA data_use_restriction (#6131)
Browse files Browse the repository at this point in the history
Refactor test
  • Loading branch information
hannes-ucsc authored and dsotirho-ucsc committed Sep 16, 2024
1 parent ec7898a commit 3eefe27
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions test/service/test_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 3eefe27

Please sign in to comment.