Skip to content

Commit 963904a

Browse files
committed
Fix patch methods in batch requests (fixes #171)
1 parent bdc4a21 commit 963904a

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

CHANGELOG.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ This document describes changes between each past release.
77
9.2.0 (unreleased)
88
==================
99

10-
- Nothing changed yet.
10+
**Bug fixes**
1111

12+
- Fix patch methods in batch requests (fixes #171)
1213

1314
9.1.0 (2018-02-05)
1415
==================

kinto_http/batch.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,17 @@ def __init__(self, client, batch_max_requests=0):
1919
self._results = []
2020

2121
def request(self, method, endpoint, data=None, permissions=None,
22-
headers=None):
22+
payload=None, headers=None):
2323
# Store all the requests in a dict, to be read later when .send()
2424
# is called.
25-
self.requests.append((method, endpoint, data, permissions, headers))
25+
payload = payload or {}
26+
if data is not None:
27+
payload['data'] = data
28+
if permissions is not None:
29+
payload['permissions'] = permissions
30+
31+
self.requests.append((method, endpoint, payload.get("data"),
32+
payload.get("permissions"), headers))
2633
# This is the signature of the session request.
2734
return defaultdict(dict), defaultdict(dict)
2835

kinto_http/tests/test_client.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def test_context_manager_works_as_expected(self):
2525
with self.client.batch(bucket='mozilla', collection='test') as batch:
2626
batch.create_record(id=1234, data={'foo': 'bar'})
2727
batch.create_record(id=5678, data={'bar': 'baz'})
28+
batch.patch_record(id=5678, data={'bar': 'biz'})
2829

2930
self.session.request.assert_called_with(
3031
method='POST',
@@ -37,7 +38,11 @@ def test_context_manager_works_as_expected(self):
3738
{'body': {'data': {'bar': 'baz'}},
3839
'path': '/buckets/mozilla/collections/test/records/5678',
3940
'method': 'PUT',
40-
'headers': {'If-None-Match': '*'}}]})
41+
'headers': {'If-None-Match': '*'}},
42+
{'body': {'data': {'bar': 'biz'}},
43+
'path': '/buckets/mozilla/collections/test/records/5678',
44+
'method': 'PATCH',
45+
'headers': {'Content-Type': 'application/json'}}]})
4146

4247
def test_batch_raises_exception(self):
4348
# Make the next call to sess.request raise a 403.

0 commit comments

Comments
 (0)