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

        assert agg.parse_result(elasticsearch_result) == [
            {
                'tag': 'tag-4',
                'count': 42
            },
            {
                'tag': 'tag-2',
                'count': 28
            },
        ]
Esempio n. 2
0
    def test_it_returns_annotation_counts_by_tag(self, Annotation, search):
        for i in range(2):
            Annotation(tags=["tag_a"])
        Annotation(tags=["tag_b"])

        search.append_aggregation(query.TagsAggregation())
        result = search.run(webob.multidict.MultiDict({}))

        tag_results = result.aggregations["tags"]
        count_for_tag_a = next(r for r in tag_results if r["tag"] == "tag_a")["count"]
        count_for_tag_b = next(r for r in tag_results if r["tag"] == "tag_b")["count"]

        assert len(tag_results) == 2
        assert count_for_tag_a == 2
        assert count_for_tag_b == 1
Esempio n. 3
0
    def test_it_limits_number_of_annotation_counts_by_tag_returned(self, Annotation, search):
        bucket_limit = 2

        Annotation(tags=["tag_a"])
        for i in range(3):
            Annotation(tags=["tag_b"])
        for i in range(2):
            Annotation(tags=["tag_c"])

        search.append_aggregation(query.TagsAggregation(bucket_limit))
        result = search.run({})

        tag_results = result.aggregations["tags"]
        count_for_tag_b = next(r for r in tag_results if r["tag"] == "tag_b")["count"]
        count_for_tag_c = next(r for r in tag_results if r["tag"] == "tag_c")["count"]

        assert len(tag_results) == bucket_limit
        assert count_for_tag_b == 3
        assert count_for_tag_c == 2
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': 10}
     }
Esempio n. 6
0
 def test_key_is_tags(self):
     assert query.TagsAggregation().key == 'tags'
Esempio n. 7
0
 def test_parse_result_with_empty(self):
     agg = query.TagsAggregation()
     assert agg.parse_result({}) == {}
Esempio n. 8
0
 def test_parse_result_with_none(self):
     agg = query.TagsAggregation()
     assert agg.parse_result(None) == {}
Esempio n. 9
0
 def search(self, search):
     search.append_aggregation(query.TagsAggregation())
     return search