def parse_result(self): agg = query.UsersAggregation() elasticsearch_result = { 'buckets': [ { 'key': 'alice', 'doc_count': 42 }, { 'key': 'luke', 'doc_count': 28 }, ] } assert agg(elasticsearch_result) == [ { 'user': '******', 'count': 42 }, { 'user': '******', 'count': 28 }, ]
def test_parse_result_with_empty(self): agg = query.UsersAggregation() assert agg.parse_result({}) == {}
def test_parse_result_with_none(self): agg = query.UsersAggregation() assert agg.parse_result(None) == {}
def test_it_allows_to_set_a_limit(self): agg = query.UsersAggregation(limit=14) assert agg({}) == { 'terms': {'field': 'user_raw', 'size': 14} }
def test_elasticsearch_aggregation(self): agg = query.UsersAggregation() assert agg({}) == { 'terms': {'field': 'user_raw', 'size': 0} }
def test_key_is_users(self): assert query.UsersAggregation().key == 'users'