def test_aggregate(site): """Test simple aggregation functions""" agg = {"count": func.count()} results = list(site.view("second_ap", aggregate=agg)) eq_(len(results), 1) eq_(results[0]['count'], 2) agg = {"count": func.count(), "second_ap_name": ""} results = site.view("first_ap", aliases={"second_ap_name": "second_ap.name"}, aggregate=agg) counts = dict((result["second_ap_name"], result["count"]) for result in results) eq_({None: 1, 'second_ap AAA': 2, 'second_ap BBB': 2}, counts)
def test_view_aggregate(site): results = list(site.view("things", aggregate={'name': '', 'count': func.count()})) counts = dict((item['name'], item['count']) for item in results) eq_(counts, {'bar': 2, 'foo': 1}) results = list(site.view("things", aggregate={'max': func.max('id')})) eq_(results, [{'max': 3}]) results = list(site.view("things", aggregate={'min': func.min('id')})) eq_(results, [{'min': 1}]) results = list(site.view("things", aggregate={'sum': func.sum('id')})) eq_(results, [{'sum': 6}]) results = list(site.view("things", aggregate={'sum': func.sum('name')})) eq_(len(results), 1)
def test_filter_aggregate(site): query = q.aggregate({'name': '', 'count': func.count()})\ | q.filter(Condition('count', '>', 1)) results = list(site.view('things', query=query)) eq_(len(results), 1) eq_(results[0], {'name': 'bar', 'count': 2})