Skip to content

Commit

Permalink
Fix a bug that caused batch requests with a body to fail.
Browse files Browse the repository at this point in the history
Fixes #55.
  • Loading branch information
jgorset committed Aug 6, 2012
1 parent d0cf02b commit a5c58ba
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 5 additions & 0 deletions facepy/graph_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ def batch(self, requests):
Yields a list of responses and/or exceptions.
"""

for request in requests:
if 'body' in request:
request['body'] = urlencode(request['body'])

responses = self.post(
batch = json.dumps(requests)
)
Expand Down
9 changes: 7 additions & 2 deletions tests/test_graph_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,8 @@ def test_batch():

requests = [
{ 'method': 'GET', 'relative_url': 'me/friends' },
{ 'method': 'GET', 'relative_url': 'me/photos' }
{ 'method': 'GET', 'relative_url': 'me/photos' },
{ 'method': 'POST', 'relative_url': 'me/feed', 'body': { 'message': 'Hi me.' } }
]

batch = graph.batch(
Expand All @@ -337,7 +338,11 @@ def test_batch():
mock_request.assert_called_with('POST', 'https://graph.facebook.com/',
files = {},
data = {
'batch': json.dumps(requests),
'batch': json.dumps([
{ 'method': 'GET', 'relative_url': 'me/friends' },
{ 'method': 'GET', 'relative_url': 'me/photos' },
{ 'method': 'POST', 'relative_url': 'me/feed', 'body': 'message=Hi+me.' }
]),
'access_token': '<access token>'
}
)
Expand Down

0 comments on commit a5c58ba

Please sign in to comment.