Пример #1
0
    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
            },
        ]
Пример #2
0
 def test_parse_result_with_empty(self):
     agg = query.UsersAggregation()
     assert agg.parse_result({}) == {}
Пример #3
0
 def test_parse_result_with_none(self):
     agg = query.UsersAggregation()
     assert agg.parse_result(None) == {}
Пример #4
0
 def test_it_allows_to_set_a_limit(self):
     agg = query.UsersAggregation(limit=14)
     assert agg({}) == {
         'terms': {'field': 'user_raw', 'size': 14}
     }
Пример #5
0
 def test_elasticsearch_aggregation(self):
     agg = query.UsersAggregation()
     assert agg({}) == {
         'terms': {'field': 'user_raw', 'size': 0}
     }
Пример #6
0
 def test_key_is_users(self):
     assert query.UsersAggregation().key == 'users'