Permalink
Browse files

Fix a bug that caused batch requests with a body to fail.

Fixes #55.
  • Loading branch information...
jgorset committed Aug 6, 2012
1 parent d0cf02b commit a5c58baeb633beac55c609de3cdf06fae636c0e9
Showing with 12 additions and 2 deletions.
  1. +5 −0 facepy/graph_api.py
  2. +7 −2 tests/test_graph_api.py
View
@@ -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)
)
View
@@ -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(
@@ -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>'
}
)

0 comments on commit a5c58ba

Please sign in to comment.