Skip to content

Commit

Permalink
Merge pull request #60 from mdhaman/aggregations
Browse files Browse the repository at this point in the history
If req.args is not specified then aggregations is false
  • Loading branch information
petrjasek committed Apr 13, 2016
2 parents 2732d87 + 4eb8f87 commit bb5f50a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion eve_elastic/elastic.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,8 @@ def find(self, resource, req, sub_resource_lookup):
return self._parse_hits(hits, resource)

def should_aggregate(self, req):
return current_app.config.get('ELASTICSEARCH_AUTO_AGGREGATIONS') or req.args.get('aggregations')
return current_app.config.get('ELASTICSEARCH_AUTO_AGGREGATIONS') or \
(req.args and req.args.get('aggregations'))

def find_one(self, resource, req, **lookup):

Expand Down
7 changes: 7 additions & 0 deletions test/test_elastic.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,13 @@ def test_filters_with_aggregations(self):
self.assertIn({'key': 'test', 'doc_count': 1}, res['_aggregations']['type']['buckets'])
self.assertEqual(1, res['_aggregations']['type']['buckets'][0]['doc_count'],)

def test_filter_without_args(self):
with self.app.app_context():
self.app.data.insert('items', [{'uri': 'foo'}, {'uri': 'bar'}])
req = ParsedRequest()
self.assertEqual(2, self.app.data.find('items', req, None).count())
self.assertEqual(1, self.app.data.find('items', req, {'uri': 'foo'}).count())

def test_filters_with_filtered_query(self):
with self.app.app_context():
self.app.data.insert('items', [
Expand Down

0 comments on commit bb5f50a

Please sign in to comment.