Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit 19b14ab

Browse filesBrowse files
authored
Support boolean type for key, endkey, and startkey in view requests (#504)
1 parent f0c0883 commit 19b14ab
Copy full SHA for 19b14ab

File tree

Expand file treeCollapse file tree

3 files changed

+22
-8
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+22
-8
lines changed

‎CHANGES.md

Copy file name to clipboardExpand all lines: CHANGES.md
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- [FIXED] Incorrect use of username as account name in `Cloudant.bluemix()`.
77
- [IMPROVED] Documented use of None account name and url override for `Cloudant.iam()`.
88
- [FIXED] Use custom encoder (if provided) for all view `key` params not just `keys`.
9+
- [FIXED] Support boolean type for `key`, `endkey`, and `startkey` in view requests.
910

1011
# 2.14.0 (2020-08-17)
1112

‎src/cloudant/_common_util.py

Copy file name to clipboardExpand all lines: src/cloudant/_common_util.py
+6-5Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,20 @@
5656

5757
RESULT_ARG_TYPES = {
5858
'descending': (bool,),
59-
'endkey': (int, LONGTYPE, STRTYPE, Sequence,),
59+
'endkey': (int, LONGTYPE, STRTYPE, Sequence, bool,),
6060
'endkey_docid': (STRTYPE,),
6161
'group': (bool,),
6262
'group_level': (int, LONGTYPE, NONETYPE,),
6363
'include_docs': (bool,),
6464
'inclusive_end': (bool,),
65-
'key': (int, LONGTYPE, STRTYPE, Sequence,),
65+
'key': (int, LONGTYPE, STRTYPE, Sequence, bool,),
6666
'keys': (list,),
6767
'limit': (int, LONGTYPE, NONETYPE,),
6868
'reduce': (bool,),
6969
'skip': (int, LONGTYPE, NONETYPE,),
7070
'stable': (bool,),
7171
'stale': (STRTYPE,),
72-
'startkey': (int, LONGTYPE, STRTYPE, Sequence,),
72+
'startkey': (int, LONGTYPE, STRTYPE, Sequence, bool,),
7373
'startkey_docid': (STRTYPE,),
7474
'update': (STRTYPE,),
7575
}
@@ -191,12 +191,13 @@ def py_to_couch_validate(key, val):
191191
# Validate argument values and ensure that a boolean is not passed in
192192
# if an integer is expected
193193
if (not isinstance(val, RESULT_ARG_TYPES[key]) or
194-
(type(val) is bool and int in RESULT_ARG_TYPES[key])):
194+
(type(val) is bool and bool not in RESULT_ARG_TYPES[key] and
195+
int in RESULT_ARG_TYPES[key])):
195196
raise CloudantArgumentError(117, key, RESULT_ARG_TYPES[key])
196197
if key == 'keys':
197198
for key_list_val in val:
198199
if (not isinstance(key_list_val, RESULT_ARG_TYPES['key']) or
199-
type(key_list_val) is bool):
200+
isinstance(key_list_val, bool)):
200201
raise CloudantArgumentError(134, RESULT_ARG_TYPES['key'])
201202
if key == 'stale':
202203
if val not in ('ok', 'update_after'):

‎tests/unit/param_translation_tests.py

Copy file name to clipboardExpand all lines: tests/unit/param_translation_tests.py
+15-3Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ def test_valid_endkey(self):
5555
python_to_couch({'endkey': ['foo', 10]}),
5656
{'endkey': '["foo", 10]'}
5757
)
58+
self.assertEqual(
59+
python_to_couch({'endkey': True}),
60+
{'endkey': 'true'}
61+
)
5862

5963
def test_valid_endkey_docid(self):
6064
"""
@@ -128,6 +132,10 @@ def test_valid_key(self):
128132
python_to_couch({'key': ['foo', 10]}),
129133
{'key': '["foo", 10]'}
130134
)
135+
self.assertEqual(
136+
python_to_couch({'key': True}),
137+
{'key': 'true'}
138+
)
131139

132140
def test_valid_keys(self):
133141
"""
@@ -205,6 +213,10 @@ def test_valid_startkey(self):
205213
python_to_couch({'startkey': ['foo', 10]}),
206214
{'startkey': '["foo", 10]'}
207215
)
216+
self.assertEqual(
217+
python_to_couch({'startkey': True}),
218+
{'startkey': 'true'}
219+
)
208220

209221
def test_valid_startkey_docid(self):
210222
"""
@@ -247,7 +259,7 @@ def test_invalid_endkey(self):
247259
"""
248260
msg = 'Argument endkey not instance of expected type:'
249261
with self.assertRaises(CloudantArgumentError) as cm:
250-
python_to_couch({'endkey': True})
262+
python_to_couch({'endkey': {'foo': 'bar'}})
251263
self.assertTrue(str(cm.exception).startswith(msg))
252264

253265
def test_invalid_endkey_docid(self):
@@ -302,7 +314,7 @@ def test_invalid_key(self):
302314
"""
303315
msg = 'Argument key not instance of expected type:'
304316
with self.assertRaises(CloudantArgumentError) as cm:
305-
python_to_couch({'key': True})
317+
python_to_couch({'key': {'foo': 'bar'}})
306318
self.assertTrue(str(cm.exception).startswith(msg))
307319

308320
def test_invalid_keys_not_list(self):
@@ -372,7 +384,7 @@ def test_invalid_startkey(self):
372384
"""
373385
msg = 'Argument startkey not instance of expected type:'
374386
with self.assertRaises(CloudantArgumentError) as cm:
375-
python_to_couch({'startkey': True})
387+
python_to_couch({'startkey': {'foo': 'bar'}})
376388
self.assertTrue(str(cm.exception).startswith(msg))
377389

378390
def test_invalid_startkey_docid(self):

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.