Esempio n. 1
0
    def parse_result(self):
        agg = query.TagsAggregation()
        elasticsearch_result = {
            'buckets': [
                {
                    'key': 'tag-4',
                    'doc_count': 42
                },
                {
                    'key': 'tag-2',
                    'doc_count': 28
                },
            ]
        }

        assert agg(elasticsearch_result) == [
            {
                'tag': 'tag-4',
                'count': 42
            },
            {
                'tag': 'tag-2',
                'count': 28
            },
        ]
Esempio n. 2
0
 def test_parse_result_with_empty(self):
     agg = query.TagsAggregation()
     assert agg.parse_result({}) == {}
Esempio n. 3
0
 def test_parse_result_with_none(self):
     agg = query.TagsAggregation()
     assert agg.parse_result(None) == {}
Esempio n. 4
0
 def test_it_allows_to_set_a_limit(self):
     agg = query.TagsAggregation(limit=14)
     assert agg({}) == {
         'terms': {'field': 'tags_raw', 'size': 14}
     }
Esempio n. 5
0
 def test_elasticsearch_aggregation(self):
     agg = query.TagsAggregation()
     assert agg({}) == {
         'terms': {'field': 'tags_raw', 'size': 0}
     }
Esempio n. 6
0
 def test_key_is_tags(self):
     assert query.TagsAggregation().key == 'tags'