diff --git a/citadel/indico_citadel/util.py b/citadel/indico_citadel/util.py index 42460a5..92380b0 100644 --- a/citadel/indico_citadel/util.py +++ b/citadel/indico_citadel/util.py @@ -155,7 +155,6 @@ def format_aggregations(aggregations, filters): key: { 'label': str(filters[key]), 'buckets': [{ - **bucket, 'key': bucket['most_common']['buckets'][0]['key'] if 'most_common' in bucket else bucket['key'], 'count': bucket['doc_count'] } for bucket in value['buckets']] diff --git a/citadel/indico_citadel/util_test.py b/citadel/indico_citadel/util_test.py index 431123a..7cb3e9c 100644 --- a/citadel/indico_citadel/util_test.py +++ b/citadel/indico_citadel/util_test.py @@ -7,7 +7,7 @@ import pytest -from indico_citadel.util import format_query, remove_none_entries +from indico_citadel.util import _flatten, format_query, remove_none_entries @pytest.mark.parametrize(('query', 'expected'), [ @@ -39,3 +39,13 @@ def test_query_placeholders(query, expected): ]) def test_remove_none_entries(val, expected): assert remove_none_entries(val) == expected + + +@pytest.mark.parametrize(('val', 'expected'), [ + ({'person': {'name': {'buckets': []}, 'affiliation': {'buckets': []}}, 'other': {'other': {'buckets': []}}}, + {'person_name', 'person_affiliation', 'other_other'}), + ({'other': {'other': {'other': {'other': {'buckets': []}}}}}, + {'other_other_other_other'}) +]) +def test_flatten(val, expected): + assert {key for key, _ in _flatten(val)} == expected