Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit fe5d2a1

Browse files
authored
Merge pull request #321 from cloudant/233-add-result-all-convenience-method
Add ``Result.all()`` convenience method
2 parents 73cb8b1 + 3242823 commit fe5d2a1

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

CHANGES.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Unreleased
22
==========
3+
- [NEW] Added ``Result.all()`` convenience method.
34
- [IMPROVED] Updated ``posixpath.join`` references to use ``'/'.join`` when concatenating URL parts.
45

56
2.6.0 (2017-08-10)

src/cloudant/result.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,18 @@ def _parse_data(self, data):
359359
"""
360360
return data.get('rows', [])
361361

362+
def all(self):
363+
"""
364+
Retrieve all results.
365+
366+
Specifying a ``limit`` parameter in the ``Result`` constructor will
367+
limit the number of documents returned. Be aware that the ``page_size``
368+
parameter is not honoured.
369+
370+
:return: results data as list in JSON format.
371+
"""
372+
return self[:]
373+
362374
class QueryResult(Result):
363375
"""
364376
Provides a index key accessible, sliceable and iterable interface to query

tests/unit/result_tests.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,16 @@ def test_get_item_slice_no_start_no_stop(self):
248248
{'key': 'julia002', 'id': 'julia002', 'value': 1}]
249249
self.assertEqual(result[:], expected)
250250

251+
def test_get_all_items(self):
252+
"""
253+
Test that all results can be retrieved.
254+
"""
255+
result = Result(self.view001, limit=3)
256+
expected = [{'key': 'julia000', 'id': 'julia000', 'value': 1},
257+
{'key': 'julia001', 'id': 'julia001', 'value': 1},
258+
{'key': 'julia002', 'id': 'julia002', 'value': 1}]
259+
self.assertEqual(result.all(), expected)
260+
251261
def test_get_item_invalid_index_slice(self):
252262
"""
253263
Test that when invalid start and stop values are provided in a slice

0 commit comments

Comments
 (0)