Skip to content

Commit

Permalink
@leplatrem comments
Browse files Browse the repository at this point in the history
  • Loading branch information
gabisurita committed May 22, 2017
1 parent 704fa97 commit d3a3b31
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 16 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This document describes changes between each past release.
8.1.0 (unreleased)
==================

- Allow reading from batch contexts using the ``parse_results`` method. (#146)
- Allow reading responses from batch requests with the ``results()`` method. (#146)


8.0.1 (2017-05-16)
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ It is possible to do batch requests using a Python context manager (``with``):
for idx in range(0, 100):
batch.update_record(data={'id': idx})
Reading data from batch operations is achived by using the ``parse_results`` method
Reading data from batch operations is achived by using the ``results()`` method
available ater a batch context is closed.

.. code-block:: python
Expand Down
3 changes: 1 addition & 2 deletions kinto_http/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,8 @@ def batch(self, **kwargs):
batch_max_requests=batch_max_requests)
batch_client = self.clone(session=batch_session, **kwargs)

# set a reference for parsing results from the context
# set a reference for reading results from the context
batch_client.results = batch_session.results
batch_client.parse_results = batch_session.parse_results

yield batch_client
batch_session.send()
Expand Down
12 changes: 6 additions & 6 deletions kinto_http/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def __init__(self, client, batch_max_requests=0):
self.endpoints = client.endpoints
self.batch_max_requests = batch_max_requests
self.requests = []
self.results = []
self._results = []

def request(self, method, endpoint, data=None, permissions=None,
headers=None):
Expand Down Expand Up @@ -58,15 +58,15 @@ def send(self):
exception.request = chunk[i]
exception.response = response
raise exception
self.results.append((resp, headers))
return self.results
self._results.append((resp, headers))
return self._results

def parse_results(self):
# Get each batch block response
block_responses = [resp for resp, _ in self.results]
chunks = [resp for resp, _ in self._results]

responses = []
for block in block_responses:
responses += block['responses']
for chunk in chunks:
responses += chunk['responses']

return [resp['body'] for resp in responses]
6 changes: 0 additions & 6 deletions kinto_http/tests/test_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,6 @@ def test_batch_raises_exception_as_soon_as_subrequest_fails(self):
batch.send()
assert self.client.session.request.call_count == 1

def test_results_attribute_is_available(self):
batch = BatchSession(self.client)
batch.request('GET', '/v1/foobar')
batch.send()
assert len(batch.results) == 1

def test_parse_results_retrieves_response_data(self):
batch_response = {
"body": {"data": {"id": "hey"}},
Expand Down

0 comments on commit d3a3b31

Please sign in to comment.