Skip to content

Commit 609bc70

Browse files
check non-boolean value
1 parent 357b7bd commit 609bc70

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

rejson/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def __init__(self, encoder=None, decoder=None, *args, **kwargs):
5757
'JSON.SET': lambda r: r and nativestr(r) == 'OK',
5858
'JSON.NUMINCRBY': self._decode,
5959
'JSON.NUMMULTBY': self._decode,
60-
'JSON.TOGGLE': bool,
60+
'JSON.TOGGLE': lambda b: b == 'true',
6161
'JSON.STRAPPEND': long,
6262
'JSON.STRLEN': long,
6363
'JSON.ARRAPPEND': long,
@@ -71,7 +71,7 @@ def __init__(self, encoder=None, decoder=None, *args, **kwargs):
7171
}
7272
for k, v in six.iteritems(MODULE_CALLBACKS):
7373
self.set_response_callback(k, v)
74-
74+
7575
def setEncoder(self, encoder):
7676
"""
7777
Sets the client's encoder

tests/test_rejson.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import pytest
2+
import redis
13
import six
24
import json
35
import unittest
@@ -36,7 +38,7 @@ def testJSONSetGetDelNonAsciiShouldSucceed(self):
3638
def testJSONSetExistentialModifiersShouldSucceed(self):
3739
"Test JSONSet's NX/XX flags"
3840

39-
obj = { 'foo': 'bar' }
41+
obj = {'foo': 'bar'}
4042
self.assertTrue(rj.jsonset('obj', Path.rootPath(), obj))
4143

4244
# Test that flags prevent updates when conditions are unmet
@@ -93,8 +95,12 @@ def testToggleShouldSucceed(self):
9395
"Test JSONToggle"
9496

9597
rj.jsonset('bool', Path.rootPath(), False)
96-
self.assertTrue(rj.jsontoggle('bool', Path.rootPath()))
98+
self.assertTrue(rj.jsontoggle('bool', Path.rootPath()))
9799
self.assertFalse(rj.jsontoggle('bool', Path.rootPath()))
100+
# check non-boolean value
101+
rj.jsonset('num', Path.rootPath(), 1)
102+
with pytest.raises(redis.exceptions.ResponseError):
103+
rj.jsontoggle('num', Path.rootPath())
98104

99105
def testStrAppendShouldSucceed(self):
100106
"Test JSONStrAppend"

0 commit comments

Comments
 (0)