diff options
author | Chayim I. Kirshen <c@kirshen.com> | 2021-11-09 14:17:41 +0200 |
---|---|---|
committer | Chayim I. Kirshen <c@kirshen.com> | 2021-11-09 14:17:41 +0200 |
commit | e1ad33bf1de2b4c2bf64423098f10fe19d878e76 (patch) | |
tree | c5938ce3130f1de4d918133150e2b2d1b8ffd17b | |
parent | c19f120e069ab805d2a337beaed3de064e5875f7 (diff) | |
download | redis-py-e1ad33bf1de2b4c2bf64423098f10fe19d878e76.tar.gz |
Test to validate custom JSON decoders
-rw-r--r-- | dev_requirements.txt | 1 | ||||
-rw-r--r-- | tests/test_json.py | 16 |
2 files changed, 17 insertions, 0 deletions
diff --git a/dev_requirements.txt b/dev_requirements.txt index 0ca7727..e59a9ee 100644 --- a/dev_requirements.txt +++ b/dev_requirements.txt @@ -6,3 +6,4 @@ tox-docker==3.1.0 invoke==1.6.0 pytest-cov>=3.0.0 vulture>=2.3.0 +ujson>=4.2.0 diff --git a/tests/test_json.py b/tests/test_json.py index b3f38f7..319e6e1 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,17 @@ 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)
\ No newline at end of file |