Exemplo n.º 1
0
    def test_parse_result(self):
        agg = query.UsersAggregation()
        elasticsearch_result = {
            'buckets': [
                {
                    'key': 'alice',
                    'doc_count': 42
                },
                {
                    'key': 'luke',
                    'doc_count': 28
                },
            ]
        }

        assert agg.parse_result(elasticsearch_result) == [
            {
                'user': '******',
                'count': 42
            },
            {
                'user': '******',
                'count': 28
            },
        ]
Exemplo n.º 2
0
    def test_it_limits_number_of_annotation_counts_by_user_returned(
        self, Annotation, search
    ):
        bucket_limit = 2

        Annotation(userid="acct:[email protected]")
        for i in range(3):
            Annotation(userid="acct:[email protected]")
        for i in range(2):
            Annotation(userid="acct:[email protected]")

        search.append_aggregation(query.UsersAggregation(limit=bucket_limit))
        result = search.run(webob.multidict.MultiDict({}))

        users_results = result.aggregations["users"]
        count_pb = next(r for r in users_results if r["user"] == "acct:[email protected]")[
            "count"
        ]
        count_pc = next(r for r in users_results if r["user"] == "acct:[email protected]")[
            "count"
        ]

        assert len(users_results) == bucket_limit
        assert count_pb == 3
        assert count_pc == 2
Exemplo n.º 3
0
    def test_it_returns_annotation_counts_by_user(self, Annotation, search):
        for i in range(2):
            Annotation(userid="acct:[email protected]")
        Annotation(userid="acct:[email protected]")

        search.append_aggregation(query.UsersAggregation())
        result = search.run({})

        users_results = result.aggregations["users"]
        count_pa = next(r for r in users_results if r["user"] == "acct:[email protected]")["count"]
        count_pb = next(r for r in users_results if r["user"] == "acct:[email protected]")["count"]

        assert len(users_results) == 2
        assert count_pa == 2
        assert count_pb == 1
Exemplo n.º 4
0
 def test_it_allows_to_set_a_limit(self):
     agg = query.UsersAggregation(limit=14)
     assert agg({}) == {
         'terms': {'field': 'user_raw', 'size': 14}
     }
Exemplo n.º 5
0
 def test_elasticsearch_aggregation(self):
     agg = query.UsersAggregation()
     assert agg({}) == {
         'terms': {'field': 'user_raw', 'size': 10}
     }
Exemplo n.º 6
0
 def test_key_is_users(self):
     assert query.UsersAggregation().key == 'users'
Exemplo n.º 7
0
 def test_parse_result_with_empty(self):
     agg = query.UsersAggregation()
     assert agg.parse_result({}) == {}
Exemplo n.º 8
0
 def test_parse_result_with_none(self):
     agg = query.UsersAggregation()
     assert agg.parse_result(None) == {}
Exemplo n.º 9
0
 def search(self, search):
     search.append_aggregation(query.UsersAggregation())
     return search