diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 7d1a517..aa51657 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -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) diff --git a/README.rst b/README.rst index 9b241f8..7f62ade 100644 --- a/README.rst +++ b/README.rst @@ -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 diff --git a/kinto_http/__init__.py b/kinto_http/__init__.py index 5dae572..8938077 100644 --- a/kinto_http/__init__.py +++ b/kinto_http/__init__.py @@ -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() diff --git a/kinto_http/batch.py b/kinto_http/batch.py index 065cb80..0587bfd 100644 --- a/kinto_http/batch.py +++ b/kinto_http/batch.py @@ -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): @@ -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] diff --git a/kinto_http/tests/test_batch.py b/kinto_http/tests/test_batch.py index 30bb0d3..9b3a6a3 100644 --- a/kinto_http/tests/test_batch.py +++ b/kinto_http/tests/test_batch.py @@ -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"}},