Skip to content
This repository has been archived by the owner on Mar 24, 2021. It is now read-only.

Commit

Permalink
Conform response for grouping query to api design
Browse files Browse the repository at this point in the history
  • Loading branch information
Max Fliri authored and robyoung committed Mar 28, 2013
1 parent 86816c8 commit c6716ac
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
3 changes: 2 additions & 1 deletion backdrop/core/bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ def execute_weekly_group_query(self, key2, query):

def execute_grouped_query(self, group_by, query):
cursor = self.repository.group(group_by, query)
result = [{doc[group_by]: doc['_count']} for doc in cursor]
result = [{group_by: doc[group_by], '_count': doc['_count']} for doc
in cursor]
return result

def execute_period_query(self, query):
Expand Down
10 changes: 5 additions & 5 deletions features/read_api.feature
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,22 @@ Feature: the performance platform read api
when I go to "/foo?group_by=authority"
then I should get back a status of "200"
and the JSON should have "2" results
and the "1st" result should be "{"Westminster": 4}"
and the "2nd" result should be "{"Camden": 2}"
and the "1st" result should be "{"authority": "Westminster", "_count": 4}"
and the "2nd" result should be "{"authority": "Camden", "_count": 2}"

Scenario: extracting data for a representation
Given "licensing_2.json" is in "foo" bucket
when I go to "/foo?group_by=authority&filter_by=licence_name:Temporary%20events%20notice"
then I should get back a status of "200"
and the JSON should have "2" results
and the "1st" result should be "{"Westminster": 3}"
and the "1st" result should be "{"authority": "Westminster", "_count": 3}"

Given "licensing_2.json" is in "foo" bucket
when I go to "/foo?group_by=licence_name&filter_by=authority:Westminster"
then I should get back a status of "200"
and the JSON should have "2" results
and the "1st" result should be "{"Temporary events notice": 3}"
and the "2nd" result should be "{"Cat herding licence": 1}"
and the "1st" result should be "{"licence_name": "Temporary events notice", "_count": 3}"
and the "2nd" result should be "{"licence_name": "Cat herding licence", "_count": 1}"

Scenario: invalid request parameters
When I go to "/foo?start_at=not+a+date"
Expand Down
6 changes: 4 additions & 2 deletions tests/core/test_bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@ def test_group_by_query(self):
self.mock_repository.group.assert_called_once_with("name", {})

assert_that(query_result,
has_item(has_entries({'Max': equal_to(3)})))
has_item(has_entries({'name': equal_to('Max'),
'_count': equal_to(3)})))
assert_that(query_result,
has_item(has_entries({'Gareth': equal_to(2)})))
has_item(has_entries({'name': equal_to('Gareth'),
'_count': equal_to(2)})))

def test_query_with_start_at(self):
self.bucket.query(start_at = d(2013, 4, 1, 12, 0, 0))
Expand Down

0 comments on commit c6716ac

Please sign in to comment.