summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChayim <chayim@users.noreply.github.com>2021-11-10 10:35:45 +0200
committerGitHub <noreply@github.com>2021-11-10 10:35:45 +0200
commit2d7ceb0b110212fe50b8fa296f99f32f9a622ea7 (patch)
tree21920fca67e6a17e01eedcb4cf22953bbc85602b
parentf5160f57fcfe48838cc2082cd3c1c2b86d3bd36c (diff)
downloadredis-py-2d7ceb0b110212fe50b8fa296f99f32f9a622ea7.tar.gz
Test to validate custom JSON decoders (#1681)
-rw-r--r--dev_requirements.txt1
-rw-r--r--tests/test_json.py17
2 files changed, 18 insertions, 0 deletions
diff --git a/dev_requirements.txt b/dev_requirements.txt
index 6ea5055..7f099cb 100644
--- a/dev_requirements.txt
+++ b/dev_requirements.txt
@@ -6,4 +6,5 @@ tox-docker==3.1.0
invoke==1.6.0
pytest-cov>=3.0.0
vulture>=2.3.0
+ujson>=4.2.0
wheel>=0.30.0
diff --git a/tests/test_json.py b/tests/test_json.py
index b3f38f7..abc5776 100644
--- a/tests/test_json.py
+++ b/tests/test_json.py
@@ -1003,6 +1003,7 @@ def test_debug_dollar(client):
assert client.json().debug("MEMORY", "non_existing_doc", "$..a") == []
+@pytest.mark.redismod
def test_resp_dollar(client):
data = {
@@ -1149,6 +1150,7 @@ def test_resp_dollar(client):
assert client.json().resp("non_existing_doc", "$..a") is None
+@pytest.mark.redismod
def test_arrindex_dollar(client):
client.json().set(
@@ -1397,3 +1399,18 @@ def test_decoders_and_unstring():
assert decode_list(b"45.55") == 45.55
assert decode_list("45.55") == 45.55
assert decode_list(['hello', b'world']) == ['hello', 'world']
+
+
+@pytest.mark.redismod
+def test_custom_decoder(client):
+ import ujson
+ import json
+
+ cj = client.json(encoder=ujson, decoder=ujson)
+ assert cj.set("foo", Path.rootPath(), "bar")
+ assert "bar" == cj.get("foo")
+ assert cj.get("baz") is None
+ assert 1 == cj.delete("foo")
+ assert client.exists("foo") == 0
+ assert not isinstance(cj.__encoder__, json.JSONEncoder)
+ assert not isinstance(cj.__decoder__, json.JSONDecoder)