Citadel: Add test for aggregation flattening

This commit is contained in:
Pedro Lourenço 2021-05-18 12:17:34 +01:00
parent 76d4c0562a
commit 967e146344
2 changed files with 11 additions and 2 deletions

View File

@ -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']]

View File

@ -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